Author: krosenvold Date: Sun Jun 14 09:43:41 2015 New Revision: 1685373 URL: http://svn.apache.org/r1685373 Log: Fixed unused import
Modified: maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/collection/ArtifactTransitivityFilter.java Modified: maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/collection/ArtifactTransitivityFilter.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/collection/ArtifactTransitivityFilter.java?rev=1685373&r1=1685372&r2=1685373&view=diff ============================================================================== --- maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/collection/ArtifactTransitivityFilter.java (original) +++ maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/collection/ArtifactTransitivityFilter.java Sun Jun 14 09:43:41 2015 @@ -19,14 +19,8 @@ package org.apache.maven.shared.artifact * under the License. */ -import java.lang.reflect.InvocationTargetException; -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.execution.MavenSession; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.DependencyResolutionResult; import org.apache.maven.project.ProjectBuilder; @@ -34,9 +28,14 @@ import org.apache.maven.project.ProjectB import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingResult; +import java.lang.reflect.InvocationTargetException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * This filter will exclude everything that is not a dependency of the selected artifact. - * + * * @author <a href="mailto:bri...@apache.org">Brian Fox</a> * @version $Id$ */ @@ -49,22 +48,22 @@ public class ArtifactTransitivityFilter private Set<String> transitiveArtifacts; /** - * Use {@link MavenSession#getProjectBuildingRequest()} to get the buildingRequest. + * Use {@link org.apache.maven.execution.MavenSession#getProjectBuildingRequest()} to get the buildingRequest. * The projectBuilder should be resolved with CDI. - * + * <p/> * <pre> * // For Mojo * @Component * private ProjectBuilder projectBuilder; * * // For Components - * @Requirement // or @Inject + * @Requirement // or @Inject * private ProjectBuilder projectBuilder; * </pre> - * - * @param artifact the artifact to resolve the dependencies from + * + * @param artifact the artifact to resolve the dependencies from * @param buildingRequest the buildingRequest - * @param projectBuilder the projectBuilder + * @param projectBuilder the projectBuilder * @throws ProjectBuildingException if the project descriptor could not be successfully built */ public ArtifactTransitivityFilter( Artifact artifact, ProjectBuildingRequest buildingRequest, @@ -72,9 +71,9 @@ public class ArtifactTransitivityFilter throws ProjectBuildingException { ProjectBuildingRequest request = new DefaultProjectBuildingRequest( buildingRequest ); - + request.setResolveDependencies( true ); - + ProjectBuildingResult buildingResult = projectBuilder.build( artifact, request ); DependencyResolutionResult resolutionResult = buildingResult.getDependencyResolutionResult(); @@ -84,16 +83,15 @@ public class ArtifactTransitivityFilter { try { - @SuppressWarnings( "unchecked" ) - List<org.eclipse.aether.graph.Dependency> dependencies = - (List<org.eclipse.aether.graph.Dependency>) Invoker.invoke( resolutionResult, "getDependencies" ); + @SuppressWarnings( "unchecked" ) List<org.eclipse.aether.graph.Dependency> dependencies = + (List<org.eclipse.aether.graph.Dependency>) Invoker.invoke( resolutionResult, + "getDependencies" ); for ( org.eclipse.aether.graph.Dependency dependency : dependencies ) { - Artifact mavenArtifact = - (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", - org.eclipse.aether.artifact.Artifact.class, - dependency.getArtifact() ); + Artifact mavenArtifact = (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", + org.eclipse.aether.artifact.Artifact.class, + dependency.getArtifact() ); transitiveArtifacts.add( mavenArtifact.getDependencyConflictId() ); } @@ -118,17 +116,15 @@ public class ArtifactTransitivityFilter { try { - @SuppressWarnings( "unchecked" ) - List<org.sonatype.aether.graph.Dependency> dependencies = + @SuppressWarnings( "unchecked" ) List<org.sonatype.aether.graph.Dependency> dependencies = (List<org.sonatype.aether.graph.Dependency>) Invoker.invoke( resolutionResult, "getDependencies" ); for ( org.sonatype.aether.graph.Dependency dependency : dependencies ) { - Artifact mavenArtifact = - (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", - org.sonatype.aether.artifact.Artifact.class, - dependency.getArtifact() ); + Artifact mavenArtifact = (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", + org.sonatype.aether.artifact.Artifact.class, + dependency.getArtifact() ); transitiveArtifacts.add( mavenArtifact.getDependencyConflictId() ); } @@ -152,6 +148,28 @@ public class ArtifactTransitivityFilter } } + /** + * @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; + } + } + public Set<Artifact> filter( Set<Artifact> artifacts ) { @@ -168,7 +186,7 @@ public class ArtifactTransitivityFilter /** * Compares the artifact to the list of dependencies to see if it is directly included by this project - * + * * @param artifact representing the item to compare. * @return true if artifact is a transitive dependency */ @@ -176,26 +194,4 @@ public class ArtifactTransitivityFilter { return transitiveArtifacts.contains( artifact.getDependencyConflictId() ); } - - /** - * @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; - } - } }