本文整理汇总了Java中org.apache.maven.shared.invoker.Invoker.setOutputHandler方法的典型用法代码示例。如果您正苦于以下问题:Java Invoker.setOutputHandler方法的具体用法?Java Invoker.setOutputHandler怎么用?Java Invoker.setOutputHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.shared.invoker.Invoker
的用法示例。
在下文中一共展示了Invoker.setOutputHandler方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runMaven
import org.apache.maven.shared.invoker.Invoker; //导入方法依赖的package包/类
public List<String> runMaven(final File workingDir, final String... arguments) throws IOException {
final InvocationRequest request = createRequest();
request.setGoals(asList(arguments));
request.setBaseDirectory(workingDir);
final Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(mvnHome);
final CollectingLogOutputStream logOutput = new CollectingLogOutputStream(false);
invoker.setOutputHandler(new PrintStreamHandler(new PrintStream(logOutput), true));
int exitCode;
try {
final InvocationResult result = invoker.execute(request);
exitCode = result.getExitCode();
} catch (final Exception e) {
throw new MavenExecutionException(1, logOutput.getLines());
}
final List<String> output = logOutput.getLines();
if (exitCode != 0) {
throw new MavenExecutionException(exitCode, output);
}
return output;
}
示例2: invoke
import org.apache.maven.shared.invoker.Invoker; //导入方法依赖的package包/类
private InvocationResult invoke(final InvocationRequest request, final String path) {
InvocationResult result = null;
final Invoker invoker = new DefaultInvoker();
try {
invoker.setLogger(new PrintStreamLogger(
new PrintStream(InstallLog.getInstance().getFileAbsolutePath()), 1000));
invoker.setOutputHandler(new PrintStreamHandler(
new PrintStream(InstallLog.getInstance().getFileAbsolutePath()), true));
invoker.setWorkingDirectory(new File(path));
result = invoker.execute(request);
} catch (MavenInvocationException | FileNotFoundException ex) {
final String messageError = "Maven exception: " + ex.getMessage();
handler.emitError(messageError, messageError);
InstallLog.getInstance().info(messageError);
}
return result;
}
示例3: getClassPath
import org.apache.maven.shared.invoker.Invoker; //导入方法依赖的package包/类
public static String getClassPath(File projectDir) {
InvocationRequest request = new DefaultInvocationRequest();
request.setBaseDirectory(projectDir);
request.setGoals(Collections.singletonList("dependency:build-classpath"));
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(mavenHome);
ClassPathListener cpl = new ClassPathListener();
invoker.setOutputHandler(cpl);
try {
invoker.execute(request);
} catch (MavenInvocationException e) {
e.printStackTrace();
}
return cpl.classPath;
}
示例4: setupInvokerLogger
import org.apache.maven.shared.invoker.Invoker; //导入方法依赖的package包/类
private void setupInvokerLogger(Invoker invoker) {
final Log log = getLog();
invoker.setOutputHandler(new InvocationOutputHandler() {
@Override
public void consumeLine(String myString) {
log.info(myString);
}
});
}
示例5: runGoals
import org.apache.maven.shared.invoker.Invoker; //导入方法依赖的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);
}
}
示例6: assertArtifactInLocalRepo
import org.apache.maven.shared.invoker.Invoker; //导入方法依赖的package包/类
public void assertArtifactInLocalRepo(final String groupId, final String artifactId, final String version)
throws IOException, MavenInvocationException {
final String artifact = groupId + ":" + artifactId + ":" + version + ":pom";
final InvocationRequest request = createRequest();
request.setGoals(Collections.singletonList("org.apache.maven.plugins:maven-dependency-plugin:2.10:get"));
final Properties props = new Properties();
props.setProperty("artifact", artifact);
request.setProperties(props);
final Invoker invoker = new DefaultInvoker();
final CollectingLogOutputStream logOutput = new CollectingLogOutputStream(false);
invoker.setOutputHandler(new PrintStreamHandler(new PrintStream(logOutput), true));
final InvocationResult result = invoker.execute(request);
if (result.getExitCode() != 0) {
System.out.println();
System.out.println(
"There was a problem checking for the existence of the artifact. Here is the output of the mvn command:");
System.out.println();
for (final String line : logOutput.getLines()) {
System.out.println(line);
}
}
assertThat(format("Could not find artifact %s:%s in repository", artifact, "pom"), result.getExitCode(), is(0));
}
示例7: getInvoker
import org.apache.maven.shared.invoker.Invoker; //导入方法依赖的package包/类
private Invoker getInvoker(MvnLoggerWidget progress) {
Invoker invoker = new DefaultInvoker();
String mvn = findMvn();
System.setProperty("maven.home", mvn);
invoker.setLogger(new MavenJarResolverSilentLogger());
invoker.setOutputHandler(new MavenInvocationSilentOutputHandler(progress));
invoker.setLocalRepositoryDirectory(getOrCreateFile(this.commandParams.getPathToCache()));
return invoker;
}
示例8: executeMavenRequest
import org.apache.maven.shared.invoker.Invoker; //导入方法依赖的package包/类
/**
* Runs Maven in order to execute the {@link #mavenRequest} which has been
* configured
*
* @param context
* the command context for writing in the console
*/
private void executeMavenRequest(final CommandContext context) {
final Invoker invoker = new DefaultInvoker();
try {
invoker.setOutputHandler(new ContextOutputHandler(context));
invoker.execute(mavenRequest);
} catch (final MavenInvocationException e) {
context.write(MAVEN_EXEC_ERROR.value(e.getMessage()));
Activator.sendErrorToErrorLog(
MAVEN_EXEC_ERROR.value(e.getMessage()), e);
return;
}
}