diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/pom.xml b/archiva-modules/archiva-maven/archiva-maven-scheduler/pom.xml index d08e854df..30d6e8d73 100644 --- a/archiva-modules/archiva-maven/archiva-maven-scheduler/pom.xml +++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/pom.xml @@ -44,6 +44,14 @@ org.springframework spring-context + + org.apache.archiva + archiva-common + + + org.apache.archiva + archiva-storage-api + org.apache.archiva archiva-configuration @@ -58,11 +66,28 @@ org.apache.archiva.maven - archiva-maven-proxy + archiva-maven-common org.apache.archiva - archiva-repository-admin-api + archiva-repository-api + + + org.apache.archiva + archiva-proxy-api + + + org.apache.archiva.components + archiva-components-spring-taskqueue + + + + javax.annotation + javax.annotation-api + + + javax.inject + javax.inject @@ -72,51 +97,44 @@ org.apache.maven.wagon - wagon-http + wagon-http-shared provided org.apache.maven.wagon - wagon-http-lightweight - provided + wagon-provider-api + + org.apache.commons + commons-lang3 + + + - javax.persistence - javax.persistence-api + org.apache.archiva + repository-statistics test - org.apache.archiva.redback - redback-keys-jpa + org.apache.maven.wagon + wagon-http test - org.apache.archiva.redback - redback-keys-cached + org.apache.maven.wagon + wagon-http-lightweight test - javax.transaction - javax.transaction-api - test - - - org.apache.archiva.redback - redback-common-jpa - ${redback.version} + org.apache.archiva.maven + archiva-maven-proxy test org.springframework - spring-tx - ${spring.version} - test - - - org.apache.archiva - archiva-repository-admin-default + spring-test test @@ -135,6 +153,12 @@ ${project.version} test + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + test + org.eclipse.jetty jetty-server @@ -152,19 +176,6 @@ assertj-core test - - org.apache.archiva - archiva-mock - test - - - - org.apache.archiva.redback - redback-rbac-cached - test - ${redback.version} - - org.apache.archiva @@ -173,21 +184,11 @@ - org.apache.logging.log4j - log4j-slf4j-impl - - - - org.apache.archiva.redback - redback-common-test-resources + org.apache.archiva + archiva-mock test - - org.ow2.asm - asm - test - diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/main/java/org/apache/archiva/scheduler/indexing/maven/DefaultDownloadRemoteIndexScheduler.java b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/main/java/org/apache/archiva/scheduler/indexing/maven/DefaultDownloadRemoteIndexScheduler.java index 7d3fe95c8..452ea65fd 100644 --- a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/main/java/org/apache/archiva/scheduler/indexing/maven/DefaultDownloadRemoteIndexScheduler.java +++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/main/java/org/apache/archiva/scheduler/indexing/maven/DefaultDownloadRemoteIndexScheduler.java @@ -22,7 +22,6 @@ import org.apache.archiva.proxy.ProxyRegistry; import org.apache.archiva.proxy.model.NetworkProxy; import org.apache.archiva.scheduler.indexing.DownloadRemoteIndexException; import org.apache.archiva.scheduler.indexing.DownloadRemoteIndexScheduler; -import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ConfigurationEvent; import org.apache.archiva.configuration.ConfigurationListener; diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/DownloadRemoteIndexTaskTest.java b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/DownloadRemoteIndexTaskTest.java index 01921e45d..ae7189184 100644 --- a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/DownloadRemoteIndexTaskTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/DownloadRemoteIndexTaskTest.java @@ -18,10 +18,19 @@ package org.apache.archiva.scheduler.indexing.maven; * under the License. */ -import org.apache.archiva.admin.model.beans.RemoteRepository; -import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; import org.apache.archiva.common.utils.FileUtils; +import org.apache.archiva.indexer.ArchivaIndexManager; +import org.apache.archiva.indexer.IndexCreationFailedException; +import org.apache.archiva.repository.EditableRemoteRepository; +import org.apache.archiva.repository.EditableRepository; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryProvider; import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.UnsupportedURIException; +import org.apache.archiva.repository.features.IndexCreationFeature; +import org.apache.archiva.repository.features.RemoteIndexFeature; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.maven.index.FlatSearchRequest; import org.apache.maven.index.FlatSearchResponse; @@ -49,15 +58,14 @@ 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; import java.util.Arrays; -import java.util.Locale; import java.util.concurrent.TimeUnit; -import static org.assertj.core.api.Assertions.assertThat; - /** * @author Olivier Lamy */ @@ -73,9 +81,6 @@ public class DownloadRemoteIndexTaskTest private Logger log = LoggerFactory.getLogger( getClass() ); - @Inject - RemoteRepositoryAdmin remoteRepositoryAdmin; - @Inject DefaultDownloadRemoteIndexScheduler downloadRemoteIndexScheduler; @@ -85,6 +90,9 @@ public class DownloadRemoteIndexTaskTest @Inject RepositoryRegistry repositoryRegistry; + @Inject + RepositoryProvider repositoryProvider; + @Before public void initialize() throws Exception @@ -94,7 +102,7 @@ public class DownloadRemoteIndexTaskTest Files.delete(cfgFile); } try { - remoteRepositoryAdmin.deleteRemoteRepository("test-repo-re", null); + repositoryRegistry.removeRepository( "test-repo-re" ); } catch (Exception e) { // Ignore } @@ -136,9 +144,12 @@ public class DownloadRemoteIndexTaskTest public void downloadAndMergeRemoteIndexInEmptyIndex() throws Exception { - RemoteRepository remoteRepository = getRemoteRepository(); + Path repoDirectory = Paths.get( FileUtils.getBasedir( ), "target/repo-" + Long.toString( System.currentTimeMillis( ) ) ); - remoteRepositoryAdmin.addRemoteRepository( remoteRepository, null ); + RemoteRepository remoteRepository = getRemoteRepository(repoDirectory); + + repositoryRegistry.putRepository( remoteRepository); + repositoryRegistry.reload(); downloadRemoteIndexScheduler.startup(); @@ -147,17 +158,17 @@ public class DownloadRemoteIndexTaskTest ( (ThreadPoolTaskScheduler) downloadRemoteIndexScheduler.getTaskScheduler() ).getScheduledExecutor().awaitTermination( 10, TimeUnit.SECONDS ); - remoteRepositoryAdmin.deleteRemoteRepository( "test-repo-re", null ); + repositoryRegistry.removeRepository( "test-repo-re" ); // search BooleanQuery.Builder iQuery = new BooleanQuery.Builder(); iQuery.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( "commons-logging" ) ), BooleanClause.Occur.SHOULD ); - remoteRepositoryAdmin.addRemoteRepository(remoteRepository, null); + remoteRepository = getRemoteRepository( repoDirectory ); FlatSearchRequest rq = new FlatSearchRequest( iQuery.build() ); rq.setContexts( - Arrays.asList( repositoryRegistry.getRemoteRepository(remoteRepository.getId()).getIndexingContext().getBaseContext(IndexingContext.class) ) ); + Arrays.asList( remoteRepository.getIndexingContext().getBaseContext(IndexingContext.class) ) ); FlatSearchResponse response = indexer.searchFlat(rq); @@ -166,22 +177,38 @@ public class DownloadRemoteIndexTaskTest } - protected RemoteRepository getRemoteRepository() throws IOException + protected RemoteRepository getRemoteRepository(Path repoDirectory) throws IOException, URISyntaxException, UnsupportedURIException, RepositoryException { - RemoteRepository remoteRepository = new RemoteRepository( Locale.getDefault()); - Path indexDirectory = - Paths.get( FileUtils.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) ); + + EditableRemoteRepository remoteRepository = repositoryProvider.createRemoteInstance( "test-repo-re", "foo" ); + Path indexDirectory = repoDirectory.resolve( "index" ); Files.createDirectories( indexDirectory ); - indexDirectory.toFile().deleteOnExit(); - - remoteRepository.setName( "foo" ); - remoteRepository.setIndexDirectory( indexDirectory.toAbsolutePath().toString() ); - remoteRepository.setDownloadRemoteIndex( true ); - remoteRepository.setId( "test-repo-re" ); - remoteRepository.setUrl( "http://localhost:" + port ); - remoteRepository.setRemoteIndexUrl( "http://localhost:" + port + "/index-updates/" ); + remoteRepository.setLocation( new URI( "http://localhost:" + port ) ); + repoDirectory.toFile().deleteOnExit(); + createIndexingContext( remoteRepository ); + RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get(); + rif.setDownloadRemoteIndex( true ); + rif.setIndexUri( new URI("http://localhost:" + port + "/index-updates/" ) ); + IndexCreationFeature icf = remoteRepository.getFeature( IndexCreationFeature.class ).get( ); + icf.setLocalIndexPath( remoteRepository.getAsset( "index" ) ); return remoteRepository; } + private void createIndexingContext( EditableRepository editableRepo) throws RepositoryException + { + if (editableRepo.supportsFeature(IndexCreationFeature.class)) { + ArchivaIndexManager idxManager = getIndexManager(editableRepo.getType()); + try { + editableRepo.setIndexingContext(idxManager.createContext(editableRepo)); + idxManager.updateLocalIndexPath(editableRepo); + } catch ( IndexCreationFailedException e) { + throw new RepositoryException("Could not create index for repository " + editableRepo.getId() + ": " + e.getMessage(), e); + } + } + } + + public ArchivaIndexManager getIndexManager( RepositoryType type ) { + return repositoryRegistry.getIndexManager( type ); + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/resources/spring-context.xml b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/resources/spring-context.xml index 2f4fedacd..1e5ed5806 100644 --- a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/resources/spring-context.xml @@ -19,13 +19,12 @@ ~ under the License. --> - + @@ -39,7 +38,6 @@ - @@ -62,38 +60,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/status-dep.txt b/status-dep.txt index 8dfbe2794..a8c1d435b 100644 --- a/status-dep.txt +++ b/status-dep.txt @@ -46,6 +46,7 @@ archiva-modules archiva-maven-proxy archiva-maven-indexer archiva-maven-repository + archiva-maven-scheduler