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/09/15 11:48:48 UTC

svn commit: r815243 - in /cxf/trunk/maven-plugins/codegen-plugin: pom.xml src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java

Author: cschneider
Date: Tue Sep 15 09:48:48 2009
New Revision: 815243

URL: http://svn.apache.org/viewvc?rev=815243&view=rev
Log:
CXF-2275 Added resolving wsdl artifacts by using the maven reactor

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

Modified: cxf/trunk/maven-plugins/codegen-plugin/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/pom.xml?rev=815243&r1=815242&r2=815243&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/pom.xml (original)
+++ cxf/trunk/maven-plugins/codegen-plugin/pom.xml Tue Sep 15 09:48:48 2009
@@ -40,7 +40,11 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
-
+    	<dependency>
+      		<groupId>org.apache.maven.shared</groupId>
+      		<artifactId>maven-artifact-resolver</artifactId>
+      		<version>1.0-SNAPSHOT</version>
+    	</dependency>
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-core</artifactId>

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=815243&r1=815242&r2=815243&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 Tue Sep 15 09:48:48 2009
@@ -24,6 +24,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -282,6 +283,42 @@
         downloadRemoteWsdls(effectiveWsdlOptions);
         return effectiveWsdlOptions;
     }
+    
+    @SuppressWarnings("unchecked")
+    public Artifact resolveRemoteWsdlArtifact(List remoteRepos, Artifact artifact) 
+        throws MojoExecutionException {
+        
+        /**
+         * First try to find the artifact in the reactor projects of the maven session.
+         * So an artifact that is not yet built can be resolved
+         */
+        List<MavenProject> rProjects = mavenSession.getSortedProjects();
+        for (MavenProject rProject : rProjects) {
+            if (artifact.getGroupId().equals(rProject.getGroupId())
+                && artifact.getArtifactId().equals(rProject.getArtifactId()) 
+                && artifact.getVersion().equals(rProject.getVersion())) {
+                Set<Artifact> artifacts = rProject.getArtifacts();
+                for (Artifact pArtifact : artifacts) {
+                    if ("wsdl".equals(artifact.getType())) {
+                        return pArtifact;
+                    }
+                }
+            }
+        }
+        
+        /**
+         * If this did not work resolve the artifact using the artifactResolver
+         */
+        try {
+            artifactResolver.resolve(artifact, remoteRepos, localRepository);
+        } catch (ArtifactResolutionException e) {
+            throw new MojoExecutionException("Error downloading wsdl artifact.", e);
+        } catch (ArtifactNotFoundException e) {
+            throw new MojoExecutionException("Resource can not be found.", e);
+        }
+        
+        return artifact;
+    }
 
     public void downloadRemoteWsdls(List<WsdlOption> effectiveWsdlOptions) throws MojoExecutionException {
         List remoteRepos;
@@ -291,20 +328,21 @@
         } 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());
-                }
+        
+        for (WsdlOption wsdlOption : effectiveWsdlOptions) {
+            WsdlArtifact wsdlA = wsdlOption.getWsdlArtifact();
+            if (wsdlA == null) {
+                return;
+            }
+            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();
+                getLog().info("Resolved WSDL artifact to file " + path);
+                wsdlOption.setWsdl(path);
             }
-        } catch (ArtifactResolutionException e) {
-            throw new MojoExecutionException("Error downloading wsdl artifact.", e);
-        } catch (ArtifactNotFoundException e) {
-            throw new MojoExecutionException("Resource can not be found.", e);
         }
     }