use of org.codehaus.plexus.util.cli.Commandline in project maven-plugins by apache.
the class JLinkMojo method createJLinkCommandLine.
Commandline createJLinkCommandLine() throws IOException {
File file = new File(outputDirectory.getParentFile(), "jlinkArgs");
if (!getLog().isDebugEnabled()) {
file.deleteOnExit();
}
file.getParentFile().mkdirs();
file.createNewFile();
PrintStream argsFile = new PrintStream(file);
if (stripDebug) {
argsFile.println("--strip-debug");
}
if (compression != null) {
argsFile.println("--compression");
argsFile.println(compression);
}
if (modulePaths != null) {
argsFile.println("--module-path");
argsFile.append('"').append(getColonSeparateList(modulePaths).replace("\\", "\\\\")).println('"');
}
if (limitModules != null && !limitModules.isEmpty()) {
argsFile.println("--limit-modules");
StringBuilder sb = getCommaSeparatedList(limitModules);
argsFile.println(sb.toString());
}
if (addModules != null && !addModules.isEmpty()) {
argsFile.println("--add-modules");
StringBuilder sb = getCommaSeparatedList(addModules);
argsFile.println(sb.toString());
}
if (outputDirectory != null) {
argsFile.println("--output");
argsFile.println(outputDirectory);
}
argsFile.close();
Commandline cmd = new Commandline();
cmd.createArg().setValue('@' + file.getAbsolutePath());
return cmd;
}
use of org.codehaus.plexus.util.cli.Commandline in project cxf by apache.
the class Java2WSMojo method processJavaClass.
private void processJavaClass(List<String> args) throws MojoExecutionException {
if (!fork) {
try {
CommandInterfaceUtils.commandCommonMain();
JavaToWS j2w = new JavaToWS(args.toArray(new String[args.size()]));
j2w.run();
} catch (OutOfMemoryError e) {
getLog().debug(e);
StringBuilder msg = new StringBuilder();
msg.append(e.getMessage()).append('\n');
msg.append("Try to run this goal using the <fork>true</fork> and " + "<additionalJvmArgs>-Xms128m -Xmx128m</additionalJvmArgs> parameters.");
throw new MojoExecutionException(msg.toString(), e);
} catch (Throwable e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
} else {
getLog().info("Running java2ws in fork mode...");
Commandline cmd = new Commandline();
// for JVM args
cmd.getShell().setQuotedArgumentsEnabled(true);
cmd.setWorkingDirectory(project.getBuild().getDirectory());
try {
cmd.setExecutable(getJavaExecutable().getAbsolutePath());
} catch (IOException e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
cmd.addArguments(args.toArray(new String[args.size()]));
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
} catch (CommandLineException e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
String output = StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim();
String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
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(cmdLine).append('\n').append('\n');
throw new MojoExecutionException(msg.toString());
}
if (StringUtils.isNotEmpty(err.getOutput()) && err.getOutput().contains("JavaToWS Error")) {
StringBuilder msg = new StringBuilder();
msg.append(err.getOutput());
msg.append('\n');
msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
throw new MojoExecutionException(msg.toString());
}
}
// with the enclosing project
if (attachWsdl && outputFile != null) {
File wsdlFile = new File(outputFile);
if (wsdlFile.exists()) {
if (classifier != null) {
projectHelper.attachArtifact(project, wsdlFile.getName(), classifier, wsdlFile);
} else {
projectHelper.attachArtifact(project, wsdlFile.getName(), wsdlFile);
}
boolean hasWsdlAttached = false;
for (Artifact a : project.getAttachedArtifacts()) {
if ("wsdl".equals(a.getType())) {
hasWsdlAttached = true;
}
}
if (!hasWsdlAttached) {
if (classifier != null) {
projectHelper.attachArtifact(project, "wsdl", classifier, wsdlFile);
} else {
projectHelper.attachArtifact(project, "wsdl", wsdlFile);
}
}
}
}
}
use of org.codehaus.plexus.util.cli.Commandline in project cxf by apache.
the class AbstractCodegenMoho 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());
try {
cmd.setExecutable(getJavaExecutable().getAbsolutePath());
} catch (IOException e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
cmd.createArg().setLine(additionalJvmArgs);
File file = null;
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.Commandline in project maven-scm by apache.
the class BazaarConfig method getPythonVersion.
public static VersionConsumer getPythonVersion(File workingDir) throws ScmException {
String[] versionCmd = new String[] { PYTHON_VERSION };
VersionConsumer consumer = new VersionConsumer(PYTHON_VERSION_TAG);
Commandline cmd = buildPythonCmd(workingDir, versionCmd);
// Execute command
BazaarUtils.executeCmd(consumer, cmd);
// Return result
return consumer;
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class BazaarUtils method buildCmd.
static Commandline buildCmd(File workingDir, String[] cmdAndArgs) throws ScmException {
Commandline cmd = new Commandline();
cmd.setExecutable(BazaarConstants.EXEC);
cmd.setWorkingDirectory(workingDir.getAbsolutePath());
cmd.addArguments(cmdAndArgs);
if (!workingDir.exists()) {
boolean success = workingDir.mkdirs();
if (!success) {
String msg = "Working directory did not exist" + " and it couldn't be created: " + workingDir;
throw new ScmException(msg);
}
}
return cmd;
}
Aggregations