cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r810855 - in /cxf/trunk/maven-plugins/codegen-plugin: pom.xml src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java src/main/java/org/apache/cxf/maven_plugin/WsdlOption.java
Date Thu, 03 Sep 2009 09:53:50 GMT
Author: cschneider
Date: Thu Sep  3 09:53:49 2009
New Revision: 810855

URL: http://svn.apache.org/viewvc?rev=810855&view=rev
Log:
CXF-2275 Support reading WSDLs from Maven repository. Implementation finished. We still need
an automated  test

Added:
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
  (with props)
Modified:
    cxf/trunk/maven-plugins/codegen-plugin/pom.xml
    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/WsdlOption.java

Modified: cxf/trunk/maven-plugins/codegen-plugin/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/pom.xml?rev=810855&r1=810854&r2=810855&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/pom.xml (original)
+++ cxf/trunk/maven-plugins/codegen-plugin/pom.xml Thu Sep  3 09:53:49 2009
@@ -43,6 +43,16 @@
 
         <dependency>
             <groupId>org.apache.maven</groupId>
+            <artifactId>maven-core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-artifact</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
             <artifactId>maven-plugin-api</artifactId>
             <scope>provided</scope>
         </dependency>

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=810855&r1=810854&r2=810855&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
Thu Sep  3 09:53:49 2009
@@ -29,9 +29,19 @@
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.tools.common.ToolContext;
 import org.apache.cxf.tools.wsdlto.WSDLToJava;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectUtils;
 
 /**
  * @goal wsdl2java
@@ -120,6 +130,58 @@
     String excludes[];
 
     /**
+     * The local repository taken from Maven's runtime. Typically $HOME/.m2/repository.
+     * 
+     * @parameter expression="${localRepository}"
+     * @readonly
+     * @required
+     */
+    private ArtifactRepository localRepository;
+
+    /**
+     * Artifact factory, needed to create artifacts.
+     * 
+     * @component
+     * @readonly
+     * @required
+     */
+    private ArtifactFactory artifactFactory;
+
+    /**
+     * The remote repositories used as specified in your POM.
+     * 
+     * @parameter expression="${project.repositories}"
+     * @readonly
+     * @required
+     */
+    private List repositories;
+
+    /**
+     * Artifact repository factory component.
+     * 
+     * @component
+     * @readonly
+     * @required
+     */
+    private ArtifactRepositoryFactory artifactRepositoryFactory;
+
+    /**
+     * The Maven session.
+     * 
+     * @parameter expression="${session}"
+     * @readonly
+     * @required
+     */
+    private MavenSession mavenSession;
+
+    /**
+     * @component
+     * @readonly
+     * @required
+     */
+    private ArtifactResolver artifactResolver;
+
+    /**
      * Create WsdlOption objects for each wsdl file found in the root dir. includes, excludes
filter which
      * files are considered. The defaultOptions will be applied.
      * 
@@ -150,6 +212,9 @@
      * @return wsdl file
      */
     private File getFileFromWsdlPath(String wsdlPath) {
+        if (wsdlPath == null) {
+            return null;
+        }
         File file = null;
         try {
             URI uri = new URI(wsdlPath);
@@ -182,11 +247,11 @@
             }
 
             File file = getFileFromWsdlPath(o.getWsdl());
-            if (file.exists()) {
+            if (file != null && file.exists()) {
                 file = file.getAbsoluteFile();
                 for (WsdlOption o2 : effectiveWsdlOptions) {
                     File file2 = getFileFromWsdlPath(o2.getWsdl());
-                    if (file2.exists() && file2.getAbsoluteFile().equals(file)) {
+                    if (file2 != null && file2.exists() && file2.getAbsoluteFile().equals(file))
{
                         o.getExtraargs().addAll(0, o2.getExtraargs());
                         effectiveWsdlOptions.remove(o2);
                         break;
@@ -201,7 +266,7 @@
      * @return effective WsdlOptions
      * @throws MojoExecutionException
      */
-    private WsdlOption[] createWsdlOptionsFromWsdlFilesAndExplicitWsdlOptions() 
+    private List<WsdlOption> createWsdlOptionsFromWsdlFilesAndExplicitWsdlOptions()
         throws MojoExecutionException {
         List<WsdlOption> effectiveWsdlOptions = new ArrayList<WsdlOption>();
         if (wsdlRoot != null && wsdlRoot.exists()) {
@@ -214,7 +279,33 @@
         if (wsdlOptions != null) {
             mergeOptions(effectiveWsdlOptions, wsdlOptions);
         }
-        return effectiveWsdlOptions.toArray(new WsdlOption[effectiveWsdlOptions.size()]);
+        downloadRemoteWsdls(effectiveWsdlOptions);
+        return effectiveWsdlOptions;
+    }
+
+    public void downloadRemoteWsdls(List<WsdlOption> effectiveWsdlOptions) throws MojoExecutionException
{
+        List remoteRepos;
+        try {
+            remoteRepos = ProjectUtils.buildArtifactRepositories(repositories, artifactRepositoryFactory,
+                                                                 mavenSession.getContainer());
+        } catch (InvalidRepositoryException e) {
+            throw new MojoExecutionException("Error build repositories for remote wsdls",
e);
+        }
+        try {
+            for (WsdlOption wsdlOption : effectiveWsdlOptions) {
+                WsdlArtifact wsdlA = wsdlOption.getWsdlArtifact();
+                if (wsdlA != null) {
+                    Artifact artifact = artifactFactory.createArtifact(wsdlA.getGroupId(),
wsdlA
+                        .getArtifactId(), wsdlA.getVersion(), Artifact.SCOPE_COMPILE, wsdlA.getType());
+                    artifactResolver.resolve(artifact, remoteRepos, localRepository);
+                    wsdlOption.setWsdl(artifact.getFile().getAbsolutePath());
+                }
+            }
+        } catch (ArtifactResolutionException e) {
+            throw new MojoExecutionException("Error downloading wsdl artifact.", e);
+        } catch (ArtifactNotFoundException e) {
+            throw new MojoExecutionException("Resource can not be found.", e);
+        }
     }
 
     public void execute() throws MojoExecutionException {
@@ -228,9 +319,9 @@
         classesDir.mkdirs();
         markerDirectory.mkdirs();
 
-        WsdlOption[] effectiveWsdlOptions = createWsdlOptionsFromWsdlFilesAndExplicitWsdlOptions();
+        List<WsdlOption> effectiveWsdlOptions = createWsdlOptionsFromWsdlFilesAndExplicitWsdlOptions();
 
-        if (effectiveWsdlOptions.length == 0) {
+        if (effectiveWsdlOptions.size() == 0) {
             getLog().info("Nothing to generate");
             return;
         }

Added: 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=810855&view=auto
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
(added)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
Thu Sep  3 09:53:49 2009
@@ -0,0 +1,57 @@
+/**
+ * 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;
+
+public class WsdlArtifact {
+    private String groupId;
+    private String artifactId;
+    private String version;
+    private String type;
+    
+    public WsdlArtifact() {
+        type = "wsdl";
+    }
+    
+    public String getGroupId() {
+        return groupId;
+    }
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+    public String getArtifactId() {
+        return artifactId;
+    }
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+    public String getVersion() {
+        return version;
+    }
+    public void setVersion(String version) {
+        this.version = version;
+    }
+    public String getType() {
+        return type;
+    }
+    public void setType(String type) {
+        this.type = type;
+    }
+    
+}

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

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=810855&r1=810854&r2=810855&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
Thu Sep  3 09:53:49 2009
@@ -26,6 +26,11 @@
      * The WSDL file to process.
      */
     String wsdl;
+    
+    /**
+     * Alternatively to the wsdl string an artifact can be specified
+     */
+    WsdlArtifact wsdlArtifact;
 
     public String getWsdl() {
         return wsdl;
@@ -34,6 +39,14 @@
     public void setWsdl(String w) {
         wsdl = w;
     }
+
+    public WsdlArtifact getWsdlArtifact() {
+        return wsdlArtifact;
+    }
+
+    public void setWsdlArtifact(WsdlArtifact wsdlArtifact) {
+        this.wsdlArtifact = wsdlArtifact;
+    }
     
     public int hashCode() {
         if (wsdl != null) {



Mime
View raw message