You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2009/11/29 12:03:30 UTC

svn commit: r885211 - in /cxf/trunk/maven-plugins/codegen-plugin/src: main/java/org/apache/cxf/maven_plugin/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/cxf/ test/java/org/apache/cxf/maven_plugin/ test/resources/

Author: cschneider
Date: Sun Nov 29 11:03:29 2009
New Revision: 885211

URL: http://svn.apache.org/viewvc?rev=885211&view=rev
Log:
CXF-2275: Maven plugins: Support reading WSDLs from Maven repository - Should be complete now

Added:
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/BindingFileHelper.java   (with props)
    cxf/trunk/maven-plugins/codegen-plugin/src/test/java/
    cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/
    cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/
    cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/
    cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/
    cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/BindingFileHelperTest.java   (with props)
    cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/
    cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithWsdlLocation.xml   (with props)
    cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithoutWsdlLocation.xml   (with props)
Modified:
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java

Added: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/BindingFileHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/BindingFileHelper.java?rev=885211&view=auto
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/BindingFileHelper.java (added)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/BindingFileHelper.java Sun Nov 29 11:03:29 2009
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.maven_plugin;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.URI;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+
+public final class BindingFileHelper {
+    static final String LOCATION_ATTR_NAME = "wsdlLocation";
+    
+    private BindingFileHelper() {
+    }
+
+    static Document readDocument(InputStream is) throws Exception {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        Document doc = db.parse(is);
+        doc.getDocumentElement().normalize();
+        return doc;
+    }
+
+    /**
+     * Reads bindingFile from given stream, sets the attribute wsdlLocation on the top element bindings to the
+     * given wsdlLocation and writes the resulting binding file to outBindingFile
+     * 
+     * @param bindingFileStream
+     * @param wsdlLocation
+     * @param outBindingFile
+     * @throws Exception
+     */
+    public static boolean setWsdlLocationAndWrite(InputStream bindingFileStream, URI wsdlLocation,
+                                               File outBindingFile) throws Exception {
+        Document doc = readDocument(bindingFileStream);
+
+        // Find and set wsdlLocation
+        Element bindings = doc.getDocumentElement();
+        String oldLocation = bindings.getAttribute(LOCATION_ATTR_NAME);
+        if (oldLocation != null && !"".equals(oldLocation)) {
+            return false;
+        }
+        bindings.setAttribute(LOCATION_ATTR_NAME, wsdlLocation.toURL().toExternalForm());
+
+        // Save to outBindingFile
+        TransformerFactory transformerFactory = TransformerFactory.newInstance();
+        Transformer transformer = transformerFactory.newTransformer();
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+        DOMSource source = new DOMSource(doc);
+
+        if (!outBindingFile.exists()) {
+            outBindingFile.getParentFile().mkdirs();
+        }
+        FileOutputStream fos = new FileOutputStream(outBindingFile);
+        StreamResult result = new StreamResult(fos);
+        transformer.transform(source, result);
+        return true;
+    }
+
+    static void setWsdlLocationInBindingsIfNotSet(File baseDir, File outDir, WsdlOption o, Log log) 
+        throws MojoExecutionException {
+        try {
+            String[] bindingFiles = o.getBindingFiles();
+            for (int c = 0; c < bindingFiles.length; c++) {
+                String bindingFilePath = bindingFiles[c];
+                File bindingFile = new File(bindingFilePath);
+                File outFile =  new File(outDir, "" + c + "-" + bindingFile.getName());
+                URI wsdlLocation = o.getWsdlURI(baseDir.toURI());
+                FileInputStream is = new FileInputStream(bindingFile);
+                boolean wasSet = setWsdlLocationAndWrite(is, wsdlLocation, outFile);
+                if (log != null) {
+                    log.info("Checked binding file " + bindingFilePath + " " + wasSet);
+                }
+                if (wasSet) {
+                    bindingFiles[c] = outFile.getAbsolutePath();
+                }
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Error setting wsdlLocation in binding file", e);
+        }
+    }
+
+}

Propchange: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/BindingFileHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java?rev=885211&r1=885210&r2=885211&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java (original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/Option.java Sun Nov 29 11:03:29 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/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java?rev=885211&r1=885210&r2=885211&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java (original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java Sun Nov 29 11:03:29 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/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java?rev=885211&r1=885210&r2=885211&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java (original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java Sun Nov 29 11:03:29 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/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java?rev=885211&r1=885210&r2=885211&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java (original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java Sun Nov 29 11:03:29 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/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java?rev=885211&r1=885210&r2=885211&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java (original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java Sun Nov 29 11:03:29 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

Added: cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/BindingFileHelperTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/BindingFileHelperTest.java?rev=885211&view=auto
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/BindingFileHelperTest.java (added)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/BindingFileHelperTest.java Sun Nov 29 11:03:29 2009
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.maven_plugin;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URI;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+public class BindingFileHelperTest extends TestCase {
+    private static final File OUTFILE = new File("target/test-data/testbinding.xml");
+    private static final String TEST_WSDL_URL = "http://testwsdl";
+
+    public void testBindingWithWsdlLocation() throws Exception {
+        try {
+            OUTFILE.delete();
+        } catch (Exception e) {
+            // Do not fail if delete fails
+        }
+        InputStream is = this.getClass().getResourceAsStream("/bindingWithWsdlLocation.xml");
+        boolean wasSet = BindingFileHelper.setWsdlLocationAndWrite(is, new URI(TEST_WSDL_URL), OUTFILE);
+        Assert.assertFalse("This binding file should not be changed", wasSet);
+        Assert.assertFalse(OUTFILE.exists());
+    }
+
+    public void testBindingWithoutWsdlLocation() throws Exception {
+        try {
+            OUTFILE.delete();
+        } catch (Exception e) {
+            // Do not fail if delete fails
+        }
+        InputStream is = this.getClass().getResourceAsStream("/bindingWithoutWsdlLocation.xml");
+        BindingFileHelper.setWsdlLocationAndWrite(is, new URI(TEST_WSDL_URL), OUTFILE);
+
+        Document doc = BindingFileHelper.readDocument(new FileInputStream(OUTFILE));
+        Element bindings = doc.getDocumentElement();
+        String location = bindings.getAttribute(BindingFileHelper.LOCATION_ATTR_NAME);
+        Assert.assertEquals(TEST_WSDL_URL, location);
+    }
+
+    public void testSetBindingForWsdlOption() throws MojoExecutionException {
+        WsdlOption o = new WsdlOption();
+        o.setWsdl("test.wsdl");
+        File baseDir = new File(".");
+        File tempDir = new File(baseDir, "target" + File.separator + "tempbindings");
+        File bindingFile = new File(baseDir, "src/test/resources/bindingWithoutWsdlLocation.xml");
+        o.setBindingFiles(new String[] {
+            bindingFile.getAbsolutePath()
+        });
+
+        BindingFileHelper.setWsdlLocationInBindingsIfNotSet(baseDir, tempDir, o, null);
+        String bindingFilePath = o.getBindingFiles()[0];
+        File expectedBindingFile = new File(tempDir, "0-bindingWithoutWsdlLocation.xml");
+        Assert.assertEquals("Binding file should be the temp file", expectedBindingFile.getAbsolutePath(),
+                            bindingFilePath);
+    }
+}

Propchange: cxf/trunk/maven-plugins/codegen-plugin/src/test/java/org/apache/cxf/maven_plugin/BindingFileHelperTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithWsdlLocation.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithWsdlLocation.xml?rev=885211&view=auto
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithWsdlLocation.xml (added)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithWsdlLocation.xml Sun Nov 29 11:03:29 2009
@@ -0,0 +1,16 @@
+<jaxws:bindings wsdlLocation="CustomerService.wsdl"
+          xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
+          xmlns:xs="http://www.w3.org/2001/XMLSchema"
+          xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
+          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+  <jaxws:bindings  node="wsdl:definitions/wsdl:types/xs:schema">
+      <jxb:globalBindings>
+        <jxb:javaType name="java.util.Date" xmlType="xs:dateTime"
+                      parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDateTime"
+                      printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDateTime"/>
+        <jxb:javaType name="java.util.Date" xmlType="xs:date"
+                      parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDate"
+                      printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDate"/>
+      </jxb:globalBindings>
+  </jaxws:bindings>
+</jaxws:bindings>
\ No newline at end of file

Propchange: cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithWsdlLocation.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithoutWsdlLocation.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithoutWsdlLocation.xml?rev=885211&view=auto
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithoutWsdlLocation.xml (added)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithoutWsdlLocation.xml Sun Nov 29 11:03:29 2009
@@ -0,0 +1,16 @@
+<jaxws:bindings wsdlLocation=""
+          xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
+          xmlns:xs="http://www.w3.org/2001/XMLSchema"
+          xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
+          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+  <jaxws:bindings  node="wsdl:definitions/wsdl:types/xs:schema">
+      <jxb:globalBindings>
+        <jxb:javaType name="java.util.Date" xmlType="xs:dateTime"
+                      parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDateTime"
+                      printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDateTime"/>
+        <jxb:javaType name="java.util.Date" xmlType="xs:date"
+                      parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDate"
+                      printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDate"/>
+      </jxb:globalBindings>
+  </jaxws:bindings>
+</jaxws:bindings>
\ No newline at end of file

Propchange: cxf/trunk/maven-plugins/codegen-plugin/src/test/resources/bindingWithoutWsdlLocation.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain