diff options
author | Martin Stockhammer <martin.stockhammer@ars.de> | 2018-03-24 17:41:50 +0100 |
---|---|---|
committer | Martin Stockhammer <martin.stockhammer@ars.de> | 2018-03-24 17:44:13 +0100 |
commit | c544376afbec84689eae8ca5cc1a8f6a0ddb768d (patch) | |
tree | dfa67aabe758715dad9684e1909f6c6f649ee2b0 /archiva-modules/archiva-base/archiva-consumers | |
parent | e2eb9fe940feaa1606489c894182f2923bd54458 (diff) | |
download | archiva-c544376afbec84689eae8ca5cc1a8f6a0ddb768d.tar.gz archiva-c544376afbec84689eae8ca5cc1a8f6a0ddb768d.zip |
Switching repository admin and dependent classes to RepositoryRegistry
RepositoryRegistry is used for indexing context now. There is still more work to do
to move the maven dependent parts into its own projects and update the dependencies.
Diffstat (limited to 'archiva-modules/archiva-base/archiva-consumers')
11 files changed, 55 insertions, 53 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java index a140842a2..ec13f21f0 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java @@ -230,4 +230,8 @@ public class RepositoryProviderMock implements RepositoryProvider return configuration; } + @Override + public <T> void raise(org.apache.archiva.repository.RepositoryEvent<T> event) { + + } } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resourcesstatic/archetype-resources/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resourcesstatic/archetype-resources/pom.xml index bb98a2d45..2217e8ead 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resourcesstatic/archetype-resources/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resourcesstatic/archetype-resources/pom.xml @@ -79,6 +79,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.archiva</groupId> + <artifactId>archiva-maven2-indexer</artifactId> + <version>${archiva.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.archiva.redback.components.registry</groupId> <artifactId>spring-registry-api</artifactId> <version>${redback.registry.version}</version> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml index c01a30b57..3bfca1107 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml @@ -155,6 +155,11 @@ <artifactId>archiva-mock</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.archiva</groupId> + <artifactId>archiva-maven2-indexer</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> <pluginManagement> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java index e9e73530b..345d257fa 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -19,7 +19,6 @@ package org.apache.archiva.consumers.core.repository; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySession; @@ -54,7 +53,6 @@ import java.nio.file.Paths; import java.time.Period; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import java.util.stream.Collectors; import static org.junit.Assert.assertFalse; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java index a289734d1..1ef4bf9a0 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java @@ -107,7 +107,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest { RepositoryRegistry repositoryRegistry = applicationContext.getBean( RepositoryRegistry.class ); ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( TEST_REPO_ID ); - repositoryRegistry.removeRepository( managedRepository ); + repositoryRegistry.removeRepository( TEST_REPO_ID ); repositoryRegistry.putRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME )); @@ -217,7 +217,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class); ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( TEST_REPO_ID ); - repositoryRegistry.removeRepository( managedRepository ); + repositoryRegistry.removeRepository( TEST_REPO_ID ); repositoryRegistry.putRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME )); @@ -298,7 +298,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class); ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( TEST_REPO_ID ); - repositoryRegistry.removeRepository( managedRepository ); + repositoryRegistry.removeRepository( TEST_REPO_ID ); repositoryRegistry.putRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME )); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java index 286dd38e4..4af39c33a 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java @@ -21,18 +21,7 @@ package org.apache.archiva.repository.mock; 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.*; import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; @@ -229,4 +218,8 @@ public class RepositoryProviderMock implements RepositoryProvider return configuration; } + @Override + public <T> void raise(RepositoryEvent<T> event) { + + } } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context-cleanup-released-snapshots.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context-cleanup-released-snapshots.xml index 5119c55e9..ddc8bfff8 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context-cleanup-released-snapshots.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context-cleanup-released-snapshots.xml @@ -32,7 +32,7 @@ </bean> <alias name="archivaConfiguration#cleanup-released-snapshots" alias="archivaConfiguration"/> <alias name="archivaConfiguration#cleanup-released-snapshots" alias="archivaConfiguration#default"/> - <context:component-scan base-package="org.apache.archiva.configuration,org.apache.archiva.repository.content.maven2"/> + <context:component-scan base-package="org.apache.archiva.configuration,org.apache.archiva.repository.content.maven2,org.apache.archiva.indexer.maven"/> <alias name="repositoryContentFactory#cleanup-released-snapshots" alias="repositoryContentFactory#default" /> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/pom.xml index 208825140..bb489a215 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/pom.xml @@ -136,6 +136,11 @@ <artifactId>xercesImpl</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.archiva</groupId> + <artifactId>archiva-maven2-indexer</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> <plugins> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java index 50dd8c1c4..6cadd2730 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java @@ -28,11 +28,13 @@ import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.consumers.AbstractMonitoredConsumer; import org.apache.archiva.consumers.ConsumerException; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.indexer.UnsupportedBaseContextException; 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.ManagedRepository; import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.maven.index.NexusIndexer; @@ -124,11 +126,14 @@ public class NexusIndexerConsumer try { log.info( "Creating indexing context for repo : {}", repository.getId() ); - indexingContext = managedRepositoryAdmin.createIndexContext( repository ); - } - catch ( RepositoryAdminException e ) - { - throw new ConsumerException( e.getMessage(), e ); + if (repository.getType()== RepositoryType.MAVEN) { + indexingContext = repository.getIndexingContext().getBaseContext(IndexingContext.class); + } else { + indexingContext= null; + } + } catch (UnsupportedBaseContextException e) { + log.error("Bad repository type. Not nexus indexer compatible."); + throw new ConsumerException("Bad repository type "+repository.getType()); } } @@ -154,7 +159,7 @@ public class NexusIndexerConsumer Path artifactFile = managedRepository.resolve(path); ArtifactIndexingTask task = - new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD, getIndexingContext() ); + new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD, repository.getIndexingContext() ); try { log.debug( "Queueing indexing task '{}' to add or update the artifact in the index.", task ); @@ -181,7 +186,7 @@ public class NexusIndexerConsumer // specify in indexing task that this is not a repo scan request! ArtifactIndexingTask task = new ArtifactIndexingTask( repository, artifactFile, ArtifactIndexingTask.Action.ADD, - getIndexingContext(), false ); + repository.getIndexingContext(), false ); // only update index we don't need to scan the full repo here task.setOnlyUpdate( true ); try @@ -199,21 +204,8 @@ public class NexusIndexerConsumer @Override public void completeScan() { - IndexingContext context = this.indexingContext; - if ( context == null ) - { - try - { - context = getIndexingContext(); - } - catch ( ConsumerException e ) - { - log.warn( "failed to get an IndexingContext:{}", e.getMessage() ); - return; - } - } ArtifactIndexingTask task = - new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, context ); + new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, repository.getIndexingContext()); try { log.debug( "Queueing indexing task '{}' to finish indexing.", task ); @@ -292,11 +284,10 @@ public class NexusIndexerConsumer { try { - indexingContext = managedRepositoryAdmin.createIndexContext( repository ); - } - catch ( RepositoryAdminException e ) - { - throw new ConsumerException( e.getMessage(), e ); + indexingContext = repository.getIndexingContext().getBaseContext(IndexingContext.class); + } catch (UnsupportedBaseContextException e) { + log.error("Bad repository type. Not nexus indexer compatible. "+repository.getType()); + throw new ConsumerException("Bad repository type "+repository.getType()); } } return indexingContext; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java index e34dc7e12..2efebfb78 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java @@ -26,14 +26,13 @@ import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.redback.components.taskqueue.TaskQueueException; import org.apache.archiva.repository.BasicManagedRepository; -import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ReleaseScheme; +import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexCreator; -import org.apache.regexp.RE; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -47,12 +46,7 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Calendar; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Set; +import java.util.*; /** * NexusIndexerConsumerTest @@ -111,6 +105,9 @@ public class NexusIndexerConsumerTest @Inject private ManagedRepositoryAdmin managedRepositoryAdmin; + @Inject + RepositoryRegistry repositoryRegistry; + @Override @Before @@ -138,6 +135,7 @@ public class NexusIndexerConsumerTest repositoryConfig.setScanned( true ); repositoryConfig.addActiveReleaseScheme( ReleaseScheme.RELEASE ); repositoryConfig.removeActiveReleaseScheme( ReleaseScheme.SNAPSHOT ); + repositoryRegistry.putRepository(repositoryConfig); } @@ -156,6 +154,8 @@ public class NexusIndexerConsumerTest org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDir ); assertFalse( Files.exists(indexDir) ); + repositoryRegistry.destroy(); + super.tearDown(); } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/spring-context.xml index a89137295..ebf31812a 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/resources/spring-context.xml @@ -28,7 +28,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-lazy-init="true"> <context:annotation-config/> - <context:component-scan base-package="org.apache.archiva.consumers.lucene.test"/> + <context:component-scan base-package="org.apache.archiva.consumers.lucene.test,org.apache.maven.index"/> <bean name="commons-configuration" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry"> <property name="properties"> |