change resolve() methods to not return Artifact - but instead modify the original. Artifact is immutable except for version so it is safe - but will it cost flexibility later. Currently, this makes it much simpler as less copying vigilance is required.

This has ironed out most wrinkles. Still need to implement the snapshot checking cache, and special case the use of installed snapshots over deployed ones.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163706 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-29 16:41:13 +00:00
parent 16ea34c8c1
commit d3781103e8
15 changed files with 83 additions and 435 deletions

View File

@ -42,6 +42,8 @@ public interface Artifact
String getVersion();
void setVersion( String version );
/**
* Get the scope of the artifact. If the artifact is a standalone rather than a dependency, it's scope will be
* <code>null</code>. The scope may not be the same as it was declared on the original dependency, as this is the
@ -64,6 +66,9 @@ public interface Artifact
String getBaseVersion();
/**
* @todo would like to get rid of this - or at least only have one. Base version should be immutable.
*/
void setBaseVersion( String baseVersion );
// ----------------------------------------------------------------------

View File

@ -37,8 +37,9 @@ public class DefaultArtifact
private final String artifactId;
private final String version;
private String version;
// TODO: should be final
private String baseVersion;
private final String type;
@ -119,6 +120,11 @@ public class DefaultArtifact
return version;
}
public void setVersion( String version )
{
this.version = version;
}
public String getType()
{
return type;

View File

@ -68,7 +68,7 @@ public class DefaultArtifactDeployer
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
{
ArtifactTransformation transform = (ArtifactTransformation) i.next();
artifact = transform.transformForDeployment( artifact, deploymentRepository );
transform.transformForDeployment( artifact, deploymentRepository );
}
wagonManager.putArtifact( source, artifact, deploymentRepository );

View File

@ -66,7 +66,7 @@ public class DefaultArtifactInstaller
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
{
ArtifactTransformation transform = (ArtifactTransformation) i.next();
artifact = transform.transformForInstall( artifact, localRepository );
transform.transformForInstall( artifact, localRepository );
}
String localPath = localRepository.pathOf( artifact );

View File

@ -36,16 +36,13 @@ public interface ArtifactResolver
{
static String ROLE = ArtifactResolver.class.getName();
Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source )
throws ArtifactResolutionException;
Set resolve( Set artifacts, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException;
ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,
ArtifactRepository localRepository, ArtifactMetadataSource source )
throws ArtifactResolutionException;

View File

@ -35,7 +35,6 @@ import org.codehaus.plexus.logging.Logger;
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@ -65,8 +64,7 @@ public class DefaultArtifactResolver
// Implementation
// ----------------------------------------------------------------------
// TODO: would like to avoid the returning of a new artifact - is it ok to modify the original though?
public Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
// ----------------------------------------------------------------------
@ -85,7 +83,7 @@ public class DefaultArtifactResolver
ArtifactTransformation transform = (ArtifactTransformation) i.next();
try
{
artifact = transform.transformForResolve( artifact, remoteRepositories, localRepository );
transform.transformForResolve( artifact, remoteRepositories, localRepository );
}
catch ( ArtifactMetadataRetrievalException e )
{
@ -107,44 +105,40 @@ public class DefaultArtifactResolver
File destination = new File( localRepository.getBasedir(), localPath );
artifact.setFile( destination );
if ( destination.exists() )
if ( !destination.exists() )
{
return artifact;
}
try
{
if ( artifact.getRepository() != null )
{
// the transformations discovered the artifact - so use it exclusively
wagonManager.getArtifact( artifact, artifact.getRepository(), destination );
}
else
{
wagonManager.getArtifact( artifact, remoteRepositories, destination );
}
try
{
if ( artifact.getRepository() != null )
{
// the transformations discovered the artifact - so use it exclusively
wagonManager.getArtifact( artifact, artifact.getRepository(), destination );
// must be after the artifact is downloaded
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
{
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
metadata.storeInLocalRepository( localRepository );
}
}
else
catch ( ResourceDoesNotExistException e )
{
wagonManager.getArtifact( artifact, remoteRepositories, destination );
throw new ArtifactResolutionException( artifactNotFound( localPath, remoteRepositories ), e );
}
// must be after the artifact is downloaded
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
catch ( TransferFailedException e )
{
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
metadata.storeInLocalRepository( localRepository );
throw new ArtifactResolutionException( "Error downloading artifact " + artifact, e );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new ArtifactResolutionException( "Error downloading artifact " + artifact, e );
}
}
catch ( ResourceDoesNotExistException e )
{
throw new ArtifactResolutionException( artifactNotFound( localPath, remoteRepositories ), e );
}
catch ( TransferFailedException e )
{
throw new ArtifactResolutionException( "Error downloading artifact " + artifact, e );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new ArtifactResolutionException( "Error downloading artifact " + artifact, e );
}
return artifact;
}
private static final String LS = System.getProperty( "line.separator" );
@ -177,23 +171,6 @@ public class DefaultArtifactResolver
return sb.toString();
}
public Set resolve( Set artifacts, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
Set resolvedArtifacts = new HashSet();
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
Artifact resolvedArtifact = resolve( artifact, remoteRepositories, localRepository );
resolvedArtifacts.add( resolvedArtifact );
}
return resolvedArtifacts;
}
// ----------------------------------------------------------------------
// Transitive modes
// ----------------------------------------------------------------------
@ -214,19 +191,12 @@ public class DefaultArtifactResolver
throw new ArtifactResolutionException( "Error transitively resolving artifacts: ", e );
}
// TODO: this is unclean, but necessary as long as resolve may return a different artifact
Map collectedArtifacts = artifactResolutionResult.getArtifacts();
Map resolvedArtifacts = new HashMap( collectedArtifacts.size() );
for ( Iterator i = collectedArtifacts.keySet().iterator(); i.hasNext(); )
for ( Iterator i = artifactResolutionResult.getArtifacts().values().iterator(); i.hasNext(); )
{
Object key = i.next();
resolvedArtifacts.put( key, resolve( (Artifact) collectedArtifacts.get( key ), remoteRepositories,
localRepository ) );
Artifact artifact = (Artifact) i.next();
resolve( artifact, remoteRepositories, localRepository );
}
collectedArtifacts.clear();
collectedArtifacts.putAll( resolvedArtifacts );
return artifactResolutionResult;
}

View File

@ -38,10 +38,8 @@ public interface ArtifactTransformation
* @param artifact Artifact to be transformed.
* @param remoteRepositories the repositories to check
* @param localRepository the local repository
* @return The transformed Artifact
*/
public Artifact transformForResolve( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository )
public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException;
/**
@ -50,9 +48,8 @@ public interface ArtifactTransformation
*
* @param artifact Artifact to be transformed.
* @param localRepository the local repository it will be stored in
* @return The transformed Artifact
*/
Artifact transformForInstall( Artifact artifact, ArtifactRepository localRepository );
void transformForInstall( Artifact artifact, ArtifactRepository localRepository );
/**
* Take in a artifact and return the transformed artifact for distributing toa remote repository. If no
@ -60,8 +57,7 @@ public interface ArtifactTransformation
*
* @param artifact Artifact to be transformed.
* @param remoteRepository the repository to deploy to
* @return The transformed Artifact
*/
Artifact transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException;
}

View File

@ -17,9 +17,7 @@ package org.apache.maven.artifact.transform;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -47,8 +45,7 @@ public class SnapshotTransformation
*/
private static Set resolvedArtifactCache = new HashSet();
public Artifact transformForResolve( Artifact artifact, List remoteRepositories,
ArtifactRepository localRepository )
public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
// TODO: remove hack
@ -56,11 +53,6 @@ public class SnapshotTransformation
!Boolean.valueOf( System.getProperty( "maven.debug.snapshot.disabled", "true" ) ).booleanValue() )
{
// TODO: this mostly works, however...
// - poms and jars are different, so both are checked individually
// - when a pom is downloaded, it prevents the JAR getting downloaded because of the timestamp
// - need to gather first, group them all up by groupId/artifactId, then go after them
// - alternatively, keep the timestamp when downloading (as is done here), and use the SNAPSHOT file for install
// - however, there is no mechanism to flip back and forward, and presently it keeps looking for 2.0-TIMESTAMP-0 instead as that is in the build file
// - we definitely need the manual/daily check as this is quite slow given the large number of snapshots inside m2 presently
SnapshotArtifactMetadata localMetadata;
@ -101,13 +93,11 @@ public class SnapshotTransformation
{
artifact.addMetadata( localMetadata );
}
resolvedArtifactCache.add( getCacheKey( artifact ) );
}
artifact = createArtifactCopy( artifact, localMetadata );
resolvedArtifactCache.add( getCacheKey( artifact ) );
artifact.setVersion( localMetadata.constructVersion() );
}
return artifact;
}
private boolean alreadyResolved( Artifact artifact )
@ -121,7 +111,7 @@ public class SnapshotTransformation
return artifact.getGroupId() + ":" + artifact.getArtifactId();
}
public Artifact transformForInstall( Artifact artifact, ArtifactRepository localRepository )
public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
{
// Nothing to do
/* TODO: remove
@ -132,10 +122,9 @@ public class SnapshotTransformation
artifact.addMetadata( metadata );
}
*/
return artifact;
}
public Artifact transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
if ( isSnapshot( artifact ) )
@ -145,31 +134,10 @@ public class SnapshotTransformation
wagonManager );
metadata.update();
// TODO: note, we could currently transform this in place, as it is only used through the deploy mojo,
// which creates the artifact and then disposes of it
artifact = createArtifactCopy( artifact, metadata );
artifact.setVersion( metadata.constructVersion() );
artifact.addMetadata( metadata );
}
return artifact;
}
private Artifact createArtifactCopy( Artifact artifact, SnapshotArtifactMetadata metadata )
{
Artifact newArtifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
metadata.constructVersion(), artifact.getScope(),
artifact.getType(), artifact.getClassifier() );
newArtifact.setBaseVersion( artifact.getBaseVersion() );
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
{
ArtifactMetadata m = (ArtifactMetadata) i.next();
m.setArtifact( newArtifact );
newArtifact.addMetadata( m );
}
newArtifact.setRepository( artifact.getRepository() );
return newArtifact;
}
private static boolean isSnapshot( Artifact artifact )

View File

@ -26,16 +26,12 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
// It would be cool if there was a hook that i could use to setup a test environment.
// I want to setup a local/remote repositories for testing but i don't want to have
// to change them when i change the layout of the repositories. So i want to generate
// the structure i want to test by using the artifact handler manager which dictates
// the layout used for a particular artifact type.
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
@ -45,7 +41,8 @@ public class ArtifactResolverTest
{
private ArtifactResolver artifactResolver;
protected void setUp() throws Exception
protected void setUp()
throws Exception
{
super.setUp();
@ -57,7 +54,8 @@ public class ArtifactResolverTest
return "resolver";
}
public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository() throws Exception
public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository()
throws Exception
{
Artifact a = createLocalArtifact( "a", "1.0" );
@ -77,70 +75,21 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( b );
}
public void testResolutionOfASetOfArtifactsWhereTheArtifactsArePresentInTheLocalRepository() throws Exception
{
Set artifacts = new HashSet();
Artifact c = createLocalArtifact( "c", "1.0" );
Artifact d = createLocalArtifact( "d", "1.0" );
artifacts.add( c );
artifacts.add( d );
Set resolvedArtifacts = artifactResolver.resolve( artifacts, remoteRepositories(), localRepository() );
assertEquals( 2, resolvedArtifacts.size() );
// The artifacts have undergone no transformations and they are present so the original
// artifacts sent into the resolver should be returned as they were sent in.
assertTrue( resolvedArtifacts.contains( c ) );
assertTrue( resolvedArtifacts.contains( d ) );
}
public void testResolutionOfASetOfArtifactsWhereTheArtifactsAreNotPresentInTheLocalRepositoryAndMustBeRetrievedFromTheRemoteRepository()
throws Exception
{
Set artifacts = new HashSet();
Artifact e = createRemoteArtifact( "e", "1.0" );
deleteLocalArtifact( e );
Artifact f = createRemoteArtifact( "f", "1.0" );
deleteLocalArtifact( f );
artifacts.add( e );
artifacts.add( f );
Set resolvedArtifacts = artifactResolver.resolve( artifacts, remoteRepositories(), localRepository() );
assertEquals( 2, resolvedArtifacts.size() );
// The artifacts have undergone no transformations and they are present so the original
// artifacts sent into the resolver should be returned as they were sent in.
assertTrue( resolvedArtifacts.contains( e ) );
assertTrue( resolvedArtifacts.contains( f ) );
}
protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
{
// for the anonymous classes
return super.createArtifact( groupId, artifactId, version, type );
}
public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() throws Exception
public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository()
throws Exception
{
Artifact g = createLocalArtifact( "g", "1.0" );
Artifact h = createLocalArtifact( "h", "1.0" );
ArtifactMetadataSource mds = new ArtifactMetadataSource() {
ArtifactMetadataSource mds = new ArtifactMetadataSource()
{
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
{
Set dependencies = new HashSet();
@ -177,7 +126,8 @@ public class ArtifactResolverTest
Artifact j = createRemoteArtifact( "j", "1.0" );
deleteLocalArtifact( j );
ArtifactMetadataSource mds = new ArtifactMetadataSource() {
ArtifactMetadataSource mds = new ArtifactMetadataSource()
{
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
{
Set dependencies = new HashSet();
@ -205,7 +155,8 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( j );
}
public void testResolutionFailureWhenArtifactNotPresentInRemoteRepository() throws Exception
public void testResolutionFailureWhenArtifactNotPresentInRemoteRepository()
throws Exception
{
Artifact k = createArtifact( "k", "1.0" );
@ -220,7 +171,8 @@ public class ArtifactResolverTest
}
}
public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood() throws Exception
public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood()
throws Exception
{
Artifact l = createRemoteArtifact( "l", "1.0" );
deleteLocalArtifact( l );

View File

@ -1,250 +0,0 @@
package org.apache.maven.artifact.resolver;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.artifact.ArtifactComponentTestCase;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
// It would be cool if there was a hook that i could use to setup a test environment.
// I want to setup a local/remote repositories for testing but i don't want to have
// to change them when i change the layout of the repositories. So i want to generate
// the structure i want to test by using the artifact handler manager which dictates
// the layout used for a particular artifact type.
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class NewLayoutArtifactResolverTest
extends ArtifactComponentTestCase
{
private ArtifactResolver artifactResolver;
protected void setUp() throws Exception
{
super.setUp();
artifactResolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
}
protected String component()
{
return "resolver";
}
public void testResolutionOfASingleArtifactWhereTheArtifactIsPresentInTheLocalRepository() throws Exception
{
Artifact a = createLocalArtifact( "a", "1.0" );
artifactResolver.resolve( a, remoteRepositories(), localRepository() );
assertLocalArtifactPresent( a );
}
public void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepository()
throws Exception
{
Artifact b = createRemoteArtifact( "b", "1.0" );
deleteLocalArtifact( b );
artifactResolver.resolve( b, remoteRepositories(), localRepository() );
assertLocalArtifactPresent( b );
}
public void testResolutionOfASetOfArtifactsWhereTheArtifactsArePresentInTheLocalRepository() throws Exception
{
Set artifacts = new HashSet();
Artifact c = createLocalArtifact( "c", "1.0" );
Artifact d = createLocalArtifact( "d", "1.0" );
artifacts.add( c );
artifacts.add( d );
Set resolvedArtifacts = artifactResolver.resolve( artifacts, remoteRepositories(), localRepository() );
assertEquals( 2, resolvedArtifacts.size() );
// The artifacts have undergone no transformations and they are present so the original
// artifacts sent into the resolver should be returned as they were sent in.
assertTrue( resolvedArtifacts.contains( c ) );
assertTrue( resolvedArtifacts.contains( d ) );
}
public void testResolutionOfASetOfArtifactsWhereTheArtifactsAreNotPresentInTheLocalRepositoryAndMustBeRetrievedFromTheRemoteRepository()
throws Exception
{
Set artifacts = new HashSet();
Artifact e = createRemoteArtifact( "e", "1.0" );
deleteLocalArtifact( e );
Artifact f = createRemoteArtifact( "f", "1.0" );
deleteLocalArtifact( f );
artifacts.add( e );
artifacts.add( f );
Set resolvedArtifacts = artifactResolver.resolve( artifacts, remoteRepositories(), localRepository() );
assertEquals( 2, resolvedArtifacts.size() );
// The artifacts have undergone no transformations and they are present so the original
// artifacts sent into the resolver should be returned as they were sent in.
assertTrue( resolvedArtifacts.contains( e ) );
assertTrue( resolvedArtifacts.contains( f ) );
}
protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
{
// for the anonymous classes
return super.createArtifact( groupId, artifactId, version, type );
}
public void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalRepository() throws Exception
{
Artifact g = createLocalArtifact( "g", "1.0" );
Artifact h = createLocalArtifact( "h", "1.0" );
ArtifactMetadataSource mds = new ArtifactMetadataSource() {
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
{
Set dependencies = new HashSet();
if ( artifact.getArtifactId().equals( "g" ) )
{
dependencies.add( createArtifact( "org.apache.maven", "h", "1.0", "jar" ) );
}
return dependencies;
}
};
ArtifactResolutionResult result = artifactResolver.resolveTransitively( g, remoteRepositories(),
localRepository(), mds );
assertEquals( 2, result.getArtifacts().size() );
assertTrue( result.getArtifacts().containsKey( g.getId() ) );
assertTrue( result.getArtifacts().containsKey( h.getId() ) );
assertLocalArtifactPresent( g );
assertLocalArtifactPresent( h );
}
public void testTransitiveResolutionWhereAllArtifactsAreNotPresentInTheLocalRepositoryAndMustBeRetrievedFromTheRemoteRepository()
throws Exception
{
Artifact i = createRemoteArtifact( "i", "1.0" );
deleteLocalArtifact( i );
Artifact j = createRemoteArtifact( "j", "1.0" );
deleteLocalArtifact( j );
ArtifactMetadataSource mds = new ArtifactMetadataSource() {
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
{
Set dependencies = new HashSet();
if ( artifact.getArtifactId().equals( "i" ) )
{
dependencies.add( createArtifact( "org.apache.maven", "j", "1.0", "jar" ) );
}
return dependencies;
}
};
ArtifactResolutionResult result = artifactResolver.resolveTransitively( i, remoteRepositories(),
localRepository(), mds );
assertEquals( 2, result.getArtifacts().size() );
assertTrue( result.getArtifacts().containsKey( i.getId() ) );
assertTrue( result.getArtifacts().containsKey( j.getId() ) );
assertLocalArtifactPresent( i );
assertLocalArtifactPresent( j );
}
public void testResolutionFailureWhenArtifactNotPresentInRemoteRepository() throws Exception
{
Artifact k = createArtifact( "k", "1.0" );
try
{
artifactResolver.resolve( k, remoteRepositories(), localRepository() );
fail( "Resolution succeeded when it should have failed" );
}
catch ( ArtifactResolutionException expected )
{
assertTrue( true );
}
}
public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood() throws Exception
{
Artifact l = createRemoteArtifact( "l", "1.0" );
deleteLocalArtifact( l );
List repositories = new ArrayList();
repositories.add( remoteRepository() );
repositories.add( badRemoteRepository() );
artifactResolver.resolve( l, repositories, localRepository() );
assertLocalArtifactPresent( l );
}
/*
public void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepositoryAndLocalCannotBeCreated()
throws Exception
{
Artifact m = createRemoteArtifact( "m", "1.0" );
artifactResolver.resolve( m, remoteRepositories(), badLocalRepository() );
// TODO [failing test case]: throw and handle a more informative exception
}
*/
}

View File

@ -92,7 +92,7 @@ public class MavenMetadataSource
try
{
metadataArtifact = artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository );
artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{

View File

@ -42,10 +42,15 @@ public class MavenMetadata
public MavenMetadata( Artifact artifact, File file )
{
super( artifact, artifact.getArtifactId() + "-" + artifact.getVersion() + ".pom" );
super( artifact, null );
this.file = file;
}
public String getFilename()
{
return getArtifact().getArtifactId() + "-" + getArtifact().getVersion() + ".pom";
}
public void storeInLocalRepository( ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{

View File

@ -458,7 +458,7 @@ public class DefaultMavenProjectBuilder
try
{
artifact = artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{

View File

@ -710,8 +710,8 @@ public class MavenProject
existing.getVersion(),
a.getScope(), existing.getType() );
artifact.setFile( artifact.getFile() );
artifact.setBaseVersion( artifact.getBaseVersion() );
artifact.setFile( existing.getFile() );
artifact.setBaseVersion( existing.getBaseVersion() );
artifacts.put( id, artifact );
}

View File

@ -68,11 +68,10 @@ public class ProjectClasspathArtifactResolver
}
}
public Artifact resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException
{
artifact.setFile( new File( "dummy" ) );
return artifact;
}
public ArtifactResolutionResult resolveTransitively( Set artifacts, List remoteRepositories,