diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-09-14 15:15:31 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-09-22 00:09:54 +0200 |
commit | df8da96f9869522b6fc1b9270927942550555b99 (patch) | |
tree | 40784d3b630b6eae89f085f06751a41821079075 /archiva-modules/archiva-maven | |
parent | d9d87966655ca4a82e9be780caf3f70b2bcdc853 (diff) | |
download | archiva-df8da96f9869522b6fc1b9270927942550555b99.tar.gz archiva-df8da96f9869522b6fc1b9270927942550555b99.zip |
Modifying repository registry behaviour
Diffstat (limited to 'archiva-modules/archiva-maven')
8 files changed, 94 insertions, 37 deletions
diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java index 7f18ad185..c4c5e3b9f 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java @@ -37,6 +37,7 @@ import java.nio.file.Path; import java.sql.Date; import java.time.ZonedDateTime; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; /** * Maven implementation of index context @@ -45,6 +46,8 @@ public class MavenIndexContext implements ArchivaIndexingContext { private static final Logger log = LoggerFactory.getLogger(ArchivaIndexingContext.class); + + private AtomicBoolean openStatus = new AtomicBoolean(false); private IndexingContext delegate; private Repository repository; private StorageAsset dir = null; @@ -52,6 +55,7 @@ public class MavenIndexContext implements ArchivaIndexingContext { protected MavenIndexContext(Repository repository, IndexingContext delegate) { this.delegate = delegate; this.repository = repository; + this.openStatus.set(true); } @@ -107,23 +111,32 @@ public class MavenIndexContext implements ArchivaIndexingContext { @Override public void close(boolean deleteFiles) throws IOException { - try { - delegate.close(deleteFiles); - } catch (NoSuchFileException e) { - // Ignore missing directory + if (openStatus.compareAndSet(true,false)) { + try { + delegate.close(deleteFiles); + } catch (NoSuchFileException e) { + // Ignore missing directory + } } } @Override public void close() throws IOException { - try { - delegate.close(false); - } catch (NoSuchFileException e) { - // Ignore missing directory + if (openStatus.compareAndSet(true,false)) { + try { + delegate.close(false); + } catch (NoSuchFileException e) { + // Ignore missing directory + } } } @Override + public boolean isOpen() { + return openStatus.get(); + } + + @Override public void purge() throws IOException { delegate.purge(); } diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java index f2170f2f8..f36e261a5 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/AbstractMavenRepositorySearch.java @@ -26,6 +26,7 @@ import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ConfigurationListener; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.indexer.search.SearchResultHit; import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.repository.Repository; @@ -145,7 +146,7 @@ public abstract class AbstractMavenRepositorySearch EasyMock.expectLastCall().anyTimes(); archivaConfigControl.replay(); repositoryRegistry.reload(); - archivaConfigControl.reset(); + } @After @@ -210,11 +211,12 @@ public abstract class AbstractMavenRepositorySearch IndexCreationFeature icf = rRepo.getFeature(IndexCreationFeature.class).get(); - IndexingContext context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class); + ArchivaIndexingContext archivaCtx = rRepo.getIndexingContext(); + IndexingContext context = archivaCtx.getBaseContext(IndexingContext.class); - if ( context != null ) + if ( archivaCtx != null ) { - context.close(true); + archivaCtx.close(true); } Path repoDir = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir()).resolve("target").resolve("repos").resolve(repository); @@ -233,13 +235,7 @@ public abstract class AbstractMavenRepositorySearch { Files.delete(lockFile); } - assertFalse( Files.exists(lockFile) ); - - Path repo = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + repository ); - assertTrue( Files.exists(repo) ); - org.apache.commons.io.FileUtils.copyDirectory(repo.toFile(), repoDir.toFile()); - if (indexDir==null) { Path indexDirectory = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/index/test-" + Long.toString(System.currentTimeMillis())); @@ -250,7 +246,28 @@ public abstract class AbstractMavenRepositorySearch icf.setIndexPath(indexDir.toUri()); } - context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class); + Path repo = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + repository ); + assertTrue( Files.exists(repo) ); + org.apache.commons.io.FileUtils.copyDirectory(repo.toFile(), repoDir.toFile()); + + + + + archivaConfigControl.reset(); + archivaConfig.addListener( EasyMock.anyObject( ConfigurationListener.class ) ); + EasyMock.expect( archivaConfig.getConfiguration() ).andReturn(config).anyTimes(); + archivaConfig.save(EasyMock.anyObject(Configuration.class)); + EasyMock.expectLastCall().anyTimes(); + archivaConfigControl.replay(); + repositoryRegistry.reload(); + archivaConfigControl.reset(); + + rRepo = repositoryRegistry.getRepository(repository); + icf = rRepo.getFeature(IndexCreationFeature.class).get(); + + + archivaCtx = rRepo.getIndexingContext(); + context = archivaCtx.getBaseContext(IndexingContext.class); // minimize datas in memory diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java index 066b2af92..74819f984 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchOSGITest.java @@ -61,7 +61,7 @@ public class MavenRepositorySearchOSGITest List<String> selectedRepos = Arrays.asList( TEST_REPO_1 ); // search artifactId - EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchTest.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchTest.java index cb43a1a08..0b5b1bd50 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearchTest.java @@ -410,10 +410,10 @@ public class MavenRepositorySearchTest List<String> selectedRepos = new ArrayList<>(); selectedRepos.add( TEST_REPO_1 ); - EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); - EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); + // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); - archivaConfigControl.replay(); + // archivaConfigControl.replay(); SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null ); assertNotNull( results ); @@ -429,7 +429,7 @@ public class MavenRepositorySearchTest List<String> selectedRepos = new ArrayList<>(); selectedRepos.add( "non-existing-repo" ); - archivaConfigControl.replay(); + // archivaConfigControl.replay(); SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null ); assertNotNull( results ); @@ -621,10 +621,10 @@ public class MavenRepositorySearchTest try { - EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); - EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); + // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); - archivaConfigControl.replay(); + // archivaConfigControl.replay(); search.search( "user", searchFields, null ); @@ -657,9 +657,9 @@ public class MavenRepositorySearchTest try { - EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); - EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); - archivaConfigControl.replay(); + // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); + // archivaConfigControl.replay(); search.search( "user", searchFields, null ); @@ -805,10 +805,10 @@ public class MavenRepositorySearchTest searchFields.setGroupId( "org.apache.archiva" ); searchFields.setRepositories( selectedRepos ); - EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); - EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); + // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); - archivaConfigControl.replay(); + // archivaConfigControl.replay(); SearchResults results = search.search( "user", searchFields, null ); @@ -913,7 +913,7 @@ public class MavenRepositorySearchTest SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); limits.setPageSize( 300 ); - EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); + // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes(); EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes(); archivaConfigControl.replay(); diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java index 2836ca204..96eb6e947 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java @@ -22,6 +22,7 @@ package org.apache.archiva.repository.maven2; import org.apache.archiva.common.filelock.DefaultFileLockManager; import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.utils.PathUtil; +import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.repository.*; import org.apache.archiva.repository.storage.FilesystemStorage; import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo; @@ -131,4 +132,10 @@ public class MavenManagedRepository extends AbstractManagedRepository FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); return new MavenManagedRepository(id, name, storage); } + + @Override + public void setIndexingContext(ArchivaIndexingContext context) { + super.setIndexingContext(context); + } + } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java index 15dbf6ad6..ec78a942f 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java @@ -23,12 +23,11 @@ import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.configuration.*; import org.apache.archiva.repository.*; import org.apache.archiva.repository.events.Event; -import org.apache.archiva.repository.events.RepositoryValueEvent; -import org.apache.archiva.repository.storage.FilesystemStorage; 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.apache.archiva.repository.storage.FilesystemStorage; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -184,9 +183,13 @@ public class MavenRepositoryProvider implements RepositoryProvider { repo.setScanned(cfg.isScanned()); if (cfg.isReleases()) { repo.addActiveReleaseScheme(ReleaseScheme.RELEASE); + } else { + repo.removeActiveReleaseScheme(ReleaseScheme.RELEASE); } if (cfg.isSnapshots()) { repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT); + } else { + repo.removeActiveReleaseScheme(ReleaseScheme.SNAPSHOT); } StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get(); @@ -349,13 +352,20 @@ public class MavenRepositoryProvider implements RepositoryProvider { cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath())); RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get(); - if (remoteIndexFeature.getIndexUri()!=null) { + if (remoteIndexFeature.getIndexUri() != null) { cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString()); } cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS)); cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup()); cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex()); cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId()); + if (!StringUtils.isEmpty(remoteIndexFeature.getProxyId())) { + cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId()); + } else { + cfg.setRemoteDownloadNetworkProxyId(""); + } + + return cfg; diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java index 3bb6146c1..1788b9f17 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java @@ -36,6 +36,7 @@ import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest; import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException; import org.apache.archiva.proxy.maven.WagonFactory; import org.apache.archiva.proxy.maven.WagonFactoryRequest; +import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; @@ -311,6 +312,7 @@ public class Maven2RepositoryMetadataResolverMRM1411Test testRepo.setSnapshots( false ); configuration.save( c ); repositoryRegistry.reload(); + assertFalse(repositoryRegistry.getManagedRepository(testRepo.getId()).getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)); assertFalse( c.getManagedRepositories().get( 0 ).isSnapshots() ); copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a", "target/test-repository/com/example/test/test-snapshot-artifact-module-a" ); diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java index a6dddae4e..ded8ed387 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java @@ -38,6 +38,7 @@ import java.util.Set; */ public class MavenIndexContextMock implements ArchivaIndexingContext { + private boolean open = true; private IndexingContext delegate; private Repository repository; private FilesystemStorage indexStorage; @@ -86,6 +87,7 @@ public class MavenIndexContextMock implements ArchivaIndexingContext { @Override public void close(boolean deleteFiles) throws IOException { + open = false; try { delegate.close(deleteFiles); } catch (NoSuchFileException e) { @@ -95,6 +97,7 @@ public class MavenIndexContextMock implements ArchivaIndexingContext { @Override public void close() throws IOException { + open = false; try { delegate.close(false); } catch (NoSuchFileException e) { @@ -103,6 +106,11 @@ public class MavenIndexContextMock implements ArchivaIndexingContext { } @Override + public boolean isOpen() { + return open; + } + + @Override public void purge() throws IOException { delegate.purge(); } |