DefaultRemoteRepositoryManager implements RemoteRepositoryManager, Service { public List<RemoteRepository> aggregateRepositories( RepositorySystemSession session, List<RemoteRepository> dominantRepositories, List<RemoteRepository> recessiveRepositories, boolean recessiveIsRaw ) { if ( recessiveRepositories.isEmpty() ) { return dominantRepositories; } MirrorSelector mirrorSelector = session.getMirrorSelector(); AuthenticationSelector authSelector = session.getAuthenticationSelector(); ProxySelector proxySelector = session.getProxySelector(); List<RemoteRepository> result = new ArrayList<RemoteRepository>( dominantRepositories ); next: for ( RemoteRepository recessiveRepository : recessiveRepositories ) { RemoteRepository repository = recessiveRepository; if ( recessiveIsRaw ) { RemoteRepository mirrorRepository = mirrorSelector.getMirror( recessiveRepository ); if ( mirrorRepository == null ) { repository = recessiveRepository; } else { logger.debug( "Using mirror " + mirrorRepository.getId() + " (" + mirrorRepository.getUrl() + ") for " + recessiveRepository.getId() + " (" + recessiveRepository.getUrl() + ")." ); repository = mirrorRepository; } } String key = getKey( repository ); for ( ListIterator<RemoteRepository> it = result.listIterator(); it.hasNext(); ) { RemoteRepository dominantRepository = it.next(); if ( key.equals( getKey( dominantRepository ) ) ) { if ( !dominantRepository.getMirroredRepositories().isEmpty() && !repository.getMirroredRepositories().isEmpty() ) { RemoteRepository mergedRepository = mergeMirrors( session, dominantRepository, repository ); if ( mergedRepository != dominantRepository ) { it.set( mergedRepository ); } } continue next; } } if ( recessiveIsRaw ) { Authentication auth = authSelector.getAuthentication( repository ); if ( auth != null ) { repository.setAuthentication( auth ); } Proxy proxy = proxySelector.getProxy( repository ); if ( proxy != null ) { repository.setProxy( proxy ); } } result.add( repository ); } return result; } DefaultRemoteRepositoryManager();  DefaultRemoteRepositoryManager( Logger logger, UpdateCheckManager updateCheckManager,
                                           List<RepositoryConnectorFactory> connectorFactories ); void initService( ServiceLocator locator ); DefaultRemoteRepositoryManager setLogger( Logger logger ); DefaultRemoteRepositoryManager setUpdateCheckManager( UpdateCheckManager updateCheckManager ); DefaultRemoteRepositoryManager addRepositoryConnectorFactory( RepositoryConnectorFactory factory ); DefaultRemoteRepositoryManager setRepositoryConnectorFactories( List<RepositoryConnectorFactory> factories ); List<RemoteRepository> aggregateRepositories( RepositorySystemSession session,
                                                         List<RemoteRepository> dominantRepositories,
                                                         List<RemoteRepository> recessiveRepositories,
                                                         boolean recessiveIsRaw ); RepositoryPolicy getPolicy( RepositorySystemSession session, RemoteRepository repository, boolean releases,
                                       boolean snapshots ); RepositoryConnector getRepositoryConnector( RepositorySystemSession session, RemoteRepository repository );  }
@Test public void testAggregateSimpleRepos() { RemoteRepository dominant1 = newRepo( "a", "file: RemoteRepository recessive1 = newRepo( "a", "http: RemoteRepository recessive2 = newRepo( "b", "file: List<RemoteRepository> result = manager.aggregateRepositories( session, Arrays.asList( dominant1 ), Arrays.asList( recessive1, recessive2 ), false ); assertEquals( 2, result.size() ); assertEqual( dominant1, result.get( 0 ) ); assertEqual( recessive2, result.get( 1 ) ); }
@Test public void testAggregateMirrorRepos_DominantMirrorComplete() { RemoteRepository dominant1 = newRepo( "a", "http: RemoteRepository dominantMirror1 = newRepo( "x", "file: dominantMirror1.setMirroredRepositories( Arrays.asList( dominant1 ) ); RemoteRepository recessive1 = newRepo( "a", "https: RemoteRepository recessiveMirror1 = newRepo( "x", "http: recessiveMirror1.setMirroredRepositories( Arrays.asList( recessive1 ) ); List<RemoteRepository> result = manager.aggregateRepositories( session, Arrays.asList( dominantMirror1 ), Arrays.asList( recessiveMirror1 ), false ); assertEquals( 1, result.size() ); assertEqual( dominantMirror1, result.get( 0 ) ); assertEquals( 1, result.get( 0 ).getMirroredRepositories().size() ); assertEquals( dominant1, result.get( 0 ).getMirroredRepositories().get( 0 ) ); }
@Test public void testAggregateMirrorRepos_DominantMirrorIncomplete() { RemoteRepository dominant1 = newRepo( "a", "http: RemoteRepository dominantMirror1 = newRepo( "x", "file: dominantMirror1.setMirroredRepositories( Arrays.asList( dominant1 ) ); RemoteRepository recessive1 = newRepo( "a", "https: RemoteRepository recessive2 = newRepo( "b", "https: RemoteRepository recessiveMirror1 = newRepo( "x", "http: recessiveMirror1.setMirroredRepositories( Arrays.asList( recessive1, recessive2 ) ); List<RemoteRepository> result = manager.aggregateRepositories( session, Arrays.asList( dominantMirror1 ), Arrays.asList( recessiveMirror1 ), false ); assertEquals( 1, result.size() ); assertEqual( newRepo( "x", "file: assertEquals( 2, result.get( 0 ).getMirroredRepositories().size() ); assertEquals( dominant1, result.get( 0 ).getMirroredRepositories().get( 0 ) ); assertEquals( recessive2, result.get( 0 ).getMirroredRepositories().get( 1 ) ); }
@Test public void testMirrorAuthentication() { final RemoteRepository repo = newRepo( "a", "http: final RemoteRepository mirror = newRepo( "a", "http: mirror.setAuthentication( new Authentication( "username", "password" ) ); session.setMirrorSelector( new MirrorSelector() { public RemoteRepository getMirror( RemoteRepository repository ) { return mirror; } } ); List<RemoteRepository> result = manager.aggregateRepositories( session, Collections.<RemoteRepository> emptyList(), Arrays.asList( repo ), true ); assertEquals( 1, result.size() ); assertEquals( "username", result.get( 0 ).getAuthentication().getUsername() ); assertEquals( "password", result.get( 0 ).getAuthentication().getPassword() ); }
@Test public void testMirrorProxy() { final RemoteRepository repo = newRepo( "a", "http: final RemoteRepository mirror = newRepo( "a", "http: mirror.setProxy( new Proxy( "http", "host", 2011, null ) ); session.setMirrorSelector( new MirrorSelector() { public RemoteRepository getMirror( RemoteRepository repository ) { return mirror; } } ); List<RemoteRepository> result = manager.aggregateRepositories( session, Collections.<RemoteRepository> emptyList(), Arrays.asList( repo ), true ); assertEquals( 1, result.size() ); assertEquals( "http", result.get( 0 ).getProxy().getType() ); assertEquals( "host", result.get( 0 ).getProxy().getHost() ); assertEquals( 2011, result.get( 0 ).getProxy().getPort() ); }
@Test public void testProxySelector() { final RemoteRepository repo = newRepo( "a", "http: final Proxy proxy = new Proxy( "http", "host", 2011, null ); session.setProxySelector( new ProxySelector() { public Proxy getProxy( RemoteRepository repository ) { return proxy; } } ); session.setMirrorSelector( new MirrorSelector() { public RemoteRepository getMirror( RemoteRepository repository ) { return null; } } ); List<RemoteRepository> result = manager.aggregateRepositories( session, Collections.<RemoteRepository> emptyList(), Arrays.asList( repo ), true ); assertEquals( 1, result.size() ); assertEquals( "http", result.get( 0 ).getProxy().getType() ); assertEquals( "host", result.get( 0 ).getProxy().getHost() ); assertEquals( 2011, result.get( 0 ).getProxy().getPort() ); }