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 2008/01/04 21:27:08 UTC

svn commit: r608984 - in /incubator/cxf/trunk: maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ rt/javascript/ systests/ testutils/ tools/javato/ws/

Author: dkulp
Date: Fri Jan  4 12:27:07 2008
New Revision: 608984

URL: http://svn.apache.org/viewvc?rev=608984&view=rev
Log:
Updates to codegen plugin to hopefully allow it to work correctly on OSX
Also parameterize stuff to make it more useful from command line

Modified:
    incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java
    incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
    incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java
    incubator/cxf/trunk/rt/javascript/pom.xml
    incubator/cxf/trunk/systests/pom.xml
    incubator/cxf/trunk/testutils/pom.xml
    incubator/cxf/trunk/tools/javato/ws/pom.xml

Modified: incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java?rev=608984&r1=608983&r2=608984&view=diff
==============================================================================
--- incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java (original)
+++ incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java Fri Jan  4 12:27:07 2008
@@ -24,20 +24,20 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.tools.common.ToolContext;
 import org.apache.cxf.tools.wsdlto.WSDLToJava;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
-import org.apache.tools.ant.ExitException;
-import org.apache.tools.ant.util.optional.NoExitSecurityManager;
 
 /**
  * @goal wsdl2java
@@ -46,18 +46,19 @@
 */
 public class WSDL2JavaMojo extends AbstractMojo {
     /**
-     * @parameter
+     * @parameter expression="${cxf.testSourceRoot}"
      */
-    String testSourceRoot;
+    File testSourceRoot;
 
     /**
-     * @parameter  expression="${project.build.directory}/generated/src/main/java"
+     * @parameter expression="${cxf.sourceRoot}" 
+     *             default-value="${project.build.directory}/generated/src/main/java"
      * @required
      */
-    String sourceRoot;
+    File sourceRoot;
 
     /**
-     * @parameter  expression="${project.build.outputDirectory}"
+     * @parameter expression="${project.build.outputDirectory}"
      * @required
      */
     String classesDirectory;
@@ -75,21 +76,43 @@
     WsdlOption wsdlOptions[];
 
     /**
-     * @parameter
+     * @parameter expression="${cxf.wsdlRoot}" default-value="${basedir}/src/main/resources/wsdl"
      */
-    String wsdlRoot;
-
+    File wsdlRoot;
+    
+    /**
+     * @parameter expression="${cxf.testWsdlRoot}" default-value="${basedir}/src/test/resources/wsdl"
+     */
+    File testWsdlRoot;
 
     /**
      * Use the compile classpath rather than the test classpath for execution
      * useful if the test dependencies clash with those of wsdl2java
-     * @parameter
+     * @parameter expression="${cxf.useCompileClasspath}" default-value="false"
      */
     boolean useCompileClasspath;
+    
+    /**
+     * A list of wsdl files to include. Can contain ant-style wildcards and double wildcards.  
+     * Defaults to *.wsdl
+     * @parameter
+     */
+    String includes[];
+    /**
+     * A list of wsdl files to exclude. Can contain ant-style wildcards and double wildcards.  
+     * @parameter
+     */
+    String excludes[];
+                    
 
-    private List<WsdlOption> getWsdlOptionsFromDir(final File root) throws MojoExecutionException {
+    private List<WsdlOption> getWsdlOptionsFromDir(final File root,
+                                                   final File output)
+        throws MojoExecutionException {
         List<WsdlOption> options = new ArrayList<WsdlOption>();
-        for (WsdlOption o : new WsdlOptionLoader().load(root)) {
+        for (WsdlOption o : new WsdlOptionLoader().load(root, includes, excludes)) {
+            if (o.getOutputDir() == null) {
+                o.setOutputDir(output);
+            }
             if (!options.contains(o)) {
                 options.add(o);
             }
@@ -98,30 +121,29 @@
     }
 
     public void execute() throws MojoExecutionException {
-        String outputDir = testSourceRoot == null ? sourceRoot : testSourceRoot;
-        File outputDirFile = new File(outputDir);
-        outputDirFile.mkdirs();
-
+        if (includes == null) {
+            includes = new String[] {"*.wsdl"};
+        }
+        
         File classesDir = new File(classesDirectory);
         classesDir.mkdirs();
 
         List<WsdlOption> options = new ArrayList<WsdlOption>();
-        if (wsdlRoot == null) {
-            File sourceWsdlRoot = new File(project.getBasedir(), "/src/main/resources/wsdl");
-            if (sourceWsdlRoot.exists()) {
-                options.addAll(getWsdlOptionsFromDir(sourceWsdlRoot));
-            }
-
-            File testWsdlRoot = new File(project.getBasedir(), "/src/test/resources/wsdl");
-            if (testWsdlRoot.exists()) {
-                options.addAll(getWsdlOptionsFromDir(testWsdlRoot));
-            }
-        } else {
-            options.addAll(getWsdlOptionsFromDir(new File(wsdlRoot)));
+        if (wsdlRoot != null && wsdlRoot.exists()) {
+            options.addAll(getWsdlOptionsFromDir(wsdlRoot, sourceRoot));
+        }
+        if (testWsdlRoot != null && testWsdlRoot.exists()) {
+            options.addAll(getWsdlOptionsFromDir(testWsdlRoot, testSourceRoot));
         }
 
         if (wsdlOptions != null) {
-            options.addAll(Arrays.asList(wsdlOptions));
+            File outputDirFile = testSourceRoot == null ? sourceRoot : testSourceRoot;
+            for (WsdlOption o : wsdlOptions) {
+                if (o.getOutputDir() == null) {
+                    o.setOutputDir(outputDirFile);
+                }
+                options.add(o);
+            }
         }
         wsdlOptions = options.toArray(new WsdlOption[options.size()]);
 
@@ -163,24 +185,28 @@
                                                    origContext);
         String newCp = buf.toString();
 
+        //with some VM's, creating an XML parser (which we will do to parse wsdls)
+        //will set some system properties that then interferes with mavens 
+        //dependency resolution.  (OSX is the major culprit here)
+        //We'll save the props and then set them back later.
+        Map<Object, Object> origProps = new HashMap<Object, Object>(System.getProperties());
+        
         String cp = System.getProperty("java.class.path");
-        SecurityManager oldSm = System.getSecurityManager();
         long timestamp = CodegenUtils.getCodegenTimestamp();
         boolean result = true;
         
         try {
             Thread.currentThread().setContextClassLoader(loader);
             System.setProperty("java.class.path", newCp);
-            System.setSecurityManager(new NoExitSecurityManager());
-            for (int x = 0; x < wsdlOptions.length; x++) {
-                processWsdl(wsdlOptions[x], outputDirFile, timestamp);
+            for (WsdlOption o : wsdlOptions) {
+                processWsdl(o, timestamp);
 
-                File dirs[] = wsdlOptions[x].getDeleteDirs();
+                File dirs[] = o.getDeleteDirs();
                 if (dirs != null) {
                     for (int idx = 0; idx < dirs.length; ++idx) {
                         result = result && deleteDir(dirs[idx]);
                     }
-                }
+                }                
             }
         } finally {
             //cleanup as much as we can.
@@ -189,22 +215,32 @@
                 bus.shutdown(true);
             }
             Thread.currentThread().setContextClassLoader(origContext);
-            System.setSecurityManager(oldSm);
             System.setProperty("java.class.path", cp);
+            
+            Map<Object, Object> newProps = new HashMap<Object, Object>(System.getProperties());
+            for (Object o : newProps.keySet()) {
+                if (!origProps.containsKey(o)) {
+                    System.clearProperty(o.toString());
+                }
+            }
+            System.getProperties().putAll(origProps);
         }
-        if (project != null && sourceRoot != null) {
-            project.addCompileSourceRoot(sourceRoot);
+        if (project != null && sourceRoot != null && sourceRoot.exists()) {
+            project.addCompileSourceRoot(sourceRoot.getAbsolutePath());
         }
-        if (project != null && testSourceRoot != null) {
-            project.addTestCompileSourceRoot(testSourceRoot);
+        if (project != null && testSourceRoot != null && testSourceRoot.exists()) {
+            project.addTestCompileSourceRoot(testSourceRoot.getAbsolutePath());
         }
 
         System.gc();
     }
 
     private void processWsdl(WsdlOption wsdlOption,
-                             File outputDirFile,
                              long cgtimestamp) throws MojoExecutionException {
+        
+        File outputDirFile = wsdlOption.getOutputDir();
+        outputDirFile.mkdirs();
+        
         File file = new File(wsdlOption.getWsdl());
         // If URL to WSDL, replace ? and & since they're invalid chars for file names
         File doneFile =
@@ -253,26 +289,7 @@
 
 
             try {
-                String exitOnFinish = System.getProperty("exitOnFinish", "");
-
-                try {
-                    StringBuffer strBuffer = new StringBuffer();
-                    for (int i = 0; i < list.size(); i++) {
-                        strBuffer.append(list.get(i));
-                        strBuffer.append(" ");
-                    }
-                    System.setProperty("exitOnFinish", "YES");
-                    WSDLToJava.main((String[])list.toArray(new String[list.size()]));
-                    doneFile.createNewFile();
-                } catch (ExitException e) {
-                    if (e.getStatus() == 0) {
-                        doneFile.createNewFile();
-                    } else {
-                        throw e;
-                    }
-                } finally {
-                    System.setProperty("exitOnFinish", exitOnFinish);
-                }
+                new WSDLToJava((String[])list.toArray(new String[list.size()])).run(new ToolContext());
             } catch (Throwable e) {
                 getLog().debug(e);
                 throw new MojoExecutionException(e.getMessage(), e);

Modified: incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java?rev=608984&r1=608983&r2=608984&view=diff
==============================================================================
--- incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java (original)
+++ incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java Fri Jan  4 12:27:07 2008
@@ -27,6 +27,7 @@
     String wsdl;
     List<String> packagenames;
     List<String> extraargs = new ArrayList<String>();
+    File outputDir;
     File dependencies[];
     File redundantDirs[];
 
@@ -64,6 +65,13 @@
     }
     public File[] getDeleteDirs() {
         return redundantDirs;
+    }
+    
+    public File getOutputDir() {
+        return outputDir;
+    }
+    public void setOutputDir(File f) {
+        outputDir = f;
     }
     
     public int hashCode() {

Modified: incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java?rev=608984&r1=608983&r2=608984&view=diff
==============================================================================
--- incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java (original)
+++ incubator/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java Fri Jan  4 12:27:07 2008
@@ -20,10 +20,12 @@
 package org.apache.cxf.maven_plugin;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.maven.plugin.MojoExecutionException;
 
@@ -33,15 +35,34 @@
  */
 
 public final class WsdlOptionLoader {
-    private static final String WSDL_SUFFIX = ".+\\.wsdl$";
     private static final String WSDL_OPTIONS = "-options$";
     private static final String WSDL_BINDINGS = "-binding-?\\d*.xml$";
 
+    
+    private String getIncludeExcludeString(String[] arr) {
+        if (arr == null) {
+            return "";
+        }
+        StringBuilder str = new StringBuilder();
+
+        if (arr != null) {
+            for (String s : arr) {
+                if (str.length() > 0) {
+                    str.append(',');
+                }
+                str.append(s);
+            }
+        }
+        return str.toString();
+    }
+    
     public List<WsdlOption> load(String wsdlRoot) throws MojoExecutionException {
-        return load(new File(wsdlRoot));
+        return load(new File(wsdlRoot), new String[] {"*.wsdl"}, null);
     }
 
-    public List<WsdlOption> load(File wsdlBasedir) throws MojoExecutionException {
+    public List<WsdlOption> load(File wsdlBasedir, String includes[], String excludes[])
+        throws MojoExecutionException {
+        
         if (wsdlBasedir == null) {
             return new ArrayList<WsdlOption>();
         }
@@ -50,11 +71,27 @@
             throw new MojoExecutionException(wsdlBasedir + " not exists");
         }
 
-        return findJobs(wsdlBasedir, getWsdlFiles(wsdlBasedir));
+        return findJobs(wsdlBasedir, getWsdlFiles(wsdlBasedir, includes, excludes));
     }
 
-    private List<File> getWsdlFiles(File dir) {
-        return FileUtils.getFiles(dir, WSDL_SUFFIX);
+    private List<File> getWsdlFiles(File dir, String includes[], String excludes[])
+        throws MojoExecutionException {
+        
+        List<String> exList = new ArrayList<String>();
+        if (excludes != null) {
+            exList.addAll(Arrays.asList(excludes));
+        }
+        exList.addAll(Arrays.asList(org.codehaus.plexus.util.FileUtils.getDefaultExcludes()));
+        
+        String inc = getIncludeExcludeString(includes);
+        String ex = getIncludeExcludeString(exList.toArray(new String[exList.size()]));
+        
+        try {
+            List newfiles = org.codehaus.plexus.util.FileUtils.getFiles(dir, inc, ex);
+            return CastUtils.cast(newfiles);
+        } catch (IOException exc) {
+            throw new MojoExecutionException(exc.getMessage(), exc);
+        }
     }
 
     private File getOptions(File dir, String pattern) {

Modified: incubator/cxf/trunk/rt/javascript/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/pom.xml?rev=608984&r1=608983&r2=608984&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/pom.xml (original)
+++ incubator/cxf/trunk/rt/javascript/pom.xml Fri Jan  4 12:27:07 2008
@@ -178,7 +178,7 @@
                         <phase>generate-test-sources</phase>
                         <configuration>
                             <testSourceRoot>${basedir}/target/generated/src/test/java</testSourceRoot>
-			    <wsdlRoot>${basedir}/src/test/resources/wsdl</wsdlRoot>
+                            <testWsdlRoot>${basedir}/src/test/resources/wsdl</testWsdlRoot>
                         </configuration>
                         <goals>
                             <goal>wsdl2java</goal>

Modified: incubator/cxf/trunk/systests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/pom.xml?rev=608984&r1=608983&r2=608984&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/pom.xml (original)
+++ incubator/cxf/trunk/systests/pom.xml Fri Jan  4 12:27:07 2008
@@ -66,7 +66,7 @@
                         <phase>generate-test-sources</phase>
                         <configuration>
                             <testSourceRoot>${basedir}/target/generated/src/test/java</testSourceRoot>
-			    <wsdlRoot>${basedir}/src/test/resources/wsdl</wsdlRoot>
+                            <testWsdlRoot>${basedir}/src/test/resources/wsdl</testWsdlRoot>
                         </configuration>
                         <goals>
                             <goal>wsdl2java</goal>

Modified: incubator/cxf/trunk/testutils/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/pom.xml?rev=608984&r1=608983&r2=608984&view=diff
==============================================================================
--- incubator/cxf/trunk/testutils/pom.xml (original)
+++ incubator/cxf/trunk/testutils/pom.xml Fri Jan  4 12:27:07 2008
@@ -168,7 +168,7 @@
                         <phase>generate-sources</phase>
                         <configuration>
                             <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
-			    <wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot>
+                            <wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot>
                             <wsdlOptions>
                                 <wsdlOption>
                                     <wsdl>

Modified: incubator/cxf/trunk/tools/javato/ws/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/javato/ws/pom.xml?rev=608984&r1=608983&r2=608984&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/javato/ws/pom.xml (original)
+++ incubator/cxf/trunk/tools/javato/ws/pom.xml Fri Jan  4 12:27:07 2008
@@ -185,7 +185,7 @@
                         <phase>generate-test-sources</phase>
                         <configuration>
                             <testSourceRoot>${basedir}/target/generated/src/test/java</testSourceRoot>
-			    <wsdlRoot>${basedir}/src/test/resources/java2wsdl_wsdl</wsdlRoot>
+                            <testWsdlRoot>${basedir}/src/test/resources/java2wsdl_wsdl</testWsdlRoot>
                         </configuration>
                         <goals>
                             <goal>wsdl2java</goal>