mirror of https://github.com/apache/maven.git
Making resolution of artifacts from the reactor work with classifiers (hopefully).
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@541942 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
856767d7f8
commit
a55e9c24fe
|
@ -31,68 +31,95 @@ import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.project.build.ProjectBuildCache;
|
import org.apache.maven.project.build.ProjectBuildCache;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CacheAwareArtifactResolver
|
public class CacheAwareArtifactResolver
|
||||||
extends DefaultArtifactResolver
|
extends DefaultArtifactResolver
|
||||||
{
|
{
|
||||||
|
|
||||||
private ArtifactResolver delegate;
|
private ArtifactResolver delegate;
|
||||||
|
|
||||||
private BuildContextManager buildContextManager;
|
private BuildContextManager buildContextManager;
|
||||||
|
|
||||||
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
public void resolve( final Artifact artifact, final List remoteRepositories,
|
||||||
|
final ArtifactRepository localRepository )
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
resolveFromCache( artifact );
|
resolveFromCache( artifact );
|
||||||
|
|
||||||
if ( !artifact.isResolved() )
|
if ( !artifact.isResolved() )
|
||||||
{
|
{
|
||||||
delegate.resolve( artifact, remoteRepositories, localRepository );
|
delegate.resolve( artifact, remoteRepositories, localRepository );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolveAlways( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
public void resolveAlways( final Artifact artifact, final List remoteRepositories,
|
||||||
|
final ArtifactRepository localRepository )
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
resolveFromCache( artifact );
|
resolveFromCache( artifact );
|
||||||
|
|
||||||
if ( !artifact.isResolved() )
|
if ( !artifact.isResolved() )
|
||||||
{
|
{
|
||||||
delegate.resolveAlways( artifact, remoteRepositories, localRepository );
|
delegate.resolveAlways( artifact, remoteRepositories, localRepository );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveFromCache( Artifact artifact )
|
private void resolveFromCache( final Artifact artifact )
|
||||||
{
|
{
|
||||||
ProjectBuildCache cache = ProjectBuildCache.read( buildContextManager );
|
ProjectBuildCache cache = ProjectBuildCache.read( buildContextManager );
|
||||||
|
|
||||||
if ( "pom".equals( artifact.getType() ) )
|
if ( "pom".equals( artifact.getType() ) )
|
||||||
{
|
{
|
||||||
File pomFile = cache.getCachedModelFile( artifact );
|
File pomFile = cache.getCachedModelFile( artifact );
|
||||||
|
|
||||||
if ( pomFile != null )
|
if ( pomFile != null )
|
||||||
{
|
{
|
||||||
artifact.setFile( pomFile );
|
artifact.setFile( pomFile );
|
||||||
artifact.setResolved( true );
|
artifact.setResolved( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// currently, artifacts with classifiers are not really supported as the main project artifact...
|
|
||||||
else if ( artifact.getClassifier() == null )
|
else if ( artifact.getClassifier() == null )
|
||||||
{
|
{
|
||||||
MavenProject project = cache.getCachedProject( artifact );
|
MavenProject project = cache.getCachedProject( artifact );
|
||||||
ArtifactHandler handler = artifact.getArtifactHandler();
|
String classifier = artifact.getClassifier();
|
||||||
|
String type = artifact.getType();
|
||||||
if ( project != null && handler.getPackaging().equals( project.getPackaging() ) )
|
|
||||||
|
if ( classifier == null )
|
||||||
{
|
{
|
||||||
File projectArtifactFile = project.getArtifact().getFile();
|
ArtifactHandler handler = artifact.getArtifactHandler();
|
||||||
|
if ( ( project != null ) && handler.getPackaging().equals( project.getPackaging() ) )
|
||||||
if ( projectArtifactFile != null )
|
|
||||||
{
|
{
|
||||||
artifact.setFile( projectArtifactFile );
|
File projectArtifactFile = project.getArtifact().getFile();
|
||||||
artifact.setResolved( true );
|
|
||||||
|
if ( projectArtifactFile != null )
|
||||||
|
{
|
||||||
|
artifact.setFile( projectArtifactFile );
|
||||||
|
artifact.setResolved( true );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List attachments = project.getAttachedArtifacts();
|
||||||
|
for ( Iterator it = attachments.iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
Artifact attachment = (Artifact) it.next();
|
||||||
|
|
||||||
|
if ( classifier.equals( attachment.getClassifier() ) && type.equals( attachment.getType() ) )
|
||||||
|
{
|
||||||
|
File attachedFile = attachment.getFile();
|
||||||
|
|
||||||
|
if ( attachedFile != null )
|
||||||
|
{
|
||||||
|
artifact.setFile( attachedFile );
|
||||||
|
artifact.setResolved( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue