You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/12/03 23:04:11 UTC
svn commit: r886941 - in /cxf/branches/2.2.x-fixes: ./
maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java
maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
Author: dkulp
Date: Thu Dec 3 22:04:11 2009
New Revision: 886941
URL: http://svn.apache.org/viewvc?rev=886941&view=rev
Log:
Merged revisions 882711 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r882711 | cschneider | 2009-11-20 16:02:00 -0500 (Fri, 20 Nov 2009) | 1 line
Refactoring
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java
cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java?rev=886941&r1=886940&r2=886941&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java (original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java Thu Dec 3 22:04:11 2009
@@ -22,7 +22,6 @@
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -192,34 +191,7 @@
*/
private ArtifactResolver artifactResolver;
- /**
- * Try to find a file matching the given wsdlPath (either absolutely, relatively to the current dir or to
- * the project base dir)
- *
- * @param wsdlPath
- * @return wsdl file
- */
- private File getFileFromWsdlPath(String wsdlPath) {
- if (wsdlPath == null) {
- return null;
- }
- File file = null;
- try {
- URI uri = new URI(wsdlPath);
- if (uri.isAbsolute()) {
- file = new File(uri);
- }
- } catch (Exception e) {
- // ignore
- }
- if (file == null || !file.exists()) {
- file = new File(wsdlPath);
- }
- if (!file.exists()) {
- file = new File(project.getBasedir(), wsdlPath);
- }
- return file;
- }
+
/**
* Merge WsdlOptions that point to the same file by adding the extraargs to the first option and deleting
@@ -240,11 +212,11 @@
o.setOutputDir(outputDirFile);
}
- File file = getFileFromWsdlPath(o.getWsdl());
+ File file = o.getWsdlFile(project.getBasedir());
if (file != null && file.exists()) {
file = file.getAbsoluteFile();
for (WsdlOption o2 : effectiveWsdlOptions) {
- File file2 = getFileFromWsdlPath(o2.getWsdl());
+ File file2 = o2.getWsdlFile(project.getBasedir());
if (file2 != null && file2.exists() && file2.getAbsoluteFile().equals(file)) {
o.getExtraargs().addAll(0, o2.getExtraargs());
effectiveWsdlOptions.remove(o2);
@@ -365,7 +337,7 @@
classLoaderSwitcher.switchClassLoader(project, useCompileClasspath, classesDir);
for (WsdlOption o : effectiveWsdlOptions) {
- processWsdl(o);
+ callWsdl2Java(o);
File dirs[] = o.getDeleteDirs();
if (dirs != null) {
@@ -393,34 +365,63 @@
System.gc();
}
- private void processWsdl(WsdlOption wsdlOption) throws MojoExecutionException {
-
+ private void callWsdl2Java(WsdlOption wsdlOption) throws MojoExecutionException {
File outputDirFile = wsdlOption.getOutputDir();
outputDirFile.mkdirs();
String wsdlLocation = wsdlOption.getWsdl();
File wsdlFile = new File(wsdlLocation);
URI basedir = project.getBasedir().toURI();
- URI wsdlURI;
- if (wsdlFile.exists()) {
- wsdlURI = wsdlFile.toURI();
- } else {
- wsdlURI = basedir.resolve(wsdlLocation);
+ URI wsdlURI = wsdlFile.exists() ? wsdlFile.toURI() : basedir.resolve(wsdlLocation);
+ File doneFile = getDoneFile(basedir, wsdlURI);
+
+ if (!shouldRun(wsdlOption, doneFile, wsdlURI)) {
+ return;
+ }
+
+ doneFile.delete();
+ List<String> list = wsdlOption.generateCommandLine(outputDirFile, basedir, wsdlURI,
+ getLog().isDebugEnabled());
+ getLog().debug("Calling wsdl2java with args: " + list);
+ try {
+ new WSDLToJava((String[])list.toArray(new String[list.size()])).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);
+ }
+ }
+ private File getDoneFile(URI basedir, URI wsdlURI) {
String doneFileName = wsdlURI.toString();
+
+ // Strip the basedir from the doneFileName
if (doneFileName.startsWith(basedir.toString())) {
doneFileName = doneFileName.substring(basedir.toString().length());
}
// If URL to WSDL, replace ? and & since they're invalid chars for file names
// Not to mention slashes.
-
doneFileName = doneFileName.replace('?', '_').replace('&', '_').replace('/', '_').replace('\\', '_')
.replace(':', '_');
- File doneFile = new File(markerDirectory, "." + doneFileName + ".DONE");
+ return new File(markerDirectory, "." + doneFileName + ".DONE");
+ }
+ /**
+ * Determine if code should be generated from the given wsdl
+ *
+ * @param wsdlOption
+ * @param doneFile
+ * @param wsdlURI
+ * @return
+ */
+ private boolean shouldRun(WsdlOption wsdlOption, File doneFile, URI wsdlURI) {
long timestamp = 0;
if ("file".equals(wsdlURI.getScheme())) {
timestamp = new File(wsdlURI).lastModified();
@@ -431,13 +432,12 @@
// ignore
}
}
-
boolean doWork = false;
if (!doneFile.exists()) {
doWork = true;
} else if (timestamp > doneFile.lastModified()) {
doWork = true;
- } else if (isDefServiceName(wsdlOption)) {
+ } else if (wsdlOption.isDefServiceName()) {
doWork = true;
} else {
File files[] = wsdlOption.getDependencies();
@@ -449,140 +449,15 @@
}
}
}
-
- if (doWork) {
- doneFile.delete();
-
- List<String> list = generateCommandLine(wsdlOption, outputDirFile, basedir, wsdlURI);
-
- getLog().debug("Calling wsdl2java with args: " + list);
- try {
- new WSDLToJava((String[])list.toArray(new String[list.size()])).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);
- }
- }
- }
-
- private List<String> generateCommandLine(WsdlOption wsdlOption, File outputDirFile, URI basedir,
- URI wsdlURI) {
- List<String> list = new ArrayList<String>();
- if (wsdlOption.getPackagenames() != null) {
- Iterator<String> it = wsdlOption.getPackagenames().iterator();
- while (it.hasNext()) {
- list.add("-p");
- list.add(it.next());
- }
- }
- if (wsdlOption.getNamespaceExcludes() != null) {
- Iterator<String> it = wsdlOption.getNamespaceExcludes().iterator();
- while (it.hasNext()) {
- list.add("-nexclude");
- list.add(it.next());
- }
- }
-
- // -d specify the dir for generated source code
- list.add("-d");
- list.add(outputDirFile.toString());
-
- for (String binding : wsdlOption.getBindingFiles()) {
- File bindingFile = new File(binding);
- URI bindingURI;
- if (bindingFile.exists()) {
- bindingURI = bindingFile.toURI();
- } else {
- bindingURI = basedir.resolve(binding);
- }
- list.add("-b");
- list.add(bindingURI.toString());
- }
- if (wsdlOption.getFrontEnd() != null) {
- list.add("-fe");
- list.add(wsdlOption.getFrontEnd());
- }
- if (wsdlOption.getDataBinding() != null) {
- list.add("-db");
- list.add(wsdlOption.getDataBinding());
- }
- if (wsdlOption.getWsdlVersion() != null) {
- list.add("-wv");
- list.add(wsdlOption.getWsdlVersion());
- }
- if (wsdlOption.getCatalog() != null) {
- list.add("-catalog");
- list.add(wsdlOption.getCatalog());
- }
- if (wsdlOption.isExtendedSoapHeaders()) {
- list.add("-exsh");
- list.add("true");
- }
- if (wsdlOption.isAllowElementRefs()) {
- list.add("-allowElementRefs");
- }
- if (wsdlOption.isValidateWsdl()) {
- list.add("-validate");
- }
- if (wsdlOption.getDefaultExcludesNamespace() != null) {
- list.add("-dex");
- list.add(wsdlOption.getDefaultExcludesNamespace().toString());
- }
- if (wsdlOption.getDefaultNamespacePackageMapping() != null) {
- list.add("-dns");
- list.add(wsdlOption.getDefaultNamespacePackageMapping().toString());
- }
- if (wsdlOption.getServiceName() != null) {
- list.add("-sn");
- list.add(wsdlOption.getServiceName());
- }
- if (wsdlOption.isAutoNameResolution()) {
- list.add("-autoNameResolution");
- }
- if (wsdlOption.isNoAddressBinding()) {
- list.add("-noAddressBinding");
- }
- if (wsdlOption.getXJCargs() != null) {
-
- for (String value : wsdlOption.getXJCargs()) {
- if (value == null) {
- value = ""; // Maven makes empty tags into null
- // instead of empty strings.
- }
- list.add("-xjc" + value);
- }
- }
- if (wsdlOption.getExtraargs() != null) {
- Iterator<String> it = wsdlOption.getExtraargs().iterator();
- while (it.hasNext()) {
- Object value = it.next();
- if (value == null) {
- value = ""; // Maven makes empty tags into null
- // instead of empty strings.
- }
- list.add(value.toString());
- }
- }
- if (wsdlOption.isSetWsdlLocation()) {
- list.add("-wsdlLocation");
- list.add(wsdlOption.getWsdlLocation() == null ? "" : wsdlOption.getWsdlLocation());
- }
- if (wsdlOption.isWsdlList()) {
- list.add("-wsdlList");
- }
- if (getLog().isDebugEnabled() && !list.contains("-verbose")) {
- list.add("-verbose");
- }
- list.add(wsdlURI.toString());
- return list;
+ return doWork;
}
+ /**
+ * Recursively delete the given directory
+ *
+ * @param f
+ * @return
+ */
private boolean deleteDir(File f) {
if (f.isDirectory()) {
File files[] = f.listFiles();
@@ -598,18 +473,4 @@
return true;
}
- private boolean isDefServiceName(WsdlOption wsdlOption) {
- List<String> args = wsdlOption.extraargs;
- if (args == null) {
- return false;
- }
- for (int i = 0; i < args.size(); i++) {
- if ("-sn".equalsIgnoreCase(args.get(i))) {
- return true;
- }
- }
- return false;
-
- }
-
}
Modified: cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java?rev=886941&r1=886940&r2=886941&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java (original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java Thu Dec 3 22:04:11 2009
@@ -19,6 +19,10 @@
package org.apache.cxf.maven_plugin;
+import java.io.File;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
public class WsdlOption extends Option {
@@ -26,7 +30,7 @@
* The WSDL file to process.
*/
String wsdl;
-
+
/**
* Alternatively to the wsdl string an artifact can be specified
*/
@@ -48,6 +52,47 @@
this.wsdlArtifact = wsdlArtifact;
}
+ /**
+ * Try to find a file matching the wsdl path (either absolutely, relatively to the current dir or to
+ * the project base dir)
+ *
+ * @return wsdl file
+ */
+ public File getWsdlFile(File baseDir) {
+ if (wsdl == null) {
+ return null;
+ }
+ File file = null;
+ try {
+ URI uri = new URI(wsdl);
+ if (uri.isAbsolute()) {
+ file = new File(uri);
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ if (file == null || !file.exists()) {
+ file = new File(wsdl);
+ }
+ if (!file.exists()) {
+ file = new File(baseDir, wsdl);
+ }
+ return file;
+ }
+
+ public boolean isDefServiceName() {
+ if (extraargs == null) {
+ return false;
+ }
+ for (int i = 0; i < extraargs.size(); i++) {
+ if ("-sn".equalsIgnoreCase(extraargs.get(i))) {
+ return true;
+ }
+ }
+ return false;
+
+ }
+
public int hashCode() {
if (wsdl != null) {
return wsdl.hashCode();
@@ -59,11 +104,11 @@
if (!(obj instanceof WsdlOption)) {
return false;
}
-
- WsdlOption t = (WsdlOption) obj;
+
+ WsdlOption t = (WsdlOption)obj;
return t.getWsdl().equals(getWsdl());
}
-
+
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WSDL: ").append(wsdl).append('\n');
@@ -75,4 +120,72 @@
return builder.toString();
}
+ public List<String> generateCommandLine(File outputDirFile, URI basedir, URI wsdlURI, boolean debug) {
+ List<String> list = new ArrayList<String>();
+ addList(list, "-p", true, getPackagenames());
+ addList(list, "-nexclude", true, getNamespaceExcludes());
+ addIfNotNull(list, outputDirFile, "-d");
+ for (String binding : getBindingFiles()) {
+ File bindingFile = new File(binding);
+ URI bindingURI = bindingFile.exists() ? bindingFile.toURI() : basedir.resolve(binding);
+ list.add("-b");
+ list.add(bindingURI.toString());
+ }
+ addIfNotNull(list, getFrontEnd(), "-fe");
+ addIfNotNull(list, getDataBinding(), "-db");
+ addIfNotNull(list, getWsdlVersion(), "-wv");
+ addIfNotNull(list, getCatalog(), "-catalog");
+ if (isExtendedSoapHeaders()) {
+ list.add("-exsh");
+ list.add("true");
+ }
+ addIfTrue(list, isAllowElementRefs(), "-allowElementRefs");
+ addIfTrue(list, isValidateWsdl(), "-validate");
+ addIfNotNull(list, getDefaultExcludesNamespace(), "-dex");
+ addIfNotNull(list, getDefaultNamespacePackageMapping(), "-dns");
+ addIfNotNull(list, getServiceName(), "-sn");
+ addIfTrue(list, isAutoNameResolution(), "-autoNameResolution");
+ addIfTrue(list, isNoAddressBinding(), "-noAddressBinding");
+ addList(list, "-xjc", false, getXJCargs());
+ addList(list, "", false, getExtraargs());
+ if (isSetWsdlLocation()) {
+ list.add("-wsdlLocation");
+ list.add(getWsdlLocation() == null ? "" : getWsdlLocation());
+ }
+ addIfTrue(list, isWsdlList(), "-wsdlList");
+ addIfTrue(list, debug && !list.contains("-verbose"), "-verbose");
+ list.add(wsdlURI.toString());
+ return list;
+ }
+
+ private static void addIfTrue(List<String> list, boolean expression, String key) {
+ if (expression) {
+ list.add(key);
+ }
+ }
+
+ private static void addIfNotNull(List<String> list, Object value, String key) {
+ if (value != null) {
+ list.add(key);
+ list.add(value.toString());
+ }
+ }
+
+ private static void addList(List<String> destList, String key, boolean keyAsOwnElement,
+ List<String> sourceList) {
+ if (sourceList == null) {
+ return;
+ }
+ for (String value : sourceList) {
+ if (keyAsOwnElement) {
+ destList.add(key);
+ destList.add(value);
+ } else {
+ // Maven makes empty tags into null
+ // instead of empty strings. so replace null by ""
+ destList.add(key + ((value == null) ? "" : value));
+ }
+ }
+ }
+
}