本文整理汇总了Java中org.apache.maven.shared.invoker.InvocationOutputHandler类的典型用法代码示例。如果您正苦于以下问题:Java InvocationOutputHandler类的具体用法?Java InvocationOutputHandler怎么用?Java InvocationOutputHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvocationOutputHandler类属于org.apache.maven.shared.invoker包,在下文中一共展示了InvocationOutputHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeMavenBuild
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
private void executeMavenBuild(List<String> goals, InvocationOutputHandler outputHandler) {
log.debug("Invoking maven with goals {}", goals);
InvocationRequest request = new DefaultInvocationRequest();
request.setBatchMode(true);
request.setGoals(goals);
// reset MAVEN_DEBUG_OPTS to allow debugging without blocking the invoker calls
request.addShellEnvironment("MAVEN_DEBUG_OPTS", "");
InvocationOutputHandler outHandler = outputHandler;
if (outHandler == null) {
outHandler = log::debug;
}
request.setOutputHandler(outHandler);
try {
InvocationResult result = maven.execute(request);
if (result.getExitCode() != 0) {
throw new MavenInvocationException("Maven process exited with non-zero code [" + result.getExitCode() + "]. "
+ "Retry with debug log level enabled to see the maven invocation logs");
}
}
catch (MavenInvocationException e) {
throw new CarnotzetDefinitionException("Error invoking mvn " + goals, e);
}
}
示例2: runJar
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
private ExecuteWatchdog runJar(InvocationOutputHandler buildLogHandler, InvocationOutputHandler consoleLogHandler, Map<String, String> envVarsForApp, Waiter startupWaiter) {
Path libsPath = Paths.get(projectRoot.getPath(), "build", "libs");
File libsFolder = libsPath.toFile();
// To simplify implementation, now I assume only 1 uberjar named "artifact-version-all.jar" under libs folder
// As we clean the project every time, I can't foresee any possibility that will mix up other uberjars.
File[] files = libsFolder.listFiles();
if(files == null) {
throw new ProjectCannotStartException(libsFolder.getPath() + " doesn't exist");
}
Optional<File> jar = Stream.of(files).filter((f) -> f.getName().contains("all")).findFirst();
if (!jar.isPresent() || !jar.get().isFile()) {
throw new ProjectCannotStartException("Could not find the jar file at " + jar.get().getPath());
}
CommandLine command = javaHomeProvider.commandLine(envVarsForApp)
.addArgument("-Djava.io.tmpdir=" + envVarsForApp.get("TEMP"))
.addArgument("-jar")
.addArgument(fullPath(jar.get()));
return ProcessStarter.startDaemon(buildLogHandler, consoleLogHandler, envVarsForApp, command, projectRoot, startupWaiter);
}
示例3: setupInvokerLogger
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
private void setupInvokerLogger(Invoker invoker) {
final Log log = getLog();
invoker.setOutputHandler(new InvocationOutputHandler() {
@Override
public void consumeLine(String myString) {
log.info(myString);
}
});
}
示例4: update
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
public void update(String name, InvocationOutputHandler outputHandler) throws Exception {
for (AppDescription manager : managers) {
if (manager.name().equalsIgnoreCase(name)) {
manager.update(runnerProvider, outputHandler);
return;
}
}
throw new AppNotFoundException("No app found with name '" + name + "'. Valid names: " + allAppNames());
}
示例5: runLein
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
private void runLein(InvocationOutputHandler buildLogHandler, Map<String, String> envVarsForApp, String... arguments) {
CommandLine command = leinCmd.commandLine(envVarsForApp);
for (String argument : arguments)
command.addArgument(argument);
buildLogHandler.consumeLine("Running lein " + StringUtils.join(arguments, " ") + " with " + command);
ProcessStarter.run(buildLogHandler, envVarsForApp, command, projectRoot, TimeUnit.MINUTES.toMillis(20));
}
示例6: start
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
public void start(InvocationOutputHandler buildLogHandler, InvocationOutputHandler consoleLogHandler, Map<String, String> envVarsForApp, Waiter startupWaiter) throws ProjectCannotStartException {
runNPM(buildLogHandler, envVarsForApp, "install");
runNPM(buildLogHandler, envVarsForApp, "test");
CommandLine command = new CommandLine(nodeExec)
.addArgument("server.js")
.addArgument("--app-name=" + envVarsForApp.get("APP_NAME"));
watchDog = ProcessStarter.startDaemon(buildLogHandler, consoleLogHandler, envVarsForApp, command, projectRoot, startupWaiter);
}
示例7: start
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
public void start(InvocationOutputHandler buildLogHandler, InvocationOutputHandler consoleLogHandler, Map<String, String> envVarsForApp, Waiter startupWaiter) throws ProjectCannotStartException {
envVarsForApp.put("GOPATH", instanceDir.getAbsolutePath());
rungo(buildLogHandler, envVarsForApp, "get");
rungo(buildLogHandler, envVarsForApp, "build");
rungo(buildLogHandler, envVarsForApp, "test");
CommandLine command = new CommandLine("." + File.separator + projectRoot.getName());
watchDog = ProcessStarter.startDaemon(buildLogHandler, consoleLogHandler, envVarsForApp, command, projectRoot, startupWaiter);
}
示例8: rungo
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
private void rungo(InvocationOutputHandler buildLogHandler, Map<String, String> envVarsForApp, String... arguments) {
CommandLine command = goCmd.commandLine(envVarsForApp);
for (String argument : arguments)
command.addArgument(argument);
buildLogHandler.consumeLine("Running go " + StringUtils.join(arguments, " ") + " with " + command);
ProcessStarter.run(buildLogHandler, envVarsForApp, command, projectRoot, TimeUnit.MINUTES.toMillis(20));
}
示例9: createExecutor
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
private static Executor createExecutor(InvocationOutputHandler consoleLogHandler, CommandLine command, File projectRoot, ExecuteWatchdog watchDog) {
Executor executor = new DefaultExecutor();
executor.setWorkingDirectory(projectRoot);
executor.setWatchdog(watchDog);
executor.setStreamHandler(new PumpStreamHandler(new WriterOutputStream(new WriterToOutputBridge(consoleLogHandler))));
consoleLogHandler.consumeLine(fullPath(executor.getWorkingDirectory()) + "> " + String.join(" ", command.toStrings()) + LINE_SEPARATOR);
return executor;
}
示例10: start
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
@Override
public void start(final InvocationOutputHandler buildLogHandler,
final InvocationOutputHandler consoleLogHandler,
final Map<String, String> envVarsForApp,
final Waiter startupWaiter) throws ProjectCannotStartException {
final String artifactPath = runSbt(buildLogHandler, envVarsForApp, CLEAN_AND_PACKAGE);
final CommandLine command = javaCmd
.commandLine(envVarsForApp)
.addArgument("-jar")
.addArgument(artifactPath);
watchDog = ProcessStarter.startDaemon(buildLogHandler, consoleLogHandler, envVarsForApp, command, projectRoot, startupWaiter);
}
示例11: buildAndStartUberJar
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
private static void buildAndStartUberJar(List<String> goals) throws Exception {
mavenRunner = new MavenRunner(new File("."), new HomeProvider() {
public InvocationRequest mungeMavenInvocationRequest(InvocationRequest request) {
return HomeProvider.default_java_home.mungeMavenInvocationRequest(request);
}
public CommandLine commandLine(Map<String, String> envVarsForApp) {
return HomeProvider.default_java_home.commandLine(envVarsForApp).addArgument("-Dlogback.configurationFile=src/test/resources/logback-test.xml");
}
}, goals);
Map<String, String> env = new HashMap<String, String>(System.getenv()) {{
put(Config.SERVER_HTTPS_PORT, String.valueOf(httpsPort));
put("apprunner.keystore.path", fullPath(new File("local/test.keystore")));
put("apprunner.keystore.password", "password");
put("apprunner.keymanager.password", "password");
put(Config.DATA_DIR, fullPath(dataDir));
}};
InvocationOutputHandler logHandler = line -> System.out.print("Uber jar output > " + line);
try (Waiter startupWaiter = new Waiter("AppRunner uber jar", httpClient -> {
try {
JSONObject sysInfo = new JSONObject(client.GET(appRunnerUrl + "/api/v1/system").getContentAsString());
return sysInfo.getBoolean("appRunnerStarted");
} catch (Exception e) {
return false;
}
}, 2, TimeUnit.MINUTES)) {
mavenRunner.start(logHandler, logHandler, env, startupWaiter);
}
}
示例12: invokePlugin
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
/***
* <p>Invokes a goal on a separate process programmatically using the Maven invoker tool.</p>
* @param goal the maven goal, such as <code>jar:package</code> or <code>mandebrlot:ocamljava-maven-plugin:compile</code>.
* @param forkAgain sets a system property ({@value #FORK_PROPERTY_NAME}} as a hint to the invoking process on whether it should fork once more.
* @param properties system properties to pass to the Maven command.
* @param outputHandler
* @return the invocation result.
* @throws MojoExecutionException if an invocation exception occurs, or the invoked process did not exit with a return value of 0.
*/
protected InvocationResult invokePlugin(final String goal, final boolean forkAgain, Properties properties, final InvocationOutputHandler
outputHandler) throws MojoExecutionException {
Preconditions.checkNotNull(project, "no project defined- this plugin must be invoked on a maven project!");
properties = properties == null ? new Properties() : (Properties)properties.clone();
properties.put(FORK_PROPERTY_NAME, Boolean.valueOf(forkAgain).toString());
final InvocationRequest defaultInvocationRequest = new DefaultInvocationRequest()
.setDebug(getLog().isDebugEnabled())
.setShellEnvironmentInherited(true)
.setMavenOpts(System.getenv("MAVEN_OPTS"))
.setGoals(ImmutableList.of(goal))
.setProperties(properties)
.setOffline(isOffline())
.setOutputHandler(outputHandler)
.setPomFile(project.getFile());
final Invoker invoker = new DefaultInvoker();
try {
final InvocationResult execution = invoker
.execute(defaultInvocationRequest);
switch (execution.getExitCode()) {
case 0:
return execution;
default:
throw new MojoExecutionException(
"process did not exit cleanly (exit code = " + execution.getExitCode() + ")");
}
} catch (final MavenInvocationException e) {
throw new MojoExecutionException("problem during fork operation", e);
}
}
示例13: invokeMaven
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
protected static int invokeMaven(String[] args, String outDir, File logFile) {
List<String> goals = Arrays.asList(args);
String commandLine = Strings.join(goals, " ");
InvocationResult result = null;
try {
File dir = new File(outDir);
InvocationRequest request = new DefaultInvocationRequest();
request.setGoals(goals);
InvocationOutputHandler outputHandler = new SystemOutAndFileHandler(logFile);
outputHandler.consumeLine("");
outputHandler.consumeLine("");
outputHandler.consumeLine(dir.getName() + " : starting: mvn " + commandLine);
outputHandler.consumeLine("");
request.setOutputHandler(outputHandler);
request.setErrorHandler(outputHandler);
DefaultInvoker invoker = new DefaultInvoker();
request.setPomFile(new File(dir, "pom.xml"));
result = invoker.execute(request);
CommandLineException executionException = result.getExecutionException();
if (executionException != null) {
LOG.error("Failed to invoke maven with: mvn " + commandLine + ". " + executionException, executionException);
}
} catch (Exception e) {
LOG.error("Failed to invoke maven with: mvn " + commandLine + ". " + e, e);
}
return result == null ? 1 : result.getExitCode();
}
示例14: update
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
public synchronized void update(AppRunnerFactoryProvider runnerProvider, InvocationOutputHandler outputHandler) throws Exception {
clearLogs();
markBuildAsFetching();
InvocationOutputHandler buildLogHandler = line -> {
outputHandler.consumeLine(line);
latestBuildLog += line + LINE_SEPARATOR;
};
// Well this is complicated.
// Basically, we want the build log to contain a bit of the startup, and then detach itself.
AtomicReference<InvocationOutputHandler> buildLogHandle = new AtomicReference<>(buildLogHandler);
InvocationOutputHandler consoleLogHandler = line -> {
InvocationOutputHandler another = buildLogHandle.get();
if (another != null) {
another.consumeLine(StringUtils.stripEnd(line, "\r\n"));
}
synchronized (consoleLog) {
consoleLog.add(line);
}
};
buildLogHandler.consumeLine("Fetching latest changes from git...");
File instanceDir = fetchChangesAndCreateInstanceDir();
buildLogHandler.consumeLine("Created new instance in " + fullPath(instanceDir));
AppRunner oldRunner = currentRunner;
AppRunnerFactory appRunnerFactory = runnerProvider.runnerFor(name(), instanceDir);
String runnerId = appRunnerFactory.id();
markBuildAsStarting(runnerId);
currentRunner = appRunnerFactory.appRunner(instanceDir);
log.info("Using " + appRunnerFactory.id() + " for " + name);
int port = WebServer.getAFreePort();
Map<String, String> envVarsForApp = createAppEnvVars(port, name, dataDir, tempDir);
try (Waiter startupWaiter = Waiter.waitForApp(name, port)) {
currentRunner.start(buildLogHandler, consoleLogHandler, envVarsForApp, startupWaiter);
} catch (Exception e) {
recordBuildFailure("Crashed during startup", runnerId);
throw e;
}
recordBuildSuccess(runnerId);
buildLogHandle.set(null);
for (AppChangeListener listener : listeners) {
listener.onAppStarted(name, new URL("http://localhost:" + port + "/" + name));
}
if (oldRunner != null) {
buildLogHandler.consumeLine("Shutting down previous version");
log.info("Shutting down previous version of " + name);
oldRunner.shutdown();
buildLogHandler.consumeLine("Deployment complete.");
File oldInstanceDir = oldRunner.getInstanceDir();
quietlyDeleteTheOldInstanceDirInTheBackground(oldInstanceDir);
}
}
示例15: runNPM
import org.apache.maven.shared.invoker.InvocationOutputHandler; //导入依赖的package包/类
private void runNPM(InvocationOutputHandler buildLogHandler, Map<String, String> envVarsForApp, String argument) {
CommandLine command = new CommandLine(npmExec).addArgument(argument);
buildLogHandler.consumeLine("Running " + StringUtils.join(command.toStrings(), " "));
ProcessStarter.run(buildLogHandler, envVarsForApp, command, projectRoot, TimeUnit.MINUTES.toMillis(30));
}