diff options
author | Martin Stockhammer <martin_s@apache.org> | 2017-11-01 15:33:06 +0100 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2017-11-01 15:33:06 +0100 |
commit | 4bcf4c0cd05220156cbba00be5408985f182805c (patch) | |
tree | 4cd6300464adc33b1441092032a1a7e39e03dbc1 | |
parent | fd51964c13cdeb633aad1944c0b95b1a571681e2 (diff) | |
download | archiva-4bcf4c0cd05220156cbba00be5408985f182805c.tar.gz archiva-4bcf4c0cd05220156cbba00be5408985f182805c.zip |
Adapting consumers to new repository api interfaces.
Using the repository api where necessary.
32 files changed, 964 insertions, 177 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/pom.xml index 598ffa1f4..4824291de 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/pom.xml @@ -38,6 +38,10 @@ <artifactId>archiva-common</artifactId> </dependency> <dependency> + <groupId>org.apache.archiva</groupId> + <artifactId>archiva-repository-layer</artifactId> + </dependency> + <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> </dependency> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/RepositoryContentConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/RepositoryContentConsumer.java index c923f24be..cfe937b09 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/RepositoryContentConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/RepositoryContentConsumer.java @@ -19,7 +19,7 @@ package org.apache.archiva.consumers; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.repository.ManagedRepository; import java.util.Date; import java.util.List; @@ -60,7 +60,7 @@ public interface RepositoryContentConsumer * @param whenGathered the start of the repository scan * @throws ConsumerException if there was a problem with using the provided repository with the consumer. */ - void beginScan( ManagedRepository repository, Date whenGathered ) + void beginScan( org.apache.archiva.repository.ManagedRepository repository, Date whenGathered ) throws ConsumerException; /** diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java index 07dc5276e..91f58acbc 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java @@ -19,9 +19,11 @@ package org.apache.archiva.consumers.functors; * under the License. */ +import java.nio.file.Paths; import java.util.List; -import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.commons.collections.Predicate; import org.apache.commons.io.FilenameUtils; import org.apache.archiva.common.utils.BaseFile; @@ -136,7 +138,21 @@ public class ConsumerWantsFilePredicate if ( managedRepository != null ) { - String indexDirectory = managedRepository.getIndexDirectory(); + String indexDirectory; + if (managedRepository.supportsFeature( IndexCreationFeature.class )) { + IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get(); + if (icf.getIndexPath()==null) { + indexDirectory=".index"; + } else + { + indexDirectory = ( icf.getIndexPath( ).getScheme( ) == null ? Paths.get( icf.getIndexPath( ).getPath( ) ) : Paths.get( icf.getIndexPath( ) ) ).toString( ); + } + } else { + indexDirectory = ".index"; + } + if (StringUtils.isEmpty( indexDirectory )) { + indexDirectory = ".index"; + } if ( StringUtils.startsWith( relativePath, indexDirectory ) ) { logger.debug( "ignore file {} part of the index directory {}", relativePath, indexDirectory ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java index 9c9a41e80..59ca6b012 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java @@ -47,7 +47,7 @@ import javax.inject.Named; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; -import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.repository.ManagedRepository; /** * <code>SimpleArtifactConsumer</code> @@ -119,13 +119,13 @@ public class SimpleArtifactConsumer try { - ManagedRepositoryContent repositoryContent = repositoryContentFactory.getManagedRepositoryContent( repository.getId() ); + ManagedRepositoryContent repositoryContent = repository.getContent(); ArtifactReference artifact = repositoryContent.toArtifactReference( path ); repositorySession.getRepository().getArtifacts( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); } - catch ( RepositoryException | LayoutException | MetadataResolutionException e ) + catch ( LayoutException | MetadataResolutionException e ) { throw new ConsumerException( e.getLocalizedMessage(), e ); } 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 new file mode 100644 index 000000000..55151f337 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java @@ -0,0 +1,231 @@ +package $package; + +/* + * 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<RepositoryType> TYPES = new HashSet<>( ); + + static + { + TYPES.add( RepositoryType.MAVEN ); + TYPES.add( RepositoryType.NPM ); + } + + @Override + public Set<RepositoryType> 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-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java index b3150df95..68d03a873 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java @@ -20,7 +20,10 @@ package $package; */ import org.apache.archiva.admin.model.RepositoryAdminException; -import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.BasicManagedRepository; +import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySession; @@ -56,9 +59,12 @@ public class SimpleArtifactConsumerTest private ManagedRepositoryAdmin managedRepositoryAdmin; @Inject + private RepositoryRegistry repositoryRegistry; + + @Inject private RepositorySessionFactory repositorySessionFactory; - private ManagedRepository testRepository; + private BasicManagedRepository testRepository; private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class ); @@ -72,18 +78,18 @@ public class SimpleArtifactConsumerTest } private void setUpMockRepository() - throws RepositoryAdminException, IOException + throws RepositoryAdminException, IOException, RepositoryException { Path repoDir = Paths.get( "target/test-consumer-repo" ); Files.createDirectories( repoDir ); repoDir.toFile().deleteOnExit(); - testRepository = new ManagedRepository(); - testRepository.setName( "Test-Consumer-Repository" ); - testRepository.setId( "test-consumer-repository" ); - testRepository.setLocation( repoDir.toAbsolutePath().toString() ); + testRepository = new BasicManagedRepository("test-consumer-repository","Test-Consumer-Repository" ); + testRepository.setLocation( repoDir.toAbsolutePath().toUri() ); + + repositoryRegistry.putRepository(testRepository); - when( managedRepositoryAdmin.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository ); + // when( repositoryRegistry.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository ); } @Test diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml index cd7557742..b5ff21555 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml @@ -20,15 +20,24 @@ --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mockito="http://www.mockito.org/spring/mockito" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.mockito.org/spring/mockito http://www.mockito.org/spring/mockito.xsd" default-lazy-init="true"> <mockito:mock id="mockManagedRepositoryAdmin" class="org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin" /> <mockito:mock id="mockRemoteRepositoryAdmin" class="org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin" /> + <context:component-scan base-package="org.apache.archiva.repository.mock,org.apache.archiva.repository.content.maven2,$package"/> + + <alias name="managedRepositoryContent#maven" alias="managedRepositoryContent#default" /> + <alias name="remoteRepositoryContent#maven" alias="remoteRepositoryContent#default" /> + <alias name="mockRepositoryProvider" alias="mavenRepositoryProvider" /> + <alias alias="repositorySessionFactory#jcr" name="repositorySessionFactory#file" /> <bean name="proxyConnectorAdmin#mock" class="org.apache.archiva.mock.MockProxyConnectorAdmin"/> 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 c66cdab51..56016ea18 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 @@ -251,6 +251,12 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.20</version> + <configuration> + <systemPropertyVariables> + <appserver.base>${project.build.directory}/appserver-base</appserver.base> + </systemPropertyVariables> + </configuration> + </plugin> </plugins> </pluginManagement> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java index c99ab4bbf..0cc3aa59a 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java @@ -19,7 +19,6 @@ package org.apache.archiva.consumers.core; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; import org.apache.archiva.configuration.ArchivaConfiguration; @@ -27,6 +26,7 @@ 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.repository.ManagedRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Scope; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRemoveConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRemoveConsumer.java index e7aa8cb66..15013c64a 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRemoveConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRemoveConsumer.java @@ -19,7 +19,6 @@ package org.apache.archiva.consumers.core; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ConfigurationNames; import org.apache.archiva.configuration.FileTypes; @@ -28,6 +27,7 @@ import org.apache.archiva.consumers.ConsumerException; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.redback.components.registry.Registry; import org.apache.archiva.redback.components.registry.RegistryListener; +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-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRenameConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRenameConsumer.java index 1317682f2..3f064ede7 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRenameConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRenameConsumer.java @@ -19,11 +19,10 @@ package org.apache.archiva.consumers.core; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.archiva.consumers.Consumer; import org.apache.archiva.consumers.ConsumerException; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.repository.ManagedRepository; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java index 263e0422c..33da78606 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java @@ -19,7 +19,6 @@ package org.apache.archiva.consumers.core; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.consumers.AbstractMonitoredConsumer; @@ -29,6 +28,7 @@ import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.VersionedReference; import org.apache.archiva.repository.ContentNotFoundException; +import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RepositoryContentFactory; import org.apache.archiva.repository.RepositoryException; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java index e0d80214b..6e60bc55f 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java @@ -19,13 +19,13 @@ package org.apache.archiva.consumers.core; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.plexusbridge.DigesterUtils; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; 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 org.codehaus.plexus.digest.ChecksumFile; import org.codehaus.plexus.digest.Digester; import org.codehaus.plexus.digest.DigesterException; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index 97280273b..181cbf45c 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -32,19 +32,23 @@ import org.apache.archiva.model.ProjectReference; import org.apache.archiva.model.VersionedReference; import org.apache.archiva.repository.ContentNotFoundException; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryContentFactory; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; +import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.archiva.repository.layout.LayoutException; import org.apache.archiva.repository.metadata.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; +import javax.inject.Inject; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; @@ -73,20 +77,16 @@ public class CleanupReleasedSnapshotsRepositoryPurge { private MetadataTools metadataTools; - private ManagedRepositoryAdmin managedRepositoryAdmin; - - private RepositoryContentFactory repoContentFactory; + private RepositoryRegistry repositoryRegistry; public CleanupReleasedSnapshotsRepositoryPurge( ManagedRepositoryContent repository, MetadataTools metadataTools, - ManagedRepositoryAdmin managedRepositoryAdmin, - RepositoryContentFactory repoContentFactory, + RepositoryRegistry repositoryRegistry, RepositorySession repositorySession, List<RepositoryListener> listeners ) { super( repository, repositorySession, listeners ); this.metadataTools = metadataTools; - this.managedRepositoryAdmin = managedRepositoryAdmin; - this.repoContentFactory = repoContentFactory; + this.repositoryRegistry = repositoryRegistry; } @Override @@ -118,15 +118,15 @@ public class CleanupReleasedSnapshotsRepositoryPurge // Gether the released versions List<String> releasedVersions = new ArrayList<>( ); - List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories( ); - for ( ManagedRepository repo : repos ) + Collection<org.apache.archiva.repository.ManagedRepository> repos = repositoryRegistry.getManagedRepositories( ); + for ( org.apache.archiva.repository.ManagedRepository repo : repos ) { - if ( repo.isReleases( ) ) + + if ( repo.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE )) { try { - ManagedRepositoryContent repoContent = - repoContentFactory.getManagedRepositoryContent( repo.getId( ) ); + ManagedRepositoryContent repoContent = repo.getContent(); for ( String version : repoContent.getVersions( reference ) ) { if ( !VersionUtil.isSnapshot( version ) ) @@ -135,10 +135,6 @@ public class CleanupReleasedSnapshotsRepositoryPurge } } } - catch ( RepositoryNotFoundException e ) - { - // swallow - } catch ( RepositoryException e ) { // swallow @@ -179,10 +175,6 @@ public class CleanupReleasedSnapshotsRepositoryPurge updateMetadata( artifactRef ); } } - catch ( RepositoryAdminException e ) - { - throw new RepositoryPurgeException( e.getMessage( ), e ); - } catch ( LayoutException e ) { log.debug( "Not processing file that is not an artifact: {}", e.getMessage( ) ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java index 8687313b7..73fc456d0 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java @@ -53,15 +53,15 @@ public class DaysOldRepositoryPurge { private SimpleDateFormat timestampParser; - private int retentionTime; + private int retentionPeriod; private int retentionCount; - public DaysOldRepositoryPurge( ManagedRepositoryContent repository, int retentionTime, int retentionCount, + public DaysOldRepositoryPurge( ManagedRepositoryContent repository, int retentionPeriod, int retentionCount, RepositorySession repositorySession, List<RepositoryListener> listeners ) { super( repository, repositorySession, listeners ); - this.retentionTime = retentionTime; + this.retentionPeriod = retentionPeriod; this.retentionCount = retentionCount; timestampParser = new SimpleDateFormat( "yyyyMMdd.HHmmss" ); timestampParser.setTimeZone( DateUtils.UTC_TIME_ZONE ); @@ -83,7 +83,7 @@ public class DaysOldRepositoryPurge ArtifactReference artifact = repository.toArtifactReference( path ); Calendar olderThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE ); - olderThanThisDate.add( Calendar.DATE, -retentionTime ); + olderThanThisDate.add( Calendar.DATE, -retentionPeriod ); // respect retention count VersionedReference reference = new VersionedReference( ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java index f761bfce6..d869666f7 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.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.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ConfigurationNames; @@ -31,11 +30,14 @@ import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.redback.components.registry.Registry; import org.apache.archiva.redback.components.registry.RegistryListener; +import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RepositoryContentFactory; import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; +import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.metadata.MetadataTools; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -77,6 +79,9 @@ public class RepositoryPurgeConsumer private ManagedRepositoryAdmin managedRepositoryAdmin; @Inject + private RepositoryRegistry repositoryRegistry; + + @Inject @Named( value = "repositoryContentFactory#default" ) private RepositoryContentFactory repositoryContentFactory; @@ -136,37 +141,35 @@ public class RepositoryPurgeConsumer throws ConsumerException { ManagedRepositoryContent repositoryContent; - try - { - repositoryContent = repositoryContentFactory.getManagedRepositoryContent( repository.getId( ) ); - } - catch ( RepositoryNotFoundException e ) - { - throw new ConsumerException( "Can't run repository purge: " + e.getMessage( ), e ); - } - catch ( RepositoryException e ) - { - throw new ConsumerException( "Can't run repository purge: " + e.getMessage( ), e ); - } + repositoryContent = repository.getContent(); repositorySession = repositorySessionFactory.createSession( ); - if ( repository.getDaysOlder( ) != 0 ) - { - repoPurge = new DaysOldRepositoryPurge( repositoryContent, repository.getDaysOlder( ), - repository.getRetentionCount( ), repositorySession, listeners ); - } - else + if (repository.supportsFeature( ArtifactCleanupFeature.class )) { - repoPurge = - new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount( ), repositorySession, - listeners ); + ArtifactCleanupFeature acf = repository.getFeature( ArtifactCleanupFeature.class ).get(); + int retentionPeriodInDays = acf.getRetentionPeriod( ).getDays( ); + int retentionCount = acf.getRetentionCount(); + if ( retentionPeriodInDays != 0 ) + { + repoPurge = new DaysOldRepositoryPurge( repositoryContent, retentionPeriodInDays, + retentionCount, repositorySession, listeners ); + } + else + { + repoPurge = + new RetentionCountRepositoryPurge( repositoryContent, retentionCount, repositorySession, + listeners ); + } + deleteReleasedSnapshots = acf.isDeleteReleasedSnapshots( ); + } else { + throw new ConsumerException( "The repository does not support the ArtifactCleanup feature "+repository.getId() ); } - cleanUp = new CleanupReleasedSnapshotsRepositoryPurge( repositoryContent, metadataTools, managedRepositoryAdmin, - repositoryContentFactory, repositorySession, listeners ); - deleteReleasedSnapshots = repository.isDeleteReleasedSnapshots( ); + cleanUp = new CleanupReleasedSnapshotsRepositoryPurge( repositoryContent, metadataTools, repositoryRegistry, + repositorySession, listeners ); + } @Override diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/conf/repository-manager-daysOld.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/conf/repository-manager-daysOld.xml index 6b1779c47..4b0a1429d 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/conf/repository-manager-daysOld.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/conf/repository-manager-daysOld.xml @@ -68,7 +68,7 @@ <snapshots>true</snapshots> <indexed>true</indexed> <refreshCronExpression>0 0 * * * ?</refreshCronExpression> - <retentionTime>100</retentionTime> + <retentionPeriod>100</retentionPeriod> <deleteReleasedSnapshots>true</deleteReleasedSnapshots> </repository> </repositories> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java index 4e2e664dd..1ad70c389 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java @@ -1,9 +1,11 @@ package org.apache.archiva.consumers.core; -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; +import org.apache.archiva.common.utils.PathUtil; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.repository.BasicManagedRepository; +import org.apache.archiva.repository.EditableManagedRepository; import org.apache.commons.io.FileUtils; import org.assertj.core.api.Assertions; import org.junit.Before; @@ -36,7 +38,7 @@ import java.util.Calendar; public class ArtifactMissingChecksumsConsumerTest extends AbstractArtifactConsumerTest { - private ManagedRepository repoConfig; + private EditableManagedRepository repoConfig; @Before @Override @@ -45,11 +47,9 @@ public class ArtifactMissingChecksumsConsumerTest { super.setUp(); - repoConfig = new ManagedRepository(); - repoConfig.setId( "test-repo" ); - repoConfig.setName( "Test Repository" ); + repoConfig = new BasicManagedRepository( "test-repo", "Test Repository"); repoConfig.setLayout( "default" ); - repoConfig.setLocation( Paths.get( "target/test-classes/test-repo/" ).toString() ); + repoConfig.setLocation( Paths.get( "target/test-classes/test-repo/" ).toUri() ); consumer = applicationContext.getBean( "knownRepositoryContentConsumer#create-missing-checksums", KnownRepositoryContentConsumer.class ); @@ -61,8 +61,9 @@ public class ArtifactMissingChecksumsConsumerTest { String path = "no-checksums-artifact/1.0/no-checksums-artifact-1.0.jar"; - Path sha1Path = Paths.get( repoConfig.getLocation(), path + ".sha1" ); - Path md5FilePath = Paths.get( repoConfig.getLocation(), path + ".md5" ); + Path basePath = PathUtil.getPathFromUri( repoConfig.getLocation() ); + Path sha1Path = basePath.resolve(path + ".sha1" ); + Path md5FilePath = basePath.resolve(path + ".md5" ); Files.deleteIfExists( sha1Path ); Files.deleteIfExists( md5FilePath ); @@ -96,15 +97,16 @@ public class ArtifactMissingChecksumsConsumerTest Path newLocation = Paths.get( "target/test-repo" ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( newLocation ); FileUtils.copyDirectory( Paths.get(repoConfig.getLocation() ).toFile(), newLocation.toFile() ); - repoConfig.setLocation( newLocation.toAbsolutePath().toString() ); + repoConfig.setLocation( newLocation.toAbsolutePath().toUri() ); + Path basePath = PathUtil.getPathFromUri( repoConfig.getLocation() ); String path = "incorrect-checksums/1.0/incorrect-checksums-1.0.jar"; - Path sha1Path = Paths.get( repoConfig.getLocation(), path + ".sha1" ); + Path sha1Path = basePath.resolve( path + ".sha1" ); - Path md5Path = Paths.get( repoConfig.getLocation(), path + ".md5" ); + Path md5Path = basePath.resolve( path + ".md5" ); - ChecksummedFile checksum = new ChecksummedFile( Paths.get(repoConfig.getLocation(), path ) ); + ChecksummedFile checksum = new ChecksummedFile( basePath.resolve( path ) ); Assertions.assertThat( sha1Path.toFile() ).exists(); Assertions.assertThat( md5Path.toFile() ).exists(); 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 e3fee9408..b0e9a9898 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 @@ -24,8 +24,11 @@ import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator; +import org.apache.archiva.repository.BasicManagedRepository; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; @@ -42,11 +45,15 @@ 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.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; @@ -87,7 +94,7 @@ public abstract class AbstractRepositoryPurgeTest protected static final String RELEASES_TEST_REPO_NAME = "Releases Test Repo One"; - private ManagedRepository config; + private BasicManagedRepository config; private ManagedRepositoryContent repo; @@ -156,19 +163,18 @@ public abstract class AbstractRepositoryPurgeTest return path; } - public ManagedRepository getRepoConfiguration( String repoId, String repoName ) + public org.apache.archiva.repository.ManagedRepository getRepoConfiguration( String repoId, String repoName ) throws URISyntaxException { - config = new ManagedRepository(); - config.setId( repoId ); - config.setName( repoName ); - config.setDaysOlder( TEST_DAYS_OLDER ); + config = new BasicManagedRepository( repoId, repoName); + config.addActiveReleaseScheme( ReleaseScheme.RELEASE ); + config.addActiveReleaseScheme( ReleaseScheme.SNAPSHOT ); + ArtifactCleanupFeature atf = config.getFeature( ArtifactCleanupFeature.class ).get(); + atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER) ); String path = AbstractRepositoryPurgeTest.fixPath( Paths.get( "target/test-" + getName() + "/" + repoId ).toAbsolutePath().toString() ); - config.setLocation( path ); - config.setReleases( true ); - config.setSnapshots( true ); - config.setDeleteReleasedSnapshots( true ); - config.setRetentionCount( TEST_RETENTION_COUNT ); + config.setLocation( new URI( path ) ); + atf.setDeleteReleasedSnapshots( true ); + atf.setRetentionCount( TEST_RETENTION_COUNT ); return config; } 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 0b575151a..a289734d1 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 @@ -24,10 +24,11 @@ import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.MetadataFacet; +import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.RepositoryContentFactory; +import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.archiva.repository.metadata.MetadataTools; -import org.apache.commons.io.FileUtils; import org.custommonkey.xmlunit.XMLAssert; import org.easymock.EasyMock; import org.junit.Before; @@ -92,7 +93,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest List<RepositoryListener> listeners = Collections.singletonList( listener ); repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools, applicationContext.getBean( - ManagedRepositoryAdmin.class ), factory, + RepositoryRegistry.class ), repositorySession, listeners ); ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( @@ -104,9 +105,11 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest public void testReleasedSnapshotsExistsInSameRepo() throws Exception { - applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, true ); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); + RepositoryRegistry repositoryRegistry = applicationContext.getBean( RepositoryRegistry.class ); + ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( TEST_REPO_ID ); + repositoryRegistry.removeRepository( managedRepository ); + repositoryRegistry.putRepository( + getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME )); String repoRoot = prepareTestRepos(); String projectNs = "org.apache.maven.plugins"; @@ -180,9 +183,11 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest throws Exception { - applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); + RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class); + ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( TEST_REPO_ID ); + repositoryRegistry.removeRepository( managedRepository ); + repositoryRegistry.putRepository( + getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME )); String repoRoot = prepareTestRepos(); @@ -210,12 +215,15 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest throws Exception { - applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); + RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class); + ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( TEST_REPO_ID ); + repositoryRegistry.removeRepository( managedRepository ); + repositoryRegistry.putRepository( + getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME )); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME ), false, null ); + + repositoryRegistry.putRepository( + getRepoConfiguration( RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME )); String repoRoot = prepareTestRepos(); String projectNs = "org.apache.archiva"; @@ -288,9 +296,11 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest throws Exception { - applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); + RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class); + ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( TEST_REPO_ID ); + repositoryRegistry.removeRepository( managedRepository ); + repositoryRegistry.putRepository( + getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME )); String repoRoot = prepareTestRepos(); String projectNs = "org.apache.maven.plugins"; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java index 1d4ddebcb..3c7083700 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java @@ -19,9 +19,9 @@ 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.repository.events.RepositoryListener; +import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.commons.lang.time.DateUtils; import org.junit.After; import org.junit.Test; @@ -73,9 +73,10 @@ public class DaysOldRepositoryPurgeTest public void testByLastModified() throws Exception { - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), - repoConfiguration.getRetentionCount(), repositorySession, + org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get(); + repoPurge = new DaysOldRepositoryPurge( getRepository(), atf.getRetentionPeriod().getDays(), + atf.getRetentionCount(), repositorySession, Collections.singletonList( listener ) ); String repoRoot = prepareTestRepos(); @@ -163,10 +164,11 @@ public class DaysOldRepositoryPurgeTest public void testOrderOfDeletion() throws Exception { - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get(); List<RepositoryListener> listeners = Collections.singletonList( listener ); - repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), - repoConfiguration.getRetentionCount(), repositorySession, listeners ); + repoPurge = new DaysOldRepositoryPurge( getRepository(), atf.getRetentionPeriod().getDays(), + atf.getRetentionCount(), repositorySession, listeners ); String repoRoot = prepareTestRepos(); String projectNs = "org.apache.maven.plugins"; @@ -241,10 +243,11 @@ public class DaysOldRepositoryPurgeTest public void testMetadataDrivenSnapshots() throws Exception { - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get(); List<RepositoryListener> listeners = Collections.singletonList( listener ); - repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), - repoConfiguration.getRetentionCount(), repositorySession, listeners ); + repoPurge = new DaysOldRepositoryPurge( getRepository(), atf.getRetentionPeriod().getDays(), + atf.getRetentionCount(), repositorySession, listeners ); String repoRoot = prepareTestRepos(); String projectNs = "org.codehaus.plexus"; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java index f052915ea..11e0ffeb4 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java @@ -33,9 +33,12 @@ import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.MetadataFacet; import org.apache.archiva.mock.MockRepositorySessionFactory; +import org.apache.archiva.repository.RepositoryRegistry; +import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.custommonkey.xmlunit.XMLAssert; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.slf4j.Logger; @@ -48,6 +51,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.FileTime; +import java.time.Period; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -168,9 +172,10 @@ public class RepositoryPurgeConsumerTest applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count", KnownRepositoryContentConsumer.class ); - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoConfiguration.setDaysOlder( 0 ); // force days older off to allow retention count purge to execute. - repoConfiguration.setRetentionCount( TEST_RETENTION_COUNT ); + org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get(); + atf.setRetentionPeriod( Period.ofDays( 0 ) ); // force days older off to allow retention count purge to execute. + atf.setRetentionCount( TEST_RETENTION_COUNT ); addRepoToConfiguration( "retention-count", repoConfiguration ); repoPurgeConsumer.beginScan( repoConfiguration, null ); @@ -247,40 +252,18 @@ public class RepositoryPurgeConsumerTest removeRepoFromConfiguration( "retention-count", repoConfiguration ); } - private void addRepoToConfiguration( String configHint, ManagedRepository repoConfiguration ) + private void addRepoToConfiguration( String configHint, org.apache.archiva.repository.ManagedRepository repoConfiguration ) throws Exception { - ArchivaConfiguration archivaConfiguration = - applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class ); - ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( - ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); - // skygo: Default Validator was not looking at same config - ( (DefaultRepositoryCommonValidator) applicationContext.getBean( - RepositoryCommonValidator.class ) ).setArchivaConfiguration( archivaConfiguration ); - ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); - if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null ) - { - managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, false ); - } - managedRepositoryAdmin.addManagedRepository( repoConfiguration, false, null ); + RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class); + repositoryRegistry.putRepository( repoConfiguration ); } - private void removeRepoFromConfiguration( String configHint, ManagedRepository repoConfiguration ) + private void removeRepoFromConfiguration( String configHint, org.apache.archiva.repository.ManagedRepository repoConfiguration ) throws Exception { - ArchivaConfiguration archivaConfiguration = - applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class ); - - ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( - ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); - // skygo: Default Validator was not looking at same config - ( (DefaultRepositoryCommonValidator) applicationContext.getBean( - RepositoryCommonValidator.class ) ).setArchivaConfiguration( archivaConfiguration ); - ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); - if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null ) - { - managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, true ); - } + RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class); + repositoryRegistry.removeRepository( repoConfiguration ); } @Test @@ -291,8 +274,9 @@ public class RepositoryPurgeConsumerTest applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old", KnownRepositoryContentConsumer.class ); - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoConfiguration.setDaysOlder( TEST_DAYS_OLDER ); + org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get(); + atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER ) ); addRepoToConfiguration( "days-old", repoConfiguration ); repoPurgeConsumer.beginScan( repoConfiguration, null ); @@ -375,8 +359,9 @@ public class RepositoryPurgeConsumerTest applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count", KnownRepositoryContentConsumer.class ); - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoConfiguration.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots. + org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get(); + acf.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots. addRepoToConfiguration( "retention-count", repoConfiguration ); repoPurgeConsumer.beginScan( repoConfiguration, null ); @@ -437,10 +422,12 @@ public class RepositoryPurgeConsumerTest applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old", KnownRepositoryContentConsumer.class ); - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoConfiguration.setDeleteReleasedSnapshots( true ); + org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get(); + acf.setDeleteReleasedSnapshots( true ); addRepoToConfiguration( "days-old", repoConfiguration ); + repoPurgeConsumer.beginScan( repoConfiguration, null ); String repoRoot = prepareTestRepos(); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java index 009830c41..13d6b6857 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java @@ -22,6 +22,7 @@ package org.apache.archiva.consumers.core.repository; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -50,9 +51,10 @@ public class RetentionCountRepositoryPurgeTest { super.setUp(); - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); List<RepositoryListener> listeners = Collections.singletonList( listener ); - repoPurge = new RetentionCountRepositoryPurge( getRepository(), repoConfiguration.getRetentionCount(), + ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get(); + repoPurge = new RetentionCountRepositoryPurge( getRepository(), acf.getRetentionCount(), repositorySession, listeners ); } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java new file mode 100644 index 000000000..9a53bf28d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java @@ -0,0 +1,181 @@ +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.model.ArchivaArtifact; +import org.apache.archiva.model.ArtifactReference; +import org.apache.archiva.model.ProjectReference; +import org.apache.archiva.model.VersionedReference; +import org.apache.archiva.repository.ContentNotFoundException; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.layout.LayoutException; +import org.springframework.stereotype.Service; + +import java.net.URI; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Set; + +/** + * @author Martin Stockhammer <martin_s@apache.org> + */ +@Service("managedRepositoryContent#mock") +public class ManagedRepositoryContentMock implements ManagedRepositoryContent +{ + private ManagedRepository repository; + + @Override + public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException + { + + } + + @Override + public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException + { + + } + + @Override + public void deleteGroupId( String groupId ) throws ContentNotFoundException + { + + } + + @Override + public void deleteProject( String namespace, String projectId ) throws RepositoryException + { + + } + + @Override + public String getId( ) + { + return null; + } + + @Override + public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException + { + return null; + } + + @Override + public String getRepoRoot() + { + return convertUriToPath( repository.getLocation() ); + } + + private String convertUriToPath( URI uri ) { + if (uri.getScheme()==null) { + return Paths.get(uri.getPath()).toString(); + } else if ("file".equals(uri.getScheme())) { + return Paths.get(uri).toString(); + } else { + return uri.toString(); + } + } + + @Override + public ManagedRepository getRepository( ) + { + return repository; + } + + @Override + public Set<String> getVersions( ProjectReference reference ) throws ContentNotFoundException, LayoutException + { + return null; + } + + @Override + public Set<String> getVersions( VersionedReference reference ) throws ContentNotFoundException + { + return null; + } + + @Override + public boolean hasContent( ArtifactReference reference ) + { + return false; + } + + @Override + public boolean hasContent( ProjectReference reference ) + { + return false; + } + + @Override + public boolean hasContent( VersionedReference reference ) + { + return false; + } + + @Override + public void setRepository( ManagedRepository repo ) + { + this.repository = repo; + } + + @Override + public ArtifactReference toArtifactReference( String path ) throws LayoutException + { + return null; + } + + @Override + public Path toFile( ArtifactReference reference ) + { + return null; + } + + @Override + public Path toFile( ArchivaArtifact reference ) + { + return null; + } + + @Override + public String toMetadataPath( ProjectReference reference ) + { + return null; + } + + @Override + public String toMetadataPath( VersionedReference reference ) + { + return null; + } + + @Override + public String toPath( ArtifactReference reference ) + { + return null; + } + + @Override + public String toPath( ArchivaArtifact reference ) + { + return null; + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java new file mode 100644 index 000000000..238b0cf61 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RemoteRepositoryContentMock.java @@ -0,0 +1,78 @@ +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.model.ArtifactReference; +import org.apache.archiva.model.RepositoryURL; +import org.apache.archiva.repository.RemoteRepository; +import org.apache.archiva.repository.RemoteRepositoryContent; +import org.apache.archiva.repository.layout.LayoutException; +import org.springframework.stereotype.Service; + +/** + * @author Martin Stockhammer <martin_s@apache.org> + */ +@Service("remoteRepositoryContent#mock") +public class RemoteRepositoryContentMock implements RemoteRepositoryContent +{ + RemoteRepository repository; + + @Override + public String getId( ) + { + return null; + } + + @Override + public RemoteRepository getRepository( ) + { + return null; + } + + @Override + public RepositoryURL getURL( ) + { + return null; + } + + @Override + public void setRepository( RemoteRepository repo ) + { + this.repository = repo; + } + + @Override + public ArtifactReference toArtifactReference( String path ) throws LayoutException + { + return null; + } + + @Override + public String toPath( ArtifactReference reference ) + { + return null; + } + + @Override + public RepositoryURL toURL( ArtifactReference reference ) + { + return null; + } +} 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 new file mode 100644 index 000000000..ad98c9963 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/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<RepositoryType> TYPES = new HashSet<>( ); + + static + { + TYPES.add( RepositoryType.MAVEN ); + TYPES.add( RepositoryType.NPM ); + } + + @Override + public Set<RepositoryType> 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.setScanned( managedRepository.isScanned( ) ); + configuration.setRefreshCronExpression( managedRepository.getSchedulingDefinition( ) ); + configuration.setReleases( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE) ); + configuration.setSnapshots( managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT) ); + configuration.setLayout( managedRepository.getLayout() ); + 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-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 9e36b9959..c6fa2a127 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,6 +32,11 @@ </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.repository.mock,org.apache.archiva.repository.content.maven2"/> + + <alias name="managedRepositoryContent#maven" alias="managedRepositoryContent#default" /> + <alias name="repositoryContentFactory#cleanup-released-snapshots" alias="repositoryContentFactory#default" /> + <bean name="registry#cleanup-released-snapshots" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry"> <property name="properties"> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context.xml index e63eb7af3..360e20d92 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context.xml @@ -44,6 +44,7 @@ </property> </bean> + <alias name="managedRepositoryContent#maven" alias="managedRepositoryContent#default" /> <alias name="userConfiguration#redback" alias="userConfiguration#default"/> <!-- *** 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 434f864e6..50dd8c1c4 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 @@ -20,8 +20,8 @@ package org.apache.archiva.consumers.lucene; */ import org.apache.archiva.admin.model.RepositoryAdminException; -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; +import org.apache.archiva.common.utils.PathUtil; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ConfigurationNames; import org.apache.archiva.configuration.FileTypes; @@ -31,6 +31,8 @@ import org.apache.archiva.consumers.KnownRepositoryContentConsumer; 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.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.maven.index.NexusIndexer; @@ -60,6 +62,10 @@ public class NexusIndexerConsumer extends AbstractMonitoredConsumer implements KnownRepositoryContentConsumer, RegistryListener { + + @Inject + private RepositoryRegistry repositoryRegistry; + private Logger log = LoggerFactory.getLogger( getClass() ); private ArchivaConfiguration configuration; @@ -113,7 +119,7 @@ public class NexusIndexerConsumer throws ConsumerException { this.repository = repository; - managedRepository = Paths.get( repository.getLocation() ); + managedRepository = PathUtil.getPathFromUri( repository.getLocation() ); try { diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/conf/repository-manager.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/conf/repository-manager.xml index 6c836b81c..106fcea10 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/conf/repository-manager.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/conf/repository-manager.xml @@ -30,7 +30,7 @@ <snapshots>true</snapshots> <indexed>true</indexed> <refreshCronExpression>0 0 * * * ?</refreshCronExpression> - <retentionTime>0</retentionTime> + <retentionPeriod>0</retentionPeriod> <retentionCount>2</retentionCount> </repository> </repositories> 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 2b76279a0..2a8546a72 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 @@ -20,16 +20,20 @@ package org.apache.archiva.consumers.lucene; */ import junit.framework.TestCase; -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; +import org.apache.archiva.common.utils.PathUtil; 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.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; @@ -39,6 +43,7 @@ import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import java.io.IOException; +import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -46,6 +51,7 @@ import java.util.Calendar; import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Set; /** @@ -89,7 +95,7 @@ public class NexusIndexerConsumerTest private NexusIndexerConsumer nexusIndexerConsumer; - private ManagedRepository repositoryConfig; + private BasicManagedRepository repositoryConfig; private ArchivaTaskSchedulerStub scheduler; @@ -126,27 +132,27 @@ public class NexusIndexerConsumerTest // initialize to set the file types to be processed nexusIndexerConsumer.initialize(); - repositoryConfig = new ManagedRepository(); - repositoryConfig.setId( "test-repo" ); - repositoryConfig.setLocation( "target/test-classes/test-repo" ); + repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository" ); + repositoryConfig.setLocation( new URI("target/test-classes/test-repo") ); repositoryConfig.setLayout( "default" ); - repositoryConfig.setName( "Test Repository" ); repositoryConfig.setScanned( true ); - repositoryConfig.setSnapshots( false ); - repositoryConfig.setReleases( true ); + repositoryConfig.addActiveReleaseScheme( ReleaseScheme.RELEASE ); + repositoryConfig.removeActiveReleaseScheme( ReleaseScheme.SNAPSHOT ); } + @Override @After public void tearDown() throws Exception { // delete created index in the repository - Path indexDir = Paths.get( repositoryConfig.getLocation(), ".indexer" ); + Path basePath = PathUtil.getPathFromUri( repositoryConfig.getLocation() ); + Path indexDir = basePath.resolve( ".indexer" ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDir ); assertFalse( Files.exists(indexDir) ); - indexDir = Paths.get( repositoryConfig.getLocation(), ".index" ); + indexDir = basePath.resolve( ".index" ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDir ); assertFalse( Files.exists(indexDir) ); @@ -157,7 +163,8 @@ public class NexusIndexerConsumerTest public void testIndexerIndexArtifact() throws Exception { - Path artifactFile = Paths.get( repositoryConfig.getLocation(), + Path basePath = PathUtil.getPathFromUri( repositoryConfig.getLocation() ); + Path artifactFile = basePath.resolve( "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ); // begin scan @@ -174,7 +181,8 @@ public class NexusIndexerConsumerTest public void testIndexerArtifactAlreadyIndexed() throws Exception { - Path artifactFile = Paths.get( repositoryConfig.getLocation(), + Path basePath = PathUtil.getPathFromUri( repositoryConfig.getLocation() ); + Path artifactFile = basePath.resolve( "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ); // begin scan @@ -200,7 +208,8 @@ public class NexusIndexerConsumerTest public void testIndexerIndexArtifactThenPom() throws Exception { - Path artifactFile = Paths.get( repositoryConfig.getLocation(), + Path basePath = PathUtil.getPathFromUri( repositoryConfig.getLocation( ) ); + Path artifactFile = basePath.resolve( "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" ); // begin scan @@ -213,7 +222,7 @@ public class NexusIndexerConsumerTest assertTrue( scheduler.indexed.contains( artifactFile ) ); artifactFile = - Paths.get( repositoryConfig.getLocation(), "org/apache/archiva/archiva-index-methods-jar-test/1.0/pom.xml" ); + basePath.resolve( "org/apache/archiva/archiva-index-methods-jar-test/1.0/pom.xml" ); // scan and index again now = Calendar.getInstance().getTime(); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java index a25457cb3..407b2399b 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java @@ -19,7 +19,6 @@ package org.apache.archiva.consumers.metadata; * under the License. */ -import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ConfigurationNames; @@ -41,6 +40,7 @@ import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataN import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException; import org.apache.archiva.redback.components.registry.Registry; import org.apache.archiva.redback.components.registry.RegistryListener; +import org.apache.archiva.repository.ManagedRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Scope; |