o no choice but to shunt the ProjectUtils which is used by the remote resources plugin into using the MavenRepositorySystem.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@750324 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-05 06:00:07 +00:00
parent 0262109e2b
commit 7d32348c3d
8 changed files with 81 additions and 48 deletions

View File

@ -176,7 +176,7 @@ public class DefaultArtifactRepository
sb.append( " id: " + getId() ).append( "\n" );
sb.append( " url: " + getUrl() ).append( "\n" );
sb.append( " layout: " + layout.getId() ).append( "\n" );
sb.append( " layout: " + layout != null ? layout.getId() : "none" ).append( "\n" );
sb.append( "snapshot policy: [update => " + snapshots.getUpdatePolicy() ).append( " ]\n" );
sb.append( " release policy: [update => " + releases.getUpdatePolicy() ).append( " ]\n" );

View File

@ -318,36 +318,7 @@ public class DefaultMavenExecutionRequestPopulator
// </mirror>
// </mirrors>
if ( request.getRemoteRepositories() != null )
{
Set<ArtifactRepository> remoteRepositoriesWithMirrors = new LinkedHashSet<ArtifactRepository>();
for ( ArtifactRepository repository : request.getRemoteRepositories() )
{
// Check to see if we have a valid mirror for this repository
ArtifactRepository mirror = repositorySystem.getMirror( repository );
if ( mirror != null )
{
// Make sure that we take the the properties of the repository we are mirroring we want to direct
// all requests for this mirror at the mirror, but the mirror specification does not allow for
// any of the regular settings.
mirror.setLayout( repository.getLayout() );
mirror.setSnapshotUpdatePolicy( repository.getSnapshots() );
mirror.setReleaseUpdatePolicy( repository.getReleases() );
// If there is a valid mirror for this repository then we'll enter the mirror as a replacement for this repository.
remoteRepositoriesWithMirrors.add( mirror );
}
else
{
// If we have no valid mirrors for this repository we will keep this repository in the list.
remoteRepositoriesWithMirrors.add( repository );
}
}
request.setRemoteRepositories( new ArrayList<ArtifactRepository>( remoteRepositoriesWithMirrors ) );
}
request.setRemoteRepositories( repositorySystem.getMirrors( request.getRemoteRepositories() ) );
}
// ------------------------------------------------------------------------

View File

@ -26,39 +26,37 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy;
import org.apache.maven.repository.MavenRepositorySystem;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
// This class needs to stick around because it was exposed the the remote resources plugin started using it instead of
// getting the repositories from the project.
public final class ProjectUtils
{
private ProjectUtils()
{
}
public static List buildArtifactRepositories( List repositories,
public static List buildArtifactRepositories( List<Repository> repositories,
ArtifactRepositoryFactory artifactRepositoryFactory,
PlexusContainer container )
throws InvalidRepositoryException
{
List repos = new ArrayList();
List<ArtifactRepository> remoteRepositories = new ArrayList<ArtifactRepository>();
for ( Iterator i = repositories.iterator(); i.hasNext(); )
for ( Repository r : repositories )
{
Repository mavenRepo = (Repository) i.next();
ArtifactRepository artifactRepo =
buildArtifactRepository( mavenRepo, artifactRepositoryFactory, container );
if ( !repos.contains( artifactRepo ) )
{
repos.add( artifactRepo );
}
remoteRepositories.add( buildArtifactRepository( r, artifactRepositoryFactory, container ) );
}
return repos;
return rs( container ).getMirrors( remoteRepositories );
}
public static ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo,
@ -71,8 +69,7 @@ public final class ProjectUtils
String id = repo.getId();
String url = repo.getUrl();
return artifactRepositoryFactory.createDeploymentArtifactRepository( id, url, repo.getLayout(),
repo.isUniqueVersion() );
return artifactRepositoryFactory.createDeploymentArtifactRepository( id, url, repo.getLayout(), repo.isUniqueVersion() );
}
else
{
@ -134,4 +131,18 @@ public final class ProjectUtils
return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy );
}
private static MavenRepositorySystem rs( PlexusContainer c )
{
MavenRepositorySystem rs = null;
try
{
rs = c.lookup( MavenRepositorySystem.class );
}
catch ( ComponentLookupException e )
{
}
return rs;
}
}

View File

@ -2,7 +2,10 @@ package org.apache.maven.repository;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -86,6 +89,40 @@ public class DefaultMirrorBuilder
anonymousMirrorIdSeed = 0;
}
public List<ArtifactRepository> getMirrors( List<ArtifactRepository> remoteRepositories )
{
Set<ArtifactRepository> remoteRepositoriesWithMirrors = new LinkedHashSet<ArtifactRepository>();
if ( remoteRepositories != null )
{
for ( ArtifactRepository repository : remoteRepositories)
{
// Check to see if we have a valid mirror for this repository
ArtifactRepository mirror = getMirror( repository );
if ( mirror != null )
{
// Make sure that we take the the properties of the repository we are mirroring we want to direct
// all requests for this mirror at the mirror, but the mirror specification does not allow for
// any of the regular settings.
mirror.setLayout( repository.getLayout() );
mirror.setSnapshotUpdatePolicy( repository.getSnapshots() );
mirror.setReleaseUpdatePolicy( repository.getReleases() );
// If there is a valid mirror for this repository then we'll enter the mirror as a replacement for this repository.
remoteRepositoriesWithMirrors.add( mirror );
}
else
{
// If we have no valid mirrors for this repository we will keep this repository in the list.
remoteRepositoriesWithMirrors.add( repository );
}
}
}
return new ArrayList<ArtifactRepository>( remoteRepositoriesWithMirrors );
}
// Make these available to tests
ArtifactRepository getMirrorRepository( ArtifactRepository repository )

View File

@ -634,4 +634,9 @@ public class LegacyMavenRepositorySystem
{
return mirrorBuilder.getMirror( repository );
}
public List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories )
{
return mirrorBuilder.getMirrors( repositories );
}
}

View File

@ -129,4 +129,7 @@ public interface MavenRepositorySystem
void addMirror( String id, String mirrorOf, String url );
ArtifactRepository getMirror( ArtifactRepository repository );
List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories );
}

View File

@ -1,11 +1,17 @@
package org.apache.maven.repository;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository;
public interface MirrorBuilder
{
ArtifactRepository getMirror( ArtifactRepository repository );
List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories );
void addMirror( String id, String mirrorOf, String url );
void clearMirrors();