use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class AbstractCodeGeneratorMojo method callCodeGenerator.
protected Bus callCodeGenerator(WadlOption option, Bus bus, Set<URI> classPath) throws MojoExecutionException {
File outputDirFile = option.getOutputDir();
outputDirFile.mkdirs();
URI basedir = project.getBasedir().toURI();
for (URI wadlURI : option.getWadlURIs(basedir, getResourceLoader())) {
File doneFile = getDoneFile(basedir, wadlURI);
if (!shouldRun(option, doneFile, wadlURI)) {
return bus;
}
doneFile.delete();
List<String> list = option.generateCommandLine(outputDirFile, basedir, wadlURI, getLog().isDebugEnabled());
String[] args = list.toArray(new String[list.size()]);
getLog().debug("Calling wadl2java with args: " + Arrays.toString(args));
if (!"false".equals(fork)) {
Set<URI> artifactsPath = new LinkedHashSet<URI>();
for (Artifact a : pluginArtifacts) {
File file = a.getFile();
if (file == null) {
throw new MojoExecutionException("Unable to find file for artifact " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
}
artifactsPath.add(file.toURI());
}
addPluginArtifact(artifactsPath);
artifactsPath.addAll(classPath);
runForked(artifactsPath, WADLToJava.class, args);
} else {
if (bus == null) {
bus = BusFactory.newInstance().createBus();
BusFactory.setThreadDefaultBus(bus);
}
try {
new WADLToJava(args).run(new ToolContext());
} catch (Throwable e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
}
try {
doneFile.createNewFile();
} catch (Throwable e) {
getLog().warn("Could not create marker file " + doneFile.getAbsolutePath());
getLog().debug(e);
}
}
return bus;
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class WSDL2JavaMojo method generate.
@Override
protected Bus generate(GenericWsdlOption genericWsdlOption, Bus bus, Set<URI> classPath) throws MojoExecutionException {
WsdlOption wsdlOption = (WsdlOption) genericWsdlOption;
File outputDirFile = wsdlOption.getOutputDir();
outputDirFile.mkdirs();
URI basedir = project.getBasedir().toURI();
URI wsdlURI = wsdlOption.getWsdlURI(basedir);
File doneFile = getDoneFile(basedir, wsdlURI, "java");
if (!shouldRun(wsdlOption, doneFile, wsdlURI)) {
return bus;
}
doneFile.delete();
try {
File file = new File(getBaseFileURI(wsdlURI));
if (file.exists()) {
buildContext.removeMessages(file);
}
} catch (Throwable t) {
// ignore
}
if (wsdlOption.getDependencies() != null) {
for (URI dependency : wsdlOption.getDependencyURIs(project.getBasedir().toURI())) {
URI baseDependency = getBaseFileURI(dependency);
if ("file".equals(baseDependency.getScheme())) {
buildContext.removeMessages(new File(baseDependency));
}
}
}
List<String> list = wsdlOption.generateCommandLine(outputDirFile, basedir, wsdlURI, getLog().isDebugEnabled());
if (encoding != null) {
list.add(0, "-encoding");
list.add(1, encoding);
}
String[] args = list.toArray(new String[list.size()]);
getLog().debug("Calling wsdl2java with args: " + Arrays.toString(args));
if (!"false".equals(fork)) {
Set<URI> artifactsPath = new LinkedHashSet<URI>();
for (Artifact a : pluginArtifacts) {
File file = a.getFile();
if (file == null) {
throw new MojoExecutionException("Unable to find (null) file for artifact " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
}
artifactsPath.add(file.toURI());
}
addPluginArtifact(artifactsPath);
artifactsPath.addAll(classPath);
runForked(artifactsPath, WSDLToJava.class.getName(), args);
} else {
if (bus == null) {
bus = BusFactory.newInstance().createBus();
BusFactory.setThreadDefaultBus(bus);
}
try {
ToolContext ctx = new ToolContext();
final List<File> files = new ArrayList<>();
final List<File> errorfiles = new ArrayList<>();
ctx.put(OutputStreamCreator.class, new OutputStreamCreator() {
public OutputStream createOutputStream(File file) throws IOException {
files.add(file);
return buildContext.newFileOutputStream(file);
}
});
ctx.setErrorListener(new MavenToolErrorListener(errorfiles));
new WSDLToJava(args).run(ctx);
List<File> oldFiles = CastUtils.cast((List<?>) buildContext.getValue("cxf.file.list." + doneFile.getName()));
if (oldFiles != null) {
for (File f : oldFiles) {
if (!files.contains(f)) {
f.delete();
buildContext.refresh(f);
}
}
}
buildContext.setValue("cxf.file.list." + doneFile.getName(), files);
} catch (Throwable e) {
buildContext.setValue("cxf.file.list." + doneFile.getName(), null);
getLog().debug(e);
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new MojoExecutionException(e.getMessage(), e);
}
}
try {
createMarkerFile(wsdlOption, doneFile, wsdlURI);
buildContext.refresh(doneFile);
} catch (Throwable e) {
getLog().warn("Could not create marker file " + doneFile.getAbsolutePath());
getLog().debug(e);
throw new MojoExecutionException("Failed to create marker file " + doneFile.getAbsolutePath());
}
if (project != null && getGeneratedSourceRoot() != null && getGeneratedSourceRoot().exists()) {
project.addCompileSourceRoot(getGeneratedSourceRoot().getAbsolutePath());
buildContext.refresh(getGeneratedSourceRoot().getAbsoluteFile());
}
if (project != null && getGeneratedTestRoot() != null && getGeneratedTestRoot().exists()) {
project.addTestCompileSourceRoot(getGeneratedTestRoot().getAbsolutePath());
buildContext.refresh(getGeneratedTestRoot().getAbsoluteFile());
}
return bus;
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class ForkOnceWSDL2Javascript method main.
public static void main(String[] args) throws Exception {
File file = new File(args[0]);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
while (line != null) {
int i = Integer.parseInt(line);
if (i == -1) {
reader.close();
return;
}
String[] wargs = new String[i];
for (int x = 0; x < i; x++) {
wargs[x] = reader.readLine();
}
new WSDLToJavaScript(wargs).run(new ToolContext());
line = reader.readLine();
}
reader.close();
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class WSDL2JavaScriptMojo method generate.
@Override
protected Bus generate(GenericWsdlOption genericWsdlOption, Bus bus, Set<URI> classPath) throws MojoExecutionException {
WsdlOption wsdlOption = (WsdlOption) genericWsdlOption;
File outputDirFile = wsdlOption.getOutputDir();
outputDirFile.mkdirs();
URI basedir = project.getBasedir().toURI();
URI wsdlURI;
try {
wsdlURI = new URI(wsdlOption.getUri());
} catch (URISyntaxException e) {
throw new MojoExecutionException("Failed to get URI for wsdl " + wsdlOption.getUri(), e);
}
File doneFile = getDoneFile(basedir, wsdlURI, "js");
if (!shouldRun(wsdlOption, doneFile, wsdlURI)) {
return bus;
}
doneFile.delete();
List<String> list = wsdlOption.generateCommandLine(outputDirFile, basedir, wsdlURI, getLog().isDebugEnabled());
String[] args = list.toArray(new String[list.size()]);
getLog().debug("Calling wsdl2js with args: " + Arrays.toString(args));
if (!"false".equals(fork)) {
Set<URI> artifactsPath = new LinkedHashSet<URI>();
for (Artifact a : pluginArtifacts) {
File file = a.getFile();
if (file == null) {
throw new MojoExecutionException("Unable to find file for artifact " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
}
artifactsPath.add(file.toURI());
}
addPluginArtifact(artifactsPath);
artifactsPath.addAll(classPath);
runForked(artifactsPath, WSDLToJavaScript.class.getName(), args);
} else {
if (bus == null) {
bus = BusFactory.newInstance().createBus();
BusFactory.setThreadDefaultBus(bus);
}
try {
new WSDLToJavaScript(args).run(new ToolContext());
} catch (Throwable e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
}
try {
createMarkerFile(wsdlOption, doneFile, wsdlURI);
} catch (Throwable e) {
getLog().warn("Could not create marker file " + doneFile.getAbsolutePath());
getLog().debug(e);
throw new MojoExecutionException("Failed to create marker file " + doneFile.getAbsolutePath());
}
if (project != null && getGeneratedSourceRoot() != null && getGeneratedSourceRoot().exists()) {
project.addCompileSourceRoot(getGeneratedSourceRoot().getAbsolutePath());
}
if (project != null && getGeneratedTestRoot() != null && getGeneratedTestRoot().exists()) {
project.addTestCompileSourceRoot(getGeneratedTestRoot().getAbsolutePath());
}
return bus;
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class WSDLToJavaScript method main.
public static void main(String[] pargs) {
CommandInterfaceUtils.commandCommonMain();
WSDLToJavaScript w2j = new WSDLToJavaScript(pargs);
try {
w2j.run(new ToolContext());
} catch (ToolException ex) {
System.err.println();
System.err.println("WSDLToJS Error : " + ex.getMessage());
System.err.println();
if (w2j.isVerbose()) {
ex.printStackTrace();
}
if (w2j.isExitOnFinish()) {
System.exit(1);
}
} catch (Exception ex) {
System.err.println("WSDLToJS Error : " + ex.getMessage());
System.err.println();
if (w2j.isVerbose()) {
ex.printStackTrace();
}
if (w2j.isExitOnFinish()) {
System.exit(1);
}
}
if (w2j.isExitOnFinish()) {
System.exit(0);
}
}
Aggregations