MNG-4245: can't access protected mirrors with latest 3.0-SNAPSHOT (rev 795227)

Submitted by: Igor Fedorenko


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@795913 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-07-20 16:52:08 +00:00
parent fa40714be3
commit 4363bdecef
4 changed files with 24 additions and 19 deletions

View File

@ -28,7 +28,7 @@ import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.Authentication;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -53,7 +53,7 @@ public class DefaultMirrorBuilder
//used LinkedMap to preserve the order.
private Map<String, ArtifactRepository> mirrors = new LinkedHashMap<String, ArtifactRepository>();
public void addMirror( String id, String mirrorOf, String url )
public void addMirror( String id, String mirrorOf, String url, Authentication auth )
{
if ( id == null )
{
@ -61,10 +61,12 @@ public class DefaultMirrorBuilder
logger.warn( "You are using a mirror that doesn't declare an <id/> element. Using \'" + id + "\' instead:\nId: " + id + "\nmirrorOf: " + mirrorOf + "\nurl: " + url + "\n" );
}
ArtifactRepository mirror = repositoryFactory.createArtifactRepository( id, url, (ArtifactRepositoryLayout)null, null, null );
if ( !mirrors.containsKey( mirrorOf ) )
{
ArtifactRepository mirror = repositoryFactory.createArtifactRepository( id, url, (ArtifactRepositoryLayout)null, null, null );
mirror.setAuthentication( auth );
mirrors.put( mirrorOf, mirror );
}
}
@ -120,6 +122,7 @@ public class DefaultMirrorBuilder
{
// We basically just want to take the URL
repository.setUrl( mirror.getUrl() );
repository.setAuthentication( mirror.getAuthentication() );
// I would like a mirrored repository to be visually different but we'll put another field
// in the repository as changing the ID hoses up authentication.

View File

@ -327,7 +327,8 @@ public class LegacyRepositorySystem
// Mirror
public void addMirror( String id, String mirrorOf, String url )
{
mirrorBuilder.addMirror( id, mirrorOf, url );
Authentication auth = id != null ? authentications.get( id ) : null;
mirrorBuilder.addMirror( id, mirrorOf, url, auth );
}
public List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories )

View File

@ -22,6 +22,7 @@ package org.apache.maven.repository;
import java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.Authentication;
public interface MirrorBuilder
{
@ -29,7 +30,7 @@ public interface MirrorBuilder
List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories );
void addMirror( String id, String mirrorOf, String url );
void addMirror( String id, String mirrorOf, String url, Authentication auth );
void clearMirrors();
}

View File

@ -28,7 +28,7 @@ public class MirrorProcessorTest
public void testAddMirrorWithNullRepositoryId()
{
mirrorBuilder.addMirror( null, "test", "http://www.nowhere.com/" );
mirrorBuilder.addMirror( null, "test", "http://www.nowhere.com/", null );
}
public void testExternalURL()
@ -55,8 +55,8 @@ public class MirrorProcessorTest
public void testMirrorLookup()
{
mirrorBuilder.addMirror( "a", "a", "http://a" );
mirrorBuilder.addMirror( "b", "b", "http://b" );
mirrorBuilder.addMirror( "a", "a", "http://a", null );
mirrorBuilder.addMirror( "b", "b", "http://b", null );
ArtifactRepository repo = null;
repo = mirrorBuilder.getMirrorRepository( getRepo( "a", "http://a.a" ) );
@ -72,9 +72,9 @@ public class MirrorProcessorTest
public void testMirrorWildcardLookup()
{
mirrorBuilder.addMirror( "a", "a", "http://a" );
mirrorBuilder.addMirror( "b", "b", "http://b" );
mirrorBuilder.addMirror( "c", "*", "http://wildcard" );
mirrorBuilder.addMirror( "a", "a", "http://a", null );
mirrorBuilder.addMirror( "b", "b", "http://b", null );
mirrorBuilder.addMirror( "c", "*", "http://wildcard", null );
ArtifactRepository repo = null;
repo = mirrorBuilder.getMirrorRepository( getRepo( "a", "http://a.a" ) );
@ -91,15 +91,15 @@ public class MirrorProcessorTest
public void testMirrorStopOnFirstMatch()
{
//exact matches win first
mirrorBuilder.addMirror( "a2", "a,b", "http://a2" );
mirrorBuilder.addMirror( "a", "a", "http://a" );
mirrorBuilder.addMirror( "a2", "a,b", "http://a2", null );
mirrorBuilder.addMirror( "a", "a", "http://a", null );
//make sure repeated entries are skipped
mirrorBuilder.addMirror( "a", "a", "http://a3" );
mirrorBuilder.addMirror( "a", "a", "http://a3", null );
mirrorBuilder.addMirror( "b", "b", "http://b" );
mirrorBuilder.addMirror( "c", "d,e", "http://de" );
mirrorBuilder.addMirror( "c", "*", "http://wildcard" );
mirrorBuilder.addMirror( "c", "e,f", "http://ef" );
mirrorBuilder.addMirror( "b", "b", "http://b", null );
mirrorBuilder.addMirror( "c", "d,e", "http://de", null );
mirrorBuilder.addMirror( "c", "*", "http://wildcard", null );
mirrorBuilder.addMirror( "c", "e,f", "http://ef", null );
ArtifactRepository repo = null;
repo = mirrorBuilder.getMirrorRepository( getRepo( "a", "http://a.a" ) );