本文整理匯總了Java中org.srcdeps.core.BuildException類的典型用法代碼示例。如果您正苦於以下問題:Java BuildException類的具體用法?Java BuildException怎麽用?Java BuildException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BuildException類屬於org.srcdeps.core包,在下文中一共展示了BuildException類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: openBuildDirectory
import org.srcdeps.core.BuildException; //導入依賴的package包/類
/**
* Goes sequentially over integers form {@code 0} to {@link #CONCURRENCY_THRESHOLD} until it finds such {@code i} of
* them which when appended to <code>"${rootDirectory}/${projectBuildHome}"</code>, makes up a new or existing
* directory <code>"${rootDirectory}/${projectBuildHome}/${i}"</code> that can be locked using {@link #pathLocker}.
* The {@link PathLock} returned contains a reference to the first
* <code>"${rootDirectory}/${projectBuildHome}/${i}"</code> that could be locked successfully.
* <p>
* The returned {@link PathLock} should be released using its {@link Closeable#close()} method.
*
* @param projectBuildHome
* the given project's build home (something like {@code Paths.get("org", "project", "component")})
* relative to {@link #rootDirectory} under which a subdirectory will be taken or created and
* subsequently locked via {@link PathLocker#tryLockDirectory(Path)}
* @param srcVersion
* @return a {@link PathLock} whose holder is guaranteed to have an exclusive access to {@link PathLock#getPath()}
* @throws BuildException
* when no such {@code i} between {@code 0} and {@link #CONCURRENCY_THRESHOLD} could be found that a
* directory <code>"${rootDirectory}/${projectBuildHome}/${i}"</code> could be locked.
* @throws IOException
*/
public PathLock openBuildDirectory(Path projectBuildHome, SrcVersion srcVersion) throws BuildException, IOException {
Path scmRepositoryDir = rootDirectory.resolve(projectBuildHome);
SrcdepsCoreUtils.ensureDirectoryExists(scmRepositoryDir);
Throwable lastException = null;
for (int i = 0; i < CONCURRENCY_THRESHOLD; i++) {
Path checkoutDirectoryPath = scmRepositoryDir.resolve(String.valueOf(i));
try {
return pathLocker.lockDirectory(checkoutDirectoryPath, srcVersion);
} catch (CannotAcquireLockException e) {
/* nevermind, another i will work */
lastException = e;
log.debug("Could not get PathLock for path {}", checkoutDirectoryPath);
}
}
throw new BuildException(String.format("Could not get PathLock for any of 0-%d subpaths of [%s]",
CONCURRENCY_THRESHOLD - 1, scmRepositoryDir), lastException);
}
示例2: execute
import org.srcdeps.core.BuildException; //導入依賴的package包/類
/**
* Executes the given {@link ShellCommand} synchronously.
*
* @param command
* the command to execute
* @return the {@link CommandResult} that can be used to determine if the execution was successful
* @throws BuildException
* on any build related problems
* @throws CommandTimeoutException
* if the execution is not finished within the timeout defined in {@link ShellCommand#getTimeoutMs()}
*/
public static CommandResult execute(ShellCommand command) throws BuildException, CommandTimeoutException {
final String[] cmdArray = command.asCmdArray();
String cmdArrayString = Arrays.toString(cmdArray);
final IoRedirects redirects = command.getIoRedirects();
final Map<String, String> env = command.getEnvironment();
log.info("About to execute command {} using redirects {} and env {}", cmdArrayString, redirects, env);
ProcessBuilder builder = new ProcessBuilder(cmdArray) //
.directory(command.getWorkingDirectory().toFile()) //
.redirectInput(redirects.getStdin()) //
.redirectOutput(redirects.getStdout()) //
;
if (redirects.isErr2Out()) {
builder.redirectErrorStream(redirects.isErr2Out());
} else {
builder.redirectError(redirects.getStderr());
}
if (!env.isEmpty()) {
builder.environment().putAll(env);
}
try (CommandProcess process = new CommandProcess(builder.start())) {
return process.waitFor(command.getTimeoutMs(), TimeUnit.MILLISECONDS, cmdArray).assertSuccess();
} catch (IOException | InterruptedException e) {
throw new BuildException(String.format("Could not start command [%s]", cmdArrayString), e);
}
}
示例3: build
import org.srcdeps.core.BuildException; //導入依賴的package包/類
@Override
public void build(BuildRequest request) throws BuildException {
/*
* restTimeoutMs == Long.MIN_VALUE means that the restTimeoutMs was not set by setVersions() and it will
* therefore be ignored
*/
long timeoutMs = restTimeoutMs == Long.MIN_VALUE ? request.getTimeoutMs() : restTimeoutMs;
List<String> args = mergeArguments(request);
ShellCommand command = ShellCommand.builder() //
.executable(locateExecutable(request)) //
.arguments(args) //
.workingDirectory(request.getProjectRootDirectory()) //
.environment(mergeEnvironment(request)) //
.ioRedirects(request.getIoRedirects()) //
.timeoutMs(timeoutMs) //
.build();
Shell.execute(command).assertSuccess();
}
示例4: setVersions
import org.srcdeps.core.BuildException; //導入依賴的package包/類
@Override
public void setVersions(BuildRequest request) throws BuildException {
final List<String> args = new ArrayList<>();
args.add("org.codehaus.mojo:versions-maven-plugin:" + request.getVersionsMavenPluginVersion() + ":set");
args.add("-DnewVersion=" + request.getSrcVersion().toString());
args.add("-DartifactId=*");
args.add("-DgroupId=*");
args.add("-DoldVersion=*");
args.add("-DgenerateBackupPoms=false");
args.addAll(getVerbosityArguments(request.getVerbosity()));
ShellCommand cliRequest = ShellCommand.builder() //
.executable(locateExecutable(request)).arguments(args) //
.workingDirectory(request.getProjectRootDirectory()) //
.environment(mergeEnvironment(request)) //
.ioRedirects(request.getIoRedirects()) //
.timeoutMs(request.getTimeoutMs()) //
.build();
CommandResult result = Shell.execute(cliRequest).assertSuccess();
this.restTimeoutMs = request.getTimeoutMs() - result.getRuntimeMs();
}
示例5: build
import org.srcdeps.core.BuildException; //導入依賴的package包/類
@Override
public void build(BuildRequest request) throws BuildException {
final Path dir = request.getProjectRootDirectory();
final String firstUrl = request.getScmUrls().iterator().next();
log.info("About to build request {}", request);
boolean checkedOut = false;
for (Scm scm : scms) {
if (scm.supports(firstUrl)) {
log.info("About to use Scm implementation {} to check out URL {} to directory {}",
scm.getClass().getName(), firstUrl, dir);
scm.checkout(request);
checkedOut = true;
break;
}
}
if (!checkedOut) {
throw new BuildException(String.format("No Scm found for URL [%s]", firstUrl));
}
boolean built = false;
for (Builder builder : builders) {
if (builder.canBuild(dir)) {
log.info("About to build project in {} using Builder {}", dir, builder.getClass().getName());
builder.setVersions(request);
builder.build(request);
built = true;
break;
}
}
if (!built) {
throw new BuildException(String.format("No Builder found for directory [%s]", dir));
}
}
示例6: buildIfNecessary
import org.srcdeps.core.BuildException; //導入依賴的package包/類
/**
* Builds the artifact given by the arguments if necessary and installs it to the Local Maven Repository.
*
* @param groupId
* @param artifactId
* @param version
*/
public void buildIfNecessary(String groupId, String artifactId, String version) {
final Configuration configuration = configurationService.getConfiguration();
if (configuration.isSkip()) {
log.info("srcdeps: Skipped");
}
Gavtc artifactGavtc = new Gavtc(groupId, artifactId, version, "jar"); // FIXME: "jar" should not be hard
// coded but Gradle does not seem to have
// a notion of type an classifier (does
// it?)
Path artfactPath = localRepository.resolve(artifactGavtc);
if (!Files.exists(artfactPath)) {
ScmRepository scmRepo = findScmRepo(configuration.getRepositories(), groupId, artifactId, version);
SrcVersion srcVersion = SrcVersion.parse(version);
try (PathLock projectBuildDir = buildDirectoriesManager.openBuildDirectory(scmRepo.getIdAsPath(),
srcVersion)) {
/* query the delegate again, because things may have changed since we requested the lock */
if (Files.exists(artfactPath)) {
log.debug("srcdeps: Found in the local repo and using it as is: {}", artfactPath);
return;
} else {
/* no change in the local repo, let's build */
BuilderIo builderIo = scmRepo.getBuilderIo();
IoRedirects ioRedirects = IoRedirects.builder() //
.stdin(IoRedirects.parseUri(builderIo.getStdin())) //
.stdout(IoRedirects.parseUri(builderIo.getStdout())) //
.stderr(IoRedirects.parseUri(builderIo.getStderr())) //
.build();
List<String> buildArgs = enhanceBuildArguments(scmRepo.getBuildArguments(),
configurationService.getConfigurationLocation(),
localRepository.getRootDirectory().toString());
BuildRequest buildRequest = BuildRequest.builder() //
.dependentProjectRootDirectory(configurationService.getMultimoduleProjectRootDirectory())
.projectRootDirectory(projectBuildDir.getPath()) //
.scmUrls(scmRepo.getUrls()) //
.srcVersion(srcVersion) //
.buildArguments(buildArgs) //
.timeoutMs(scmRepo.getBuildTimeout().toMilliseconds()) //
.skipTests(scmRepo.isSkipTests()) //
.forwardProperties(configuration.getForwardProperties()) //
.addDefaultBuildArguments(scmRepo.isAddDefaultBuildArguments()) //
.verbosity(scmRepo.getVerbosity()) //
.ioRedirects(ioRedirects) //
.versionsMavenPluginVersion(scmRepo.getMaven().getVersionsMavenPluginVersion())
.gradleModelTransformer(scmRepo.getGradle().getModelTransformer()).build();
buildService.build(buildRequest);
/* check once again if the delegate sees the newly built artifact */
if (!Files.exists(artfactPath)) {
log.error(
"srcdeps: Build succeeded but the artifact {}:{}:{} is still not available in the local repository",
groupId, artifactId, version);
}
}
} catch (BuildException | IOException e) {
log.error("srcdeps: Could not build {}:{}:{}" + groupId, artifactId, version, e);
}
}
}
示例7: setVersions
import org.srcdeps.core.BuildException; //導入依賴的package包/類
@Override
public void setVersions(BuildRequest request) throws BuildException {
Path buildGradle = request.getProjectRootDirectory().resolve("build.gradle");
try {
if (!Files.exists(buildGradle)) {
throw new BuildException(String.format("File not found [%s]", buildGradle));
}
final Path rootPath = request.getProjectRootDirectory();
final StringBuilder settingsAppendix = new StringBuilder("\n");
final char[] buf = new char[10240];
for (String innerClass : INNER_CLASSES) {
String srcdepsInnerSrc = SrcdepsCoreUtils.read( //
getClass().getResource("/gradle/settings/" + innerClass), //
buf //
);
srcdepsInnerSrc = PACKAGE_PATTERN.matcher(srcdepsInnerSrc).replaceFirst("");
settingsAppendix.append(srcdepsInnerSrc).append("\n");
}
settingsAppendix.append("def srcdepsInner = new SrcdepsInner()\n");
try (Reader r = request.getGradleModelTransformer().openReader(StandardCharsets.UTF_8,
request.getDependentProjectRootDirectory())) {
String src = SrcdepsCoreUtils.read(r, buf);
settingsAppendix.append(src).append("\n");
}
final Path settingsGradlePath = rootPath.resolve("settings.gradle");
if (Files.exists(settingsGradlePath)) {
Files.write(settingsGradlePath, settingsAppendix.toString().getBytes(StandardCharsets.UTF_8),
StandardOpenOption.APPEND);
} else {
Files.write(settingsGradlePath, settingsAppendix.toString().getBytes(StandardCharsets.UTF_8));
}
} catch (IOException e) {
throw new BuildException(String.format("Could not change the version in file [%s]", buildGradle), e);
}
}
示例8: find
import org.srcdeps.core.BuildException; //導入依賴的package包/類
/**
* In case the {@link #delegate} does not find the given artifact and the given artifact's version string is a
* srcdeps version string, then the version is built from source and returned.
*
* @see org.eclipse.aether.repository.LocalRepositoryManager#find(org.eclipse.aether.RepositorySystemSession,
* org.eclipse.aether.repository.LocalArtifactRequest)
*/
@Override
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
log.debug("Srcdeps looking up locally {}", request.getArtifact());
final LocalArtifactResult result = delegate.find(session, request);
Artifact artifact = request.getArtifact();
String version = artifact.getVersion();
if (!result.isAvailable() && SrcVersion.isSrcVersion(version)) {
final Configuration configuration = configurationProducer.getConfiguration();
if (!configuration.isSkip()) {
final ScmRepository scmRepo = findScmRepo(configuration.getRepositories(), artifact.getGroupId(), artifact.getArtifactId(),
version);
SrcVersion srcVersion = SrcVersion.parse(version);
try (PathLock projectBuildDir = buildDirectoriesManager.openBuildDirectory(scmRepo.getIdAsPath(),
srcVersion)) {
/* query the delegate again, because things may have changed since we requested the lock */
final LocalArtifactResult result2 = delegate.find(session, request);
if (result2.isAvailable()) {
return result2;
} else {
/* no change in the local repo, let's build */
BuilderIo builderIo = scmRepo.getBuilderIo();
IoRedirects ioRedirects = IoRedirects.builder() //
.stdin(IoRedirects.parseUri(builderIo.getStdin())) //
.stdout(IoRedirects.parseUri(builderIo.getStdout())) //
.stderr(IoRedirects.parseUri(builderIo.getStderr())) //
.build();
List<String> buildArgs = enhanceBuildArguments(scmRepo.getBuildArguments(),
configurationProducer.getConfigurationLocation(),
delegate.getRepository().getBasedir().getAbsolutePath());
BuildRequest buildRequest = BuildRequest.builder() //
.dependentProjectRootDirectory(configurationProducer.getMultimoduleProjectRootDirectory()) //
.projectRootDirectory(projectBuildDir.getPath()) //
.scmUrls(scmRepo.getUrls()) //
.srcVersion(srcVersion) //
.buildArguments(buildArgs) //
.timeoutMs(scmRepo.getBuildTimeout().toMilliseconds()) //
.skipTests(scmRepo.isSkipTests()) //
.forwardProperties(configuration.getForwardProperties()) //
.addDefaultBuildArguments(scmRepo.isAddDefaultBuildArguments()) //
.verbosity(scmRepo.getVerbosity()) //
.ioRedirects(ioRedirects) //
.versionsMavenPluginVersion(scmRepo.getMaven().getVersionsMavenPluginVersion())
.gradleModelTransformer(scmRepo.getGradle().getModelTransformer()).build();
buildService.build(buildRequest);
/* check once again if the delegate sees the newly built artifact */
final LocalArtifactResult newResult = delegate.find(session, request);
if (!newResult.isAvailable()) {
log.error(
"Srcdeps build succeeded but the artifact {} is still not available in the local repository",
artifact);
}
return newResult;
}
} catch (BuildException | IOException e) {
log.error("Srcdeps could not build " + request, e);
}
}
}
return result;
}