Author: dkulp
Date: Fri Mar 2 21:06:23 2012
New Revision: 1296460
URL: http://svn.apache.org/viewvc?rev=1296460&view=rev
Log:
Merged revisions 1296452 via svn merge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1296452 | dkulp | 2012-03-02 15:53:41 -0500 (Fri, 02 Mar 2012) | 2 lines
[CXF-4136] Handle wsdls not as a dependency
Patch from Owen Farrell applied
........
Modified:
cxf/branches/2.5.x-fixes/ (props changed)
cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java?rev=1296460&r1=1296459&r2=1296460&view=diff
==============================================================================
---
cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
(original)
+++
cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
Fri Mar 2 21:06:23 2012
@@ -34,17 +34,23 @@ import java.util.Set;
import org.apache.commons.lang.SystemUtils;
import org.apache.cxf.Bus;
+import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.helpers.FileUtils;
import org.apache.cxf.tools.util.URIParserUtil;
import org.apache.maven.ProjectDependenciesResolver;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Repository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectUtils;
import org.apache.maven.settings.Proxy;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.jar.Manifest;
@@ -142,7 +148,14 @@ public abstract class AbstractCodegenMoh
* @since 2.4
*/
private String additionalJvmArgs;
-
+ /**
+ * 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.
*
@@ -160,6 +173,22 @@ public abstract class AbstractCodegenMoh
*/
private String javaExecutable;
/**
+ * The remote repositories used as specified in your POM.
+ *
+ * @parameter expression="${project.repositories}"
+ * @readonly
+ * @required
+ */
+ private List<Repository> repositories;
+ /**
+ * Artifact repository factory component.
+ *
+ * @component
+ * @readonly
+ * @required
+ */
+ private ArtifactRepositoryFactory artifactRepositoryFactory;
+ /**
* The Maven session.
*
* @parameter expression="${session}"
@@ -173,6 +202,12 @@ public abstract class AbstractCodegenMoh
* @required
*/
private ProjectDependenciesResolver projectDependencyResolver;
+ /**
+ * @component
+ * @readonly
+ * @required
+ */
+ private ArtifactResolver artifactResolver;
public AbstractCodegenMoho() {
super();
@@ -572,9 +607,9 @@ public abstract class AbstractCodegenMoh
if (wsdlA == null) {
return;
}
- Artifact wsdlArtifact =
artifactFactory.createArtifact(wsdlA.getGroupId(), wsdlA.getArtifactId(),
-
wsdlA.getVersion(),
-
Artifact.SCOPE_COMPILE, wsdlA.getType());
+ Artifact wsdlArtifact =
artifactFactory.createBuildArtifact(wsdlA.getGroupId(),
+
wsdlA.getArtifactId(),
+
wsdlA.getVersion(), wsdlA.getType());
wsdlArtifact = resolveRemoteWsdlArtifact(wsdlArtifact);
if (wsdlArtifact != null) {
File supposedFile = wsdlArtifact.getFile();
@@ -606,29 +641,73 @@ public abstract class AbstractCodegenMoh
}
private Artifact resolveRemoteWsdlArtifact(Artifact artifact) throws
MojoExecutionException {
+ Artifact remoteWsdl = resolveDependentWsdl(artifact);
+ if (remoteWsdl == null) {
+ remoteWsdl = resolveAttachedWsdl(artifact);
+ }
+ if (remoteWsdl == null) {
+ remoteWsdl = resolveArbitraryWsdl(artifact);
+ }
+ if (remoteWsdl != null && remoteWsdl.isResolved()) {
+ return remoteWsdl;
+ }
+ throw new MojoExecutionException(String.format("Failed to resolve WSDL
artifact %s",
+ artifact.toString()));
+ }
+ private Artifact resolveDependentWsdl(Artifact artifact) {
Collection<String> scopes = new ArrayList<String>();
- scopes.add(artifact.getScope());
- Set<Artifact> resolvedArtifacts = null;
+ scopes.add(Artifact.SCOPE_RUNTIME);
+ Set<Artifact> artifactSet = null;
try {
- resolvedArtifacts = projectDependencyResolver.resolve(project,
scopes, mavenSession);
- } catch (ArtifactResolutionException e) {
- throw new MojoExecutionException("Error downloading wsdl
artifact.", e);
- } catch (ArtifactNotFoundException e) {
- throw new MojoExecutionException("Resource can not be found.", e);
+ artifactSet = projectDependencyResolver.resolve(project, scopes,
mavenSession);
+ } catch (AbstractArtifactResolutionException e) {
+ getLog().info("Error resolving dependent wsdl artifact.", e);
}
+ return findWsdlArtifact(artifact, artifactSet);
+ }
- if (resolvedArtifacts != null && resolvedArtifacts.size() != 0) {
- for (Artifact pArtifact : resolvedArtifacts) {
- if ("wsdl".equals(pArtifact.getType())) {
+ private Artifact resolveAttachedWsdl(Artifact artifact) {
+ List<MavenProject> rProjects = mavenSession.getSortedProjects();
+ List<Artifact> artifactList = new ArrayList<Artifact>();
+ for (MavenProject rProject : rProjects) {
+ List<Artifact> list =
CastUtils.cast(rProject.getAttachedArtifacts());
+ if (list != null) {
+ artifactList.addAll(list);
+ }
+ }
+ return findWsdlArtifact(artifact, artifactList);
+ }
+
+ private Artifact resolveArbitraryWsdl(Artifact artifact) {
+ try {
+ @SuppressWarnings("rawtypes")
+ List remoteRepos =
ProjectUtils.buildArtifactRepositories(repositories,
+
artifactRepositoryFactory,
+
mavenSession.getContainer());
+ artifactResolver.resolve(artifact, remoteRepos, localRepository);
+ } catch (InvalidRepositoryException e) {
+ getLog().info("Error build repositories for remote wsdls.", e);
+ } catch (AbstractArtifactResolutionException e) {
+ getLog().info("Error resolving arbitrary wsdl artifact.", e);
+ }
+ return artifact;
+ }
+
+ private Artifact findWsdlArtifact(Artifact targetArtifact,
Collection<Artifact> artifactSet) {
+ if (artifactSet != null && !artifactSet.isEmpty()) {
+ for (Artifact pArtifact : artifactSet) {
+ if (targetArtifact.getGroupId().equals(pArtifact.getGroupId())
+ &&
targetArtifact.getArtifactId().equals(pArtifact.getArtifactId())
+ &&
targetArtifact.getVersion().equals(pArtifact.getVersion())
+ && "wsdl".equals(pArtifact.getType())) {
getLog().info(String.format("%s resolved to %s",
pArtifact.toString(), pArtifact
.getFile().getAbsolutePath()));
return pArtifact;
}
}
}
- throw new MojoExecutionException(String.format("Failed to resolve WSDL
artifact %s",
- artifact.toString()));
+ return null;
}
}