Add DependencyCollector

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1689174 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/CollectorResult.java b/src/main/java/org/apache/maven/shared/artifact/collect/CollectorResult.java
new file mode 100644
index 0000000..aece98f
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/CollectorResult.java
@@ -0,0 +1,29 @@
+package org.apache.maven.shared.artifact.collect;

+

+/*

+ * 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.List;

+

+import org.apache.maven.artifact.repository.ArtifactRepository;

+

+public interface CollectorResult

+{

+    List<ArtifactRepository> getRemoteRepositories();

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/DependencyCollector.java b/src/main/java/org/apache/maven/shared/artifact/collect/DependencyCollector.java
new file mode 100644
index 0000000..d7dee1f
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/DependencyCollector.java
@@ -0,0 +1,41 @@
+package org.apache.maven.shared.artifact.collect;

+

+/*

+ * 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 org.apache.maven.artifact.Artifact;

+import org.apache.maven.model.Dependency;

+import org.apache.maven.project.ProjectBuildingRequest;

+

+/**

+ * Will only download the pom files when not available, never the artifact. 

+ * 

+ * @author Robert Scholte

+ *

+ */

+public interface DependencyCollector

+{

+

+    CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Dependency root )

+        throws DependencyCollectorException;

+

+    CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Artifact root )

+        throws DependencyCollectorException;

+    

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/DependencyCollectorException.java b/src/main/java/org/apache/maven/shared/artifact/collect/DependencyCollectorException.java
new file mode 100644
index 0000000..9daefdb
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/DependencyCollectorException.java
@@ -0,0 +1,30 @@
+package org.apache.maven.shared.artifact.collect;

+

+/*

+ * 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.

+ */

+

+public class DependencyCollectorException extends Exception

+{

+

+    public DependencyCollectorException( String message, Throwable cause )

+    {

+        super( message, cause );

+    }

+

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/internal/DefaultDependencyCollector.java b/src/main/java/org/apache/maven/shared/artifact/collect/internal/DefaultDependencyCollector.java
new file mode 100644
index 0000000..b416f04
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/internal/DefaultDependencyCollector.java
@@ -0,0 +1,111 @@
+package org.apache.maven.shared.artifact.collect.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 org.apache.maven.artifact.Artifact;

+import org.apache.maven.model.Dependency;

+import org.apache.maven.project.ProjectBuildingRequest;

+import org.apache.maven.shared.artifact.collect.CollectorResult;

+import org.apache.maven.shared.artifact.collect.DependencyCollector;

+import org.apache.maven.shared.artifact.collect.DependencyCollectorException;

+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.personality.plexus.lifecycle.phase.Contextualizable;

+

+@Component( role = DependencyCollector.class, hint = "default" )

+public class DefaultDependencyCollector implements DependencyCollector, Contextualizable 

+{

+    private PlexusContainer container;

+   

+    @Override

+    public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Dependency root )

+        throws DependencyCollectorException

+    {

+        try

+        {

+            String hint = isMaven31() ? "maven31" : "maven3";

+

+            DependencyCollector effectiveDependencyCollector = container.lookup( DependencyCollector.class, hint );

+

+            return effectiveDependencyCollector.collectDependencies( buildingRequest, root );

+        }

+        catch ( ComponentLookupException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+    }

+

+    @Override

+    public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Artifact root )

+        throws DependencyCollectorException

+    {

+        try

+        {

+            String hint = isMaven31() ? "maven31" : "maven3";

+

+            DependencyCollector effectiveDependencyCollector = container.lookup( DependencyCollector.class, hint );

+

+            return effectiveDependencyCollector.collectDependencies( buildingRequest, root );

+        }

+        catch ( ComponentLookupException e )

+        {

+            throw new DependencyCollectorException( 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.

+     */

+    public void contextualize( Context context )

+        throws ContextException

+    {

+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );

+    }

+

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/internal/Invoker.java b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Invoker.java
new file mode 100644
index 0000000..de7f6f6
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Invoker.java
@@ -0,0 +1,165 @@
+package org.apache.maven.shared.artifact.collect.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.artifact.collect.DependencyCollectorException;

+

+/**

+ * Invokes method on objects using reflection.

+ */

+final class Invoker

+{

+    private Invoker()

+    {

+        // do not instantiate

+    }

+

+    public static Object invoke( Object object, String method )

+        throws DependencyCollectorException

+    {

+        return invoke( object.getClass(), object, method );

+    }

+

+    public static Object invoke( Class<?> objectClazz, Object object, String method )

+        throws DependencyCollectorException

+    {

+        try

+        {

+            return objectClazz.getMethod( method ).invoke( object );

+        }

+        catch ( IllegalAccessException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( InvocationTargetException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( NoSuchMethodException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+    }

+

+    public static Object invoke( Object object, String method, Class<?> argClazz, Object arg )

+        throws DependencyCollectorException

+    {

+        try

+        {

+            final Class<?> objectClazz = object.getClass();

+            return objectClazz.getMethod( method, argClazz ).invoke( object, arg );

+        }

+        catch ( IllegalAccessException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( InvocationTargetException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( NoSuchMethodException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+    }

+    

+    public static Object invoke( Class<?> objectClazz, String staticMethod, Class<?> argClazz, Object arg )

+                    throws DependencyCollectorException

+    {

+        try

+        {

+            return objectClazz.getMethod( staticMethod, argClazz ).invoke( null, arg );

+        }

+        catch ( IllegalAccessException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( InvocationTargetException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( NoSuchMethodException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+    }

+    

+    /**

+     * <strong>Note:</strong> Ensure that argClasses and args have the same number of elements 

+     * 

+     * @param objectClazz the class of the static method

+     * @param staticMethod the static method to call

+     * @param argClasses the classes of the argument, used to select the right static method

+     * @param args the actual arguments to be passed

+     * @return the result of the method invocation

+     * @throws DependencyCollectorException if any checked exception occurs

+     */

+    public static Object invoke( Class<?> objectClazz, String staticMethod, Class<?>[] argClasses, Object[] args )

+                    throws DependencyCollectorException

+    {

+        try

+        {

+            return objectClazz.getMethod( staticMethod, argClasses ).invoke( null, args );

+        }

+        catch ( IllegalAccessException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( InvocationTargetException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( NoSuchMethodException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+    }

+

+    public static Object newInstance( Class<?> objectClazz, Class<?> argClazz, Object arg )

+        throws DependencyCollectorException

+    {

+        try

+        {

+            return objectClazz.getConstructor( argClazz ).newInstance( arg );

+        }

+        catch ( InstantiationException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( IllegalAccessException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( IllegalArgumentException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( InvocationTargetException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+        catch ( NoSuchMethodException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+    }

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven30ArtifactRepositoryAdapter.java b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven30ArtifactRepositoryAdapter.java
new file mode 100644
index 0000000..e0074d7
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven30ArtifactRepositoryAdapter.java
@@ -0,0 +1,257 @@
+package org.apache.maven.shared.artifact.collect.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.List;

+

+import org.apache.maven.artifact.Artifact;

+import org.apache.maven.artifact.metadata.ArtifactMetadata;

+import org.apache.maven.artifact.repository.ArtifactRepository;

+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;

+import org.apache.maven.artifact.repository.Authentication;

+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;

+import org.apache.maven.repository.Proxy;

+import org.sonatype.aether.repository.RemoteRepository;

+import org.sonatype.aether.repository.RepositoryPolicy;

+

+public class Maven30ArtifactRepositoryAdapter implements ArtifactRepository

+{

+    

+    private RemoteRepository remoteRepository;

+

+    public Maven30ArtifactRepositoryAdapter( RemoteRepository remoteRepository )

+    {

+        this.remoteRepository = remoteRepository;

+    }

+

+    @Override

+    public String pathOf( Artifact artifact )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getUrl()

+    {

+        return remoteRepository.getUrl();

+    }

+

+    @Override

+    public void setUrl( String url )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getBasedir()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getProtocol()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getId()

+    {

+        return remoteRepository.getId();

+    }

+

+    @Override

+    public void setId( String id )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public ArtifactRepositoryPolicy getSnapshots()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy policy )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public ArtifactRepositoryPolicy getReleases()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setReleaseUpdatePolicy( ArtifactRepositoryPolicy policy )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public ArtifactRepositoryLayout getLayout()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setLayout( ArtifactRepositoryLayout layout )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getKey()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public boolean isUniqueVersion()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public boolean isBlacklisted()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setBlacklisted( boolean blackListed )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public Artifact find( Artifact artifact )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public List<String> findVersions( Artifact artifact )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public boolean isProjectAware()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setAuthentication( Authentication authentication )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public Authentication getAuthentication()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setProxy( Proxy proxy )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public Proxy getProxy()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String toString()

+    {

+        StringBuilder sb = new StringBuilder();

+

+        sb.append( "       id: " ).append( getId() ).append( "\n" );

+        sb.append( "      url: " ).append( getUrl() ).append( "\n" );

+        sb.append( "   layout: " ).append( "default" ).append( "\n" );

+

+        RepositoryPolicy snapshotPolicy = remoteRepository.getPolicy( true ); 

+        sb.append( "snapshots: [enabled => " ).append( snapshotPolicy.isEnabled() );

+        sb.append( ", update => " ).append( snapshotPolicy.getUpdatePolicy() ).append( "]\n" );

+

+        RepositoryPolicy releasePolicy = remoteRepository.getPolicy( false ); 

+        sb.append( " releases: [enabled => " ).append( releasePolicy.isEnabled() );

+        sb.append( ", update => " ).append( releasePolicy.getUpdatePolicy() ).append( "]\n" );

+

+        return sb.toString();

+    }

+    

+    

+    @Override

+    public int hashCode()

+    {

+        return remoteRepository.hashCode();

+    }

+

+    @Override

+    public boolean equals( Object obj )

+    {

+        if ( this == obj )

+        {

+            return true;

+        }

+        if ( obj == null )

+        {

+            return false;

+        }

+        if ( getClass() != obj.getClass() )

+        {

+            return false;

+        }

+        

+        Maven30ArtifactRepositoryAdapter other = (Maven30ArtifactRepositoryAdapter) obj;

+        if ( remoteRepository == null )

+        {

+            if ( other.remoteRepository != null )

+            {

+                return false;

+            }

+        }

+        else if ( !remoteRepository.equals( other.remoteRepository ) )

+        {

+            return false;

+        }

+        return true;

+    }

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven30CollectorResult.java b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven30CollectorResult.java
new file mode 100644
index 0000000..3ca1dd9
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven30CollectorResult.java
@@ -0,0 +1,76 @@
+package org.apache.maven.shared.artifact.collect.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.HashSet;

+import java.util.List;

+import java.util.Set;

+

+import org.apache.maven.artifact.repository.ArtifactRepository;

+import org.apache.maven.shared.artifact.collect.CollectorResult;

+import org.sonatype.aether.collection.CollectResult;

+import org.sonatype.aether.graph.DependencyNode;

+import org.sonatype.aether.graph.DependencyVisitor;

+import org.sonatype.aether.repository.RemoteRepository;

+

+public class Maven30CollectorResult implements CollectorResult

+{

+    private final CollectResult collectResult;

+    

+    public Maven30CollectorResult( CollectResult collectResult )

+    {

+        this.collectResult = collectResult;

+    }

+

+    @Override

+    public List<ArtifactRepository> getRemoteRepositories()

+    {

+        final Set<RemoteRepository> aetherRepositories = new HashSet<RemoteRepository>();

+        

+        DependencyVisitor visitor = new DependencyVisitor()

+        {

+            @Override

+            public boolean visitEnter( DependencyNode node )

+            {

+                aetherRepositories.addAll( node.getRepositories() );

+                return true;

+            }

+            

+            @Override

+            public boolean visitLeave( DependencyNode node )

+            {

+                return true;

+            }

+        };

+        

+        collectResult.getRoot().accept( visitor );

+        

+        List<ArtifactRepository> mavenRepositories = new ArrayList<ArtifactRepository>( aetherRepositories.size() );

+        

+        for ( RemoteRepository aetherRepository : aetherRepositories )

+        {

+            mavenRepositories.add( new Maven30ArtifactRepositoryAdapter( aetherRepository ) );

+        }

+        

+        return mavenRepositories;

+    }

+

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven30DependencyCollector.java b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven30DependencyCollector.java
new file mode 100644
index 0000000..63fef57
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven30DependencyCollector.java
@@ -0,0 +1,104 @@
+package org.apache.maven.shared.artifact.collect.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.Collection;

+import java.util.List;

+

+import org.apache.maven.RepositoryUtils;

+import org.apache.maven.artifact.Artifact;

+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;

+import org.apache.maven.project.ProjectBuildingRequest;

+import org.apache.maven.shared.artifact.collect.CollectorResult;

+import org.apache.maven.shared.artifact.collect.DependencyCollector;

+import org.apache.maven.shared.artifact.collect.DependencyCollectorException;

+import org.codehaus.plexus.component.annotations.Component;

+import org.codehaus.plexus.component.annotations.Requirement;

+import org.sonatype.aether.RepositorySystem;

+import org.sonatype.aether.RepositorySystemSession;

+import org.sonatype.aether.artifact.ArtifactTypeRegistry;

+import org.sonatype.aether.collection.CollectRequest;

+import org.sonatype.aether.collection.DependencyCollectionException;

+import org.sonatype.aether.graph.Dependency;

+import org.sonatype.aether.repository.RemoteRepository;

+

+@Component( role = DependencyCollector.class, hint = "maven3" )

+public class Maven30DependencyCollector

+    implements DependencyCollector

+{

+    @Requirement

+    private RepositorySystem repositorySystem;

+

+    @Requirement

+    private ArtifactHandlerManager artifactHandlerManager;

+

+    @Override

+    public CollectorResult collectDependencies( final ProjectBuildingRequest buildingRequest, Artifact root )

+        throws DependencyCollectorException

+    {

+        Class<?>[] argClasses = new Class<?>[] { Artifact.class, Collection.class };

+        Object[] args = new Object[] { root, null };

+        Dependency aetherRoot = (Dependency) Invoker.invoke( RepositoryUtils.class, "toDependency", argClasses, args );

+

+        return collectDependencies( buildingRequest, aetherRoot );

+    }

+

+    @Override

+    public CollectorResult collectDependencies( final ProjectBuildingRequest buildingRequest,

+                                                org.apache.maven.model.Dependency root )

+        throws DependencyCollectorException

+    {

+        ArtifactTypeRegistry typeRegistry =

+            (ArtifactTypeRegistry) Invoker.invoke( RepositoryUtils.class, "newArtifactTypeRegistry",

+                                                   ArtifactHandlerManager.class, artifactHandlerManager );

+

+        Class<?>[] argClasses = new Class<?>[] { Dependency.class, ArtifactTypeRegistry.class };

+        Object[] args = new Object[] { root, typeRegistry };

+        Dependency aetherRoot = (Dependency) Invoker.invoke( RepositoryUtils.class, "toDependency", argClasses, args );

+

+        return collectDependencies( buildingRequest, aetherRoot );

+    }

+

+    private CollectorResult collectDependencies( final ProjectBuildingRequest buildingRequest, Dependency aetherRoot )

+        throws DependencyCollectorException

+    {

+        RepositorySystemSession session =

+            (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );

+

+        CollectRequest request = new CollectRequest();

+        request.setRoot( aetherRoot );

+

+        @SuppressWarnings( "unchecked" )

+        List<RemoteRepository> aetherRepositories =

+            (List<RemoteRepository>) Invoker.invoke( RepositoryUtils.class, "toRepos", List.class,

+                                                     buildingRequest.getRemoteRepositories() );

+        request.setRepositories( aetherRepositories );

+

+        try

+        {

+            return new Maven30CollectorResult( repositorySystem.collectDependencies( session, request ) );

+        }

+        catch ( DependencyCollectionException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+    }

+

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven31ArtifactRepositoryAdapter.java b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven31ArtifactRepositoryAdapter.java
new file mode 100644
index 0000000..a42486f
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven31ArtifactRepositoryAdapter.java
@@ -0,0 +1,257 @@
+package org.apache.maven.shared.artifact.collect.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.List;

+

+import org.apache.maven.artifact.Artifact;

+import org.apache.maven.artifact.metadata.ArtifactMetadata;

+import org.apache.maven.artifact.repository.ArtifactRepository;

+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;

+import org.apache.maven.artifact.repository.Authentication;

+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;

+import org.apache.maven.repository.Proxy;

+import org.eclipse.aether.repository.RemoteRepository;

+import org.eclipse.aether.repository.RepositoryPolicy;

+

+public class Maven31ArtifactRepositoryAdapter implements ArtifactRepository

+{

+    

+    private RemoteRepository remoteRepository;

+

+    public Maven31ArtifactRepositoryAdapter( RemoteRepository remoteRepository )

+    {

+        this.remoteRepository = remoteRepository;

+    }

+

+    @Override

+    public String pathOf( Artifact artifact )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getUrl()

+    {

+        return remoteRepository.getUrl();

+    }

+

+    @Override

+    public void setUrl( String url )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getBasedir()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getProtocol()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getId()

+    {

+        return remoteRepository.getId();

+    }

+

+    @Override

+    public void setId( String id )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public ArtifactRepositoryPolicy getSnapshots()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy policy )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public ArtifactRepositoryPolicy getReleases()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setReleaseUpdatePolicy( ArtifactRepositoryPolicy policy )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public ArtifactRepositoryLayout getLayout()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setLayout( ArtifactRepositoryLayout layout )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String getKey()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public boolean isUniqueVersion()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public boolean isBlacklisted()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setBlacklisted( boolean blackListed )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public Artifact find( Artifact artifact )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public List<String> findVersions( Artifact artifact )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public boolean isProjectAware()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setAuthentication( Authentication authentication )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public Authentication getAuthentication()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public void setProxy( Proxy proxy )

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public Proxy getProxy()

+    {

+        throw new UnsupportedOperationException();

+    }

+

+    @Override

+    public String toString()

+    {

+        StringBuilder sb = new StringBuilder();

+

+        sb.append( "       id: " ).append( getId() ).append( "\n" );

+        sb.append( "      url: " ).append( getUrl() ).append( "\n" );

+        sb.append( "   layout: " ).append( "default" ).append( "\n" );

+

+        RepositoryPolicy snapshotPolicy = remoteRepository.getPolicy( true ); 

+        sb.append( "snapshots: [enabled => " ).append( snapshotPolicy.isEnabled() );

+        sb.append( ", update => " ).append( snapshotPolicy.getUpdatePolicy() ).append( "]\n" );

+

+        RepositoryPolicy releasePolicy = remoteRepository.getPolicy( false ); 

+        sb.append( " releases: [enabled => " ).append( releasePolicy.isEnabled() );

+        sb.append( ", update => " ).append( releasePolicy.getUpdatePolicy() ).append( "]\n" );

+

+        return sb.toString();

+    }

+    

+    

+    @Override

+    public int hashCode()

+    {

+        return remoteRepository.hashCode();

+    }

+

+    @Override

+    public boolean equals( Object obj )

+    {

+        if ( this == obj )

+        {

+            return true;

+        }

+        if ( obj == null )

+        {

+            return false;

+        }

+        if ( getClass() != obj.getClass() )

+        {

+            return false;

+        }

+        

+        Maven31ArtifactRepositoryAdapter other = (Maven31ArtifactRepositoryAdapter) obj;

+        if ( remoteRepository == null )

+        {

+            if ( other.remoteRepository != null )

+            {

+                return false;

+            }

+        }

+        else if ( !remoteRepository.equals( other.remoteRepository ) )

+        {

+            return false;

+        }

+        return true;

+    }

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven31CollectorResult.java b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven31CollectorResult.java
new file mode 100644
index 0000000..5b0e1c1
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven31CollectorResult.java
@@ -0,0 +1,77 @@
+package org.apache.maven.shared.artifact.collect.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.HashSet;

+import java.util.List;

+import java.util.Set;

+

+import org.apache.maven.artifact.repository.ArtifactRepository;

+import org.apache.maven.shared.artifact.collect.CollectorResult;

+import org.eclipse.aether.collection.CollectResult;

+import org.eclipse.aether.graph.DependencyNode;

+import org.eclipse.aether.graph.DependencyVisitor;

+import org.eclipse.aether.repository.RemoteRepository;

+

+

+public class Maven31CollectorResult implements CollectorResult

+{

+    private final CollectResult collectResult;

+    

+    public Maven31CollectorResult( CollectResult collectResult )

+    {

+        this.collectResult = collectResult;

+    }

+

+    @Override

+    public List<ArtifactRepository> getRemoteRepositories()

+    {

+        final Set<RemoteRepository> aetherRepositories = new HashSet<RemoteRepository>();

+        

+        DependencyVisitor visitor = new DependencyVisitor()

+        {

+            @Override

+            public boolean visitEnter( DependencyNode node )

+            {

+                aetherRepositories.addAll( node.getRepositories() );

+                return true;

+            }

+            

+            @Override

+            public boolean visitLeave( DependencyNode node )

+            {

+                return true;

+            }

+        };

+        

+        collectResult.getRoot().accept( visitor );

+        

+        List<ArtifactRepository> mavenRepositories = new ArrayList<ArtifactRepository>( aetherRepositories.size() );

+        

+        for ( RemoteRepository aetherRepository : aetherRepositories )

+        {

+            mavenRepositories.add( new Maven31ArtifactRepositoryAdapter( aetherRepository ) );

+        }

+        

+        return mavenRepositories;

+    }

+

+}

diff --git a/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven31DependencyCollector.java b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven31DependencyCollector.java
new file mode 100644
index 0000000..f21405d
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/artifact/collect/internal/Maven31DependencyCollector.java
@@ -0,0 +1,104 @@
+package org.apache.maven.shared.artifact.collect.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.Collection;

+import java.util.List;

+

+import org.apache.maven.RepositoryUtils;

+import org.apache.maven.artifact.Artifact;

+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;

+import org.apache.maven.project.ProjectBuildingRequest;

+import org.apache.maven.shared.artifact.collect.CollectorResult;

+import org.apache.maven.shared.artifact.collect.DependencyCollector;

+import org.apache.maven.shared.artifact.collect.DependencyCollectorException;

+import org.codehaus.plexus.component.annotations.Component;

+import org.codehaus.plexus.component.annotations.Requirement;

+import org.eclipse.aether.RepositorySystem;

+import org.eclipse.aether.RepositorySystemSession;

+import org.eclipse.aether.artifact.ArtifactTypeRegistry;

+import org.eclipse.aether.collection.CollectRequest;

+import org.eclipse.aether.collection.DependencyCollectionException;

+import org.eclipse.aether.graph.Dependency;

+import org.eclipse.aether.repository.RemoteRepository;

+

+@Component( role = DependencyCollector.class, hint = "maven31" )

+public class Maven31DependencyCollector

+    implements DependencyCollector

+{

+    @Requirement

+    private RepositorySystem repositorySystem;

+

+    @Requirement

+    private ArtifactHandlerManager artifactHandlerManager;

+

+    @Override

+    public CollectorResult collectDependencies( final ProjectBuildingRequest buildingRequest,

+                                                org.apache.maven.model.Dependency root )

+        throws DependencyCollectorException

+    {

+        ArtifactTypeRegistry typeRegistry =

+            (ArtifactTypeRegistry) Invoker.invoke( RepositoryUtils.class, "newArtifactTypeRegistry",

+                                                   ArtifactHandlerManager.class, artifactHandlerManager );

+

+        Class<?>[] argClasses = new Class<?>[] { org.apache.maven.model.Dependency.class, ArtifactTypeRegistry.class };

+        Object[] args = new Object[] { root, typeRegistry };

+        Dependency aetherRoot = (Dependency) Invoker.invoke( RepositoryUtils.class, "toDependency", argClasses, args );

+

+        return collectDependencies( buildingRequest, aetherRoot );

+    }

+

+    @Override

+    public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Artifact root )

+        throws DependencyCollectorException

+    {

+        Class<?>[] argClasses = new Class<?>[] { Artifact.class, Collection.class };

+        Object[] args = new Object[] { root, null };

+        Dependency aetherRoot = (Dependency) Invoker.invoke( RepositoryUtils.class, "toDependency", argClasses, args );

+

+        return collectDependencies( buildingRequest, aetherRoot );

+    }

+

+    private CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, Dependency aetherRoot )

+        throws DependencyCollectorException

+    {

+        CollectRequest request = new CollectRequest();

+        request.setRoot( aetherRoot );

+

+        RepositorySystemSession session =

+            (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );

+

+        @SuppressWarnings( "unchecked" )

+        List<RemoteRepository> aetherRepositories =

+            (List<RemoteRepository>) Invoker.invoke( RepositoryUtils.class, "toRepos", List.class,

+                                                     buildingRequest.getRemoteRepositories() );

+        request.setRepositories( aetherRepositories );

+

+        try

+        {

+            return new Maven31CollectorResult( repositorySystem.collectDependencies( session, request ) );

+        }

+        catch ( DependencyCollectionException e )

+        {

+            throw new DependencyCollectorException( e.getMessage(), e );

+        }

+    }

+

+}