Blame SOURCES/0001-Port-to-current-maven-dependency-tree.patch

ad18db
From ebccbeb7befb0f2d02e64a9e15496f46f7a260b2 Mon Sep 17 00:00:00 2001
ad18db
From: Michael Simacek <msimacek@redhat.com>
ad18db
Date: Fri, 12 Feb 2016 09:45:20 +0100
ad18db
Subject: [PATCH 1/4] Port to current maven-dependency-tree
ad18db
ad18db
---
ad18db
 pom.xml                                            |  2 +-
ad18db
 .../apache/felix/bundleplugin/BundleAllPlugin.java | 54 ++++++++++++----------
ad18db
 .../apache/felix/bundleplugin/BundlePlugin.java    | 30 ++++++------
ad18db
 3 files changed, 46 insertions(+), 40 deletions(-)
ad18db
ad18db
diff --git a/pom.xml b/pom.xml
ad18db
index c64ff31..8231d7c 100644
ad18db
--- a/pom.xml
ad18db
+++ b/pom.xml
ad18db
@@ -187,7 +187,7 @@
ad18db
   <dependency>
ad18db
    <groupId>org.apache.maven.shared</groupId>
ad18db
    <artifactId>maven-dependency-tree</artifactId>
ad18db
-   <version>2.1</version>
ad18db
+   <version>3.0</version>
ad18db
   </dependency>
ad18db
   <dependency>
ad18db
    <groupId>org.codehaus.plexus</groupId>
ad18db
diff --git a/src/main/java/org/apache/felix/bundleplugin/BundleAllPlugin.java b/src/main/java/org/apache/felix/bundleplugin/BundleAllPlugin.java
ad18db
index f3b5509..6591923 100644
ad18db
--- a/src/main/java/org/apache/felix/bundleplugin/BundleAllPlugin.java
ad18db
+++ b/src/main/java/org/apache/felix/bundleplugin/BundleAllPlugin.java
ad18db
@@ -21,8 +21,10 @@ package org.apache.felix.bundleplugin;
ad18db
 
ad18db
 import java.io.File;
ad18db
 import java.io.FilenameFilter;
ad18db
+import java.util.ArrayDeque;
ad18db
 import java.util.Arrays;
ad18db
 import java.util.Collection;
ad18db
+import java.util.Deque;
ad18db
 import java.util.HashSet;
ad18db
 import java.util.Iterator;
ad18db
 import java.util.LinkedHashMap;
ad18db
@@ -38,7 +40,6 @@ import org.apache.maven.artifact.Artifact;
ad18db
 import org.apache.maven.artifact.factory.ArtifactFactory;
ad18db
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
ad18db
 import org.apache.maven.artifact.repository.ArtifactRepository;
ad18db
-import org.apache.maven.artifact.resolver.ArtifactCollector;
ad18db
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
ad18db
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
ad18db
 import org.apache.maven.artifact.resolver.ArtifactResolver;
ad18db
@@ -49,13 +50,14 @@ import org.apache.maven.plugins.annotations.LifecyclePhase;
ad18db
 import org.apache.maven.plugins.annotations.Mojo;
ad18db
 import org.apache.maven.plugins.annotations.Parameter;
ad18db
 import org.apache.maven.plugins.annotations.ResolutionScope;
ad18db
+import org.apache.maven.project.DefaultProjectBuildingRequest;
ad18db
 import org.apache.maven.project.MavenProject;
ad18db
 import org.apache.maven.project.MavenProjectBuilder;
ad18db
 import org.apache.maven.project.ProjectBuildingException;
ad18db
+import org.apache.maven.project.ProjectBuildingRequest;
ad18db
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
ad18db
-import org.apache.maven.shared.dependency.tree.DependencyNode;
ad18db
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
ad18db
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
ad18db
+import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
ad18db
+import org.apache.maven.shared.dependency.graph.DependencyNode;
ad18db
 import org.codehaus.plexus.util.FileUtils;
ad18db
 
ad18db
 import aQute.bnd.osgi.Analyzer;
ad18db
@@ -92,24 +94,18 @@ public class BundleAllPlugin extends ManifestPlugin
ad18db
      */
ad18db
     @Parameter( property = "wrapImportPackage", defaultValue = "*" )
ad18db
     private String wrapImportPackage;
ad18db
-
ad18db
     @Component
ad18db
     private ArtifactFactory m_factory;
ad18db
 
ad18db
     @Component
ad18db
     private ArtifactMetadataSource m_artifactMetadataSource;
ad18db
 
ad18db
-    @Component
ad18db
-    private ArtifactCollector m_collector;
ad18db
-
ad18db
     /**
ad18db
      * Artifact resolver, needed to download jars.
ad18db
      */
ad18db
     @Component
ad18db
     private ArtifactResolver m_artifactResolver;
ad18db
 
ad18db
-    @Component
ad18db
-    private DependencyTreeBuilder m_dependencyTreeBuilder;
ad18db
 
ad18db
     @Component
ad18db
     private MavenProjectBuilder m_mavenProjectBuilder;
ad18db
@@ -180,17 +176,19 @@ public class BundleAllPlugin extends ManifestPlugin
ad18db
 
ad18db
         try
ad18db
         {
ad18db
-            dependencyTree = m_dependencyTreeBuilder.buildDependencyTree( project, localRepository, m_factory,
ad18db
-                m_artifactMetadataSource, null, m_collector );
ad18db
+            ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
ad18db
+            request.setProject(getProject());
ad18db
+            request.setRepositorySession(session.getRepositorySession());
ad18db
+            dependencyTree = m_dependencyGraphBuilder.buildDependencyGraph(request, null);
ad18db
         }
ad18db
-        catch ( DependencyTreeBuilderException e )
ad18db
+        catch ( DependencyGraphBuilderException e )
ad18db
         {
ad18db
             throw new MojoExecutionException( "Unable to build dependency tree", e );
ad18db
         }
ad18db
 
ad18db
         BundleInfo bundleInfo = new BundleInfo();
ad18db
 
ad18db
-        if ( !dependencyTree.hasChildren() )
ad18db
+        if ( dependencyTree.getChildren().isEmpty())
ad18db
         {
ad18db
             /* no need to traverse the tree */
ad18db
             return bundleRoot( project, bundleInfo );
ad18db
@@ -198,20 +196,27 @@ public class BundleAllPlugin extends ManifestPlugin
ad18db
 
ad18db
         getLog().debug( "Will bundle the following dependency tree" + LS + dependencyTree );
ad18db
 
ad18db
-        for ( Iterator it = dependencyTree.inverseIterator(); it.hasNext(); )
ad18db
+        Deque<DependencyNode> stack = new ArrayDeque<DependencyNode>();
ad18db
+        stack.push(dependencyTree);
ad18db
+        Set<DependencyNode> visited = new HashSet<DependencyNode>();
ad18db
+        while (!stack.isEmpty())
ad18db
         {
ad18db
-            DependencyNode node = ( DependencyNode ) it.next();
ad18db
-            if ( !it.hasNext() )
ad18db
+            DependencyNode node = stack.pop();
ad18db
+            if (visited.contains(node))
ad18db
             {
ad18db
-                /* this is the root, current project */
ad18db
-                break;
ad18db
+                continue;
ad18db
             }
ad18db
-
ad18db
-            if ( node.getState() != DependencyNode.INCLUDED )
ad18db
+            visited.add(node);
ad18db
+            if (node.getChildren() != null)
ad18db
             {
ad18db
-                continue;
ad18db
+                stack.addAll(node.getChildren());
ad18db
             }
ad18db
 
ad18db
+            //if ( node.getState() != DependencyNode.INCLUDED )
ad18db
+            //{
ad18db
+            //    continue;
ad18db
+            //}
ad18db
+
ad18db
             if ( Artifact.SCOPE_SYSTEM.equals( node.getArtifact().getScope() ) )
ad18db
             {
ad18db
                 getLog().debug( "Ignoring system scoped artifact " + node.getArtifact() );
ad18db
@@ -235,12 +240,11 @@ public class BundleAllPlugin extends ManifestPlugin
ad18db
 
ad18db
             node.getArtifact().setFile( artifact.getFile() );
ad18db
 
ad18db
-            int nodeDepth = node.getDepth();
ad18db
-            if ( nodeDepth > maxDepth )
ad18db
+            if ( stack.size() > maxDepth )
ad18db
             {
ad18db
                 /* node is deeper than we want */
ad18db
                 getLog().debug(
ad18db
-                    "Ignoring " + node.getArtifact() + ", depth is " + nodeDepth + ", bigger than " + maxDepth );
ad18db
+                    "Ignoring " + node.getArtifact() + ", depth is " + stack.size() + ", bigger than " + maxDepth );
ad18db
                 continue;
ad18db
             }
ad18db
 
ad18db
diff --git a/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java b/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
ad18db
index 67d0915..c3e9366 100644
ad18db
--- a/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
ad18db
+++ b/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
ad18db
@@ -72,15 +72,15 @@ import org.apache.maven.plugins.annotations.LifecyclePhase;
ad18db
 import org.apache.maven.plugins.annotations.Mojo;
ad18db
 import org.apache.maven.plugins.annotations.Parameter;
ad18db
 import org.apache.maven.plugins.annotations.ResolutionScope;
ad18db
+import org.apache.maven.project.DefaultProjectBuildingRequest;
ad18db
 import org.apache.maven.project.MavenProject;
ad18db
 import org.apache.maven.project.MavenProjectBuilder;
ad18db
 import org.apache.maven.project.MavenProjectHelper;
ad18db
 import org.apache.maven.project.ProjectBuildingException;
ad18db
+import org.apache.maven.project.ProjectBuildingRequest;
ad18db
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
ad18db
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
ad18db
 import org.apache.maven.shared.dependency.graph.DependencyNode;
ad18db
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
ad18db
-import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
ad18db
 import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
ad18db
 import org.apache.maven.shared.osgi.Maven2OsgiConverter;
ad18db
 import org.codehaus.plexus.archiver.UnArchiver;
ad18db
@@ -225,9 +225,6 @@ public class BundlePlugin extends AbstractMojo
ad18db
     @Component
ad18db
     protected MavenProjectBuilder mavenProjectBuilder;
ad18db
 
ad18db
-    @Component
ad18db
-    private DependencyTreeBuilder dependencyTreeBuilder;
ad18db
-
ad18db
     /**
ad18db
      * The dependency graph builder to use.
ad18db
      */
ad18db
@@ -347,7 +344,10 @@ public class BundlePlugin extends AbstractMojo
ad18db
         DependencyNode dependencyGraph;
ad18db
         try
ad18db
         {
ad18db
-            dependencyGraph = m_dependencyGraphBuilder.buildDependencyGraph( mavenProject, null );
ad18db
+            ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
ad18db
+            request.setProject(mavenProject);
ad18db
+            request.setRepositorySession(session.getRepositorySession());
ad18db
+            dependencyGraph = m_dependencyGraphBuilder.buildDependencyGraph( request, null );
ad18db
         }
ad18db
         catch ( DependencyGraphBuilderException e )
ad18db
         {
ad18db
@@ -755,7 +755,7 @@ public class BundlePlugin extends AbstractMojo
ad18db
     // We need to find the direct dependencies that have been included in the uber JAR so that we can modify the
ad18db
     // POM accordingly.
ad18db
     private void createDependencyReducedPom( Set<String> artifactsToRemove )
ad18db
-            throws IOException, DependencyTreeBuilderException, ProjectBuildingException
ad18db
+            throws IOException, DependencyGraphBuilderException, ProjectBuildingException
ad18db
     {
ad18db
         Model model = project.getOriginalModel();
ad18db
         List<Dependency> dependencies = new ArrayList<Dependency>();
ad18db
@@ -898,24 +898,26 @@ public class BundlePlugin extends AbstractMojo
ad18db
     }
ad18db
 
ad18db
     public boolean updateExcludesInDeps( MavenProject project, List<Dependency> dependencies, List<Dependency> transitiveDeps )
ad18db
-            throws DependencyTreeBuilderException
ad18db
+    throws DependencyGraphBuilderException
ad18db
     {
ad18db
-        org.apache.maven.shared.dependency.tree.DependencyNode node = dependencyTreeBuilder.buildDependencyTree(project, localRepository, artifactFactory,
ad18db
-                artifactMetadataSource, null,
ad18db
-                artifactCollector);
ad18db
+        ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
ad18db
+        request.setProject(project);
ad18db
+        request.setRepositorySession(session.getRepositorySession());
ad18db
+        DependencyNode node = dependencyGraphBuilder.buildDependencyGraph(request, null);
ad18db
         boolean modified = false;
ad18db
         Iterator it = node.getChildren().listIterator();
ad18db
         while ( it.hasNext() )
ad18db
         {
ad18db
-            org.apache.maven.shared.dependency.tree.DependencyNode n2 = (org.apache.maven.shared.dependency.tree.DependencyNode) it.next();
ad18db
+            DependencyNode n2 = (DependencyNode) it.next();
ad18db
             Iterator it2 = n2.getChildren().listIterator();
ad18db
             while ( it2.hasNext() )
ad18db
             {
ad18db
-                org.apache.maven.shared.dependency.tree.DependencyNode n3 = (org.apache.maven.shared.dependency.tree.DependencyNode) it2.next();
ad18db
+                DependencyNode n3 = (DependencyNode) it2.next();
ad18db
                 //anything two levels deep that is marked "included"
ad18db
                 //is stuff that was excluded by the original poms, make sure it
ad18db
                 //remains excluded IF promoting transitives.
ad18db
-                if ( n3.getState() == org.apache.maven.shared.dependency.tree.DependencyNode.INCLUDED )
ad18db
+                //if ( n3.getState() == org.apache.maven.shared.dependency.tree.DependencyNode.INCLUDED )
ad18db
+                if (true)
ad18db
                 {
ad18db
                     //check if it really isn't in the list of original dependencies.  Maven
ad18db
                     //prior to 2.0.8 may grab versions from transients instead of
ad18db
-- 
ad18db
2.9.3
ad18db