use of org.apache.cxf.maven_plugin.GenericWsdlOption in project cxf by apache.
the class WSDL2JavaMojo method createWsdlOptionsFromScansAndExplicitWsdlOptions.
/**
* @return effective WsdlOptions
* @throws MojoExecutionException
*/
protected List<GenericWsdlOption> createWsdlOptionsFromScansAndExplicitWsdlOptions() throws MojoExecutionException {
List<GenericWsdlOption> effectiveWsdlOptions = new ArrayList<>();
if (wsdlOptions != null) {
for (WsdlOption wo : wsdlOptions) {
effectiveWsdlOptions.add(wo);
}
}
List<GenericWsdlOption> temp;
if (wsdlRoot != null && wsdlRoot.exists() && !disableDirectoryScan) {
temp = WsdlOptionLoader.loadWsdlOptionsFromFiles(wsdlRoot, includes, excludes, getGeneratedSourceRoot());
effectiveWsdlOptions.addAll(temp);
}
if (testWsdlRoot != null && testWsdlRoot.exists() && !disableDirectoryScan) {
temp = WsdlOptionLoader.loadWsdlOptionsFromFiles(testWsdlRoot, includes, excludes, getGeneratedTestRoot());
effectiveWsdlOptions.addAll(temp);
}
if (!disableDependencyScan) {
temp = WsdlOptionLoader.loadWsdlOptionsFromDependencies(project, getGeneratedSourceRoot());
effectiveWsdlOptions.addAll(temp);
}
mergeOptions(effectiveWsdlOptions);
downloadRemoteWsdls(effectiveWsdlOptions);
return effectiveWsdlOptions;
}
use of org.apache.cxf.maven_plugin.GenericWsdlOption 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.maven_plugin.GenericWsdlOption in project cxf by apache.
the class WsdlOptionLoader method loadWsdlOptionsFromFiles.
/**
* Scan files in a directory and generate one wsdlOption per file found. Extra args for code generation
* can be defined in a file that is named like the wsdl file and ends in -options. Binding files can be
* defined in files named like the wsdl file and end in -binding-*.xml
*
* @param wsdlBasedir
* @param includes file name patterns to include
* @param excludes file name patterns to exclude
* @param defaultOutputDir output directory that should be used if no special file is given
* @return list of one WsdlOption object for each wsdl found
* @throws MojoExecutionException
*/
public static List<GenericWsdlOption> loadWsdlOptionsFromFiles(File wsdlBasedir, String[] includes, String[] excludes, File defaultOutputDir) throws MojoExecutionException {
if (wsdlBasedir == null) {
return Collections.emptyList();
}
if (!wsdlBasedir.exists()) {
throw new MojoExecutionException(wsdlBasedir + " does not exist");
}
List<File> wsdlFiles = WsdlUtilities.getWsdlFiles(wsdlBasedir, includes, excludes);
List<GenericWsdlOption> wsdlOptions = new ArrayList<>();
for (File wsdl : wsdlFiles) {
WsdlOption wsdlOption = generateWsdlOptionFromFile(wsdl, defaultOutputDir);
if (wsdlOption != null) {
wsdlOptions.add(wsdlOption);
}
}
return wsdlOptions;
}
use of org.apache.cxf.maven_plugin.GenericWsdlOption 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.maven_plugin.GenericWsdlOption in project cxf by apache.
the class WSDL2JavaMojo method shouldRun.
/**
* Determine if code should be generated from the given wsdl
*
* @param genericWsdlOption
* @param doneFile
* @param wsdlURI
* @return
*/
protected boolean shouldRun(GenericWsdlOption genericWsdlOption, File doneFile, URI wsdlURI) {
WsdlOption wsdlOption = (WsdlOption) genericWsdlOption;
long timestamp = getTimestamp(wsdlURI);
boolean doWork = false;
if (!doneFile.exists()) {
doWork = true;
} else if (timestamp > doneFile.lastModified()) {
doWork = true;
} else if (wsdlOption.isDefServiceName()) {
doWork = true;
} else {
URI[] dependencies = wsdlOption.getDependencyURIs(project.getBasedir().toURI());
if (dependencies != null) {
for (int z = 0; z < dependencies.length; ++z) {
long dependencyTimestamp = getTimestamp(dependencies[z]);
if (dependencyTimestamp > doneFile.lastModified()) {
doWork = true;
break;
}
}
}
}
if (!doWork) {
URI basedir = project.getBasedir().toURI();
String options = wsdlOption.generateCommandLine(null, basedir, wsdlURI, false).toString();
DataInputStream reader = null;
try {
reader = new DataInputStream(Files.newInputStream(doneFile.toPath()));
String s = reader.readUTF();
if (!options.equals(s)) {
doWork = true;
}
} catch (Exception ex) {
// ignore
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// ignore
}
}
}
}
return doWork;
}
Aggregations