From: Martin Stockhammer Date: Wed, 1 Nov 2017 14:38:00 +0000 (+0100) Subject: Adapting base modules to the new repository api X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9469c1b67f5a667b99b1810ddd95642164ba2ec3;p=archiva.git Adapting base modules to the new repository api Using the repository api and RepositoryRegistry for repo access --- diff --git a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java index ff04828e3..3e8e168f9 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java +++ b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java @@ -26,6 +26,7 @@ import org.apache.archiva.common.utils.PathUtil; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.converter.RepositoryConversionException; +import org.apache.archiva.repository.BasicManagedRepository; import org.apache.archiva.repository.scanner.RepositoryScanner; import org.apache.archiva.repository.scanner.RepositoryScannerException; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -40,6 +41,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Locale; /** * DefaultLegacyRepositoryConverter @@ -90,10 +92,8 @@ public class DefaultLegacyRepositoryConverter { String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory ); - ManagedRepository legacyRepository = new ManagedRepository(); - legacyRepository.setId( "legacy" ); - legacyRepository.setName( "Legacy Repository" ); - legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toString() ); + BasicManagedRepository legacyRepository = new BasicManagedRepository( "legacy", "Legacy Repository"); + legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() ); legacyRepository.setLayout( "legacy" ); ArtifactRepository repository = diff --git a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/LegacyConverterArtifactConsumer.java b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/LegacyConverterArtifactConsumer.java index 1dc82a50d..7fb542eb1 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/LegacyConverterArtifactConsumer.java +++ b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/LegacyConverterArtifactConsumer.java @@ -19,7 +19,6 @@ package org.apache.archiva.converter.legacy; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; import org.apache.archiva.consumers.AbstractMonitoredConsumer; @@ -28,6 +27,7 @@ import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.converter.artifact.ArtifactConversionException; import org.apache.archiva.converter.artifact.ArtifactConverter; import org.apache.archiva.model.ArtifactReference; +import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent; import org.apache.archiva.repository.layout.LayoutException; @@ -85,7 +85,7 @@ public class LegacyConverterArtifactConsumer } @Override - public void beginScan( ManagedRepository repository, Date whenGathered ) + public void beginScan( org.apache.archiva.repository.ManagedRepository repository, Date whenGathered ) throws ConsumerException { this.managedRepository = new ManagedDefaultRepositoryContent(); diff --git a/archiva-modules/archiva-base/archiva-indexer/pom.xml b/archiva-modules/archiva-base/archiva-indexer/pom.xml index a9f24ef0e..992fcf7ef 100644 --- a/archiva-modules/archiva-base/archiva-indexer/pom.xml +++ b/archiva-modules/archiva-base/archiva-indexer/pom.xml @@ -38,6 +38,11 @@ org.apache.archiva archiva-common + + org.apache.archiva + archiva-repository-layer + + org.springframework diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java index 0e4101648..892d7b71a 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java @@ -261,6 +261,12 @@ public class MavenRepositorySearch { throw new RepositorySearchException( "No search fields set." ); } + System.err.println("CLAUSES "+q.getClauses()); + if (q.getClauses()!=null) { + for (BooleanClause cl : q.getClauses()) { + System.err.println("Clause "+cl); + } + } return search( limits, q, indexingContextIds, Collections.emptyList(), searchFields.getRepositories(), searchFields.isIncludePomArtifacts() ); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java index e2946ff00..ab85ec59b 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java @@ -26,7 +26,9 @@ import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.utils.FileUtils; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; +import org.apache.archiva.configuration.ConfigurationListener; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang.SystemUtils; import org.apache.maven.index.ArtifactContext; @@ -52,6 +54,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.Locale; /** * @author Olivier Lamy @@ -78,6 +81,9 @@ public abstract class AbstractMavenRepositorySearch @Inject ArtifactContextProducer artifactContextProducer; + @Inject + RepositoryRegistry repositoryRegistry; + IMocksControl archivaConfigControl; Configuration config; @@ -116,17 +122,28 @@ public abstract class AbstractMavenRepositorySearch DefaultProxyConnectorAdmin defaultProxyConnectorAdmin = new DefaultProxyConnectorAdmin(); defaultProxyConnectorAdmin.setArchivaConfiguration( archivaConfig ); + repositoryRegistry.setArchivaConfiguration( archivaConfig ); search = new MavenRepositorySearch( nexusIndexer, defaultManagedRepositoryAdmin, defaultProxyConnectorAdmin, queryCreator ); defaultManagedRepositoryAdmin.setIndexer( nexusIndexer ); defaultManagedRepositoryAdmin.setIndexCreators( indexCreators ); + assertNotNull( repositoryRegistry ); + defaultManagedRepositoryAdmin.setRepositoryRegistry( repositoryRegistry ); config = new Configuration(); config.addManagedRepository( createRepositoryConfig( TEST_REPO_1 ) ); config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) ); config.addManagedRepository( createRepositoryConfig( REPO_RELEASE ) ); + + + archivaConfig.addListener( EasyMock.anyObject( ConfigurationListener.class ) ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn(config).anyTimes(); + archivaConfigControl.replay(); + repositoryRegistry.reload(); + archivaConfigControl.reset(); } @After diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java index 7257e4a92..69429303d 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchOSGITest.java @@ -26,6 +26,7 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Locale; /** * @author Olivier Lamy @@ -44,7 +45,8 @@ public class MavenRepositorySearchOSGITest List selectedRepos = Arrays.asList( TEST_REPO_1 ); // search artifactId - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java index a9893111c..3c10633b0 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java @@ -19,15 +19,20 @@ package org.apache.archiva.indexer.search; * under the License. */ +import org.apache.archiva.configuration.ConfigurationEvent; +import org.apache.archiva.configuration.ConfigurationListener; import org.apache.archiva.indexer.util.SearchUtil; +import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.maven.index_shaded.lucene.index.IndexUpgrader; import org.codehaus.plexus.util.FileUtils; import org.easymock.EasyMock; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; +import javax.inject.Inject; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -35,6 +40,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; @RunWith( ArchivaSpringJUnit4ClassRunner.class ) @@ -106,7 +112,8 @@ public class MavenRepositorySearchTest List selectedRepos = Arrays.asList( TEST_REPO_1 ); // search artifactId - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -125,9 +132,10 @@ public class MavenRepositorySearchTest archivaConfigControl.reset(); - // search groupId - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); + // search groupId archivaConfigControl.replay(); results = search.search( "user", selectedRepos, "org.apache.archiva", null, null ); @@ -149,7 +157,8 @@ public class MavenRepositorySearchTest List selectedRepos = Arrays.asList( TEST_REPO_1 ); // search artifactId - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -169,7 +178,8 @@ public class MavenRepositorySearchTest archivaConfigControl.reset(); // search groupId - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -193,7 +203,8 @@ public class MavenRepositorySearchTest selectedRepos.add( TEST_REPO_1 ); // search artifactId - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -223,7 +234,8 @@ public class MavenRepositorySearchTest selectedRepos.add( TEST_REPO_1 ); // search artifactId - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -259,7 +271,8 @@ public class MavenRepositorySearchTest List selectedRepos = new ArrayList<>(); selectedRepos.add( TEST_REPO_1 ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); SearchResults results = search.search( "user", selectedRepos, "archiva search", null, null ); @@ -283,7 +296,8 @@ public class MavenRepositorySearchTest SearchResultLimits limits = new SearchResultLimits( 0 ); limits.setPageSize( 1 ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -303,7 +317,8 @@ public class MavenRepositorySearchTest limits = new SearchResultLimits( 1 ); limits.setPageSize( 1 ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -338,7 +353,8 @@ public class MavenRepositorySearchTest config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 5 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -373,7 +389,8 @@ public class MavenRepositorySearchTest List selectedRepos = new ArrayList<>(); selectedRepos.add( TEST_REPO_1 ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -392,7 +409,8 @@ public class MavenRepositorySearchTest List selectedRepos = new ArrayList<>(); selectedRepos.add( TEST_REPO_1 ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -410,8 +428,6 @@ public class MavenRepositorySearchTest List selectedRepos = new ArrayList<>(); selectedRepos.add( "non-existing-repo" ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); - archivaConfigControl.replay(); SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null ); @@ -433,7 +449,8 @@ public class MavenRepositorySearchTest List previousSearchTerms = new ArrayList<>(); previousSearchTerms.add( "archiva-test" ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -471,7 +488,8 @@ public class MavenRepositorySearchTest searchFields.setVersion( "1.0" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -506,7 +524,8 @@ public class MavenRepositorySearchTest SearchResultLimits limits = new SearchResultLimits( 0 ); limits.setPageSize( 1 ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -524,7 +543,8 @@ public class MavenRepositorySearchTest limits = new SearchResultLimits( 1 ); limits.setPageSize( 1 ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -556,7 +576,8 @@ public class MavenRepositorySearchTest searchFields.setArtifactId( "artifactid-numeric" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -599,7 +620,8 @@ public class MavenRepositorySearchTest try { - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -633,15 +655,16 @@ public class MavenRepositorySearchTest try { - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); search.search( "user", searchFields, null ); archivaConfigControl.verify(); - fail( "A RepositorySearchExcecption should have been thrown." ); + fail( "A RepositorySearchException should have been thrown." ); } catch ( RepositorySearchException e ) { @@ -666,7 +689,8 @@ public class MavenRepositorySearchTest searchFields.setClassName( "org.apache.archiva.test.App" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -697,7 +721,8 @@ public class MavenRepositorySearchTest searchFields.setPackaging( "jar" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -725,7 +750,9 @@ public class MavenRepositorySearchTest searchFields.setPackaging( "war" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); + archivaConfigControl.replay(); SearchResults results = search.search( "user", searchFields, null ); @@ -748,7 +775,8 @@ public class MavenRepositorySearchTest searchFields.setClassName( "com.classname.search.App" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -776,7 +804,8 @@ public class MavenRepositorySearchTest searchFields.setGroupId( "org.apache.archiva" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -800,7 +829,8 @@ public class MavenRepositorySearchTest searchFields.setClassName( "SomeClass" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); @@ -849,8 +879,6 @@ public class MavenRepositorySearchTest searchFields.setClassName( "SomeClass" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 2 ); - archivaConfigControl.replay(); SearchResults results = search.search( "user", searchFields, null ); @@ -881,7 +909,8 @@ public class MavenRepositorySearchTest SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); limits.setPageSize( 300 ); - EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 1, 5 ); + EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-indexer/src/test/resources/spring-context.xml index e0bf5c41c..487790661 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/resources/spring-context.xml @@ -28,6 +28,11 @@ default-lazy-init="false"> + + + + + diff --git a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyConnector.java b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyConnector.java index e8c20340a..d653de572 100644 --- a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyConnector.java +++ b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyConnector.java @@ -137,7 +137,7 @@ public class ProxyConnector sb.append( "ProxyConnector[\n" ); sb.append( " source: [managed] " ).append( this.sourceRepository.getRepoRoot() ).append( "\n" ); - sb.append( " target: [remote] " ).append( this.targetRepository.getRepository().getUrl() ).append( "\n" ); + sb.append( " target: [remote] " ).append( this.targetRepository.getRepository().getLocation() ).append( "\n" ); sb.append( " proxyId:" ).append( this.proxyId ).append( "\n" ); Iterator keys = this.policies.keySet().iterator(); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java index 4266bf734..a76e74457 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -22,17 +22,27 @@ package org.apache.archiva.proxy; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.NetworkProxy; import org.apache.archiva.admin.model.beans.ProxyConnectorRuleType; -import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin; import org.apache.archiva.common.filelock.FileLockException; import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.filelock.FileLockTimeoutException; import org.apache.archiva.common.filelock.Lock; -import org.apache.archiva.configuration.*; +import org.apache.archiva.configuration.ArchivaConfiguration; +import org.apache.archiva.configuration.Configuration; +import org.apache.archiva.configuration.ConfigurationNames; +import org.apache.archiva.configuration.NetworkProxyConfiguration; +import org.apache.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.archiva.configuration.ProxyConnectorRuleConfiguration; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.Keys; import org.apache.archiva.model.RepositoryURL; -import org.apache.archiva.policies.*; +import org.apache.archiva.policies.DownloadErrorPolicy; +import org.apache.archiva.policies.DownloadPolicy; +import org.apache.archiva.policies.PolicyConfigurationException; +import org.apache.archiva.policies.PolicyViolationException; +import org.apache.archiva.policies.PostDownloadPolicy; +import org.apache.archiva.policies.PreDownloadPolicy; +import org.apache.archiva.policies.ProxyDownloadException; import org.apache.archiva.policies.urlcache.UrlFailureCache; import org.apache.archiva.proxy.common.WagonFactory; import org.apache.archiva.proxy.common.WagonFactoryException; @@ -43,7 +53,16 @@ import org.apache.archiva.proxy.model.RepositoryProxyConnectors; import org.apache.archiva.redback.components.registry.Registry; import org.apache.archiva.redback.components.registry.RegistryListener; import org.apache.archiva.redback.components.taskqueue.TaskQueueException; -import org.apache.archiva.repository.*; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.PasswordCredentials; +import org.apache.archiva.repository.RemoteRepositoryContent; +import org.apache.archiva.repository.RepositoryContentFactory; +import org.apache.archiva.repository.RepositoryCredentials; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryNotFoundException; +import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.metadata.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.scheduler.ArchivaTaskScheduler; @@ -73,11 +92,15 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.TimeUnit; /** * DefaultRepositoryProxyConnectors @@ -125,6 +148,9 @@ public class DefaultRepositoryProxyConnectors @Named(value = "archivaTaskScheduler#repository") private ArchivaTaskScheduler scheduler; + @Inject + private RepositoryRegistry repositoryRegistry; + @Inject private NetworkProxyAdmin networkProxyAdmin; @@ -157,86 +183,83 @@ public class DefaultRepositoryProxyConnectors { String key = proxyConfig.getSourceRepoId(); - try + // Create connector object. + ProxyConnector connector = new ProxyConnector(); + + ManagedRepository repo = repositoryRegistry.getManagedRepository( proxyConfig.getSourceRepoId( ) ); + if (repo==null) { + log.error("Cannot find source repository after config change "+proxyConfig.getSourceRepoId()); + continue; + } + connector.setSourceRepository(repo.getContent()); + RemoteRepository rRepo = repositoryRegistry.getRemoteRepository( proxyConfig.getTargetRepoId() ); + if (rRepo==null) { + log.error("Cannot find target repository after config change "+proxyConfig.getSourceRepoId()); + continue; + } + connector.setTargetRepository(rRepo.getContent()); + + connector.setProxyId( proxyConfig.getProxyId() ); + connector.setPolicies( proxyConfig.getPolicies() ); + connector.setOrder( proxyConfig.getOrder() ); + connector.setDisabled( proxyConfig.isDisabled() ); + + // Copy any blacklist patterns. + List blacklist = new ArrayList<>( 0 ); + if ( CollectionUtils.isNotEmpty( proxyConfig.getBlackListPatterns() ) ) { - // Create connector object. - ProxyConnector connector = new ProxyConnector(); - - connector.setSourceRepository( - repositoryFactory.getManagedRepositoryContent( proxyConfig.getSourceRepoId() ) ); - connector.setTargetRepository( - repositoryFactory.getRemoteRepositoryContent( proxyConfig.getTargetRepoId() ) ); - - connector.setProxyId( proxyConfig.getProxyId() ); - connector.setPolicies( proxyConfig.getPolicies() ); - connector.setOrder( proxyConfig.getOrder() ); - connector.setDisabled( proxyConfig.isDisabled() ); - - // Copy any blacklist patterns. - List blacklist = new ArrayList<>( 0 ); - if ( CollectionUtils.isNotEmpty( proxyConfig.getBlackListPatterns() ) ) - { - blacklist.addAll( proxyConfig.getBlackListPatterns() ); - } - connector.setBlacklist( blacklist ); + blacklist.addAll( proxyConfig.getBlackListPatterns() ); + } + connector.setBlacklist( blacklist ); - // Copy any whitelist patterns. - List whitelist = new ArrayList<>( 0 ); - if ( CollectionUtils.isNotEmpty( proxyConfig.getWhiteListPatterns() ) ) - { - whitelist.addAll( proxyConfig.getWhiteListPatterns() ); - } - connector.setWhitelist( whitelist ); + // Copy any whitelist patterns. + List whitelist = new ArrayList<>( 0 ); + if ( CollectionUtils.isNotEmpty( proxyConfig.getWhiteListPatterns() ) ) + { + whitelist.addAll( proxyConfig.getWhiteListPatterns() ); + } + connector.setWhitelist( whitelist ); - List proxyConnectorRuleConfigurations = - findProxyConnectorRules( connector.getSourceRepository().getId(), - connector.getTargetRepository().getId(), - allProxyConnectorRuleConfigurations ); + List proxyConnectorRuleConfigurations = + findProxyConnectorRules( connector.getSourceRepository().getId(), + connector.getTargetRepository().getId(), + allProxyConnectorRuleConfigurations ); - if ( !proxyConnectorRuleConfigurations.isEmpty() ) + if ( !proxyConnectorRuleConfigurations.isEmpty() ) + { + for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : proxyConnectorRuleConfigurations ) { - for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : proxyConnectorRuleConfigurations ) + if ( StringUtils.equals( proxyConnectorRuleConfiguration.getRuleType(), + ProxyConnectorRuleType.BLACK_LIST.getRuleType() ) ) { - if ( StringUtils.equals( proxyConnectorRuleConfiguration.getRuleType(), - ProxyConnectorRuleType.BLACK_LIST.getRuleType() ) ) - { - connector.getBlacklist().add( proxyConnectorRuleConfiguration.getPattern() ); - } - - if ( StringUtils.equals( proxyConnectorRuleConfiguration.getRuleType(), - ProxyConnectorRuleType.WHITE_LIST.getRuleType() ) ) - { - connector.getWhitelist().add( proxyConnectorRuleConfiguration.getPattern() ); - } + connector.getBlacklist().add( proxyConnectorRuleConfiguration.getPattern() ); } - } - // Get other connectors - List connectors = this.proxyConnectorMap.get( key ); - if ( connectors == null ) - { - // Create if we are the first. - connectors = new ArrayList<>( 1 ); + if ( StringUtils.equals( proxyConnectorRuleConfiguration.getRuleType(), + ProxyConnectorRuleType.WHITE_LIST.getRuleType() ) ) + { + connector.getWhitelist().add( proxyConnectorRuleConfiguration.getPattern() ); + } } - - // Add the connector. - connectors.add( connector ); - - // Ensure the list is sorted. - Collections.sort( connectors, proxyOrderSorter ); - - // Set the key to the list of connectors. - this.proxyConnectorMap.put( key, connectors ); } - catch ( RepositoryNotFoundException e ) - { - log.warn( "Unable to use proxy connector: {}", e.getMessage(), e ); - } - catch ( RepositoryException e ) + + // Get other connectors + List connectors = this.proxyConnectorMap.get( key ); + if ( connectors == null ) { - log.warn( "Unable to use proxy connector: {}", e.getMessage(), e ); + // Create if we are the first. + connectors = new ArrayList<>( 1 ); } + // Add the connector. + connectors.add( connector ); + + // Ensure the list is sorted. + Collections.sort( connectors, proxyOrderSorter ); + + // Set the key to the list of connectors. + this.proxyConnectorMap.put( key, connectors ); + } @@ -1176,8 +1199,14 @@ public class DefaultRepositoryProxyConnectors } AuthenticationInfo authInfo = null; - String username = remoteRepository.getRepository().getUserName(); - String password = remoteRepository.getRepository().getPassword(); + String username = ""; + String password = ""; + RepositoryCredentials repCred = remoteRepository.getRepository().getLoginCredentials(); + if (repCred!=null && repCred instanceof PasswordCredentials) { + PasswordCredentials pwdCred = (PasswordCredentials) repCred; + username = pwdCred.getUsername(); + password = pwdCred.getPassword()==null ? "" : new String(pwdCred.getPassword()); + } if ( StringUtils.isNotBlank( username ) && StringUtils.isNotBlank( password ) ) { @@ -1188,8 +1217,8 @@ public class DefaultRepositoryProxyConnectors } // Convert seconds to milliseconds - long timeoutInMilliseconds = TimeUnit.MILLISECONDS.convert( remoteRepository.getRepository().getTimeout(), // - TimeUnit.SECONDS ); + + long timeoutInMilliseconds = remoteRepository.getRepository().getTimeout().toMillis(); // Set timeout read and connect // FIXME olamy having 2 config values diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java index a8ffb6336..2a43b862e 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java @@ -36,6 +36,8 @@ import org.apache.archiva.policies.ReleasesPolicy; import org.apache.archiva.policies.SnapshotsPolicy; import org.apache.archiva.proxy.model.RepositoryProxyConnectors; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.maven2.MavenManagedRepository; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.maven.index.NexusIndexer; @@ -55,6 +57,7 @@ import javax.inject.Inject; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; +import java.net.URI; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; @@ -117,8 +120,7 @@ public abstract class AbstractProxyTestCase WagonDelegate delegate; - @Inject - protected ManagedRepositoryAdmin managedRepositoryAdmin; + protected RepositoryRegistry repositoryRegistry; @Inject protected NexusIndexer nexusIndexer; @@ -143,38 +145,44 @@ public abstract class AbstractProxyTestCase managedDefaultDir = Paths.get( managedDefaultRepository.getRepoRoot() ); - ManagedRepository repoConfig = managedDefaultRepository.getRepository(); + org.apache.archiva.repository.ManagedRepository repoConfig = managedDefaultRepository.getRepository(); ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( config ); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( repoConfig, false, null ); + applicationContext.getBean( RepositoryRegistry.class ).putRepository( repoConfig ); // to prevent windauze file leaking removeMavenIndexes(); - ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); - - if ( managedRepositoryAdmin.getManagedRepository( repoConfig.getId() ) != null ) - { - managedRepositoryAdmin.deleteManagedRepository( repoConfig.getId(), null, true ); - } - - managedRepositoryAdmin.addManagedRepository( repoConfig, false, null ); + repositoryRegistry = applicationContext.getBean( RepositoryRegistry.class ); + repositoryRegistry.setArchivaConfiguration( config ); // Setup target (proxied to) repository. saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", - Paths.get( REPOPATH_PROXIED1 ).toUri().toURL().toExternalForm(), "default" ); + Paths.get( REPOPATH_PROXIED1 ).toUri().toURL().toExternalForm(), "default" ); // Setup target (proxied to) repository. saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", - Paths.get( REPOPATH_PROXIED2 ).toUri().toURL().toExternalForm(), "default" ); + Paths.get( REPOPATH_PROXIED2 ).toUri().toURL().toExternalForm(), "default" ); + + repositoryRegistry.reload(); + + if ( repositoryRegistry.getManagedRepository( repoConfig.getId() ) != null ) + { + org.apache.archiva.repository.ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( repoConfig.getId() ); + repositoryRegistry.removeRepository( managedRepository ); + } + + repositoryRegistry.putRepository( repoConfig ); + // Setup the proxy handler. //proxyHandler = applicationContext.getBean (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); proxyHandler = applicationContext.getBean( "repositoryProxyConnectors#test", RepositoryProxyConnectors.class ); + // Setup the wagon mock. wagonMockControl = EasyMock.createNiceControl(); wagonMock = wagonMockControl.createMock( Wagon.class ); @@ -345,10 +353,8 @@ public abstract class AbstractProxyTestCase protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout ) throws Exception { - ManagedRepository repo = new ManagedRepository(); - repo.setId( id ); - repo.setName( name ); - repo.setLocation( path ); + MavenManagedRepository repo = new MavenManagedRepository(id, name); + repo.setLocation( new URI(path) ); repo.setLayout( layout ); ManagedRepositoryContent repoContent = @@ -477,6 +483,7 @@ public abstract class AbstractProxyTestCase config.triggerChange( prefix + ".name", repoConfig.getName() ); config.triggerChange( prefix + ".url", repoConfig.getUrl() ); config.triggerChange( prefix + ".layout", repoConfig.getLayout() ); + repositoryRegistry.reload(); } protected Path saveTargetedRepositoryConfig( String id, String originalPath, String targetPath, String layout ) diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java index f1857fb1f..3445ee86d 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java @@ -112,6 +112,7 @@ public class CacheFailuresTransferTest saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/anotherrepo/", "default" ); + // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java index fad03d802..8b8d08e05 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java @@ -23,6 +23,8 @@ import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; import org.apache.archiva.proxy.model.RepositoryProxyConnectors; +import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.maven2.MavenManagedRepository; import org.apache.commons.io.FileUtils; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.NetworkProxyConfiguration; @@ -55,10 +57,12 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.net.URI; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Locale; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; @@ -118,10 +122,8 @@ public class HttpProxyTransferTest // Make the destination dir. Files.createDirectories(destRepoDir); - ManagedRepository repo = new ManagedRepository(); - repo.setId( MANAGED_ID ); - repo.setName( "Default Managed Repository" ); - repo.setLocation( repoPath ); + MavenManagedRepository repo = new MavenManagedRepository( MANAGED_ID, "Default Managed Repository" ); + repo.setLocation( new URI(repoPath) ); repo.setLayout( "default" ); ManagedRepositoryContent repoContent = @@ -133,10 +135,10 @@ public class HttpProxyTransferTest ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( config ); - ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); + RepositoryRegistry managedRepositoryAdmin = applicationContext.getBean( RepositoryRegistry.class ); if ( managedRepositoryAdmin.getManagedRepository( repo.getId() ) == null ) { - managedRepositoryAdmin.addManagedRepository( repo, false, null ); + managedRepositoryAdmin.putRepository( repo ); } //config.getConfiguration().addManagedRepository( repo ); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java index 935f2a6e0..fce694934 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java @@ -35,6 +35,7 @@ import org.springframework.stereotype.Service; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Set; import javax.annotation.PostConstruct; @@ -145,4 +146,16 @@ public class MockConfiguration { // no op } + + @Override + public Locale getDefaultLocale( ) + { + return Locale.getDefault(); + } + + @Override + public List getLanguagePriorities( ) + { + return Locale.LanguageRange.parse( "en,fr,de" ); + } } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java new file mode 100644 index 000000000..834ce5ba2 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java @@ -0,0 +1,231 @@ +package org.apache.archiva.repository.mock; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.configuration.RemoteRepositoryConfiguration; +import org.apache.archiva.repository.BasicManagedRepository; +import org.apache.archiva.repository.BasicRemoteRepository; +import org.apache.archiva.repository.EditableManagedRepository; +import org.apache.archiva.repository.EditableRemoteRepository; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.PasswordCredentials; +import org.apache.archiva.repository.ReleaseScheme; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.RepositoryCredentials; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryProvider; +import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.features.ArtifactCleanupFeature; +import org.apache.archiva.repository.features.IndexCreationFeature; +import org.apache.archiva.repository.features.RemoteIndexFeature; +import org.apache.archiva.repository.features.StagingRepositoryFeature; +import org.springframework.stereotype.Service; + +import java.net.URI; +import java.time.Duration; +import java.time.Period; +import java.util.HashSet; +import java.util.Set; + +/** + * Just a simple mock class for the repository provider + */ +@Service("mockRepositoryProvider") +public class RepositoryProviderMock implements RepositoryProvider +{ + + private static final Set TYPES = new HashSet<>( ); + + static + { + TYPES.add( RepositoryType.MAVEN ); + TYPES.add( RepositoryType.NPM ); + } + + @Override + public Set provides( ) + { + return TYPES; + } + + @Override + public EditableManagedRepository createManagedInstance( String id, String name ) + { + return new BasicManagedRepository( id, name ); + } + + @Override + public EditableRemoteRepository createRemoteInstance( String id, String name ) + { + return new BasicRemoteRepository( id, name ); + } + + @Override + public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException + { + BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) ); + updateManagedInstance( managedRepository, configuration ); + return managedRepository; + } + + + @Override + public void updateManagedInstance( EditableManagedRepository managedRepository, ManagedRepositoryConfiguration configuration ) throws RepositoryException + { + try + { + managedRepository.setName( managedRepository.getPrimaryLocale(), configuration.getName( ) ); + managedRepository.setLocation( new URI( configuration.getLocation( )==null ?"" : configuration.getLocation() ) ); + managedRepository.setBaseUri( new URI( "" ) ); + managedRepository.setBlocksRedeployment( configuration.isBlockRedeployments( ) ); + managedRepository.setDescription( managedRepository.getPrimaryLocale(), configuration.getDescription( ) ); + managedRepository.setLayout( configuration.getLayout( ) ); + managedRepository.setScanned( configuration.isScanned( ) ); + managedRepository.setSchedulingDefinition( configuration.getRefreshCronExpression( ) ); + if (configuration.isReleases()) { + managedRepository.addActiveReleaseScheme( ReleaseScheme.RELEASE ); + } + if (configuration.isSnapshots()) { + managedRepository.addActiveReleaseScheme( ReleaseScheme.SNAPSHOT ); + } + ArtifactCleanupFeature acf = managedRepository.getFeature( ArtifactCleanupFeature.class ).get( ); + acf.setRetentionPeriod( Period.ofDays( configuration.getRetentionPeriod( ) ) ); + acf.setDeleteReleasedSnapshots( configuration.isDeleteReleasedSnapshots( ) ); + acf.setRetentionCount( configuration.getRetentionCount( ) ); + IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get( ); + icf.setIndexPath( new URI( configuration.getIndexDir( ) ) ); + icf.setSkipPackedIndexCreation( configuration.isSkipPackedIndexCreation( ) ); + StagingRepositoryFeature srf = managedRepository.getFeature( StagingRepositoryFeature.class ).get( ); + srf.setStageRepoNeeded( configuration.isStageRepoNeeded( ) ); + } + catch ( Exception e ) + { + throw new RepositoryException( "Error", e ); + } + + } + + + @Override + public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException + { + String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; + BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) ); + updateManagedInstance( managedRepository, configuration ); + return managedRepository; + } + + @Override + public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException + { + BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) ); + updateRemoteInstance( remoteRepository, configuration ); + return remoteRepository; + } + + @Override + public void updateRemoteInstance( EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration ) throws RepositoryException + { + try + { + remoteRepository.setName( remoteRepository.getPrimaryLocale(), configuration.getName( ) ); + remoteRepository.setBaseUri( new URI( "" ) ); + remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), configuration.getDescription( ) ); + remoteRepository.setLayout( configuration.getLayout( ) ); + remoteRepository.setSchedulingDefinition( configuration.getRefreshCronExpression( ) ); + remoteRepository.setCheckPath( configuration.getCheckPath( ) ); + remoteRepository.setExtraHeaders( configuration.getExtraHeaders( ) ); + remoteRepository.setExtraParameters( configuration.getExtraParameters( ) ); + remoteRepository.setTimeout( Duration.ofSeconds( configuration.getTimeout( ) ) ); + char[] pwd = configuration.getPassword()==null ? "".toCharArray() : configuration.getPassword().toCharArray(); + remoteRepository.setCredentials( new PasswordCredentials( configuration.getUsername( ), pwd ) ); + remoteRepository.setLocation( new URI( configuration.getUrl( )==null ? "" : configuration.getUrl() ) ); + RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( ); + rif.setDownloadRemoteIndexOnStartup( configuration.isDownloadRemoteIndexOnStartup( ) ); + rif.setDownloadRemoteIndex( configuration.isDownloadRemoteIndex( ) ); + rif.setIndexUri( new URI( configuration.getIndexDir( ) ) ); + rif.setDownloadTimeout( Duration.ofSeconds( configuration.getRemoteDownloadTimeout( ) ) ); + rif.setProxyId( configuration.getRemoteDownloadNetworkProxyId( ) ); + } + catch ( Exception e ) + { + throw new RepositoryException( "Error", e ); + } + + } + + @Override + public ManagedRepositoryConfiguration getManagedConfiguration( ManagedRepository managedRepository ) throws RepositoryException + { + ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration( ); + configuration.setId( managedRepository.getId( ) ); + configuration.setName(managedRepository.getName()); + configuration.setLocation( managedRepository.getLocation( ) == null ? "" : managedRepository.getLocation().toString( ) ); + configuration.setBlockRedeployments( managedRepository.blocksRedeployments( ) ); + configuration.setDescription( managedRepository.getDescription( ) ); + configuration.setLayout( managedRepository.getLayout( ) ); + configuration.setScanned( managedRepository.isScanned( ) ); + configuration.setRefreshCronExpression( managedRepository.getSchedulingDefinition( ) ); + configuration.setReleases( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE) ); + configuration.setSnapshots( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT) ); + ArtifactCleanupFeature acf = managedRepository.getFeature( ArtifactCleanupFeature.class ).get( ); + configuration.setRetentionPeriod( acf.getRetentionPeriod( ).getDays( ) ); + configuration.setDeleteReleasedSnapshots( acf.isDeleteReleasedSnapshots( ) ); + configuration.setRetentionCount( acf.getRetentionCount( ) ); + IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get( ); + configuration.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation( ) ); + configuration.setIndexDir( icf.getIndexPath( ) == null ? "" : icf.getIndexPath().toString( ) ); + StagingRepositoryFeature srf = managedRepository.getFeature( StagingRepositoryFeature.class ).get( ); + configuration.setStageRepoNeeded( srf.isStageRepoNeeded( ) ); + return configuration; + } + + + @Override + public RemoteRepositoryConfiguration getRemoteConfiguration( RemoteRepository remoteRepository ) throws RepositoryException + { + RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration( ); + configuration.setId( remoteRepository.getId( ) ); + configuration.setName( remoteRepository.getName( ) ); + configuration.setDescription( remoteRepository.getDescription( ) ); + configuration.setLayout( remoteRepository.getLayout( ) ); + configuration.setRefreshCronExpression( remoteRepository.getSchedulingDefinition( ) ); + configuration.setCheckPath( remoteRepository.getCheckPath( ) ); + configuration.setExtraHeaders( remoteRepository.getExtraHeaders( ) ); + configuration.setExtraParameters( remoteRepository.getExtraParameters( ) ); + configuration.setTimeout( (int) remoteRepository.getTimeout( ).getSeconds( ) ); + RepositoryCredentials creds = remoteRepository.getLoginCredentials( ); + if (creds!=null) + { + PasswordCredentials pwdCreds = (PasswordCredentials) creds; + configuration.setUsername( pwdCreds.getUsername( ) ); + configuration.setPassword( new String( pwdCreds.getPassword( ) ) ); + } + configuration.setUrl( remoteRepository.getLocation( ) == null ? "" : remoteRepository.getLocation().toString( ) ); + RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( ); + configuration.setDownloadRemoteIndex( rif.isDownloadRemoteIndex( ) ); + configuration.setDownloadRemoteIndexOnStartup( rif.isDownloadRemoteIndexOnStartup( ) ); + configuration.setIndexDir( rif.getIndexUri( )==null ? "" : rif.getIndexUri().toString( ) ); + configuration.setRemoteDownloadNetworkProxyId( rif.getProxyId( ) ); + return configuration; + } + +} diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-proxy/src/test/resources/spring-context.xml index 7a57f01e0..6ec124f60 100755 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/resources/spring-context.xml @@ -28,7 +28,10 @@ default-lazy-init="true"> - + + + + diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java index 5daae0745..fff20693a 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java @@ -20,11 +20,11 @@ package org.apache.archiva.repository.scanner; */ import org.apache.archiva.admin.model.RepositoryAdminException; -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.consumers.RepositoryContentConsumer; +import org.apache.archiva.repository.ManagedRepository; import org.apache.commons.collections.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java index 5ccdb1ef9..c3159c733 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java @@ -21,13 +21,14 @@ package org.apache.archiva.repository.scanner; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.admin.ArchivaAdministration; -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.utils.BaseFile; +import org.apache.archiva.common.utils.PathUtil; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; import org.apache.archiva.redback.components.registry.RegistryListener; +import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure; import org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure; import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure; @@ -41,6 +42,7 @@ import org.springframework.stereotype.Service; import javax.inject.Inject; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.*; /** @@ -262,7 +264,7 @@ public class RepositoryContentConsumers * @param localFile the local file to execute the consumers against. * @param updateRelatedArtifacts TODO */ - public void executeConsumers(ManagedRepository repository, Path localFile, boolean updateRelatedArtifacts ) + public void executeConsumers( ManagedRepository repository, Path localFile, boolean updateRelatedArtifacts ) throws RepositoryAdminException { List selectedKnownConsumers = null; @@ -296,7 +298,8 @@ public class RepositoryContentConsumers // yuck. In case you can't read this, it says // "process the file if the consumer has it in the includes list, and not in the excludes list" - BaseFile baseFile = new BaseFile( repository.getLocation(), localFile.toFile() ); + Path repoPath = PathUtil.getPathFromUri( repository.getLocation() ); + BaseFile baseFile = new BaseFile( repoPath.toString(), localFile.toFile() ); ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate( repository ); predicate.setBasefile( baseFile ); predicate.setCaseSensitive( false ); diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanStatistics.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanStatistics.java index 8e2dd8341..1d9ebbeeb 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanStatistics.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanStatistics.java @@ -19,7 +19,7 @@ package org.apache.archiva.repository.scanner; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.repository.ManagedRepository; import org.apache.commons.collections.CollectionUtils; import javax.xml.bind.annotation.XmlRootElement; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java index cfa8f17a7..8c5cb8946 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java @@ -19,9 +19,9 @@ package org.apache.archiva.repository.scanner; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.repository.ManagedRepository; import java.util.List; import java.util.Set; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java index 55e0e5248..5928823ea 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java @@ -19,11 +19,12 @@ package org.apache.archiva.repository.scanner; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.utils.BaseFile; +import org.apache.archiva.common.utils.PathUtil; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; +import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure; import org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure; import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure; @@ -216,7 +217,8 @@ public class RepositoryScannerInstance stats.increaseFileCount(); // consume files regardless - the predicate will check the timestamp - BaseFile basefile = new BaseFile( repository.getLocation(), file.toFile() ); + Path repoPath = PathUtil.getPathFromUri( repository.getLocation() ); + BaseFile basefile = new BaseFile( repoPath.toString(), file.toFile() ); // Timestamp finished points to the last successful scan, not this current one. if ( Files.getLastModifiedTime(file).toMillis() >= changesSince ) diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java index b83085411..4ae19dc14 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java @@ -19,7 +19,7 @@ package org.apache.archiva.repository.scanner.functors; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.repository.ManagedRepository; import org.apache.commons.collections.Closure; import org.apache.archiva.consumers.ConsumerException; import org.apache.archiva.consumers.RepositoryContentConsumer; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java index 3b7cf9d7f..c4789be31 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java @@ -19,7 +19,7 @@ package org.apache.archiva.repository.scanner.functors; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.repository.ManagedRepository; import org.apache.commons.collections.Closure; import org.apache.archiva.consumers.RepositoryContentConsumer; import org.slf4j.Logger; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java index cee2d72ec..81f9440a9 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java @@ -19,10 +19,10 @@ package org.apache.archiva.repository.scanner; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.consumers.AbstractMonitoredConsumer; import org.apache.archiva.consumers.ConsumerException; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.repository.ManagedRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Scope; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java index f494bf4ec..7a48f71a5 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java @@ -19,12 +19,10 @@ package org.apache.archiva.repository.scanner; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.consumers.AbstractMonitoredConsumer; import org.apache.archiva.consumers.ConsumerException; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Service; +import org.apache.archiva.repository.ManagedRepository; import java.util.ArrayList; import java.util.Arrays; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java index 988e3ef8b..c24c0c26b 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java @@ -20,11 +20,13 @@ package org.apache.archiva.repository.scanner; */ import junit.framework.TestCase; -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.repository.BasicManagedRepository; +import org.apache.archiva.repository.BasicRemoteRepository; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.RemoteRepository; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang.SystemUtils; import org.easymock.IMocksControl; @@ -46,6 +48,8 @@ import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import java.io.IOException; import java.lang.annotation.Annotation; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; @@ -72,19 +76,15 @@ public class RepositoryContentConsumersTest protected ManagedRepository createRepository( String id, String name, Path location ) { - ManagedRepository repo = new ManagedRepository(); - repo.setId( id ); - repo.setName( name ); - repo.setLocation( location.toAbsolutePath().toString() ); + BasicManagedRepository repo = new BasicManagedRepository( id, name ); + repo.setLocation( location.toAbsolutePath().toUri() ); return repo; } - protected RemoteRepository createRemoteRepository( String id, String name, String url ) + protected RemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException { - RemoteRepository repo = new RemoteRepository(); - repo.setId( id ); - repo.setName( name ); - repo.setUrl( url ); + BasicRemoteRepository repo = new BasicRemoteRepository(id, name); + repo.setLocation( new URI( url ) ); return repo; } diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java index e028b94eb..e9a462b22 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java @@ -20,10 +20,13 @@ package org.apache.archiva.repository.scanner; */ import junit.framework.TestCase; -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.repository.BasicManagedRepository; +import org.apache.archiva.repository.BasicRemoteRepository; +import org.apache.archiva.repository.EditableManagedRepository; +import org.apache.archiva.repository.EditableRemoteRepository; +import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.junit.Test; @@ -33,6 +36,8 @@ import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -57,21 +62,17 @@ public class RepositoryScannerTest @Inject ApplicationContext applicationContext; - protected ManagedRepository createRepository( String id, String name, Path location ) + protected EditableManagedRepository createRepository( String id, String name, Path location ) { - ManagedRepository repo = new ManagedRepository(); - repo.setId( id ); - repo.setName( name ); - repo.setLocation( location.toAbsolutePath().toString()); + BasicManagedRepository repo = new BasicManagedRepository(id, name); + repo.setLocation( location.toAbsolutePath().toUri()); return repo; } - protected RemoteRepository createRemoteRepository( String id, String name, String url ) + protected EditableRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException { - RemoteRepository repo = new RemoteRepository(); - repo.setId( id ); - repo.setName( name ); - repo.setUrl( url ); + BasicRemoteRepository repo = new BasicRemoteRepository(id, name); + repo.setLocation( new URI( url ) ); return repo; } @@ -122,7 +123,7 @@ public class RepositoryScannerTest assertTrue( "Legacy Test Repository should exist.", Files.exists(repoDir) && Files.isDirectory(repoDir) ); - ManagedRepository repo = createRepository( "testLegacyRepo", "Test Legacy Repository", repoDir ); + EditableManagedRepository repo = createRepository( "testLegacyRepo", "Test Legacy Repository", repoDir ); repo.setLayout( "legacy" ); return repo; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java index ab9a3c8df..02d961b76 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java @@ -19,10 +19,10 @@ package org.apache.archiva.repository.scanner; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.consumers.AbstractMonitoredConsumer; import org.apache.archiva.consumers.ConsumerException; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.repository.ManagedRepository; import java.util.Date; import java.util.List; diff --git a/archiva-modules/archiva-base/archiva-test-utils/pom.xml b/archiva-modules/archiva-base/archiva-test-utils/pom.xml index bb9700158..bde3e5cc7 100644 --- a/archiva-modules/archiva-base/archiva-test-utils/pom.xml +++ b/archiva-modules/archiva-base/archiva-test-utils/pom.xml @@ -42,10 +42,5 @@ xmlunit compile - - org.slf4j - slf4j-simple - compile - - + diff --git a/archiva-modules/archiva-base/pom.xml b/archiva-modules/archiva-base/pom.xml index e78f79b76..24021289d 100644 --- a/archiva-modules/archiva-base/pom.xml +++ b/archiva-modules/archiva-base/pom.xml @@ -41,6 +41,7 @@ archiva-policies archiva-indexer archiva-consumers + archiva-repository-api archiva-repository-layer archiva-xml-tools archiva-proxy-api