use of org.codehaus.plexus.util.cli.StreamConsumer in project maven-plugins by apache.
the class ApplyMojo method applyPatches.
private String applyPatches(Map patchesApplied) throws MojoExecutionException {
final StringWriter outputWriter = new StringWriter();
StreamConsumer consumer = new StreamConsumer() {
public void consumeLine(String line) {
if (getLog().isDebugEnabled()) {
getLog().debug(line);
}
outputWriter.write(line + "\n");
}
};
// used if failFast is false
List failedPatches = new ArrayList();
for (Object o : patchesApplied.entrySet()) {
Entry entry = (Entry) o;
String patchName = (String) entry.getKey();
Commandline cli = (Commandline) entry.getValue();
try {
getLog().info("Applying patch: " + patchName);
int result = executeCommandLine(cli, consumer, consumer);
if (result != 0) {
if (failFast) {
throw new MojoExecutionException("Patch command failed with exit code " + result + " for " + patchName + ". Please see console and debug output for more information.");
} else {
failedPatches.add(patchName);
}
}
} catch (CommandLineException e) {
throw new MojoExecutionException("Failed to apply patch: " + patchName + ". See debug output for more information.", e);
}
}
if (!failedPatches.isEmpty()) {
getLog().error("Failed applying one or more patches:");
for (Object failedPatche : failedPatches) {
getLog().error("* " + failedPatche);
}
throw new MojoExecutionException("Patch command failed for one or more patches." + " Please see console and debug output for more information.");
}
return outputWriter.toString();
}
use of org.codehaus.plexus.util.cli.StreamConsumer in project jangaroo-tools by CoreMedia.
the class PhantomJsTestRunner method execute.
public boolean execute() throws CommandLineException {
final Commandline cmd = createCommandLine();
final ArrayList<String> arguments = new ArrayList<String>();
arguments.add(testRunner);
arguments.add(testPageUrl);
arguments.add(testResultFilename);
arguments.add(String.valueOf(timeout));
cmd.addArguments(arguments.toArray(new String[arguments.size()]));
final StreamConsumer outConsumer = new StreamConsumer() {
@Override
public void consumeLine(String line) {
Matcher matcher = LOG_LEVEL_PATTERN.matcher(line);
String logLevel;
String msg;
if (matcher.matches()) {
logLevel = matcher.group(1);
msg = matcher.group(2);
} else {
logLevel = "DEBUG";
msg = line;
}
if ("ERROR".equals(logLevel)) {
log.error(msg);
} else if ("WARN".equals(logLevel)) {
log.warn(msg);
} else if ("INFO".equals(logLevel)) {
log.info(msg);
} else {
log.debug(msg);
}
}
};
final StreamConsumer errConsumer = new StreamConsumer() {
@Override
public void consumeLine(String line) {
log.warn(line);
}
};
log.info("executing phantomjs cmd: " + cmd.toString());
for (int tryCount = 0; tryCount <= maxRetriesOnCrashes; ++tryCount) {
int returnCode = CommandLineUtils.executeCommandLine(cmd, outConsumer, errConsumer, timeout);
if (returnCode >= 0 && returnCode <= 4) {
// valid phantomjs-joounit-page-runner return codes!
return returnCode == 0;
}
log.warn(String.format("unexpected result %d from phantomjs run #%d", returnCode, tryCount + 1));
}
log.error(String.format("Got %d unexpected results from phantomjs, giving up.", maxRetriesOnCrashes + 1));
return false;
}
use of org.codehaus.plexus.util.cli.StreamConsumer in project cxf by apache.
the class AbstractCodegenMojo method runForked.
protected void runForked(Set<URI> classPath, String mainClassName, String[] args) throws MojoExecutionException {
getLog().info("Running code generation in fork mode...");
getLog().debug("Running code generation in fork mode with args " + Arrays.asList(args));
Commandline cmd = new Commandline();
// for JVM args
cmd.getShell().setQuotedArgumentsEnabled(true);
cmd.setWorkingDirectory(project.getBuild().getDirectory());
String javaPath = getJavaExecutable().getAbsolutePath();
cmd.setExecutable(javaPath);
setJvmForkArgs(javaPath);
cmd.createArg().setLine(additionalJvmArgs);
final File file;
try {
// file = new File("/tmp/test.jar");
file = FileUtils.createTempFile("cxf-codegen", ".jar");
JarArchiver jar = new JarArchiver();
jar.setDestFile(file.getAbsoluteFile());
Manifest manifest = new Manifest();
Attribute attr = new Attribute();
attr.setName("Class-Path");
StringBuilder b = new StringBuilder(8000);
for (URI cp : classPath) {
b.append(cp.toURL().toExternalForm()).append(' ');
}
attr.setValue(b.toString());
manifest.getMainSection().addConfiguredAttribute(attr);
attr = new Attribute();
attr.setName("Main-Class");
attr.setValue(mainClassName);
manifest.getMainSection().addConfiguredAttribute(attr);
jar.addConfiguredManifest(manifest);
jar.createArchive();
cmd.createArg().setValue("-jar");
String tmpFilePath = file.getAbsolutePath();
if (tmpFilePath.contains(" ")) {
// ensure the path is in double quotation marks if the path contain space
tmpFilePath = '"' + tmpFilePath + '"';
}
cmd.createArg().setValue(tmpFilePath);
} catch (Exception e1) {
throw new MojoExecutionException("Could not create runtime jar", e1);
}
cmd.addArguments(args);
StreamConsumer out = new StreamConsumer() {
public void consumeLine(String line) {
getLog().info(line);
}
};
final StringBuilder b = new StringBuilder();
StreamConsumer err = new StreamConsumer() {
public void consumeLine(String line) {
b.append(line);
b.append('\n');
getLog().warn(line);
}
};
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
} catch (CommandLineException e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
if (exitCode != 0) {
StringBuilder msg = new StringBuilder("\nExit code: ");
msg.append(exitCode);
msg.append('\n');
msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
throw new MojoExecutionException(msg.toString());
}
file.delete();
if (b.toString().contains("WSDL2Java Error")) {
StringBuilder msg = new StringBuilder();
msg.append(b.toString());
msg.append('\n');
msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
throw new MojoExecutionException(msg.toString());
}
}
use of org.codehaus.plexus.util.cli.StreamConsumer in project maven-scm by apache.
the class StarteamUpdateCommand method deleteLocal.
private void deleteLocal(StarteamScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
if (fileSet.getFileList().size() != 0) {
return;
}
Commandline cl = createDeleteLocalCommand(repo, fileSet, version);
StreamConsumer consumer = new DefaultConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode = StarteamCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
if (exitCode != 0) {
throw new ScmException("Error executing delete-local: " + stderr.toString());
}
}
use of org.codehaus.plexus.util.cli.StreamConsumer in project maven-scm by apache.
the class FileConsumerTest method testConsumeRemoved.
@Test
public void testConsumeRemoved() {
List<File> extractedFiles = new ArrayList<File>();
StreamConsumer consumer = new FileConsumer(extractedFiles, FileConsumer.DEFUNCT_PATTERN);
consumer.consumeLine("Recursively removing \"tcktests/src\" .");
consumer.consumeLine("Removing \"tcktests/src/main/java/Application.java\" .");
consumer.consumeLine("Removing \"tcktests/src/main/java\" .");
consumer.consumeLine("Removing \"tcktests/src/main\" .");
consumer.consumeLine("Removing \"tcktests/src\" .");
assertThat(extractedFiles.size(), is(4));
assertThat(extractedFiles, hasItem(new File("tcktests/src")));
assertThat(extractedFiles, hasItem(new File("tcktests/src/main/java/Application.java")));
}
Aggregations