Author: rfscholte
Date: Sat Jul 18 22:11:34 2015
New Revision: 1691779
URL: http://svn.apache.org/r1691779
Log:
[MDEP-494] Remove/replace Maven2 specific code
Remove dead code.
Move code from DefaultArtifactsResolver, it's only used in one place.
Remove DefaultArtifactsResolver (it is not even a Component)
Removed:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/utils/resolvers/
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java?rev=1691779&r1=1691778&r2=1691779&view=diff
==============================================================================
---
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
(original)
+++
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java
Sat Jul 18 22:11:34 2015
@@ -156,6 +156,7 @@ public class AnalyzeDuplicateMojo
}
}
+ @SuppressWarnings( "unchecked" )
private Set<String> findDuplicateDependencies( List<Dependency>
modelDependencies )
{
List<String> modelDependencies2 = new ArrayList<String>();
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java?rev=1691779&r1=1691778&r2=1691779&view=diff
==============================================================================
---
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
(original)
+++
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
Sat Jul 18 22:11:34 2015
@@ -238,76 +238,6 @@ public abstract class AbstractFromConfig
}
/**
- * Checks to see if the specified artifact is available from the reactor.
- *
- * @param artifact The artifact we are looking for.
- * @return The resolved artifact that is the same as the one we were
looking for or <code>null</code> if one could
- * not be found.
- */
- private Artifact getArtifactFomReactor( Artifact artifact )
- {
- // check project dependencies first off
- for ( Artifact a : getProject().getArtifacts() )
- {
- if ( equals( artifact, a ) && hasFile( a ) )
- {
- return a;
- }
- }
-
- // check reactor projects
- for ( MavenProject p : reactorProjects == null ?
Collections.<MavenProject>emptyList() : reactorProjects )
- {
- // check the main artifact
- if ( equals( artifact, p.getArtifact() ) && hasFile(
p.getArtifact() ) )
- {
- return p.getArtifact();
- }
-
- // check any side artifacts
- for ( Artifact a : p.getAttachedArtifacts() )
- {
- if ( equals( artifact, a ) && hasFile( a ) )
- {
- return a;
- }
- }
- }
-
- // not available
- return null;
- }
-
- /**
- * Returns <code>true</code> if the artifact has a file.
- *
- * @param artifact the artifact (may be null)
- * @return <code>true</code> if and only if the artifact is non-null and
has a file.
- */
- private static boolean hasFile( Artifact artifact )
- {
- return artifact != null && artifact.getFile() != null &&
artifact.getFile().isFile();
- }
-
- /**
- * Null-safe compare of two artifacts based on groupId, artifactId,
version, type and classifier.
- *
- * @param a the first artifact.
- * @param b the second artifact.
- * @return <code>true</code> if and only if the two artifacts have the
same groupId, artifactId, version,
- * type and classifier.
- */
- private static boolean equals( Artifact a, Artifact b )
- {
- return a == b || !( a == null || b == null )
- && StringUtils.equals( a.getGroupId(), b.getGroupId() )
- && StringUtils.equals( a.getArtifactId(), b.getArtifactId() )
- && StringUtils.equals( a.getVersion(), b.getVersion() )
- && StringUtils.equals( a.getType(), b.getType() )
- && StringUtils.equals( a.getClassifier(), b.getClassifier() );
- }
-
- /**
* Tries to find missing version from dependency list and dependency
management. If found, the artifact is updated
* with the correct version. It will first look for an exact match on
artifactId/groupId/classifier/type and if it
* doesn't find a match, it will try again looking for artifactId and
groupId only.
@@ -477,11 +407,14 @@ public abstract class AbstractFromConfig
classifier = null;
}
- Artifact toUnpack = classifier == null
- ? getFactory().createBuildArtifact( groupId, artifactId, version,
packaging )
- : getFactory().createArtifactWithClassifier( groupId, artifactId,
version, packaging, classifier );
+ ArtifactItem artifactItem = new ArtifactItem();
+ artifactItem.setGroupId( groupId );
+ artifactItem.setArtifactId( artifactId );
+ artifactItem.setVersion( version );
+ artifactItem.setType( packaging );
+ artifactItem.setClassifier( classifier );
- setArtifactItems( Collections.singletonList( new ArtifactItem(
toUnpack ) ) );
+ setArtifactItems( Collections.singletonList( artifactItem ) );
}
}
}
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java?rev=1691779&r1=1691778&r2=1691779&view=diff
==============================================================================
---
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
(original)
+++
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
Sat Jul 18 22:11:34 2015
@@ -26,15 +26,13 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.dependency.AbstractDependencyMojo;
import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
-import org.apache.maven.plugins.dependency.utils.resolvers.ArtifactsResolver;
-import
org.apache.maven.plugins.dependency.utils.resolvers.DefaultArtifactsResolver;
import
org.apache.maven.plugins.dependency.utils.translators.ArtifactTranslator;
import
org.apache.maven.plugins.dependency.utils.translators.ClassifierTypeTranslator;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
@@ -409,13 +407,8 @@ public abstract class AbstractDependency
// the unskipped artifacts are in the resolved set.
artifacts = status.getResolvedDependencies();
- ProjectBuildingRequest buildingRequest =
- new DefaultProjectBuildingRequest(
session.getProjectBuildingRequest() );
-
// resolve the rest of the artifacts
- ArtifactsResolver artifactsResolver =
- new DefaultArtifactsResolver( this.artifactResolver,
buildingRequest, stopOnFailure );
- resolvedArtifacts = artifactsResolver.resolve( artifacts, getLog()
);
+ resolvedArtifacts = resolve( artifacts, stopOnFailure );
// calculate the artifacts not resolved.
unResolvedArtifacts.addAll( artifacts );
@@ -462,6 +455,34 @@ public abstract class AbstractDependency
return new DependencyStatusSets( unMarkedArtifacts, null,
skippedArtifacts );
}
+
+ protected Set<Artifact> resolve( Set<Artifact> artifacts, boolean
stopOnFailure )
+ throws MojoExecutionException
+ {
+ ProjectBuildingRequest buildingRequest =
+ new DefaultProjectBuildingRequest(
session.getProjectBuildingRequest() );
+
+ Set<Artifact> resolvedArtifacts = new HashSet<Artifact>();
+ for ( Artifact artifact : artifacts )
+ {
+ try
+ {
+ artifact = artifactResolver.resolveArtifact( buildingRequest,
artifact ).getArtifact();
+ resolvedArtifacts.add( artifact );
+ }
+ catch ( ArtifactResolverException ex )
+ {
+ // an error occurred during resolution, log it an continue
+ getLog().debug( "error resolving: " + artifact.getId() );
+ getLog().debug( ex );
+ if ( stopOnFailure )
+ {
+ throw new MojoExecutionException( "error resolving: " +
artifact.getId(), ex );
+ }
+ }
+ }
+ return resolvedArtifacts;
+ }
/**
* @return Returns the markersDirectory.
*/
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java?rev=1691779&r1=1691778&r2=1691779&view=diff
==============================================================================
---
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
(original)
+++
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
Sat Jul 18 22:11:34 2015
@@ -187,11 +187,16 @@ public class CopyDependenciesMojo
{
if ( artifact.isSnapshot() && !artifact.getBaseVersion().equals(
artifact.getVersion() ) )
{
- Artifact baseArtifact =
- this.getFactory().createArtifact( artifact.getGroupId(),
artifact.getArtifactId(),
- artifact.getBaseVersion(),
artifact.getScope(), artifact.getType() );
- baseArtifact.setFile( artifact.getFile() );
- installer.install( buildingRequest, Collections.singletonList(
baseArtifact ) );
+ String version = artifact.getVersion();
+ try
+ {
+ artifact.setVersion( artifact.getBaseVersion() );
+ installer.install( buildingRequest, Collections.singletonList(
artifact ) );
+ }
+ finally
+ {
+ artifact.setVersion( version );
+ }
}
}