本文整理汇总了Java中org.apache.maven.shared.invoker.InvocationRequest.setJavaHome方法的典型用法代码示例。如果您正苦于以下问题:Java InvocationRequest.setJavaHome方法的具体用法?Java InvocationRequest.setJavaHome怎么用?Java InvocationRequest.setJavaHome使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.shared.invoker.InvocationRequest
的用法示例。
在下文中一共展示了InvocationRequest.setJavaHome方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeMaven
import org.apache.maven.shared.invoker.InvocationRequest; //导入方法依赖的package包/类
private void invokeMaven(File pomFile, String goal) throws CommandLineException, MavenInvocationException
{
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(pomFile);
request.setGoals(Collections.singletonList(goal));
request.setJavaHome(javaHome);
request.setShowErrors(true);
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(mavenHome);
InvocationResult result = invoker.execute(request);
// check status
CommandLineException executionException = result.getExecutionException();
if (executionException != null)
{
throw executionException;
}
assertEquals(0, result.getExitCode());
}
示例2: mavenJreVersion
import org.apache.maven.shared.invoker.InvocationRequest; //导入方法依赖的package包/类
private String mavenJreVersion() {
InvocationRequest versionRequest = new DefaultInvocationRequest();
if (System.getProperty("sahagin.maven.java.home") != null) {
versionRequest.setJavaHome(new File(System.getProperty("sahagin.maven.java.home")));
}
versionRequest.setGoals(Arrays.asList("-v"));
MavenInvokeResult versionResult = mavenInvoke(versionRequest, "version");
for (String stdOut : versionResult.stdOuts) {
String[] entries = stdOut.split(",");
for (String entry : entries) {
String[] keyValue = entry.split(":");
if (keyValue.length != 2) {
continue;
}
if (keyValue[0].trim().equals("Java version")) {
return keyValue[1].trim();
}
}
}
versionResult.printStdOutsAndErrs();
throw new RuntimeException(String.format("fails to get JRE verion"));
}
示例3: createInvocationRequest
import org.apache.maven.shared.invoker.InvocationRequest; //导入方法依赖的package包/类
public InvocationRequest createInvocationRequest()
{
InvocationRequest request = new DefaultInvocationRequest();
request.setAlsoMake( alsoMake );
request.setAlsoMakeDependents( alsoMakeDependents );
request.setDebug( debug );
request.setFailureBehavior( failureBehavior );
request.setGlobalChecksumPolicy( globalChecksumPolicy );
request.setGlobalSettingsFile( stringToFile( globalSettings ) );
request.setGoals( goals );
request.setInteractive( !batchMode );
request.setJavaHome( stringToFile( javaHome ) );
request.setLocalRepositoryDirectory( stringToFile( localRepository ) );
request.setMavenOpts( mavenOpts );
request.setOffline( offline );
request.setPomFile( stringToFile( pomFile ) );
request.setProfiles( profiles );
request.setProjects( projects );
request.setRecursive( !nonRecursive );
request.setResumeFrom( resumeFrom );
request.setShowErrors( showErrors );
request.setShowVersion( showVersion );
request.setThreads( threads );
request.setToolchainsFile( stringToFile( toolchains ) );
request.setUpdateSnapshots( updateSnapshots );
request.setUserSettingsFile( stringToFile( userSettings ) );
Properties properties = new Properties();
defines.forEach( ( key, value ) -> properties.put( key, value ) );
request.setProperties( properties );
return request;
}
示例4: runGoals
import org.apache.maven.shared.invoker.InvocationRequest; //导入方法依赖的package包/类
private int runGoals(String pathToRootOfProject, String... goals) {
InvocationRequest request = new DefaultInvocationRequest();
request.setGoals(Arrays.asList(goals));
request.setPomFile(new File(pathToRootOfProject + FILE_SEPARATOR + POM_FILE));
request.setJavaHome(new File(System.getProperty("java.home")));
Properties properties = new Properties();
properties.setProperty("enforcer.skip", "true");
properties.setProperty("checkstyle.skip", "true");
properties.setProperty("cobertura.skip", "true");
properties.setProperty("skipITs", "true");
properties.setProperty("rat.skip", "true");
properties.setProperty("license.skip", "true");
properties.setProperty("findbugs.skip", "true");
properties.setProperty("gpg.skip", "true");
request.setProperties(properties);
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File(this.mavenHome));
LOGGER.info(String.format("run maven %s", Arrays.stream(goals).collect(Collectors.joining(" "))));
if (Main.verbose) {
invoker.setOutputHandler(System.out::println);
invoker.setErrorHandler(System.err::println);
} else {
invoker.setOutputHandler(null);
invoker.setErrorHandler(null);
}
try {
return invoker.execute(request).getExitCode();
} catch (MavenInvocationException e) {
throw new RuntimeException(e);
}
}
示例5: generateTempJar
import org.apache.maven.shared.invoker.InvocationRequest; //导入方法依赖的package包/类
private void generateTempJar(String subDirName) {
// generate sahagin temp jar for test from the already generated class files
InvocationRequest jarGenRequest = new DefaultInvocationRequest();
if (System.getProperty("sahagin.maven.java.home") != null) {
jarGenRequest.setJavaHome(new File(System.getProperty("sahagin.maven.java.home")));
}
jarGenRequest.setProfiles(Arrays.asList("sahagin-temp-jar-gen"));
jarGenRequest.setGoals(Arrays.asList("jar:jar"));
MavenInvokeResult jarGenResult = mavenInvoke(jarGenRequest, subDirName + ":jarGen");
if (!jarGenResult.succeeded) {
jarGenResult.printStdOutsAndErrs();
fail("fail to generate jar");
}
}
示例6: invokeChildTest
import org.apache.maven.shared.invoker.InvocationRequest; //导入方法依赖的package包/类
private Pair<MavenInvokeResult, JavaConfig> invokeChildTest(
String subDirName, String additionalProfile) throws IOException {
// set up working directory
clearWorkDir(subDirName);
File workDir = mkWorkDir(subDirName).getAbsoluteFile();
JavaConfig conf = new JavaConfig(workDir);
conf.setTestDir(new File(workDir, "src/test/java"));
conf.setRunTestOnly(true);
YamlUtils.dump(conf.toYamlObject(), new File(workDir, "sahagin.yml"));
FileUtils.copyFile(new File("pom.xml"), new File(workDir, "pom.xml"));
FileUtils.copyDirectory(testResourceDir(subDirName + "/src"), new File(workDir, "src"));
FileUtils.copyDirectory(testResourceDir("expected/captures"), new File(workDir, "captures"));
// execute test
InvocationRequest testRequest = new DefaultInvocationRequest();
if (System.getProperty("sahagin.maven.java.home") != null) {
testRequest.setJavaHome(new File(System.getProperty("sahagin.maven.java.home")));
}
testRequest.setGoals(Arrays.asList("clean", "test"));
if (additionalProfile == null) {
testRequest.setProfiles(Arrays.asList("sahagin-jar-test"));
} else {
testRequest.setProfiles(Arrays.asList("sahagin-jar-test", additionalProfile));
}
String jarPathOpt = "-Dsahagin.temp.jar="
+ new File("target/sahagin-temp.jar").getAbsolutePath();
testRequest.setMavenOpts(jarPathOpt);
testRequest.setBaseDirectory(workDir);
MavenInvokeResult testResult = mavenInvoke(testRequest, subDirName + ":test");
return Pair.of(testResult, conf);
}
示例7: mungeMavenInvocationRequest
import org.apache.maven.shared.invoker.InvocationRequest; //导入方法依赖的package包/类
public InvocationRequest mungeMavenInvocationRequest(InvocationRequest request) {
return request.setJavaHome(javaHome);
}