cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r886944 - in /cxf/branches/2.2.x-fixes: ./ maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ maven-plugins/codegen-plugin/src/test/java/ maven-plugins/codegen-plugin/src/test/java/org/ maven-plugins/codegen-plugin/src/...
Date Thu, 03 Dec 2009 22:08:37 GMT
Author: dkulp
Date: Thu Dec  3 22:08:36 2009
New Revision: 886944

URL: http://svn.apache.org/viewvc?rev=886944&view=rev
Log:
Merged revisions 885211 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r885211 | cschneider | 2009-11-29 06:03:29 -0500 (Sun, 29 Nov 2009) | 1 line
  
  CXF-2275: Maven plugins: Support reading WSDLs from Maven repository - Should be complete
now
........

Added:
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/BindingFileHelper.java
      - copied unchanged from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/BindingFileHelper.java
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/test/java/
      - copied from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/test/java/
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/test/java/org/
      - copied from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/test/java/org/apache/
      - copied from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/
      - copied from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/
      - copied from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/BindingFileHelperTest.java
      - copied unchanged from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/BindingFileHelperTest.java
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/test/resources/
      - copied from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/test/resources/bindingWithWsdlLocation.xml
      - copied unchanged from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithWsdlLocation.xml
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/test/resources/bindingWithoutWsdlLocation.xml
      - copied unchanged from r885211, cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithoutWsdlLocation.xml
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/Option.java
    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/WsdlArtifact.java
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
    cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.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/Option.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/Option.java?rev=886944&r1=886943&r2=886944&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java
(original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java
Thu Dec  3 22:08:36 2009
@@ -25,6 +25,8 @@
 
 
 public class Option {
+    static final String DEFAULT_BINDING_FILE_PATH = "src" + File.separator + "main"
+        + File.separator + "resources" + File.separator + "defaultBinding.xml";
 
     /**
      * As maven will set null for an empty parameter we need
@@ -36,7 +38,7 @@
     /**
      * 
      */
-    protected List<String> packagenames;
+    protected List<String> packagenames = new ArrayList<String>();
 
     /**
      * Extra arguments to pass to the command-line code generator. For compatibility as well
as to
@@ -60,7 +62,7 @@
      * Also, optionally specifies the Java package name used by types described in the excluded

      * namespace(s) using schema-namespace[=java-packagename]
      */
-    List<String> namespaceExcludes;
+    List<String> namespaceExcludes = new ArrayList<String>();
 
     /**
      * Enables or disables the loading of the default excludes namespace mapping. Default
is true.
@@ -225,7 +227,14 @@
         String tmp[] = new String[bindingFiles.length + 1];
         System.arraycopy(bindingFiles, 0, tmp, 0, bindingFiles.length);
         bindingFiles = tmp;
-        bindingFiles[bindingFiles.length - 1] = file.toURI().toString();
+        bindingFiles[bindingFiles.length - 1] = file.getAbsolutePath();
+    }
+    
+    public void addDefaultBindingFileIfExists(File baseDir) {
+        File defaultBindingFile = new File(baseDir, DEFAULT_BINDING_FILE_PATH);
+        if (defaultBindingFile.exists()) {
+            addBindingFile(defaultBindingFile);
+        }
     }
 
     public void setWsdlLocation(String s) {
@@ -369,65 +378,35 @@
         }
         destination.setWsdlVersion(getWsdlVersion());
     }
-    public void merge(Option defaultOptions) {
-        if (wsdlList == null) {
-            wsdlList = defaultOptions.wsdlList;
-        }
-        if (extendedSoapHeaders == null) {
-            extendedSoapHeaders = defaultOptions.extendedSoapHeaders;
-        }
-        if (validateWsdl == null) {
-            validateWsdl = defaultOptions.validateWsdl;
-        }
-        if (autoNameResolution == null) {
-            autoNameResolution = defaultOptions.autoNameResolution;
-        }
-        if (noAddressBinding == null) {
-            noAddressBinding = defaultOptions.noAddressBinding;
-        }
-        if (allowElementRefs == null) {
-            allowElementRefs = defaultOptions.allowElementRefs;
-        }
-        if (defaultExcludesNamespace == null) {
-            defaultExcludesNamespace = defaultOptions.defaultExcludesNamespace;
-        }
-        if (defaultNamespacePackageMapping == null) {
-            defaultNamespacePackageMapping = defaultOptions.defaultNamespacePackageMapping;
-        }
-        if (frontEnd == null) {
-            frontEnd = defaultOptions.frontEnd;
-        }
-        if (dataBinding == null) {
-            dataBinding = defaultOptions.dataBinding;
-        }
-        if (wsdlVersion == null) {
-            wsdlVersion = defaultOptions.wsdlVersion;
-        }
-        if (catalog == null) {
-            catalog = defaultOptions.catalog;
-        }
-        if (serviceName == null) {
-            serviceName = defaultOptions.serviceName;
-        }
-        if (outputDir == null) {
-            outputDir = defaultOptions.outputDir;
+    
+    private void setIfNull(Object dest, Object source) {
+        if (dest == null) {
+            dest = source;
         }
+    }
+    
+    public void merge(Option defaultOptions) {
+        setIfNull(wsdlList, defaultOptions.wsdlList);
+        setIfNull(extendedSoapHeaders, defaultOptions.extendedSoapHeaders);
+        setIfNull(validateWsdl, defaultOptions.validateWsdl);
+        setIfNull(autoNameResolution, defaultOptions.autoNameResolution);
+        setIfNull(noAddressBinding, defaultOptions.noAddressBinding);
+        setIfNull(allowElementRefs, defaultOptions.allowElementRefs);
+        setIfNull(defaultExcludesNamespace, defaultOptions.defaultExcludesNamespace);
+        setIfNull(defaultNamespacePackageMapping, defaultOptions.defaultNamespacePackageMapping);
+        setIfNull(frontEnd, defaultOptions.frontEnd);
+        setIfNull(dataBinding, defaultOptions.dataBinding);
+        setIfNull(wsdlVersion, defaultOptions.wsdlVersion);
+        setIfNull(catalog, defaultOptions.catalog);
+        setIfNull(serviceName, defaultOptions.serviceName);
+        setIfNull(outputDir, defaultOptions.outputDir);
         extraargs.addAll(defaultOptions.extraargs);
         xjcargs.addAll(defaultOptions.xjcargs);
-        
         bindingFiles = mergeList(bindingFiles, defaultOptions.bindingFiles, String.class);
         dependencies = mergeList(dependencies, defaultOptions.dependencies, File.class);
         redundantDirs = mergeList(redundantDirs, defaultOptions.redundantDirs, File.class);
-        if (packagenames == null) {
-            packagenames = defaultOptions.packagenames;
-        } else {
-            packagenames.addAll(defaultOptions.packagenames);
-        }
-        if (namespaceExcludes == null) {
-            namespaceExcludes = defaultOptions.namespaceExcludes;
-        } else {
-            namespaceExcludes.addAll(defaultOptions.namespaceExcludes);
-        }
+        packagenames.addAll(defaultOptions.packagenames);
+        namespaceExcludes.addAll(defaultOptions.namespaceExcludes);
     }
     
     @SuppressWarnings("unchecked")

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=886944&r1=886943&r2=886944&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:08:36 2009
@@ -50,6 +50,8 @@
  * @requiresDependencyResolution test
  */
 public class WSDL2JavaMojo extends AbstractMojo {
+    private static final String TEMPBINDINGS_DIR = "tempbindings";
+
     /**
      * @parameter expression="${cxf.testSourceRoot}"
      */
@@ -81,7 +83,7 @@
      * 
      * @parameter
      */
-    Option defaultOptions;
+    Option defaultOptions = new Option();
 
     /**
      * @parameter
@@ -125,6 +127,12 @@
     boolean disableDirectoryScan;
 
     /**
+     * By default all maven dependencies of type "wsdl" are added to the effective wsdlOptions.
Setting this
+     * parameter to true disables this functionality
+     */
+    boolean disableDependencyScan;
+
+    /**
      * A list of wsdl files to include. Can contain ant-style wildcards and double wildcards.
Defaults to
      * *.wsdl
      * 
@@ -232,21 +240,32 @@
      * @return effective WsdlOptions
      * @throws MojoExecutionException
      */
-    private List<WsdlOption> createWsdlOptionsFromWsdlFilesAndExplicitWsdlOptions()
+    private List<WsdlOption> createWsdlOptionsFromScansAndExplicitWsdlOptions() 
         throws MojoExecutionException {
         List<WsdlOption> effectiveWsdlOptions = new ArrayList<WsdlOption>();
+        List<WsdlOption> temp;
         if (wsdlRoot != null && wsdlRoot.exists() && !disableDirectoryScan)
{
-            effectiveWsdlOptions.addAll(WsdlOptionLoader.loadWsdlOptionsFromFiles(wsdlRoot,
includes,
-                                                                                  excludes,
defaultOptions,
-                                                                                  sourceRoot));
+            temp = WsdlOptionLoader.loadWsdlOptionsFromFiles(wsdlRoot, includes, excludes,
defaultOptions,
+                                                             sourceRoot);
+            effectiveWsdlOptions.addAll(temp);
         }
         if (testWsdlRoot != null && testWsdlRoot.exists() && !disableDirectoryScan)
{
-            effectiveWsdlOptions.addAll(WsdlOptionLoader.loadWsdlOptionsFromFiles(testWsdlRoot,
includes,
-                                                                                  excludes,
defaultOptions,
-                                                                                  testSourceRoot));
+            temp = WsdlOptionLoader.loadWsdlOptionsFromFiles(testWsdlRoot, includes, excludes,
+                                                             defaultOptions, testSourceRoot);
+            effectiveWsdlOptions.addAll(temp);
+        }
+        if (!disableDependencyScan) {
+            temp = WsdlOptionLoader.loadWsdlOptionsFromDependencies(project, defaultOptions,
sourceRoot);
+            effectiveWsdlOptions.addAll(temp);
         }
         mergeOptions(effectiveWsdlOptions);
         downloadRemoteWsdls(effectiveWsdlOptions);
+        String buildDir = project.getBuild().getDirectory();
+        File tempBindingDir = new File(buildDir, TEMPBINDINGS_DIR);
+        for (WsdlOption o : effectiveWsdlOptions) {
+            BindingFileHelper.setWsdlLocationInBindingsIfNotSet(project.getBasedir(), tempBindingDir,
o,
+                                                                getLog());
+        }
         return effectiveWsdlOptions;
     }
     
@@ -300,9 +319,9 @@
             if (wsdlA == null) {
                 return;
             }
-            Artifact wsdlArtifact = artifactFactory.createArtifact(wsdlA.getGroupId(), wsdlA
-                                                               .getArtifactId(), wsdlA.getVersion(),

-                                                               Artifact.SCOPE_COMPILE, wsdlA.getType());
+            Artifact wsdlArtifact = artifactFactory.createArtifact(wsdlA.getGroupId(), wsdlA.getArtifactId(),
+                                                                   wsdlA.getVersion(),
+                                                                   Artifact.SCOPE_COMPILE,
wsdlA.getType());
             wsdlArtifact = resolveRemoteWsdlArtifact(remoteRepos, wsdlArtifact);
             if (wsdlArtifact != null) {
                 String path = wsdlArtifact.getFile().getAbsolutePath();
@@ -318,12 +337,12 @@
                 "*.wsdl"
             };
         }
-
+        defaultOptions.addDefaultBindingFileIfExists(project.getBasedir());
         File classesDir = new File(classesDirectory);
         classesDir.mkdirs();
         markerDirectory.mkdirs();
 
-        List<WsdlOption> effectiveWsdlOptions = createWsdlOptionsFromWsdlFilesAndExplicitWsdlOptions();
+        List<WsdlOption> effectiveWsdlOptions = createWsdlOptionsFromScansAndExplicitWsdlOptions();
 
         if (effectiveWsdlOptions.size() == 0) {
             getLog().info("Nothing to generate");
@@ -368,11 +387,8 @@
     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 = wsdlFile.exists() ? wsdlFile.toURI() : basedir.resolve(wsdlLocation);
+        URI wsdlURI = wsdlOption.getWsdlURI(basedir);
         File doneFile = getDoneFile(basedir, wsdlURI);
 
         if (!shouldRun(wsdlOption, doneFile, wsdlURI)) {
@@ -380,11 +396,12 @@
         }
         
         doneFile.delete();
-        List<String> list = wsdlOption.generateCommandLine(outputDirFile, basedir,
wsdlURI, 
-                                                           getLog().isDebugEnabled());
-        getLog().debug("Calling wsdl2java with args: " + list);
+        List<String> list = wsdlOption.generateCommandLine(outputDirFile, basedir,
wsdlURI, getLog()
+            .isDebugEnabled());
+        String[] args = (String[])list.toArray(new String[list.size()]);
+        getLog().debug("Calling wsdl2java with args: " + args);
         try {
-            new WSDLToJava((String[])list.toArray(new String[list.size()])).run(new ToolContext());
+            new WSDLToJava(args).run(new ToolContext());
         } catch (Throwable e) {
             getLog().debug(e);
             throw new MojoExecutionException(e.getMessage(), e);

Modified: cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.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/WsdlArtifact.java?rev=886944&r1=886943&r2=886944&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
(original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
Thu Dec  3 22:08:36 2009
@@ -57,4 +57,9 @@
         this.type = type;
     }
     
+    public boolean doesMatch(WsdlArtifact artifact) {
+        return type.equals(artifact.getType()) && groupId.equals(artifact.getGroupId())
+              && artifactId.equals(artifact.getArtifactId()) 
+              && (version == null || version.equals(artifact.getVersion()));
+    }
 }

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=886944&r1=886943&r2=886944&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:08:36 2009
@@ -79,6 +79,12 @@
         }
         return file;
     }
+    
+    public URI getWsdlURI(URI baseURI) {
+        String wsdlLocation = getWsdl();
+        File wsdlFile = new File(wsdlLocation);
+        return wsdlFile.exists() ? wsdlFile.toURI() : baseURI.resolve(wsdlLocation);
+    }
 
     public boolean isDefServiceName() {
         if (extraargs == null) {

Modified: cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.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/WsdlOptionLoader.java?rev=886944&r1=886943&r2=886944&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java
(original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java
Thu Dec  3 22:08:36 2009
@@ -24,17 +24,53 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.FileUtils;
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
 
 public final class WsdlOptionLoader {
+    private static final String WSDL_TYPE = "wsdl";
     private static final String WSDL_OPTIONS = "-options$";
     private static final String WSDL_BINDINGS = "-binding-?\\d*.xml$";
     
     private WsdlOptionLoader() {
     }
+    
+    @SuppressWarnings("unchecked")
+    public static List<WsdlOption> loadWsdlOptionsFromDependencies(MavenProject project,

+                                                                   Option defaultOptions,
File outputDir) {
+        List<WsdlOption> options = new ArrayList<WsdlOption>();
+        Set<Artifact> dependencies = project.getDependencyArtifacts();
+        for (Artifact artifact : dependencies) {
+            WsdlOption option = generateWsdlOptionFromArtifact(artifact, outputDir);
+            if (option != null) {
+                if (defaultOptions != null) {
+                    option.merge(defaultOptions);
+                }
+                options.add(option);
+            }
+        }
+        return options;
+    }
+
+    private static WsdlOption generateWsdlOptionFromArtifact(Artifact artifact, File outputDir)
{
+        if (!WSDL_TYPE.equals(artifact.getType())) {
+            return null;
+        }
+        WsdlOption option = new WsdlOption();
+        WsdlArtifact wsdlArtifact = new WsdlArtifact();
+        wsdlArtifact.setArtifactId(artifact.getArtifactId());
+        wsdlArtifact.setGroupId(artifact.getGroupId());
+        wsdlArtifact.setType(artifact.getType());
+        wsdlArtifact.setVersion(artifact.getVersion());
+        option.setWsdlArtifact(wsdlArtifact);
+        option.setOutputDir(outputDir);
+        return option;
+    }
 
     /**
      * Scan files in a directory and generate one wsdlOption per file found. Extra args for
code generation



Mime
View raw message