From 754b2d594076355d6e9d0b7698d309c87a0d672b Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Mon, 20 Nov 2017 08:20:42 +0100 Subject: [PATCH] Adding local path to repository API --- .../org/apache/archiva/cli/ArchivaCli.java | 2 +- .../configuration/ArchivaConfiguration.java | 6 + .../DefaultArchivaConfiguration.java | 22 + .../src/main/mdo/configuration.mdo | 7 + .../src/test/java/RepositoryProviderMock.java | 12 +- .../test/java/SimpleArtifactConsumerTest.java | 2 +- .../ArtifactMissingChecksumsConsumerTest.java | 5 +- .../AbstractRepositoryPurgeTest.java | 5 +- .../mock/RepositoryProviderMock.java | 11 +- .../lucene/NexusIndexerConsumerTest.java | 2 +- .../DefaultLegacyRepositoryConverter.java | 2 +- .../indexer/maven/MavenIndexManager.java | 8 +- .../indexer/maven/MavenIndexManagerTest.java | 89 ++++ .../archiva/proxy/AbstractProxyTestCase.java | 2 +- .../archiva/proxy/HttpProxyTransferTest.java | 2 +- .../archiva/proxy/MockConfiguration.java | 21 + .../mock/RepositoryProviderMock.java | 11 +- .../apache/archiva/repository/Repository.java | 19 +- .../repository/AbstractManagedRepository.java | 9 +- .../repository/AbstractRemoteRepository.java | 21 +- .../repository/AbstractRepository.java | 27 +- .../repository/BasicManagedRepository.java | 9 +- .../repository/BasicRemoteRepository.java | 9 +- .../repository/RepositoryRegistryTest.java | 12 +- .../mock/RepositoryProviderMock.java | 11 +- .../RepositoryContentConsumersTest.java | 4 +- .../scanner/RepositoryScannerTest.java | 4 +- .../ArchivaIndexingTaskExecutorTest.java | 5 +- .../archiva/webdav/DavResourceTest.java | 5 +- .../maven2/MavenManagedRepository.java | 8 +- .../maven2/MavenRemoteRepository.java | 9 +- .../maven2/MavenRepositoryProvider.java | 402 ++++++++---------- .../configuration/TestConfiguration.java | 20 + .../maven2/conf/MockConfiguration.java | 21 + .../AbstractRepositoryLayerTestCase.java | 9 +- .../content/maven2/RepositoryRequestTest.java | 2 +- .../maven2/MavenRepositoryProviderTest.java | 5 +- .../metadata/Maven2RepositoryStorageTest.java | 9 +- .../DuplicateArtifactsConsumerTest.java | 2 +- .../configuration/StubConfiguration.java | 26 ++ 40 files changed, 534 insertions(+), 323 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java diff --git a/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java b/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java index d274c3db3..b2ca3782f 100644 --- a/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java +++ b/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java @@ -168,7 +168,7 @@ public class ArchivaCli private void doScan( String path, String[] consumers ) throws ConsumerException, MalformedURLException { - BasicManagedRepository repo = new BasicManagedRepository( Paths.get(path).getFileName().toString(), "Archiva CLI Provided Repo" ); + BasicManagedRepository repo = new BasicManagedRepository( Paths.get(path).getFileName().toString(), "Archiva CLI Provided Repo", Paths.get(path).getParent()); repo.setLocation( Paths.get(path).toUri() ); List knownConsumerList = new ArrayList<>(); diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java index e656b7e9d..80959dc8d 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java @@ -102,6 +102,12 @@ public interface ArchivaConfiguration */ public Path getRepositoryBaseDir(); + /** + * Returns the base directory for remote repositories + * @return + */ + public Path getRemoteRepositoryBaseDir(); + /** * Returns the data directory where repositories and metadata reside * @return diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java index b28bed201..71b4c3103 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java @@ -90,6 +90,8 @@ import java.util.Set; *

* If the configuration is outdated, it will be upgraded when it is loaded. This is done by checking the version flag * before reading it from the registry. + * + * FIXME: The synchronization must be improved, the current impl may lead to inconsistent data or multiple getConfiguration() calls (martin_s@apache.org) *

*/ @Service("archivaConfiguration#default") @@ -176,6 +178,7 @@ public class DefaultArchivaConfiguration private volatile Path dataDirectory; private volatile Path repositoryBaseDirectory; + private volatile Path remoteRepositoryBaseDirectory; @PostConstruct private void init() { @@ -261,6 +264,17 @@ public class DefaultArchivaConfiguration dataDirectory.resolve(tmpRepoBaseDir); } } + String remoteRepoBaseDir = config.getArchivaRuntimeConfiguration().getRemoteRepositoryBaseDirectory(); + if (StringUtils.isEmpty(remoteRepoBaseDir)) { + remoteRepositoryBaseDirectory = dataDirectory.resolve("remotes"); + } else { + Path tmpRemoteRepoDir = Paths.get(remoteRepoBaseDir); + if (tmpRemoteRepoDir.isAbsolute()) { + remoteRepositoryBaseDirectory = tmpRemoteRepoDir; + } else { + dataDirectory.resolve(tmpRemoteRepoDir); + } + } config.getRepositoryGroups(); @@ -941,6 +955,14 @@ public class DefaultArchivaConfiguration } + @Override + public Path getRemoteRepositoryBaseDir() { + if (remoteRepositoryBaseDirectory==null) { + getConfiguration(); + } + return remoteRepositoryBaseDirectory; + } + @Override public Path getDataDirectory() { if (dataDirectory==null) { diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index 91dbb65b2..d687ba6af 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -1546,6 +1546,13 @@ String false + + remoteRepositoryBaseDirectory + 3.0.0+ + The base directory for local storage of remote repository data. If not set, it's ${dataDirectory}/remotes. + String + false + defaultLanguage String diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java index 55151f337..a140842a2 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java @@ -39,7 +39,9 @@ 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.nio.file.Paths; import java.time.Duration; import java.time.Period; import java.util.HashSet; @@ -69,19 +71,19 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public EditableManagedRepository createManagedInstance( String id, String name ) { - return new BasicManagedRepository( id, name ); + return new BasicManagedRepository( id, name, Paths.get("target/repositories") ); } @Override public EditableRemoteRepository createRemoteInstance( String id, String name ) { - return new BasicRemoteRepository( id, name ); + return new BasicRemoteRepository( id, name , Paths.get("target/remotes")); } @Override public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { - BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) ); + BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") ); updateManagedInstance( managedRepository, configuration ); return managedRepository; } @@ -128,7 +130,7 @@ public class RepositoryProviderMock implements RepositoryProvider public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; - BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) ); + BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ), Paths.get("target/repositories") ); updateManagedInstance( managedRepository, configuration ); return managedRepository; } @@ -136,7 +138,7 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException { - BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) ); + BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); updateRemoteInstance( remoteRepository, configuration ); return remoteRepository; } 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 68d03a873..0b134ba05 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 @@ -84,7 +84,7 @@ public class SimpleArtifactConsumerTest Files.createDirectories( repoDir ); repoDir.toFile().deleteOnExit(); - testRepository = new BasicManagedRepository("test-consumer-repository","Test-Consumer-Repository" ); + testRepository = new BasicManagedRepository("test-consumer-repository","Test-Consumer-Repository", Paths.get("target/repositories") ); testRepository.setLocation( repoDir.toAbsolutePath().toUri() ); repositoryRegistry.putRepository(testRepository); 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 1ad70c389..5851e6770 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 @@ -47,9 +47,10 @@ public class ArtifactMissingChecksumsConsumerTest { super.setUp(); - repoConfig = new BasicManagedRepository( "test-repo", "Test Repository"); + Path basePath = Paths.get("target/test-classes"); + repoConfig = new BasicManagedRepository( "test-repo", "Test Repository", basePath); repoConfig.setLayout( "default" ); - repoConfig.setLocation( Paths.get( "target/test-classes/test-repo/" ).toUri() ); + repoConfig.setLocation(basePath.resolve("test-repo/" ).toUri() ); consumer = applicationContext.getBean( "knownRepositoryContentConsumer#create-missing-checksums", KnownRepositoryContentConsumer.class ); 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 d65d1a491..e9e73530b 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 @@ -166,13 +166,14 @@ public abstract class AbstractRepositoryPurgeTest public org.apache.archiva.repository.ManagedRepository getRepoConfiguration( String repoId, String repoName ) throws URISyntaxException { - config = new BasicManagedRepository( repoId, repoName); + Path basePath = Paths.get("target/test-" + getName()).toAbsolutePath(); + config = new BasicManagedRepository( repoId, repoName, basePath); 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() ); + basePath.resolve( repoId ).toAbsolutePath().toString() ); config.setLocation( new URI( path ) ); atf.setDeleteReleasedSnapshots( true ); atf.setRetentionCount( TEST_RETENTION_COUNT ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java index ad98c9963..286dd38e4 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java @@ -40,6 +40,7 @@ import org.apache.archiva.repository.features.StagingRepositoryFeature; import org.springframework.stereotype.Service; import java.net.URI; +import java.nio.file.Paths; import java.time.Duration; import java.time.Period; import java.util.HashSet; @@ -69,19 +70,19 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public EditableManagedRepository createManagedInstance( String id, String name ) { - return new BasicManagedRepository( id, name ); + return new BasicManagedRepository( id, name, Paths.get("target/repositories") ); } @Override public EditableRemoteRepository createRemoteInstance( String id, String name ) { - return new BasicRemoteRepository( id, name ); + return new BasicRemoteRepository( id, name, Paths.get("target/remotes") ); } @Override public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { - BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) ); + BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") ); updateManagedInstance( managedRepository, configuration ); return managedRepository; } @@ -128,7 +129,7 @@ public class RepositoryProviderMock implements RepositoryProvider public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; - BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) ); + BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ), Paths.get("target/repositories") ); updateManagedInstance( managedRepository, configuration ); return managedRepository; } @@ -136,7 +137,7 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException { - BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) ); + BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); updateRemoteInstance( remoteRepository, configuration ); return remoteRepository; } 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 2a8546a72..e34dc7e12 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 @@ -132,7 +132,7 @@ public class NexusIndexerConsumerTest // initialize to set the file types to be processed nexusIndexerConsumer.initialize(); - repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository" ); + repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", Paths.get("target/test-classes") ); repositoryConfig.setLocation( new URI("target/test-classes/test-repo") ); repositoryConfig.setLayout( "default" ); repositoryConfig.setScanned( true ); diff --git a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java index 3e8e168f9..cc1af39e9 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java +++ b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java @@ -92,7 +92,7 @@ public class DefaultLegacyRepositoryConverter { String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory ); - BasicManagedRepository legacyRepository = new BasicManagedRepository( "legacy", "Legacy Repository"); + BasicManagedRepository legacyRepository = new BasicManagedRepository( "legacy", "Legacy Repository", repositoryDirectory.getParent()); legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() ); legacyRepository.setLayout( "legacy" ); diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java index 7e6d3c57f..60c2fdd3c 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java @@ -521,13 +521,7 @@ public class MavenIndexManager implements ArchivaIndexManager IndexingContext context; // take care first about repository location as can be relative - Path repositoryDirectory = PathUtil.getPathFromUri( repository.getLocation( ) ); - - if ( !repositoryDirectory.isAbsolute( ) ) - { - repositoryDirectory = - repositoryDirectory.resolve( "repositories" ).resolve( repositoryDirectory ); - } + Path repositoryDirectory = repository.getLocalPath(); if ( !Files.exists( repositoryDirectory ) ) { diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java new file mode 100644 index 000000000..a70c584d3 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java @@ -0,0 +1,89 @@ +package org.apache.archiva.indexer.maven; + +/* +* 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.indexer.ArchivaIndexingContext; +import org.apache.archiva.repository.ManagedRepository; +import org.apache.archiva.repository.features.IndexCreationFeature; +import org.apache.archiva.repository.maven2.MavenManagedRepository; +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; + +import javax.inject.Inject; + +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.junit.Assert.*; + +@RunWith( ArchivaSpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) +public class MavenIndexManagerTest { + + @Inject + MavenIndexManager mavenIndexManager; + + + + @Test + public void pack() throws Exception { + } + + @Test + public void scan() throws Exception { + } + + @Test + public void update() throws Exception { + } + + @Test + public void addArtifactsToIndex() throws Exception { + } + + @Test + public void removeArtifactsFromIndex() throws Exception { + } + + @Test + public void supportsRepository() throws Exception { + } + + @Test + public void createContext() throws Exception { + MavenManagedRepository repository = new MavenManagedRepository("test-repo", "Test Repo", Paths.get("target/repositories")); + repository.setLocation(new URI("test-repo")); + IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get(); + icf.setIndexPath(new URI(".index-test")); + ArchivaIndexingContext ctx = mavenIndexManager.createContext(repository); + assertNotNull(ctx); + assertEquals(repository, ctx.getRepository()); + assertEquals("test-repo", ctx.getId()); + Path indexPath = Paths.get("target/repositories/test-repo/.index-test"); + assertEquals(indexPath.toAbsolutePath(), Paths.get(ctx.getPath()).toAbsolutePath()); + assertTrue(Files.exists(indexPath)); + + } + +} \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java index c4bfff309..4dcf74760 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java @@ -354,7 +354,7 @@ public abstract class AbstractProxyTestCase protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout ) throws Exception { - MavenManagedRepository repo = new MavenManagedRepository(id, name); + MavenManagedRepository repo = new MavenManagedRepository(id, name, Paths.get(path).getParent()); repo.setLocation( new URI(path) ); repo.setLayout( layout ); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java index 3980d87c2..40fa894ca 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java @@ -123,7 +123,7 @@ public class HttpProxyTransferTest // Make the destination dir. Files.createDirectories(destRepoDir); - MavenManagedRepository repo = new MavenManagedRepository( MANAGED_ID, "Default Managed Repository" ); + MavenManagedRepository repo = new MavenManagedRepository( MANAGED_ID, "Default Managed Repository", Paths.get(repoPath).getParent() ); repo.setLocation( new URI(repoPath) ); repo.setLayout( "default" ); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java index 54a0b94da..30de66392 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java @@ -23,6 +23,7 @@ import org.apache.archiva.configuration.*; import org.apache.archiva.redback.components.registry.Registry; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryListener; +import org.apache.commons.lang.StringUtils; import org.easymock.EasyMock; import org.easymock.IMocksControl; import org.springframework.stereotype.Service; @@ -160,4 +161,24 @@ public class MockConfiguration return Paths.get(""); } } + + + @Override + public Path getRepositoryBaseDir() { + return getDataDirectory().resolve("repositories"); + } + + @Override + public Path getRemoteRepositoryBaseDir() { + return getDataDirectory().resolve("remotes"); + } + + @Override + public Path getDataDirectory() { + if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) { + return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory()); + } else { + return getAppServerBaseDir().resolve("data"); + } + } } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java index 834ce5ba2..c923ba960 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java @@ -40,6 +40,7 @@ import org.apache.archiva.repository.features.StagingRepositoryFeature; import org.springframework.stereotype.Service; import java.net.URI; +import java.nio.file.Paths; import java.time.Duration; import java.time.Period; import java.util.HashSet; @@ -69,19 +70,19 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public EditableManagedRepository createManagedInstance( String id, String name ) { - return new BasicManagedRepository( id, name ); + return new BasicManagedRepository( id, name , Paths.get("target/repositories")); } @Override public EditableRemoteRepository createRemoteInstance( String id, String name ) { - return new BasicRemoteRepository( id, name ); + return new BasicRemoteRepository( id, name, Paths.get("target/remotes") ); } @Override public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { - BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) ); + BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) , Paths.get("target/repositories")); updateManagedInstance( managedRepository, configuration ); return managedRepository; } @@ -128,7 +129,7 @@ public class RepositoryProviderMock implements RepositoryProvider public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; - BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) ); + BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ), Paths.get("target/repositories") ); updateManagedInstance( managedRepository, configuration ); return managedRepository; } @@ -136,7 +137,7 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException { - BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) ); + BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); updateRemoteInstance( remoteRepository, configuration ); return remoteRepository; } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java index 1c101ee48..fae5745dd 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java @@ -23,6 +23,7 @@ import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.repository.features.RepositoryFeature; import java.net.URI; +import java.nio.file.Path; import java.util.List; import java.util.Locale; import java.util.Set; @@ -86,14 +87,22 @@ public interface Repository { */ URI getLocation(); + /** - * This returns the absolute location uri of this repository. Some repository locations may be relative to - * the base repository directory or uri. This returns the absolute path of the repository. - * If the location is absolute already this method returns the same URI as getLocation(). + * Returns the local path that this repository uses, if it stores data locally. You should keep in + * mind, that repository implementations may not store any data in this directory. E.g. if the + * repository data is handled by a database. So the content of this directory is very implementation + * specific. Users of this directory must know about the repository file layout if they use this + * path. + * + * Repository implementations should always return a valid path, even if there is no locally stored data. * - * @return the absolute uri of the location. + * Some extensions may use the path to store their own repository specific data, e.g. statistics, metadata,... + * + * @return the filesystem path to the repository. */ - URI getAbsoluteLocation(); + Path getLocalPath(); + /** * A repository may allow additional locations that can be used, if the primary location is not available. diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java index 3f482ca47..06cab6b53 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java @@ -20,6 +20,7 @@ package org.apache.archiva.repository; */ +import java.nio.file.Path; import java.util.Collections; import java.util.HashSet; import java.util.Locale; @@ -35,14 +36,14 @@ public abstract class AbstractManagedRepository extends AbstractRepository imple private Set activeReleaseSchemes = new HashSet<>( ); private Set uActiveReleaseSchemes = Collections.unmodifiableSet( activeReleaseSchemes ); - public AbstractManagedRepository( RepositoryType type, String id, String name ) + public AbstractManagedRepository( RepositoryType type, String id, String name, Path basePath ) { - super( type, id, name ); + super( type, id, name, basePath ); } - public AbstractManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name ) + public AbstractManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path basePath ) { - super( primaryLocale, type, id, name ); + super( primaryLocale, type, id, name, basePath ); } @Override diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java index e1e570a78..131aad664 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java @@ -20,6 +20,10 @@ package org.apache.archiva.repository; */ +import org.apache.commons.lang.StringUtils; + +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import java.util.Collections; import java.util.HashMap; @@ -43,14 +47,14 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem private String proxyId; private RemoteRepositoryContent content; - public AbstractRemoteRepository( RepositoryType type, String id, String name ) + public AbstractRemoteRepository( RepositoryType type, String id, String name , Path repositoryBase) { - super( type, id, name ); + super( type, id, name, repositoryBase ); } - public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name ) + public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase ) { - super( primaryLocale, type, id, name ); + super( primaryLocale, type, id, name, repositoryBase ); } @Override @@ -138,4 +142,13 @@ public abstract class AbstractRemoteRepository extends AbstractRepository implem return timeout; } + /** + * Remote repositories resolve always relative to the base directory. + * @return + */ + @Override + public Path getLocalPath() { + return repositoryBase.resolve(getId()); + } + } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java index ab1c3fa83..c90c5bff6 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java @@ -23,10 +23,14 @@ import com.cronutils.model.CronType; import com.cronutils.model.definition.CronDefinition; import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.parser.CronParser; +import org.apache.archiva.common.utils.PathUtil; import org.apache.archiva.indexer.ArchivaIndexingContext; import org.apache.archiva.repository.features.RepositoryFeature; +import org.apache.commons.lang.StringUtils; import java.net.URI; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -59,17 +63,21 @@ public abstract class AbstractRepository implements EditableRepository Map>, RepositoryFeature> featureMap = new HashMap<>( ); - public AbstractRepository(RepositoryType type, String id, String name) { + protected Path repositoryBase; + + public AbstractRepository(RepositoryType type, String id, String name, Path repositoryBase) { this.id = id; this.names.put( primaryLocale, name); this.type = type; + this.repositoryBase=repositoryBase; } - public AbstractRepository(Locale primaryLocale, RepositoryType type, String id, String name) { + public AbstractRepository(Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase) { setPrimaryLocale( primaryLocale ); this.id = id; this.names.put( primaryLocale, name); this.type = type; + this.repositoryBase=repositoryBase; } protected void setPrimaryLocale(Locale locale) { @@ -118,8 +126,19 @@ public abstract class AbstractRepository implements EditableRepository return location; } - public URI getAbsoluteLocation() { - return baseUri.resolve( location ); + @Override + public Path getLocalPath() { + Path localPath; + if (getLocation().getScheme()=="file" || StringUtils.isEmpty(getLocation().getScheme())) { + localPath = PathUtil.getPathFromUri(getLocation()); + if (localPath.isAbsolute()) { + return localPath; + } else { + return repositoryBase.resolve(localPath); + } + } else { + return repositoryBase.resolve(getId()); + } } @Override diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java index 0ab88f30c..6c1a28525 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java @@ -23,6 +23,7 @@ import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.StagingRepositoryFeature; +import java.nio.file.Path; import java.util.Locale; /** @@ -46,15 +47,15 @@ public class BasicManagedRepository extends AbstractManagedRepository StagingRepositoryFeature.class.toString() }, true, true, true, true, true ); - public BasicManagedRepository( String id, String name ) + public BasicManagedRepository( String id, String name, Path basePath ) { - super( RepositoryType.MAVEN, id, name ); + super( RepositoryType.MAVEN, id, name, basePath ); initFeatures(); } - public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name ) + public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path basePath ) { - super( primaryLocale, type, id, name ); + super( primaryLocale, type, id, name, basePath ); initFeatures(); } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicRemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicRemoteRepository.java index d241854b8..64b705c3b 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicRemoteRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicRemoteRepository.java @@ -21,6 +21,7 @@ package org.apache.archiva.repository; import org.apache.archiva.repository.features.RemoteIndexFeature; +import java.nio.file.Path; import java.util.Locale; /** @@ -41,15 +42,15 @@ public class BasicRemoteRepository extends AbstractRemoteRepository RemoteIndexFeature.class.toString() }, true, true, true, true, true ); - public BasicRemoteRepository( String id, String name ) + public BasicRemoteRepository( String id, String name, Path basePath ) { - super( RepositoryType.MAVEN, id, name ); + super( RepositoryType.MAVEN, id, name, basePath); initFeatures(); } - public BasicRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name ) + public BasicRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path basePath ) { - super( primaryLocale, type, id, name ); + super( primaryLocale, type, id, name, basePath ); initFeatures(); } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java index 01dcbd253..b125f819f 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java @@ -192,14 +192,14 @@ public class RepositoryRegistryTest @Test public void putManagedRepository( ) throws Exception { - BasicManagedRepository managedRepository = new BasicManagedRepository( "test001", "Test repo" ); + BasicManagedRepository managedRepository = new BasicManagedRepository( "test001", "Test repo", archivaConfiguration.getRepositoryBaseDir() ); managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); repositoryRegistry.putRepository(managedRepository); assertNotNull(managedRepository.getContent()); assertEquals(6, repositoryRegistry.getRepositories().size()); - managedRepository = new BasicManagedRepository( "central", "Test repo" ); + managedRepository = new BasicManagedRepository( "central", "Test repo", archivaConfiguration.getRepositoryBaseDir() ); managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); ManagedRepository updatedRepo = null; try { @@ -208,7 +208,7 @@ public class RepositoryRegistryTest } catch (RepositoryException e) { // OK } - managedRepository = new BasicManagedRepository( "internal", "Test repo" ); + managedRepository = new BasicManagedRepository( "internal", "Test repo", archivaConfiguration.getRepositoryBaseDir() ); managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); updatedRepo = repositoryRegistry.putRepository( managedRepository ); @@ -283,7 +283,7 @@ public class RepositoryRegistryTest @Test public void putRemoteRepository( ) throws Exception { - BasicRemoteRepository remoteRepository = new BasicRemoteRepository( "test001", "Test repo" ); + BasicRemoteRepository remoteRepository = new BasicRemoteRepository( "test001", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); RemoteRepository newRepo = repositoryRegistry.putRepository(remoteRepository); @@ -291,7 +291,7 @@ public class RepositoryRegistryTest assertNotNull(remoteRepository.getContent()); assertEquals(6, repositoryRegistry.getRepositories().size()); - remoteRepository = new BasicRemoteRepository( "internal", "Test repo" ); + remoteRepository = new BasicRemoteRepository( "internal", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); RemoteRepository updatedRepo = null; try @@ -302,7 +302,7 @@ public class RepositoryRegistryTest // OK } - remoteRepository = new BasicRemoteRepository( "central", "Test repo" ); + remoteRepository = new BasicRemoteRepository( "central", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); updatedRepo = repositoryRegistry.putRepository( remoteRepository ); diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java index 95485cc33..d4a78a693 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java @@ -40,6 +40,7 @@ import org.apache.archiva.repository.features.StagingRepositoryFeature; import org.springframework.stereotype.Service; import java.net.URI; +import java.nio.file.Paths; import java.time.Duration; import java.time.Period; import java.util.HashSet; @@ -69,19 +70,19 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public EditableManagedRepository createManagedInstance( String id, String name ) { - return new BasicManagedRepository( id, name ); + return new BasicManagedRepository( id, name, Paths.get("target/repositories") ); } @Override public EditableRemoteRepository createRemoteInstance( String id, String name ) { - return new BasicRemoteRepository( id, name ); + return new BasicRemoteRepository( id, name , Paths.get("target/remotes")); } @Override public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { - BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) ); + BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/repositories") ); updateManagedInstance( managedRepository, configuration ); return managedRepository; } @@ -128,7 +129,7 @@ public class RepositoryProviderMock implements RepositoryProvider public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { String id = configuration.getId( ) + StagingRepositoryFeature.STAGING_REPO_POSTFIX; - BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) ); + BasicManagedRepository managedRepository = new BasicManagedRepository( id, configuration.getName( ) , Paths.get("target/repositories")); updateManagedInstance( managedRepository, configuration ); managedRepository.getFeature(StagingRepositoryFeature.class).get().setStageRepoNeeded(false); return managedRepository; @@ -137,7 +138,7 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException { - BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ) ); + BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); updateRemoteInstance( remoteRepository, configuration ); return remoteRepository; } diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java index c24c0c26b..6148fe58e 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java @@ -76,14 +76,14 @@ public class RepositoryContentConsumersTest protected ManagedRepository createRepository( String id, String name, Path location ) { - BasicManagedRepository repo = new BasicManagedRepository( id, name ); + BasicManagedRepository repo = new BasicManagedRepository( id, name , location.getParent() ); repo.setLocation( location.toAbsolutePath().toUri() ); return repo; } protected RemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException { - BasicRemoteRepository repo = new BasicRemoteRepository(id, name); + BasicRemoteRepository repo = new BasicRemoteRepository(id, name, Paths.get("remotes")); repo.setLocation( new URI( url ) ); return repo; } diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java index e9a462b22..ac867089b 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java @@ -64,14 +64,14 @@ public class RepositoryScannerTest protected EditableManagedRepository createRepository( String id, String name, Path location ) { - BasicManagedRepository repo = new BasicManagedRepository(id, name); + BasicManagedRepository repo = new BasicManagedRepository(id, name, location.getParent()); repo.setLocation( location.toAbsolutePath().toUri()); return repo; } protected EditableRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException { - BasicRemoteRepository repo = new BasicRemoteRepository(id, name); + BasicRemoteRepository repo = new BasicRemoteRepository(id, name, Paths.get("remotes")); repo.setLocation( new URI( url ) ); return repo; } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java index 02c026174..d0e6532fe 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java @@ -91,8 +91,9 @@ public class ArchivaIndexingTaskExecutorTest { super.setUp(); - repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository"); - Path repoLocation = Paths.get( System.getProperty( "basedir" ), "target/test-classes/test-repo" ).toAbsolutePath(); + Path baseDir = Paths.get(System.getProperty("basedir"), "target/test-classes").toAbsolutePath(); + repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", baseDir); + Path repoLocation = baseDir.resolve("test-repo" ); repositoryConfig.setLocation(repoLocation.toUri() ); repositoryConfig.setLayout( "default" ); repositoryConfig.setScanned( true ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/DavResourceTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/DavResourceTest.java index 48027766a..394e82aec 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/DavResourceTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/DavResourceTest.java @@ -77,8 +77,7 @@ public class DavResourceTest private LockManager lockManager; - private MavenManagedRepository repository = new MavenManagedRepository( "repo001", "repo001"); - + private MavenManagedRepository repository; @Override @Before public void setUp() @@ -88,6 +87,8 @@ public class DavResourceTest session = new ArchivaDavSession(); baseDir = Paths.get( "target/DavResourceTest" ); Files.createDirectories( baseDir ); + repository = new MavenManagedRepository( "repo001", "repo001", baseDir); + myResource = baseDir.resolve( "myresource.jar" ); Files.createFile(myResource); resourceFactory = new RootContextDavResourceFactory(); diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java index aaad382ed..0e5a37f2a 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java @@ -70,14 +70,14 @@ public class MavenManagedRepository extends AbstractManagedRepository false ); - public MavenManagedRepository( String id, String name ) + public MavenManagedRepository( String id, String name, Path basePath ) { - super( RepositoryType.MAVEN, id, name ); + super( RepositoryType.MAVEN, id, name, basePath); } - public MavenManagedRepository( Locale primaryLocale, String id, String name ) + public MavenManagedRepository( Locale primaryLocale, String id, String name, Path basePath ) { - super( primaryLocale, RepositoryType.MAVEN, id, name ); + super( primaryLocale, RepositoryType.MAVEN, id, name, basePath ); } @Override diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java index 8c7a8cf1e..c85719699 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java @@ -11,6 +11,7 @@ import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; import org.apache.archiva.repository.features.RepositoryFeature; +import java.nio.file.Path; import java.util.Locale; /* @@ -53,14 +54,14 @@ public class MavenRemoteRepository extends AbstractRemoteRepository false ); - public MavenRemoteRepository( String id, String name ) + public MavenRemoteRepository( String id, String name, Path basePath ) { - super( RepositoryType.MAVEN, id, name ); + super( RepositoryType.MAVEN, id, name, basePath ); } - public MavenRemoteRepository( Locale primaryLocale, String id, String name ) + public MavenRemoteRepository( Locale primaryLocale, String id, String name, Path basePath ) { - super( primaryLocale, RepositoryType.MAVEN, id, name ); + super( primaryLocale, RepositoryType.MAVEN, id, name, basePath ); } @Override diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java index 6bdd0b8b0..331f44bdb 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java @@ -62,63 +62,58 @@ import java.util.Set; * Provider for the maven2 repository implementations */ @Service("mavenRepositoryProvider") -public class MavenRepositoryProvider implements RepositoryProvider -{ +public class MavenRepositoryProvider implements RepositoryProvider { @Inject private ArchivaConfiguration archivaConfiguration; - private static final Logger log = LoggerFactory.getLogger( MavenRepositoryProvider.class ); + private static final Logger log = LoggerFactory.getLogger(MavenRepositoryProvider.class); + + static final Set TYPES = new HashSet<>(); - static final Set TYPES = new HashSet<>( ); static { - TYPES.add( RepositoryType.MAVEN); + TYPES.add(RepositoryType.MAVEN); } @Override - public Set provides( ) - { + public Set provides() { return TYPES; } @Override public EditableManagedRepository createManagedInstance(String id, String name) { - return new MavenManagedRepository(id, name); + return new MavenManagedRepository(id, name, archivaConfiguration.getRepositoryBaseDir()); } @Override public EditableRemoteRepository createRemoteInstance(String id, String name) { - return new MavenRemoteRepository(id, name); + return new MavenRemoteRepository(id, name, archivaConfiguration.getRemoteRepositoryBaseDir()); } - private URI getURIFromString( String uriStr) throws RepositoryException { + private URI getURIFromString(String uriStr) throws RepositoryException { URI uri; try { - if (StringUtils.isEmpty( uriStr )) { + if (StringUtils.isEmpty(uriStr)) { return new URI(""); } if (uriStr.startsWith("/")) { // only absolute paths are prepended with file scheme - uri = new URI("file://"+uriStr); - } else - { - uri = new URI( uriStr ); + uri = new URI("file://" + uriStr); + } else { + uri = new URI(uriStr); } - if (uri.getScheme()!=null && !"file".equals(uri.getScheme())) { + if (uri.getScheme() != null && !"file".equals(uri.getScheme())) { log.error("Bad URI scheme found: {}, URI={}", uri.getScheme(), uri); - throw new RepositoryException("The uri "+uriStr+" is not valid. Only file:// URI is allowed for maven."); + throw new RepositoryException("The uri " + uriStr + " is not valid. Only file:// URI is allowed for maven."); } } catch (URISyntaxException e) { - String newCfg = "file://"+uriStr; - try - { + String newCfg = "file://" + uriStr; + try { uri = new URI(newCfg); - } - catch ( URISyntaxException e1 ) - { + } catch (URISyntaxException e1) { log.error("Could not create URI from {} -> ", uriStr, newCfg); - throw new RepositoryException( "The config entry "+uriStr+" cannot be converted to URI." ); + throw new RepositoryException("The config entry " + uriStr + " cannot be converted to URI."); } } log.debug("Setting location uri: {}", uri); @@ -126,56 +121,48 @@ public class MavenRepositoryProvider implements RepositoryProvider } @Override - public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration cfg ) throws RepositoryException - { - MavenManagedRepository repo = new MavenManagedRepository(cfg.getId() ,cfg.getName()); - updateManagedInstance( repo, cfg ); + public ManagedRepository createManagedInstance(ManagedRepositoryConfiguration cfg) throws RepositoryException { + MavenManagedRepository repo = new MavenManagedRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRepositoryBaseDir()); + updateManagedInstance(repo, cfg); return repo; } @Override - public void updateManagedInstance( EditableManagedRepository repo , ManagedRepositoryConfiguration cfg ) throws RepositoryException - { - try - { - repo.setLocation( getURIFromString( cfg.getLocation() ) ); - } - catch ( UnsupportedURIException e ) - { - throw new RepositoryException( "The location entry is not a valid uri: "+cfg.getLocation() ); + public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException { + try { + repo.setLocation(getURIFromString(cfg.getLocation())); + } catch (UnsupportedURIException e) { + throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation()); } - setBaseConfig( repo, cfg ); - Path repoDir = PathUtil.getPathFromUri(repo.getAbsoluteLocation()); + setBaseConfig(repo, cfg); + Path repoDir = repo.getLocalPath(); if (!Files.exists(repoDir)) { log.debug("Creating repo directory {}", repoDir); - try - { - Files.createDirectories( repoDir ); - } - catch ( IOException e ) - { - log.error("Could not create directory {} for repository {}", repo.getAbsoluteLocation(), repo.getId(), e); - throw new RepositoryException( "Could not create directory for repository "+repo.getAbsoluteLocation() ); + try { + Files.createDirectories(repoDir); + } catch (IOException e) { + log.error("Could not create directory {} for repository {}", repo.getLocalPath(), repo.getId(), e); + throw new RepositoryException("Could not create directory for repository " + repo.getLocalPath()); } } repo.setSchedulingDefinition(cfg.getRefreshCronExpression()); - repo.setBlocksRedeployment( cfg.isBlockRedeployments() ); - repo.setScanned( cfg.isScanned() ); + repo.setBlocksRedeployment(cfg.isBlockRedeployments()); + repo.setScanned(cfg.isScanned()); if (cfg.isReleases()) { - repo.addActiveReleaseScheme( ReleaseScheme.RELEASE); + repo.addActiveReleaseScheme(ReleaseScheme.RELEASE); } if (cfg.isSnapshots()) { repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT); } - StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature( StagingRepositoryFeature.class ).get(); - stagingRepositoryFeature.setStageRepoNeeded( cfg.isStageRepoNeeded() ); + StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get(); + stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded()); - IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get( ); - indexCreationFeature.setSkipPackedIndexCreation( cfg.isSkipPackedIndexCreation() ); - indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir() ) ); + IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get(); + indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation()); + indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir())); Path indexPath; - if (indexCreationFeature.getIndexPath().getScheme()==null) { + if (indexCreationFeature.getIndexPath().getScheme() == null) { indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath()); } else { indexPath = Paths.get(indexCreationFeature.getIndexPath()); @@ -184,44 +171,39 @@ public class MavenRepositoryProvider implements RepositoryProvider if (indexPath.isAbsolute()) { absoluteIndexPath = indexPath; } else { - absoluteIndexPath = PathUtil.getPathFromUri( repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath()); + absoluteIndexPath = PathUtil.getPathFromUri(repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath()); } - try - { - Files.createDirectories( absoluteIndexPath ); - } - catch ( IOException e ) - { + try { + Files.createDirectories(absoluteIndexPath); + } catch (IOException e) { log.error("Could not create index directory {}", absoluteIndexPath); - throw new RepositoryException( "Could not create index directory "+absoluteIndexPath ); + throw new RepositoryException("Could not create index directory " + absoluteIndexPath); } - ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature( ArtifactCleanupFeature.class ).get(); + ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get(); - artifactCleanupFeature.setDeleteReleasedSnapshots( cfg.isDeleteReleasedSnapshots() ); - artifactCleanupFeature.setRetentionCount( cfg.getRetentionCount() ); - artifactCleanupFeature.setRetentionPeriod( Period.ofDays( cfg.getRetentionPeriod() ) ); + artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots()); + artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount()); + artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod())); } @Override - public ManagedRepository createStagingInstance( ManagedRepositoryConfiguration baseConfiguration ) throws RepositoryException - { + public ManagedRepository createStagingInstance(ManagedRepositoryConfiguration baseConfiguration) throws RepositoryException { log.debug("Creating staging instance for {}", baseConfiguration.getId()); - return createManagedInstance( getStageRepoConfig( baseConfiguration ) ); + return createManagedInstance(getStageRepoConfig(baseConfiguration)); } @Override - public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration cfg ) throws RepositoryException - { - MavenRemoteRepository repo = new MavenRemoteRepository( cfg.getId( ), cfg.getName( ) ); - updateRemoteInstance( repo, cfg ); + public RemoteRepository createRemoteInstance(RemoteRepositoryConfiguration cfg) throws RepositoryException { + MavenRemoteRepository repo = new MavenRemoteRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir()); + updateRemoteInstance(repo, cfg); return repo; } private String convertUriToPath(URI uri) { - if (uri.getScheme()==null) { + if (uri.getScheme() == null) { return uri.getPath(); } else if ("file".equals(uri.getScheme())) { return Paths.get(uri).toString(); @@ -231,96 +213,83 @@ public class MavenRepositoryProvider implements RepositoryProvider } @Override - public void updateRemoteInstance( EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg ) throws RepositoryException - { - setBaseConfig( repo, cfg ); - repo.setCheckPath( cfg.getCheckPath() ); - repo.setSchedulingDefinition( cfg.getRefreshCronExpression() ); - try - { + public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException { + setBaseConfig(repo, cfg); + repo.setCheckPath(cfg.getCheckPath()); + repo.setSchedulingDefinition(cfg.getRefreshCronExpression()); + try { repo.setLocation(new URI(cfg.getUrl())); + } catch (UnsupportedURIException | URISyntaxException e) { + log.error("Could not set remote url " + cfg.getUrl()); + throw new RepositoryException("The url config is not a valid uri: " + cfg.getUrl()); } - catch ( UnsupportedURIException | URISyntaxException e ) - { - log.error("Could not set remote url "+cfg.getUrl()); - throw new RepositoryException( "The url config is not a valid uri: "+cfg.getUrl() ); - } - repo.setTimeout( Duration.ofSeconds( cfg.getTimeout() ) ); - RemoteIndexFeature remoteIndexFeature = repo.getFeature( RemoteIndexFeature.class ).get(); - remoteIndexFeature.setDownloadRemoteIndex( cfg.isDownloadRemoteIndex() ); - remoteIndexFeature.setDownloadRemoteIndexOnStartup( cfg.isDownloadRemoteIndexOnStartup() ); - remoteIndexFeature.setDownloadTimeout( Duration.ofSeconds( cfg.getRemoteDownloadTimeout()) ); - remoteIndexFeature.setProxyId( cfg.getRemoteDownloadNetworkProxyId() ); - if (cfg.isDownloadRemoteIndex()) - { - try - { - remoteIndexFeature.setIndexUri( new URI( cfg.getRemoteIndexUrl( ) ) ); - } - catch ( URISyntaxException e ) - { - log.error( "Could not set remote index url " + cfg.getRemoteIndexUrl( ) ); - remoteIndexFeature.setDownloadRemoteIndex( false ); - remoteIndexFeature.setDownloadRemoteIndexOnStartup( false ); + repo.setTimeout(Duration.ofSeconds(cfg.getTimeout())); + RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get(); + remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex()); + remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup()); + remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout())); + remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId()); + if (cfg.isDownloadRemoteIndex()) { + try { + remoteIndexFeature.setIndexUri(new URI(cfg.getRemoteIndexUrl())); + } catch (URISyntaxException e) { + log.error("Could not set remote index url " + cfg.getRemoteIndexUrl()); + remoteIndexFeature.setDownloadRemoteIndex(false); + remoteIndexFeature.setDownloadRemoteIndexOnStartup(false); } } - repo.setExtraHeaders( cfg.getExtraHeaders() ); - repo.setExtraParameters( cfg.getExtraParameters() ); + repo.setExtraHeaders(cfg.getExtraHeaders()); + repo.setExtraParameters(cfg.getExtraParameters()); PasswordCredentials credentials = new PasswordCredentials("", new char[0]); - if (cfg.getPassword()!=null && cfg.getUsername()!=null) - { - credentials.setPassword( cfg.getPassword( ).toCharArray( ) ); - credentials.setUsername( cfg.getUsername() ); - repo.setCredentials( credentials ); + if (cfg.getPassword() != null && cfg.getUsername() != null) { + credentials.setPassword(cfg.getPassword().toCharArray()); + credentials.setUsername(cfg.getUsername()); + repo.setCredentials(credentials); } else { - credentials.setPassword( new char[0] ); + credentials.setPassword(new char[0]); } - if (cfg.getIndexDir()!=null) { - IndexCreationFeature indexCreationFeature = repo.getFeature( IndexCreationFeature.class ).get(); - indexCreationFeature.setIndexPath( getURIFromString( cfg.getIndexDir() ) ); + if (cfg.getIndexDir() != null) { + IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get(); + indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir())); } } @Override - public RemoteRepositoryConfiguration getRemoteConfiguration( RemoteRepository remoteRepository ) throws RepositoryException - { + public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException { if (!(remoteRepository instanceof MavenRemoteRepository)) { - log.error("Wrong remote repository type "+remoteRepository.getClass().getName()); - throw new RepositoryException( "The given repository type cannot be handled by the maven provider: "+remoteRepository.getClass().getName() ); + log.error("Wrong remote repository type " + remoteRepository.getClass().getName()); + throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName()); } RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration(); - cfg.setType( remoteRepository.getType().toString() ); - cfg.setId( remoteRepository.getId() ); - cfg.setName( remoteRepository.getName() ); - cfg.setDescription( remoteRepository.getDescription() ); + cfg.setType(remoteRepository.getType().toString()); + cfg.setId(remoteRepository.getId()); + cfg.setName(remoteRepository.getName()); + cfg.setDescription(remoteRepository.getDescription()); cfg.setUrl(remoteRepository.getLocation().toString()); - cfg.setTimeout( (int)remoteRepository.getTimeout().toMillis()/1000 ); - cfg.setCheckPath( remoteRepository.getCheckPath() ); - RepositoryCredentials creds = remoteRepository.getLoginCredentials( ); - if (creds!=null) - { + cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000); + cfg.setCheckPath(remoteRepository.getCheckPath()); + RepositoryCredentials creds = remoteRepository.getLoginCredentials(); + if (creds != null) { if (creds instanceof PasswordCredentials) { PasswordCredentials pCreds = (PasswordCredentials) creds; - cfg.setPassword( new String(pCreds.getPassword()) ); - cfg.setUsername( pCreds.getUsername() ); + cfg.setPassword(new String(pCreds.getPassword())); + cfg.setUsername(pCreds.getUsername()); } } - cfg.setLayout( remoteRepository.getLayout() ); - cfg.setExtraParameters( remoteRepository.getExtraParameters() ); - cfg.setExtraHeaders( remoteRepository.getExtraHeaders() ); - cfg.setRefreshCronExpression( remoteRepository.getSchedulingDefinition() ); - - IndexCreationFeature indexCreationFeature = remoteRepository.getFeature( IndexCreationFeature.class ).get(); - cfg.setIndexDir( convertUriToPath( indexCreationFeature.getIndexPath())); - - RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature( RemoteIndexFeature.class ).get(); - 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() ); + cfg.setLayout(remoteRepository.getLayout()); + cfg.setExtraParameters(remoteRepository.getExtraParameters()); + cfg.setExtraHeaders(remoteRepository.getExtraHeaders()); + cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition()); + IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get(); + cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath())); + RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get(); + 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()); return cfg; @@ -328,125 +297,104 @@ public class MavenRepositoryProvider implements RepositoryProvider } @Override - public ManagedRepositoryConfiguration getManagedConfiguration( ManagedRepository managedRepository ) throws RepositoryException - { + public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException { if (!(managedRepository instanceof MavenManagedRepository)) { - log.error("Wrong remote repository type "+managedRepository.getClass().getName()); - throw new RepositoryException( "The given repository type cannot be handled by the maven provider: "+managedRepository.getClass().getName() ); + log.error("Wrong remote repository type " + managedRepository.getClass().getName()); + throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + managedRepository.getClass().getName()); } ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration(); - cfg.setType( managedRepository.getType().toString() ); - cfg.setId( managedRepository.getId() ); - cfg.setName( managedRepository.getName() ); - cfg.setDescription( managedRepository.getDescription() ); - cfg.setLocation( convertUriToPath( managedRepository.getLocation() ) ); - cfg.setLayout( managedRepository.getLayout() ); - cfg.setRefreshCronExpression( managedRepository.getSchedulingDefinition() ); - cfg.setScanned( managedRepository.isScanned() ); - cfg.setBlockRedeployments( managedRepository.blocksRedeployments() ); - StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature( StagingRepositoryFeature.class ).get(); + cfg.setType(managedRepository.getType().toString()); + cfg.setId(managedRepository.getId()); + cfg.setName(managedRepository.getName()); + cfg.setDescription(managedRepository.getDescription()); + cfg.setLocation(convertUriToPath(managedRepository.getLocation())); + cfg.setLayout(managedRepository.getLayout()); + cfg.setRefreshCronExpression(managedRepository.getSchedulingDefinition()); + cfg.setScanned(managedRepository.isScanned()); + cfg.setBlockRedeployments(managedRepository.blocksRedeployments()); + StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature(StagingRepositoryFeature.class).get(); cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded()); - IndexCreationFeature indexCreationFeature = managedRepository.getFeature( IndexCreationFeature.class ).get(); - cfg.setIndexDir(convertUriToPath( indexCreationFeature.getIndexPath() )); - cfg.setSkipPackedIndexCreation( indexCreationFeature.isSkipPackedIndexCreation() ); + IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get(); + cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath())); + cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation()); - ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature( ArtifactCleanupFeature.class ).get(); - cfg.setRetentionCount( artifactCleanupFeature.getRetentionCount()); - cfg.setRetentionPeriod( artifactCleanupFeature.getRetentionPeriod().getDays() ); + ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class).get(); + cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount()); + cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays()); cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots()); - if (managedRepository.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE )) { - cfg.setReleases( true ); + if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) { + cfg.setReleases(true); } else { - cfg.setReleases( false ); + cfg.setReleases(false); } - if (managedRepository.getActiveReleaseSchemes().contains( ReleaseScheme.SNAPSHOT )) { - cfg.setSnapshots( true ); + if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)) { + cfg.setSnapshots(true); } else { - cfg.setSnapshots( false ); + cfg.setSnapshots(false); } return cfg; } - private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository ) - { + private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) { ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration(); - stagingRepository.setId( repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX ); - stagingRepository.setLayout( repository.getLayout() ); - stagingRepository.setName( repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX ); - stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() ); - stagingRepository.setRetentionPeriod( repository.getRetentionPeriod() ); - stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() ); - stagingRepository.setStageRepoNeeded( false ); + stagingRepository.setId(repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX); + stagingRepository.setLayout(repository.getLayout()); + stagingRepository.setName(repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX); + stagingRepository.setBlockRedeployments(repository.isBlockRedeployments()); + stagingRepository.setRetentionPeriod(repository.getRetentionPeriod()); + stagingRepository.setDeleteReleasedSnapshots(repository.isDeleteReleasedSnapshots()); + stagingRepository.setStageRepoNeeded(false); String path = repository.getLocation(); - int lastIndex = path.replace( '\\', '/' ).lastIndexOf( '/' ); - stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() ); + int lastIndex = path.replace('\\', '/').lastIndexOf('/'); + stagingRepository.setLocation(path.substring(0, lastIndex) + "/" + stagingRepository.getId()); - if ( StringUtils.isNotBlank( repository.getIndexDir() ) ) - { + if (StringUtils.isNotBlank(repository.getIndexDir())) { Path indexDir = null; - try - { - indexDir = Paths.get( new URI(repository.getIndexDir().startsWith( "file://" ) ? repository.getIndexDir() : "file://"+repository.getIndexDir()) ); - if ( indexDir.isAbsolute() ) - { - Path newDir = Paths.get(new URI(stagingRepository.getLocation().startsWith( "file://" ) ? stagingRepository.getLocation() : "file://"+stagingRepository.getLocation())).resolve(".index"); + try { + indexDir = Paths.get(new URI(repository.getIndexDir().startsWith("file://") ? repository.getIndexDir() : "file://" + repository.getIndexDir())); + if (indexDir.isAbsolute()) { + Path newDir = Paths.get(new URI(stagingRepository.getLocation().startsWith("file://") ? stagingRepository.getLocation() : "file://" + stagingRepository.getLocation())).resolve(".index"); log.debug("Changing index directory {} -> {}", indexDir, newDir); - stagingRepository.setIndexDir( newDir.toString() ); - } - else - { + stagingRepository.setIndexDir(newDir.toString()); + } else { log.debug("Keeping index directory {}", repository.getIndexDir()); - stagingRepository.setIndexDir( repository.getIndexDir() ); + stagingRepository.setIndexDir(repository.getIndexDir()); } - } - catch ( URISyntaxException e ) - { + } catch (URISyntaxException e) { log.error("Could not parse index path as uri {}", repository.getIndexDir()); - stagingRepository.setIndexDir( "" ); + stagingRepository.setIndexDir(""); } // in case of absolute dir do not use the same } - stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() ); - stagingRepository.setReleases( repository.isReleases() ); - stagingRepository.setRetentionCount( repository.getRetentionCount() ); - stagingRepository.setScanned( repository.isScanned() ); - stagingRepository.setSnapshots( repository.isSnapshots() ); - stagingRepository.setSkipPackedIndexCreation( repository.isSkipPackedIndexCreation() ); + stagingRepository.setRefreshCronExpression(repository.getRefreshCronExpression()); + stagingRepository.setReleases(repository.isReleases()); + stagingRepository.setRetentionCount(repository.getRetentionCount()); + stagingRepository.setScanned(repository.isScanned()); + stagingRepository.setSnapshots(repository.isSnapshots()); + stagingRepository.setSkipPackedIndexCreation(repository.isSkipPackedIndexCreation()); // do not duplicate description //stagingRepository.getDescription("") return stagingRepository; } - private void setBaseConfig( EditableRepository repo, AbstractRepositoryConfiguration cfg) throws RepositoryException { - String baseUriStr = archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().getRepositoryBaseDirectory(); - if (baseUriStr==null) { - baseUriStr = Paths.get(System.getProperty( "appserver.base" )).resolve("repositories").normalize().toString(); - } - try - { - URI baseUri = new URI(baseUriStr); - repo.setBaseUri( baseUri ); - } - catch ( URISyntaxException e ) - { - log.error("Could not set base URI {}: {}", baseUriStr, e.getMessage(), e); - throw new RepositoryException( "Could not set base URI "+ baseUriStr); - } - repo.setName( repo.getPrimaryLocale(), cfg.getName() ); - repo.setDescription( repo.getPrimaryLocale(), cfg.getDescription() ); - repo.setLayout( cfg.getLayout() ); + private void setBaseConfig(EditableRepository repo, AbstractRepositoryConfiguration cfg) throws RepositoryException { + + URI baseUri = archivaConfiguration.getRepositoryBaseDir().toUri(); + repo.setBaseUri(baseUri); + + repo.setName(repo.getPrimaryLocale(), cfg.getName()); + repo.setDescription(repo.getPrimaryLocale(), cfg.getDescription()); + repo.setLayout(cfg.getLayout()); } - public ArchivaConfiguration getArchivaConfiguration( ) - { + public ArchivaConfiguration getArchivaConfiguration() { return archivaConfiguration; } - public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) - { + public void setArchivaConfiguration(ArchivaConfiguration archivaConfiguration) { this.archivaConfiguration = archivaConfiguration; } } diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java index 1283f62f7..4a55180c6 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java @@ -2,6 +2,7 @@ package org.apache.archiva.configuration; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryListener; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import java.nio.file.Path; @@ -103,4 +104,23 @@ public class TestConfiguration return Paths.get(""); } } + + @Override + public Path getRepositoryBaseDir() { + return getDataDirectory().resolve("repositories"); + } + + @Override + public Path getRemoteRepositoryBaseDir() { + return getDataDirectory().resolve("remotes"); + } + + @Override + public Path getDataDirectory() { + if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) { + return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory()); + } else { + return getAppServerBaseDir().resolve("data"); + } + } } diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java index a8d783756..474d3dfe2 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java @@ -25,6 +25,7 @@ import org.apache.archiva.configuration.ConfigurationListener; import org.apache.archiva.redback.components.registry.Registry; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryListener; +import org.apache.commons.lang.StringUtils; import org.easymock.IMocksControl; import org.springframework.stereotype.Service; @@ -146,4 +147,24 @@ public class MockConfiguration return Paths.get(""); } } + + + @Override + public Path getRepositoryBaseDir() { + return getDataDirectory().resolve("repositories"); + } + + @Override + public Path getRemoteRepositoryBaseDir() { + return getDataDirectory().resolve("remotes"); + } + + @Override + public Path getDataDirectory() { + if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) { + return Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory()); + } else { + return getAppServerBaseDir().resolve("data"); + } + } } diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/AbstractRepositoryLayerTestCase.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/AbstractRepositoryLayerTestCase.java index 98091f3f4..56af25fc0 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/AbstractRepositoryLayerTestCase.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/AbstractRepositoryLayerTestCase.java @@ -34,6 +34,7 @@ import javax.inject.Inject; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Locale; /** @@ -53,14 +54,14 @@ public abstract class AbstractRepositoryLayerTestCase protected MavenManagedRepository createRepository( String id, String name, Path location ) { - MavenManagedRepository repo = new MavenManagedRepository( id, name); + MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent().toAbsolutePath()); repo.setLocation( location.toAbsolutePath().toUri() ); return repo; } protected MavenRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException { - MavenRemoteRepository repo = new MavenRemoteRepository(id, name); + MavenRemoteRepository repo = new MavenRemoteRepository(id, name, Paths.get("target/remotes")); repo.setLocation( new URI( url ) ); return repo; } @@ -69,7 +70,7 @@ public abstract class AbstractRepositoryLayerTestCase String layout ) throws Exception { - MavenManagedRepository repo = new MavenManagedRepository( id, name ); + MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent() ); repo.setLocation( location.toAbsolutePath().toUri() ); repo.setLayout( layout ); @@ -83,7 +84,7 @@ public abstract class AbstractRepositoryLayerTestCase protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout ) throws Exception { - MavenRemoteRepository repo = new MavenRemoteRepository(id, name); + MavenRemoteRepository repo = new MavenRemoteRepository(id, name, Paths.get("target/remotes")); repo.setLocation( new URI( url ) ); repo.setLayout( layout ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java index f918c1873..faf2ba241 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java @@ -515,7 +515,7 @@ public class RepositoryRequestTest String layout ) throws Exception { - MavenManagedRepository repo = new MavenManagedRepository( id, name); + MavenManagedRepository repo = new MavenManagedRepository( id, name, archivaConfiguration.getRepositoryBaseDir()); repo.setLocation( location.toAbsolutePath().toUri() ); repo.setLayout( layout ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java index 54810ce94..8731c7c5a 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java @@ -41,6 +41,7 @@ import org.junit.Test; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import java.time.Period; import java.time.temporal.ChronoUnit; @@ -213,7 +214,7 @@ public class MavenRepositoryProviderTest @Test public void getManagedConfiguration() throws Exception { - MavenManagedRepository repo = new MavenManagedRepository( "test01", "My Test repo" ); + MavenManagedRepository repo = new MavenManagedRepository( "test01", "My Test repo", Paths.get("target/repositories") ); repo.setLocation( new URI("file:///this.is/a/test") ); repo.setScanned( true ); @@ -258,7 +259,7 @@ public class MavenRepositoryProviderTest @Test public void getRemoteConfiguration() throws Exception { - MavenRemoteRepository repo = new MavenRemoteRepository( "test01", "My Test repo" ); + MavenRemoteRepository repo = new MavenRemoteRepository( "test01", "My Test repo", Paths.get("target/remotes") ); repo.setLocation( new URI("https://this.is/a/test") ); repo.setScanned( true ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/Maven2RepositoryStorageTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/Maven2RepositoryStorageTest.java index 92ea54ebf..ceb25db73 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/Maven2RepositoryStorageTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/Maven2RepositoryStorageTest.java @@ -30,6 +30,7 @@ import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import javax.inject.Named; +import java.nio.file.Paths; import java.util.Locale; /** @@ -48,17 +49,17 @@ public class Maven2RepositoryStorageTest { String href = "/repository/internal/org/apache/maven/someartifact.jar"; Assert.assertEquals( "/org/apache/maven/someartifact.jar", - repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01") ) ); + repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01", Paths.get("target/repositories")) ) ); href = "repository/internal/org/apache/maven/someartifact.jar"; Assert.assertEquals( "/org/apache/maven/someartifact.jar", - repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01" ) ) ); + repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01", Paths.get("target/repositories") ) ) ); href = "repository/internal/org/apache/maven/"; - Assert.assertEquals( "/org/apache/maven/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01") ) ); + Assert.assertEquals( "/org/apache/maven/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01", Paths.get("target/repositories")) ) ); href = "mypath"; - Assert.assertEquals( "/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01") ) ); + Assert.assertEquals( "/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01", Paths.get("target/repositories")) ) ); } diff --git a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java index 49cc241b2..40f1f8331 100644 --- a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java +++ b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java @@ -97,7 +97,7 @@ public class DuplicateArtifactsConsumerTest assertNotNull( consumer ); - config = new BasicManagedRepository(TEST_REPO, TEST_REPO); + config = new BasicManagedRepository(TEST_REPO, TEST_REPO, Paths.get("target")); config.setLocation( Paths.get( "target/test-repository" ).toAbsolutePath().toUri() ); metadataRepository = mock( MetadataRepository.class ); diff --git a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java index 0206edb9f..077edb9da 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java +++ b/archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java @@ -21,6 +21,7 @@ package org.apache.archiva.configuration; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryListener; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import java.nio.file.Path; @@ -103,4 +104,29 @@ public class StubConfiguration return Paths.get(""); } } + + @Override + public Path getRepositoryBaseDir() { + return getDataDirectory().resolve("repositories"); + } + + @Override + public Path getRemoteRepositoryBaseDir() { + return getDataDirectory().resolve("remotes"); + } + + @Override + public Path getDataDirectory() { + if (configuration!=null && StringUtils.isNotEmpty(configuration.getArchivaRuntimeConfiguration().getDataDirectory())) { + Path dataDir = Paths.get(configuration.getArchivaRuntimeConfiguration().getDataDirectory()); + if (dataDir.isAbsolute()) { + return dataDir; + } else { + return getAppServerBaseDir().resolve(dataDir); + } + } else { + return getAppServerBaseDir().resolve("data"); + } + + } } -- 2.39.5