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 2009/09/29 18:16:09 UTC
svn commit: r820011 - in /cxf/branches/2.2.x-fixes: ./
maven-plugins/codegen-plugin/
maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/
maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/
Author: dkulp
Date: Tue Sep 29 16:16:09 2009
New Revision: 820011
URL: http://svn.apache.org/viewvc?rev=820011&view=rev
Log:
Merged revisions 810855,810982,811235,815243,818940 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r810855 | cschneider | 2009-09-03 05:53:49 -0400 (Thu, 03 Sep 2009) | 1 line
CXF-2275 Support reading WSDLs from Maven repository. Implementation finished. We still need an automated test
........
r810982 | cschneider | 2009-09-03 10:52:43 -0400 (Thu, 03 Sep 2009) | 1 line
CXF-2276 Support attaching generated WSDLs to the Maven build. Implementation finished. We need a test for this feature
........
r811235 | cschneider | 2009-09-04 03:14:44 -0400 (Fri, 04 Sep 2009) | 1 line
Set default of attachWsdl to true
........
r815243 | cschneider | 2009-09-15 05:48:48 -0400 (Tue, 15 Sep 2009) | 1 line
CXF-2275 Added resolving wsdl artifacts by using the maven reactor
........
r818940 | dkulp | 2009-09-25 14:20:20 -0400 (Fri, 25 Sep 2009) | 1 line
1.0 was released. Remove snapshot dep.
........
Added:
cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
- copied unchanged from r810855, cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/pom.xml
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/WsdlOption.java
cxf/branches/2.2.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
svn:mergeinfo = /cxf/trunk:810855,810982,811235,815243,818940
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/pom.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/pom.xml?rev=820011&r1=820010&r2=820011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/pom.xml (original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/pom.xml Tue Sep 29 16:16:09 2009
@@ -40,7 +40,21 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-artifact-resolver</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <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>
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=820011&r1=820010&r2=820011&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 Tue Sep 29 16:16:09 2009
@@ -24,14 +24,25 @@
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;
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 +131,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 +213,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 +248,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 +267,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 +280,70 @@
if (wsdlOptions != null) {
mergeOptions(effectiveWsdlOptions, wsdlOptions);
}
- return effectiveWsdlOptions.toArray(new WsdlOption[effectiveWsdlOptions.size()]);
+ 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;
+ try {
+ remoteRepos = ProjectUtils.buildArtifactRepositories(repositories, artifactRepositoryFactory,
+ mavenSession.getContainer());
+ } catch (InvalidRepositoryException e) {
+ throw new MojoExecutionException("Error build repositories for remote wsdls", e);
+ }
+
+ 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);
+ }
+ }
}
public void execute() throws MojoExecutionException {
@@ -228,9 +357,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;
}
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=820011&r1=820010&r2=820011&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 Tue Sep 29 16:16:09 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) {
Modified: cxf/branches/2.2.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java?rev=820011&r1=820010&r2=820011&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java (original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java Tue Sep 29 16:16:09 2009
@@ -30,6 +30,7 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
/**
* @goal java2ws
@@ -91,6 +92,14 @@
private MavenProject project;
/**
+ * Maven ProjectHelper.
+ *
+ * @component
+ * @readonly
+ */
+ private MavenProjectHelper projectHelper;
+
+ /**
* @parameter
*/
private String argline;
@@ -121,6 +130,16 @@
*/
private Boolean genWrapperbean;
+ /**
+ * Attach the generated wsdl file to the list of files to be deployed
+ * on install. This means the wsdl file will be copied to the repository
+ * with groupId, artifactId and version of the project and type "wsdl".
+ *
+ * With this option you can use the maven repository as a Service Repository.
+ *
+ * @parameter default-value="true"
+ */
+ private Boolean attachWsdl;
public void execute() throws MojoExecutionException {
StringBuffer buf = new StringBuffer();
@@ -248,6 +267,13 @@
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
+
+ // Attach the generated wsdl file to the artifacts that get deployed
+ // with the enclosing project
+ if (attachWsdl && outputFile != null) {
+ File wsdlFile = new File(outputFile);
+ projectHelper.attachArtifact(project, "wsdl", wsdlFile);
+ }
}
}
\ No newline at end of file