You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/12/09 21:31:20 UTC
svn commit: r724870 - in /servicemix/maven-plugins/jbi-maven-plugin/trunk:
./ src/main/java/org/apache/servicemix/maven/plugin/jbi/
src/main/resources/META-INF/plexus/
Author: gnodet
Date: Tue Dec 9 12:31:19 2008
New Revision: 724870
URL: http://svn.apache.org/viewvc?rev=724870&view=rev
Log:
SM-1724: JBI maven plugin does not correctly prune the dependency tree wrt to referenced shared libraries
Removed:
servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GraphArtifactCollector.java
Modified:
servicemix/maven-plugins/jbi-maven-plugin/trunk/pom.xml
servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java
servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java
servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiResolutionListener.java
servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/resources/META-INF/plexus/components.xml
Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/pom.xml?rev=724870&r1=724869&r2=724870&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/pom.xml (original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/pom.xml Tue Dec 9 12:31:19 2008
@@ -201,8 +201,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.4</source>
- <target>1.4</target>
+ <source>1.5</source>
+ <target>1.5</target>
</configuration>
</plugin>
<plugin>
Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java?rev=724870&r1=724869&r2=724870&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java (original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractJbiMojo.java Tue Dec 9 12:31:19 2008
@@ -37,6 +37,7 @@
import org.apache.maven.artifact.resolver.ArtifactCollector;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
@@ -113,11 +114,11 @@
protected ArtifactResolver resolver;
/**
- * @component role="org.apache.maven.artifact.resolver.ArtifactCollector" hint="graph"
+ * @component
* @required
* @readonly
*/
- protected ArtifactCollector collector = new GraphArtifactCollector();
+ protected ArtifactCollector collector;
/**
* @component
@@ -136,57 +137,67 @@
return projectHelper;
}
- protected void removeBranch(JbiResolutionListener listener,
- Artifact artifact) {
+ protected void removeBranch(JbiResolutionListener listener, Artifact artifact) {
Node n = listener.getNode(artifact);
if (n != null) {
- for (Iterator it = n.getParents().iterator(); it.hasNext();) {
- Node parent = (Node) it.next();
+ for (Node parent : n.getParents()) {
parent.getChildren().remove(n);
}
- }
+ }
}
- protected void removeChildren(JbiResolutionListener listener,
- Artifact artifact) {
+ protected void removeChildren(JbiResolutionListener listener, Artifact artifact) {
Node n = listener.getNode(artifact);
n.getChildren().clear();
}
- protected Set getArtifacts(Node n, Set s) {
- if (!s.contains(n.getArtifact())) {
- s.add(n.getArtifact());
- for (Iterator iter = n.getChildren().iterator(); iter.hasNext();) {
- Node c = (Node) iter.next();
+ protected Set<Artifact> getArtifacts(Node n, Set<Artifact> s) {
+ if (s.add(n.getArtifact())) {
+ for (Node c : n.getChildren()) {
getArtifacts(c, s);
}
}
return s;
}
- protected void excludeBranch(Node n, Set excludes) {
- excludes.add(n);
- for (Iterator iter = n.getChildren().iterator(); iter.hasNext();) {
- Node c = (Node) iter.next();
+ protected void excludeBranch(Node n, Set<Artifact> excludes) {
+ excludes.add(n.getArtifact());
+ for (Node c : n.getChildren()) {
excludeBranch(c, excludes);
}
}
protected void print(Node rootNode) {
- for (Iterator iter = getArtifacts(rootNode, new HashSet()).iterator(); iter.hasNext();) {
- Artifact a = (Artifact) iter.next();
+ for (Artifact a : getArtifacts(rootNode, new HashSet<Artifact>())) {
getLog().info(" " + a);
}
}
- protected Set retainArtifacts(Set includes, JbiResolutionListener listener) {
- Set finalIncludes = new HashSet();
- Set filteredArtifacts = getArtifacts(listener.getRootNode(),
- new HashSet());
- for (Iterator iter = includes.iterator(); iter.hasNext();) {
- Artifact artifact = (Artifact) iter.next();
- for (Iterator iter2 = filteredArtifacts.iterator(); iter2.hasNext();) {
- Artifact filteredArtifact = (Artifact) iter2.next();
+ protected void print(Node rootNode, String pfx) {
+ getLog().info(pfx + rootNode.getArtifact());
+ for (Node child : rootNode.getChildren()) {
+ print(child, " " + pfx);
+ }
+ }
+
+ protected void pruneTree(Node node, Set<Artifact> excludes) {
+ for (Iterator<Node> iter = node.getChildren().iterator(); iter.hasNext();) {
+ Node child = iter.next();
+ if (child.getArtifact().isOptional() ||
+ (!child.getScope().equals(Artifact.SCOPE_COMPILE) && !child.getScope().equals(Artifact.SCOPE_RUNTIME)) ||
+ excludes.contains(child.getArtifact())) {
+ iter.remove();
+ } else {
+ pruneTree(child, excludes);
+ }
+ }
+ }
+
+ protected Set<Artifact> retainArtifacts(Set<Artifact> includes, JbiResolutionListener listener) {
+ Set<Artifact> finalIncludes = new HashSet<Artifact>();
+ Set<Artifact> filteredArtifacts = getArtifacts(listener.getRootNode(), new HashSet<Artifact>());
+ for (Artifact artifact : includes) {
+ for (Artifact filteredArtifact : filteredArtifacts) {
if (filteredArtifact.getArtifactId().equals(
artifact.getArtifactId())
&& filteredArtifact.getType()
@@ -208,19 +219,16 @@
}
}
-
return finalIncludes;
}
+
protected JbiResolutionListener resolveProject() {
Map managedVersions = null;
try {
- managedVersions = createManagedVersionMap(project.getId(), project
- .getDependencyManagement());
+ managedVersions = createManagedVersionMap(project.getId(), project.getDependencyManagement());
} catch (ProjectBuildingException e) {
- getLog().error(
- "An error occurred while resolving project dependencies.",
- e);
+ getLog().error("An error occurred while resolving project dependencies.", e);
}
JbiResolutionListener listener = new JbiResolutionListener();
listener.setLog(getLog());
Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java?rev=724870&r1=724869&r2=724870&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java (original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java Tue Dec 9 12:31:19 2008
@@ -27,10 +27,12 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
import org.codehaus.plexus.util.FileUtils;
/**
@@ -210,65 +212,117 @@
info.setType("jar");
uris.add(info);
- ScopeArtifactFilter filter = new ScopeArtifactFilter(
- Artifact.SCOPE_RUNTIME);
+ ArtifactFilter filter = new ArtifactFilter() {
+ public boolean include(Artifact artifact) {
+ return !artifact.isOptional() &&
+ (artifact.getScope() == Artifact.SCOPE_RUNTIME || artifact.getScope() == Artifact.SCOPE_COMPILE);
+ }
+ };
- JbiResolutionListener listener = resolveProject();
- // print(listener.getRootNode(), "");
- Set includes = new HashSet();
+ JbiResolutionListener listener = resolveProject();
+ Set<Artifact> includes = new HashSet<Artifact>();
+ Set<Artifact> excludes = new HashSet<Artifact>();
for (Iterator iter = project.getArtifacts().iterator(); iter.hasNext();) {
Artifact artifact = (Artifact) iter.next();
- if (!artifact.isOptional() && filter.include(artifact)) {
+ if (filter.include(artifact)) {
MavenProject project = null;
try {
- project = projectBuilder.buildFromRepository(artifact,
- remoteRepos, localRepo);
+ project = projectBuilder.buildFromRepository(artifact, remoteRepos, localRepo);
} catch (ProjectBuildingException e) {
- getLog().warn(
- "Unable to determine packaging for dependency : "
- + artifact.getArtifactId()
- + " assuming jar");
+ getLog().warn("Unable to determine packaging for dependency : "
+ + artifact.getArtifactId() + " assuming jar");
}
- String prjType = project != null ? project.getPackaging()
- : artifact.getType();
- if ("jbi-shared-library".equals(prjType)) {
- removeChildren(listener, artifact);
+ String type = project != null ? project.getPackaging() : artifact.getType();
+ if ("jbi-shared-library".equals(type)) {
+ // exclude children, but not the shared library itself
+ excludeBranch(listener.getNode(artifact), excludes);
+ excludes.remove(artifact);
includes.add(artifact);
- } else if ("jar".equals(prjType) || "bundle".equals(prjType) || "jbi-component".equals(prjType)) {
+ } else if ("jar".equals(type) || "bundle".equals(type) || "jbi-component".equals(type)) {
includes.add(artifact);
}
}
}
+ pruneTree(listener.getRootNode(), excludes);
// print(listener.getRootNode(), "");
-
- for (Iterator iter = retainArtifacts(includes, listener).iterator(); iter
- .hasNext();) {
- Artifact artifact = (Artifact) iter.next();
+ for (Artifact artifact : retainArtifacts(includes, listener)) {
MavenProject project = null;
try {
- project = projectBuilder.buildFromRepository(artifact,
- remoteRepos, localRepo);
+ project = projectBuilder.buildFromRepository(artifact, remoteRepos, localRepo);
} catch (ProjectBuildingException e) {
- getLog().warn(
- "Unable to determine packaging for dependency : "
+ getLog().warn("Unable to determine packaging for dependency : "
+ artifact.getArtifactId() + " assuming jar");
}
- String prjType = project != null ? project.getPackaging() : artifact
- .getType();
+ String type = project != null ? project.getPackaging() : artifact.getType();
info = new DependencyInformation();
- info.setFilename(LIB_DIRECTORY + "/"
- + artifact.getFile().getName());
+ info.setFilename(LIB_DIRECTORY + "/" + artifact.getFile().getName());
info.setVersion(artifact.getVersion());
info.setName(artifact.getArtifactId());
- info.setType(prjType);
+ info.setType(type);
uris.add(info);
}
+//
+// DependencyNode node = buildDependencyTree(filter);
+// Set<Artifact> includes = new HashSet<Artifact>();
+// Set<Artifact> excludes = new HashSet<Artifact>();
+// for (Iterator iter = project.getArtifacts().iterator(); iter.hasNext();) {
+// Artifact artifact = (Artifact) iter.next();
+// //if (filter.include(artifact)) {
+// MavenProject project = null;
+// try {
+// project = projectBuilder.buildFromRepository(artifact, remoteRepos, localRepo);
+// } catch (ProjectBuildingException e) {
+// getLog().warn("Unable to determine packaging for dependency : "
+// + artifact.getArtifactId() + " assuming jar");
+// }
+// String type = project != null ? project.getPackaging() : artifact.getType();
+// if ("jbi-shared-library".equals(type)) {
+// // exclude children, but not the shared library itself
+// excludeBranch(findNode(node, artifact), excludes, false);
+// includes.add(artifact);
+// } else if ("jar".equals(type) || "bundle".equals(type) || "jbi-component".equals(type)) {
+// includes.add(artifact);
+// }
+// //}
+// }
+// for (Artifact artifact : excludes) {
+// System.out.println("Excludes: " + artifact);
+// }
+// includes.removeAll(excludes);
+// Set<Artifact> newIncludes = new HashSet<Artifact>();
+// for (Artifact artifact : includes) {
+// DependencyNode n = findNode(node, artifact);
+// if (n != null) {
+// Artifact a = n.getArtifact();
+// if (filter.include(a)) {
+// newIncludes.add(artifact);
+// }
+// }
+// }
+// //pruneTree(node, filter, excludes);
+// for (Artifact artifact : newIncludes) {
+// MavenProject project = null;
+// try {
+// project = projectBuilder.buildFromRepository(artifact, remoteRepos, localRepo);
+// } catch (ProjectBuildingException e) {
+// getLog().warn("Unable to determine packaging for dependency : "
+// + artifact.getArtifactId() + " assuming jar");
+// }
+// String type = project != null ? project.getPackaging() : artifact.getType();
+// info = new DependencyInformation();
+// info.setFilename(LIB_DIRECTORY + "/" + artifact.getFile().getName());
+// info.setVersion(artifact.getVersion());
+// info.setName(artifact.getArtifactId());
+// info.setType(type);
+// uris.add(info);
+// }
+//
- JbiComponentDescriptorWriter writer = new JbiComponentDescriptorWriter(
- encoding);
+ JbiComponentDescriptorWriter writer = new JbiComponentDescriptorWriter(encoding);
writer.write(descriptor, component, bootstrap, type, name, description,
componentClassLoaderDelegation, bootstrapClassLoaderDelegation,
uris);
}
+
}
Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java?rev=724870&r1=724869&r2=724870&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java (original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java Tue Dec 9 12:31:19 2008
@@ -27,6 +27,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
@@ -163,55 +164,59 @@
File projectArtifact = new File(outputDirectory, finalName + ".jar");
try {
- FileUtils.copyFileToDirectory(projectArtifact, new File(
- workDirectory, LIB_DIRECTORY));
+ FileUtils.copyFileToDirectory(projectArtifact, new File(workDirectory, LIB_DIRECTORY));
} catch (IOException e) {
throw new JbiPluginException("Unable to copy file "
+ projectArtifact, e);
}
- ScopeArtifactFilter filter = new ScopeArtifactFilter(
- Artifact.SCOPE_RUNTIME);
+ ArtifactFilter filter = new ArtifactFilter() {
+ public boolean include(Artifact artifact) {
+ return !artifact.isOptional() &&
+ (artifact.getScope() == Artifact.SCOPE_RUNTIME || artifact.getScope() == Artifact.SCOPE_COMPILE);
+ }
+ };
JbiResolutionListener listener = resolveProject();
- // print(listener.getRootNode(), "");
+ if (getLog().isDebugEnabled()) {
+ print(listener.getRootNode(), " ");
+ }
- Set includes = new HashSet();
+ Set<Artifact> includes = new HashSet<Artifact>();
+ Set<Artifact> excludes = new HashSet<Artifact>();
for (Iterator iter = project.getArtifacts().iterator(); iter.hasNext();) {
Artifact artifact = (Artifact) iter.next();
- if (!artifact.isOptional() && filter.include(artifact)) {
+ if (filter.include(artifact)) {
MavenProject project = null;
try {
- project = projectBuilder.buildFromRepository(artifact,
- remoteRepos, localRepo);
+ project = projectBuilder.buildFromRepository(artifact, remoteRepos, localRepo);
} catch (ProjectBuildingException e) {
- getLog().warn(
- "Unable to determine packaging for dependency : "
+ getLog().warn("Unable to determine packaging for dependency : "
+ artifact.getArtifactId()
+ " assuming jar");
}
- String type = project != null ? project.getPackaging()
- : artifact.getType();
+ String type = project != null ? project.getPackaging() : artifact.getType();
if ("jbi-shared-library".equals(type)) {
- removeBranch(listener, artifact);
+ excludeBranch(listener.getNode(artifact), excludes);
} else if ("jar".equals(type) || "bundle".equals(type) || "jbi-component".equals(type)) {
includes.add(artifact);
}
}
}
- // print(listener.getRootNode(), "");
+ pruneTree(listener.getRootNode(), excludes);
+ if (getLog().isDebugEnabled()) {
+ getLog().info("Excludes: " + excludes);
+ print(listener.getRootNode(), " ");
+ }
- for (Iterator iter = retainArtifacts(includes, listener).iterator(); iter
- .hasNext();) {
- Artifact artifact = (Artifact) iter.next();
+ for (Artifact artifact : retainArtifacts(includes, listener)) {
try {
getLog().info("Including: " + artifact);
- FileUtils.copyFileToDirectory(artifact.getFile(), new File(
- workDirectory, LIB_DIRECTORY));
+ FileUtils.copyFileToDirectory(artifact.getFile(), new File(workDirectory, LIB_DIRECTORY));
} catch (IOException e) {
- throw new JbiPluginException("Unable to copy file "
- + artifact.getFile(), e);
+ throw new JbiPluginException("Unable to copy file " + artifact.getFile(), e);
}
}
}
+
}
Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiResolutionListener.java
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiResolutionListener.java?rev=724870&r1=724869&r2=724870&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiResolutionListener.java (original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiResolutionListener.java Tue Dec 9 12:31:19 2008
@@ -111,15 +111,14 @@
}
public void updateScope(Artifact artifact, String scope) {
- // getLog().debug("updateScope: " + artifact);
+ getLog().debug("updateScope: " + artifact);
Node node = (Node) artifacts.get(artifact.getDependencyConflictId());
- node.artifact.setScope(scope);
+ node.setScope(scope);
}
public void manageArtifact(Artifact artifact, Artifact replacement) {
- // getLog().debug("manageArtifact: artifact=" + artifact + ",
- // replacement=" + replacement);
+ getLog().debug("manageArtifact: artifact=" + artifact + ", replacement=" + replacement);
Node node = (Node) artifacts.get(artifact.getDependencyConflictId());
if (node != null) {
if (replacement.getVersion() != null) {
@@ -159,13 +158,15 @@
}
static class Node {
- private Set children = new HashSet();
+ private Set<Node> children = new HashSet<Node>();
- private Set parents = new HashSet();
+ private Set<Node> parents = new HashSet<Node>();
private Artifact artifact;
- public Set getChildren() {
+ private String scope;
+
+ public Set<Node> getChildren() {
return children;
}
@@ -173,9 +174,20 @@
return artifact;
}
- public Set getParents() {
+ public Set<Node> getParents() {
return parents;
}
+
+ public String getScope() {
+ if (scope != null) {
+ return scope;
+ }
+ return artifact.getScope();
+ }
+
+ public void setScope(String scope) {
+ this.scope = scope;
+ }
}
public Node getRootNode() {
Modified: servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/resources/META-INF/plexus/components.xml?rev=724870&r1=724869&r2=724870&view=diff
==============================================================================
--- servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/resources/META-INF/plexus/components.xml (original)
+++ servicemix/maven-plugins/jbi-maven-plugin/trunk/src/main/resources/META-INF/plexus/components.xml Tue Dec 9 12:31:19 2008
@@ -160,10 +160,6 @@
</phases>
</configuration>
</component>
- <component>
- <role>org.apache.maven.artifact.resolver.ArtifactCollector</role>
- <role-hint>graph</role-hint>
- <implementation>org.apache.servicemix.maven.plugin.jbi.GraphArtifactCollector</implementation>
- </component>
- </components>
+
+c m </components>
</component-set>