in cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractXSDToJavaMojo.java [487:611]
private int runForked(XsdOption option, String outputDir) throws Exception {
String[] args = getArguments(option, outputDir);
Commandline cmd = new Commandline();
cmd.getShell().setQuotedArgumentsEnabled(true); // for JVM args
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);
final File file;
try {
file = Files.createTempFile("cxf-xjc-plugin", ".jar").toFile();
file.deleteOnExit();
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 (String cp : getClasspathElements()) {
URI uri = mapLocation(cp);
if (uri != null) {
b.append(uri.toString()).append(' ');
}
}
for (Artifact a : pluginArtifacts) {
b.append(a.getFile().toURI().toURL().toExternalForm()).append(' ');
}
attr.setValue(b.toString());
manifest.getMainSection().addConfiguredAttribute(attr);
attr = new Attribute();
attr.setName("Main-Class");
attr.setValue(XSDToJavaRunner.class.getName());
manifest.getMainSection().addConfiguredAttribute(attr);
if (getLog().isDebugEnabled()) {
getLog().debug("Manifest: " + manifest);
}
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() {
File file;
int severity;
int linenum;
int column;
StringBuilder message = new StringBuilder();
public void consumeLine(String line) {
if (getLog().isDebugEnabled()) {
getLog().debug(line);
}
if (line.startsWith("DONE")) {
buildContext.addMessage(file, linenum, column, message.toString(), severity, null);
} else if (line.startsWith("MSG: ")
|| line.startsWith("ERROR: ")
|| line.startsWith("WARNING: ")) {
file = new File(line.substring(line.indexOf(' ')).trim());
String type = line.substring(0, line.indexOf(':'));
if (type.contains("ERROR")) {
severity = BuildContext.SEVERITY_ERROR;
} else if (type.contains("WARNING")) {
severity = BuildContext.SEVERITY_WARNING;
} else {
severity = 0;
}
linenum = 0;
column = 0;
message.setLength(0);
} else if (line.startsWith("Col: ")) {
column = Integer.parseInt(line.substring(line.indexOf(' ')).trim());
} else if (line.startsWith("Line: ")) {
linenum = Integer.parseInt(line.substring(line.indexOf(' ')).trim());
} else if (line.startsWith("Severity: ")) {
severity = Integer.parseInt(line.substring(line.indexOf(' ')).trim());
} else {
message.append(line).append('\n');
}
}
};
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cmd, out, out);
} catch (CommandLineException e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
if (exitCode != 0) {
StringBuffer msg = new StringBuffer("\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();
return 0;
}