You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/01/23 23:59:47 UTC

[maven-dependency-tree] 01/01: Require maven 3.1.1

This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch maven-311
in repository https://gitbox.apache.org/repos/asf/maven-dependency-tree.git

commit e58e830b63c3f8463894119764f74a1ebbe1ee8f
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Sun Jan 24 00:57:55 2021 +0100

    Require maven 3.1.1
---
 pom.xml                                            |  45 +----
 src/it/maven-version/pom.xml                       |   2 +-
 src/it/mshared-167/pom.xml                         |   2 +-
 src/it/reactor/module-z-deps-y/pom.xml             |   2 +-
 src/it/verbose/expected-verbose.txt                |   1 +
 src/it/verbose/pom.xml                             |   2 +-
 .../dependency/graph/DependencyGraphBuilder.java   |   2 +-
 .../internal/DefaultDependencyGraphBuilder.java    | 107 +---------
 .../shared/dependency/graph/internal/Invoker.java  | 105 ----------
 .../internal/Maven31DependencyGraphBuilder.java    |  48 ++---
 .../internal/Maven3DependencyGraphBuilder.java     | 225 ---------------------
 11 files changed, 27 insertions(+), 514 deletions(-)

diff --git a/pom.xml b/pom.xml
index fbda3ca..c01117e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,7 +55,7 @@
   </distributionManagement>
 
   <properties>
-    <mavenVersion>3.0</mavenVersion>
+    <mavenVersion>3.1.1</mavenVersion>
 	<javaVersion>7</javaVersion>
     <project.build.outputTimestamp>2020-02-07T09:03:59Z</project.build.outputTimestamp>
   </properties>
@@ -70,36 +70,13 @@
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-core</artifactId>
-      <version>3.0.4</version>
+      <version>${mavenVersion}</version>
       <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-component-annotations</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.sonatype.aether</groupId>
-      <artifactId>aether-api</artifactId>
-      <version>1.13.1</version>
-      <optional>true</optional>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.aether</groupId>
-      <artifactId>aether-api</artifactId>
-      <version>1.1.0</version>
-      <optional>true</optional>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.aether</groupId>
-      <artifactId>aether-util</artifactId>
-      <version>1.1.0</version>
-      <exclusions>
-        <exclusion>
-          <groupId>org.eclipse.aether</groupId>
-          <artifactId>aether-api</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
   </dependencies>
 
   <build>
@@ -116,14 +93,6 @@
         </executions>
       </plugin>
       <plugin>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <excludes>
-            <exclude>**/DefaultDependencyTreeBuilderTest*</exclude><!-- FIXME: conflict on DefaultArtifactFactory between maven-core 3.x and maven-artifact 2.x -->
-          </excludes>
-        </configuration>
-      </plugin>
-      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-invoker-plugin</artifactId>
         <configuration>
@@ -140,11 +109,8 @@
           <pomIncludes>
             <pomInclude>*/pom.xml</pomInclude>
           </pomIncludes>
-          <pomExcludes> <!-- Tree ITs, must be transformed to graph ITs -->
-            <pomExclude>maven-version/pom.xml</pomExclude>
-            <pomExclude>mshared-167/pom.xml</pomExclude>
-            <pomExclude>reactor/pom.xml</pomExclude>
-            <pomExclude>verbose/pom.xml</pomExclude>
+          <pomExcludes>
+            <pomExclude>verbose/pom.xml</pomExclude><!-- no verbose option for 3.x yet -->
           </pomExcludes>
           <properties>
             <maven.compiler.source>${maven.compiler.source}</maven.compiler.source>
@@ -173,7 +139,8 @@
               These files contains the expected output of this component and can not contain a license header.
             -->
             <exclude>src/it/*/expected*.txt</exclude>
-          </excludes>            
+            <exclude>src/it/**/*.iml</exclude>
+          </excludes>
         </configuration>
         <executions>
           <execution>
diff --git a/src/it/maven-version/pom.xml b/src/it/maven-version/pom.xml
index 289994a..26dc896 100644
--- a/src/it/maven-version/pom.xml
+++ b/src/it/maven-version/pom.xml
@@ -72,7 +72,7 @@
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-dependency-plugin</artifactId>
-          <version>2.8</version>
+          <version>3.1.2</version>
           <configuration>
             <outputFile>target/tree.txt</outputFile>
           </configuration>
diff --git a/src/it/mshared-167/pom.xml b/src/it/mshared-167/pom.xml
index 132e479..ba06b01 100644
--- a/src/it/mshared-167/pom.xml
+++ b/src/it/mshared-167/pom.xml
@@ -52,7 +52,7 @@
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-dependency-plugin</artifactId>
-          <version>2.8</version>
+          <version>3.1.2</version>
           <configuration>
             <outputFile>${outputFile}</outputFile>
           </configuration>
diff --git a/src/it/reactor/module-z-deps-y/pom.xml b/src/it/reactor/module-z-deps-y/pom.xml
index f6788fc..dce53b5 100644
--- a/src/it/reactor/module-z-deps-y/pom.xml
+++ b/src/it/reactor/module-z-deps-y/pom.xml
@@ -53,7 +53,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
-        <version>2.8</version>
+        <version>3.1.2</version>
         <dependencies>
           <dependency>
             <groupId>@project.groupId@</groupId>
diff --git a/src/it/verbose/expected-verbose.txt b/src/it/verbose/expected-verbose.txt
index a4453e5..bb04625 100644
--- a/src/it/verbose/expected-verbose.txt
+++ b/src/it/verbose/expected-verbose.txt
@@ -64,6 +64,7 @@ org.apache.maven.its.dependency-tree:verbose:jar:1.0-SNAPSHOT
    |  \- (org.apache.xmlgraphics:batik-xml:jar:1.7:compile - omitted for duplicate)
    +- (org.apache.xmlgraphics:batik-bridge:jar:1.7:compile - omitted for cycle)
    +- org.apache.xmlgraphics:batik-script:jar:1.7:compile
+   |  \- org.apache.xmlgraphics:batik-js:jar:1.7:compile
    +- org.apache.xmlgraphics:batik-svg-dom:jar:1.7:compile
    |  +- (org.apache.xmlgraphics:batik-svg-dom:jar:1.7:compile - omitted for cycle)
    |  +- (org.apache.xmlgraphics:batik-anim:jar:1.7:compile - omitted for duplicate)
diff --git a/src/it/verbose/pom.xml b/src/it/verbose/pom.xml
index c57704f..46de2cf 100644
--- a/src/it/verbose/pom.xml
+++ b/src/it/verbose/pom.xml
@@ -83,7 +83,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
-        <version>2.8</version>
+        <version>3.1.2</version>
         <dependencies>
           <dependency>
             <groupId>@project.groupId@</groupId>
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java
index e0e5fe9..096db37 100644
--- a/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java
+++ b/src/main/java/org/apache/maven/shared/dependency/graph/DependencyGraphBuilder.java
@@ -26,7 +26,7 @@ import org.apache.maven.project.ProjectBuildingRequest;
 import java.util.Collection;
 
 /**
- * Maven project dependency graph builder API, neutral against Maven 2 or Maven 3.
+ * Maven project dependency graph builder API, based on Maven 3.1+.
  *
  * @author Hervé Boutemy
  * @since 2.0
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java
index 593c057..3e2ddd4 100644
--- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java
+++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java
@@ -19,122 +19,19 @@ package org.apache.maven.shared.dependency.graph.internal;
  * under the License.
  */
 
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
-import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
-import org.apache.maven.shared.dependency.graph.DependencyNode;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
-
-import java.util.Collection;
 
 /**
- * Default dependency graph builder that detects current Maven version to delegate to either Maven 3.0 or 3.1+ specific
- * code.
+ * Default dependency graph builder based on Maven 3.1+ specific implementation code.
  *
- * @see Maven3DependencyGraphBuilder
  * @see Maven31DependencyGraphBuilder
  * @author Hervé Boutemy
  * @since 2.0
  */
 @Component( role = DependencyGraphBuilder.class )
 public class DefaultDependencyGraphBuilder
-    extends AbstractLogEnabled
-    implements DependencyGraphBuilder, Contextualizable
+    extends Maven31DependencyGraphBuilder
 {
-    protected PlexusContainer container;
-
-    /**
-     * Builds a dependency graph.
-     *
-     * @param buildingRequest the buildingRequest
-     * @param filter artifact filter (can be <code>null</code>)
-     * @return DependencyNode containing the dependency graph.
-     * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
-     */
-    @Override
-    public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter )
-        throws DependencyGraphBuilderException
-    {
-        return buildDependencyGraph( buildingRequest, filter, null );
-    }
-
-    /**
-     * Builds a dependency graph.
-     *
-     * @param filter artifact filter (can be <code>null</code>)
-     * @param reactorProjects Collection of those projects contained in the reactor (can be <code>null</code>)
-     * @return DependencyNode containing the dependency graph.
-     * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
-     */
-    @Override
-    public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter,
-                                                Collection<MavenProject> reactorProjects )
-        throws DependencyGraphBuilderException
-    {
-        try
-        {
-            String hint = isMaven31() ? "maven31" : "maven3";
-
-            DependencyGraphBuilder effectiveGraphBuilder =
-                (DependencyGraphBuilder) container.lookup( DependencyGraphBuilder.class.getCanonicalName(), hint );
-            
-            if ( getLogger().isDebugEnabled() )
-            {
-                MavenProject project = buildingRequest.getProject();
-                
-                getLogger().debug( "building " + hint + " dependency graph for " + project.getId() + " with "
-                                + effectiveGraphBuilder.getClass().getSimpleName() );
-            }
-
-            return effectiveGraphBuilder.buildDependencyGraph( buildingRequest, filter, reactorProjects );
-        }
-        catch ( ComponentLookupException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-    }
-
-    /**
-     * @return true if the current Maven version is Maven 3.1.
-     */
-    protected static boolean isMaven31()
-    {
-        return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific
-    }
-
-    private static boolean canFindCoreClass( String className )
-    {
-        try
-        {
-            Thread.currentThread().getContextClassLoader().loadClass( className );
-
-            return true;
-        }
-        catch ( ClassNotFoundException e )
-        {
-            return false;
-        }
-    }
 
-    /**
-     * Injects the Plexus content.
-     *
-     * @param context   Plexus context to inject.
-     * @throws ContextException if the PlexusContainer could not be located.
-     */
-    @Override
-    public void contextualize( Context context )
-        throws ContextException
-    {
-        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
-    }
 }
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Invoker.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/Invoker.java
deleted file mode 100644
index f591973..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Invoker.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.apache.maven.shared.dependency.graph.internal;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
-
-/**
- * Invokes method on objects using reflection.
- */
-final class Invoker
-{
-    private Invoker()
-    {
-        // do not instantiate
-    }
-
-    public static Object invoke( Object object, String method )
-        throws DependencyGraphBuilderException
-    {
-        return invoke( object.getClass(), object, method );
-    }
-
-    public static Object invoke( Class<?> objectClazz, Object object, String method )
-        throws DependencyGraphBuilderException
-    {
-        try
-        {
-            return objectClazz.getMethod( method ).invoke( object );
-        }
-        catch ( IllegalAccessException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-        catch ( InvocationTargetException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-        catch ( NoSuchMethodException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-    }
-
-    public static Object invoke( Object object, String method, Class<?> clazz, Object arg )
-        throws DependencyGraphBuilderException
-    {
-        try
-        {
-            final Class<?> objectClazz = object.getClass();
-            return objectClazz.getMethod( method, clazz ).invoke( object, arg );
-        }
-        catch ( IllegalAccessException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-        catch ( InvocationTargetException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-        catch ( NoSuchMethodException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-    }
-    
-    public static Object invoke( Class<?> objectClazz, String staticMethod, Class<?> argClazz, Object arg )
-                    throws DependencyGraphBuilderException
-    {
-        try
-        {
-            return objectClazz.getMethod( staticMethod, argClazz ).invoke( null, arg );
-        }
-        catch ( IllegalAccessException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-        catch ( InvocationTargetException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-        catch ( NoSuchMethodException e )
-        {
-            throw new DependencyGraphBuilderException( e.getMessage(), e );
-        }
-    }
-}
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
index 5a53dcb..2c8d2bc 100644
--- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
+++ b/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
@@ -94,8 +94,7 @@ public class Maven31DependencyGraphBuilder
     {
         MavenProject project = buildingRequest.getProject();
 
-        RepositorySystemSession session =
-            (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );
+        RepositorySystemSession session = buildingRequest.getRepositorySession();
 
         /*
          * if ( Boolean.TRUE != ( (Boolean) session.getConfigProperties().get(
@@ -106,14 +105,11 @@ public class Maven31DependencyGraphBuilder
 
         final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
         request.setMavenProject( project );
-        Invoker.invoke( request, "setRepositorySession", RepositorySystemSession.class, session );
+        request.setRepositorySession( session );
 
         final DependencyResolutionResult result = resolveDependencies( request, reactorProjects );
-        org.eclipse.aether.graph.DependencyNode graph =
-            (org.eclipse.aether.graph.DependencyNode) Invoker.invoke( DependencyResolutionResult.class, result,
-                                                                      "getDependencyGraph" );
 
-        return buildDependencyNode( null, graph, project.getArtifact(), filter );
+        return buildDependencyNode( null, result.getDependencyGraph(), project.getArtifact(), filter );
     }
 
     private DependencyResolutionResult resolveDependencies( DependencyResolutionRequest request,
@@ -145,7 +141,7 @@ public class Maven31DependencyGraphBuilder
 
         List<Dependency> reactorDeps = getReactorDependencies( reactorProjects, result.getUnresolvedDependencies() );
         result.getUnresolvedDependencies().removeAll( reactorDeps );
-        Invoker.invoke( result.getResolvedDependencies(), "addAll", Collection.class, reactorDeps );
+        result.getResolvedDependencies().addAll( reactorDeps );
 
         if ( !result.getUnresolvedDependencies().isEmpty() )
         {
@@ -158,13 +154,13 @@ public class Maven31DependencyGraphBuilder
 
     private List<Dependency> getReactorDependencies( Collection<MavenProject> reactorProjects, List<?> dependencies )
     {
-        Set<ArtifactKey> reactorProjectsIds = new HashSet<ArtifactKey>();
+        Set<ArtifactKey> reactorProjectsIds = new HashSet<>();
         for ( MavenProject project : reactorProjects )
         {
             reactorProjectsIds.add( new ArtifactKey( project ) );
         }
 
-        List<Dependency> reactorDeps = new ArrayList<Dependency>();
+        List<Dependency> reactorDeps = new ArrayList<>();
         for ( Object untypedDependency : dependencies )
         {
             Dependency dependency = (Dependency) untypedDependency;
@@ -182,27 +178,6 @@ public class Maven31DependencyGraphBuilder
         return reactorDeps;
     }
 
-    private Artifact getDependencyArtifact( Dependency dep )
-    {
-        org.eclipse.aether.artifact.Artifact artifact = dep.getArtifact();
-
-        try
-        {
-            Artifact mavenArtifact = (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact",
-                                              org.eclipse.aether.artifact.Artifact.class, artifact );
-
-            mavenArtifact.setScope( dep.getScope() );
-            mavenArtifact.setOptional( dep.isOptional() );
-
-            return mavenArtifact;
-        }
-        catch ( DependencyGraphBuilderException e )
-        {
-            // ReflectionException should not happen
-            throw new RuntimeException( e.getMessage(), e );
-        }
-    }
-
     private DependencyNode buildDependencyNode( DependencyNode parent, org.eclipse.aether.graph.DependencyNode node,
                                                 Artifact artifact, ArtifactFilter filter )
     {
@@ -228,14 +203,17 @@ public class Maven31DependencyGraphBuilder
                                        getVersionSelectedFromRange( node.getVersionConstraint() ),
                                        optional, exclusions );
 
-        List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size() );
+        List<DependencyNode> nodes = new ArrayList<>( node.getChildren().size() );
         for ( org.eclipse.aether.graph.DependencyNode child : node.getChildren() )
         {
-            Artifact childArtifact = getDependencyArtifact( child.getDependency() );
+            Dependency dep = child.getDependency();
+            Artifact mavenArtifact = RepositoryUtils.toArtifact( dep.getArtifact() );
+            mavenArtifact.setScope( dep.getScope() );
+            mavenArtifact.setOptional( dep.isOptional() );
 
-            if ( ( filter == null ) || filter.include( childArtifact ) )
+            if ( ( filter == null ) || filter.include( mavenArtifact ) )
             {
-                nodes.add( buildDependencyNode( current, child, childArtifact, filter ) );
+                nodes.add( buildDependencyNode( current, child, mavenArtifact, filter ) );
             }
         }
 
diff --git a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java b/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
deleted file mode 100644
index 2a2e58b..0000000
--- a/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
+++ /dev/null
@@ -1,225 +0,0 @@
-package org.apache.maven.shared.dependency.graph.internal;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.RepositoryUtils;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.project.DefaultDependencyResolutionRequest;
-import org.apache.maven.project.DependencyResolutionException;
-import org.apache.maven.project.DependencyResolutionRequest;
-import org.apache.maven.project.DependencyResolutionResult;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.project.ProjectDependenciesResolver;
-import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
-import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
-import org.apache.maven.shared.dependency.graph.DependencyNode;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.sonatype.aether.graph.Dependency;
-import org.sonatype.aether.version.VersionConstraint;
-
-/**
- * Wrapper around Maven 3 dependency resolver.
- *
- * @see ProjectDependenciesResolver
- * @author Hervé Boutemy
- * @since 2.0
- */
-@Component( role = DependencyGraphBuilder.class, hint = "maven3" )
-public class Maven3DependencyGraphBuilder
-    extends AbstractLogEnabled
-    implements DependencyGraphBuilder
-{
-    @Requirement
-    private ProjectDependenciesResolver resolver;
-
-    /**
-     * Builds the dependency graph for Maven 3.
-     *
-     * @param buildingRequest the buildingRequest
-     * @param filter artifact filter (can be <code>null</code>)
-     * @return DependencyNode containing the dependency graph.
-     * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
-     */
-    @Override
-    public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter )
-        throws DependencyGraphBuilderException
-    {
-        return buildDependencyGraph( buildingRequest, filter, null );
-    }
-
-    /**
-     * Builds the dependency graph for Maven 3, eventually hacking for collecting projects from
-     * reactor not yet built.
-     *
-     * @param buildingRequest the buildingRequest
-     * @param filter artifact filter (can be <code>null</code>)
-     * @param reactorProjects Collection of those projects contained in the reactor (can be <code>null</code>).
-     * @return DependencyNode containing the dependency graph.
-     * @throws DependencyGraphBuilderException if some of the dependencies could not be resolved.
-     */
-    @Override
-    public DependencyNode buildDependencyGraph( ProjectBuildingRequest buildingRequest, ArtifactFilter filter,
-                                                Collection<MavenProject> reactorProjects )
-        throws DependencyGraphBuilderException
-    {
-        MavenProject project = buildingRequest.getProject();
-
-        DependencyResolutionRequest request =
-            new DefaultDependencyResolutionRequest( project, buildingRequest.getRepositorySession() );
-
-        DependencyResolutionResult result = resolveDependencies( request, reactorProjects );
-
-        return buildDependencyNode( null, result.getDependencyGraph(), project.getArtifact(), filter );
-    }
-
-    private DependencyResolutionResult resolveDependencies( DependencyResolutionRequest request,
-                                                            Collection<MavenProject> reactorProjects )
-        throws DependencyGraphBuilderException
-    {
-        try
-        {
-            return resolver.resolve( request );
-        }
-        catch ( DependencyResolutionException e )
-        {
-            if ( reactorProjects == null )
-            {
-                throw new DependencyGraphBuilderException( "Could not resolve following dependencies: "
-                    + e.getResult().getUnresolvedDependencies(), e );
-            }
-
-            // try collecting from reactor
-            return collectDependenciesFromReactor( e, reactorProjects );
-        }
-    }
-
-    private DependencyResolutionResult collectDependenciesFromReactor( DependencyResolutionException e,
-                                                                       Collection<MavenProject> reactorProjects )
-        throws DependencyGraphBuilderException
-    {
-        DependencyResolutionResult result = e.getResult();
-
-        List<Dependency> reactorDeps = getReactorDependencies( reactorProjects, result.getUnresolvedDependencies() );
-
-        result.getUnresolvedDependencies().removeAll( reactorDeps );
-        Invoker.invoke( result.getResolvedDependencies(), "addAll", Collection.class, reactorDeps );
-
-        if ( !result.getUnresolvedDependencies().isEmpty() )
-        {
-            throw new DependencyGraphBuilderException( "Could not resolve nor collect following dependencies: "
-                + result.getUnresolvedDependencies(), e );
-        }
-
-        return result;
-    }
-
-    private List<org.sonatype.aether.graph.Dependency> getReactorDependencies( Collection<MavenProject> reactorProjects,
-                                                                               List<?> dependencies )
-    {
-        Set<ArtifactKey> reactorProjectsIds = new HashSet<ArtifactKey>();
-        for ( MavenProject project : reactorProjects )
-        {
-            reactorProjectsIds.add( new ArtifactKey( project ) );
-        }
-
-        List<Dependency> reactorDeps = new ArrayList<Dependency>();
-        for ( Object untypedDependency : dependencies )
-        {
-            Dependency dependency = (Dependency) untypedDependency;
-            org.sonatype.aether.artifact.Artifact depArtifact = dependency.getArtifact();
-
-            ArtifactKey key =
-                new ArtifactKey( depArtifact.getGroupId(), depArtifact.getArtifactId(), depArtifact.getVersion() );
-
-            if ( reactorProjectsIds.contains( key ) )
-            {
-                reactorDeps.add( dependency );
-            }
-        }
-
-        return reactorDeps;
-    }
-
-    private Artifact getDependencyArtifact( Dependency dep )
-    {
-        Artifact mavenArtifact = RepositoryUtils.toArtifact( dep.getArtifact() );
-
-        mavenArtifact.setScope( dep.getScope() );
-        mavenArtifact.setOptional( dep.isOptional() );
-
-        return mavenArtifact;
-    }
-
-    private DependencyNode buildDependencyNode( DependencyNode parent, org.sonatype.aether.graph.DependencyNode node,
-                                                Artifact artifact, ArtifactFilter filter )
-    {
-        DefaultDependencyNode current =
-            new DefaultDependencyNode( parent, artifact,
-                                       null /* node.getPremanagedVersion() */,
-                                       null /* node.getPremanagedScope() */,
-                                       getVersionSelectedFromRange( node.getVersionConstraint() ) );
-
-        List<DependencyNode> nodes = new ArrayList<DependencyNode>( node.getChildren().size() );
-        for ( org.sonatype.aether.graph.DependencyNode child : node.getChildren() )
-        {
-            Artifact childArtifact = getDependencyArtifact( child.getDependency() );
-
-            if ( ( filter == null ) || filter.include( childArtifact ) )
-            {
-                nodes.add( buildDependencyNode( current, child, childArtifact, filter ) );
-            }
-        }
-
-        current.setChildren( Collections.unmodifiableList( nodes ) );
-
-        return current;
-    }
-
-    private String getVersionSelectedFromRange( VersionConstraint constraint )
-    {
-        if ( ( constraint == null ) || ( constraint.getVersion() != null ) )
-        {
-            return null;
-        }
-
-        StringBuilder sb = new StringBuilder();
-        for ( org.sonatype.aether.version.VersionRange range : constraint.getRanges() )
-        {
-            if ( sb.length() > 0 )
-            {
-                sb.append( ',' );
-            }
-            sb.append( range );
-        }
-
-        return sb.toString();
-    }
-}