use of org.codehaus.plexus.util.cli.CommandLineException in project tycho by eclipse.
the class JDTCompiler method compileOutOfProcess.
/**
* Compile the java sources in a external process, calling an external executable, like javac.
*
* @param workingDirectory
* base directory where the process will be launched
* @param executable
* name of the executable to launch
* @param args
* arguments for the executable launched
* @return CompilerResult with the errors and warnings encountered.
* @throws CompilerException
*/
CompilerResult compileOutOfProcess(File workingDirectory, String executable, String[] args) throws CompilerException {
if (true) /* fork is not supported */
{
throw new UnsupportedOperationException("compileoutOfProcess not supported");
}
Commandline cli = new Commandline();
cli.setWorkingDirectory(workingDirectory.getAbsolutePath());
cli.setExecutable(executable);
cli.addArguments(args);
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int returnCode;
List<CompilerMessage> messages;
try {
returnCode = CommandLineUtils.executeCommandLine(cli, out, err);
messages = parseModernStream(new BufferedReader(new StringReader(err.getOutput())));
} catch (CommandLineException e) {
throw new CompilerException("Error while executing the external compiler.", e);
} catch (IOException e) {
throw new CompilerException("Error while executing the external compiler.", e);
}
if (returnCode != 0 && messages.isEmpty()) {
// TODO: exception?
messages.add(new CompilerMessage("Failure executing javac, but could not parse the error:" + EOL + err.getOutput(), Kind.ERROR));
}
return new CompilerResult(returnCode == 0, messages);
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class StarteamChangeLogCommand method executeChangeLogCommand.
// ----------------------------------------------------------------------
// AbstractChangeLogCommand Implementation
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern) throws ScmException {
if ((branch != null || StringUtils.isNotEmpty((branch == null) ? null : branch.getName())) && (getLogger().isWarnEnabled())) {
getLogger().warn("This provider doesn't support changelog with on a given branch.");
}
StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
// TODO: revision
Commandline cl = createCommandLine(repository, fileSet, startDate);
StarteamChangeLogConsumer consumer = new StarteamChangeLogConsumer(fileSet.getBasedir(), getLogger(), startDate, endDate, datePattern);
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
}
if (exitCode != 0) {
return new ChangeLogScmResult(cl.toString(), "The 'stcmd' command failed.", stderr.getOutput(), false);
}
return new ChangeLogScmResult(cl.toString(), new ChangeLogSet(consumer.getModifications(), startDate, endDate));
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-plugins by apache.
the class AbstractInvokerMojo method resolveExternalJreVersion.
private CharSequence resolveExternalJreVersion() {
Artifact pluginArtifact = mojoExecution.getMojoDescriptor().getPluginDescriptor().getPluginArtifact();
pluginArtifact.getFile();
Commandline commandLine = new Commandline();
commandLine.setExecutable(new File(javaHome, "bin/java").getAbsolutePath());
commandLine.createArg().setValue("-cp");
commandLine.createArg().setFile(pluginArtifact.getFile());
commandLine.createArg().setValue(SystemPropertyPrinter.class.getName());
commandLine.createArg().setValue("java.version");
final StringBuilder actualJreVersion = new StringBuilder();
StreamConsumer consumer = new StreamConsumer() {
public void consumeLine(String line) {
actualJreVersion.append(line);
}
};
try {
CommandLineUtils.executeCommandLine(commandLine, consumer, null);
} catch (CommandLineException e) {
getLog().warn(e.getMessage());
}
return actualJreVersion;
}
use of org.codehaus.plexus.util.cli.CommandLineException 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.CommandLineException in project maven-plugins by apache.
the class AbstractJDepsMojo method executeJDepsCommandLine.
private void executeJDepsCommandLine(Commandline cmd, File jOutputDirectory, CommandLineUtils.StringStreamConsumer consumer) throws MojoExecutionException {
if (getLog().isDebugEnabled()) {
// no quoted arguments
getLog().debug("Executing: " + CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", ""));
}
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer out;
if (consumer != null) {
out = consumer;
} else {
out = new CommandLineUtils.StringStreamConsumer();
}
try {
int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
String output = (StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim());
if (exitCode != 0) {
if (StringUtils.isNotEmpty(output)) {
getLog().info(output);
}
StringBuilder msg = new StringBuilder("\nExit code: ");
msg.append(exitCode);
if (StringUtils.isNotEmpty(err.getOutput())) {
msg.append(" - ").append(err.getOutput());
}
msg.append('\n');
msg.append("Command line was: ").append(cmd).append('\n').append('\n');
throw new MojoExecutionException(msg.toString());
}
if (StringUtils.isNotEmpty(output)) {
getLog().info(output);
}
} catch (CommandLineException e) {
throw new MojoExecutionException("Unable to execute jdeps command: " + e.getMessage(), e);
}
if (StringUtils.isNotEmpty(err.getOutput()) && getLog().isWarnEnabled()) {
getLog().warn("JDeps Warnings");
StringTokenizer token = new StringTokenizer(err.getOutput(), "\n");
while (token.hasMoreTokens()) {
String current = token.nextToken().trim();
getLog().warn(current);
}
}
}
Aggregations