diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-07-11 23:28:01 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-07-11 23:28:01 +0200 |
commit | 830ea54e0c64bb5c7fe5b2006c171ebd2625e287 (patch) | |
tree | c6e65a81b5e92e6aa2f662398e1f32de5c7e8875 /archiva-modules/archiva-maven | |
parent | 38b10a09f4c91ba6249baf95b1e4f487cb80ac79 (diff) | |
download | archiva-830ea54e0c64bb5c7fe5b2006c171ebd2625e287.tar.gz archiva-830ea54e0c64bb5c7fe5b2006c171ebd2625e287.zip |
Moving storage api to repository level
Diffstat (limited to 'archiva-modules/archiva-maven')
16 files changed, 167 insertions, 163 deletions
diff --git a/archiva-modules/archiva-maven/archiva-maven-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java b/archiva-modules/archiva-maven/archiva-maven-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java index 209fa8f99..25a3f9d64 100644 --- a/archiva-modules/archiva-maven/archiva-maven-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java +++ b/archiva-modules/archiva-maven/archiva-maven-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java @@ -99,7 +99,7 @@ public class DefaultLegacyRepositoryConverter { String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory ); - BasicManagedRepository legacyRepository = new BasicManagedRepository( "legacy", "Legacy Repository", repositoryDirectory.getParent()); + BasicManagedRepository legacyRepository = BasicManagedRepository.newFilesystemInstance( "legacy", "Legacy Repository", repositoryDirectory.getParent()); legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() ); legacyRepository.setLayout( "legacy" ); DefaultFileLockManager lockManager = new DefaultFileLockManager(); diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java index 71363dc33..ae512f14d 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/indexer/maven/MavenIndexManagerTest.java @@ -183,8 +183,8 @@ public class MavenIndexManagerTest { private ArchivaIndexingContext createTestContext() throws URISyntaxException, IndexCreationFailedException, IOException { indexPath = Paths.get("target/repositories/test-repo/.index-test"); FileUtils.deleteDirectory(indexPath); - repository = new MavenManagedRepository("test-repo", "Test Repo", Paths.get("target/repositories")); - repository.setLocation(new URI("test-repo")); + repository = MavenManagedRepository.newLocalInstance("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")); ctx = mavenIndexManager.createContext(repository); @@ -194,7 +194,7 @@ public class MavenIndexManagerTest { private ArchivaIndexingContext createTestContextForRemote() throws URISyntaxException, IndexCreationFailedException, IOException { indexPath = Paths.get("target/repositories/test-repo/.index-test"); Path repoPath = Paths.get("target/repositories").toAbsolutePath(); - repositoryRemote = new MavenRemoteRepository("test-repo", "Test Repo", repoPath); + repositoryRemote = MavenRemoteRepository.newLocalInstance("test-repo", "Test Repo", repoPath); repositoryRemote.setLocation(repoPath.resolve("test-repo").toUri()); RemoteIndexFeature icf = repositoryRemote.getFeature(RemoteIndexFeature.class).get(); icf.setIndexUri(new URI(".index-test")); diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java index 30f780c70..7e53c1d7d 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java @@ -319,7 +319,7 @@ public abstract class AbstractProxyTestCase protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout ) throws Exception { - ManagedRepository repo = new BasicManagedRepository(id, name, Paths.get(path)); + ManagedRepository repo = BasicManagedRepository.newFilesystemInstance(id, name, Paths.get(path)); repositoryRegistry.putRepository(repo); return repositoryRegistry.getManagedRepository(id).getContent(); } diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java index c3d7c1108..5d2c93b4f 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java @@ -94,7 +94,7 @@ public class HttpProxyTransferTest protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout ) throws Exception { - ManagedRepository repo = new BasicManagedRepository(id, name, Paths.get(path)); + ManagedRepository repo = BasicManagedRepository.newFilesystemInstance(id, name, Paths.get(path)); repositoryRegistry.putRepository(repo); return repositoryRegistry.getManagedRepository(id).getContent(); } diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java index 376bc00bb..2f10b16b5 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java @@ -389,33 +389,4 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return null; } - @Override - public StorageAsset getAsset(String path) { - return null; - } - - @Override - public void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException { - - } - - @Override - public StorageAsset addAsset(String path, boolean container) { - return null; - } - - @Override - public void removeAsset(StorageAsset asset) throws IOException { - - } - - @Override - public StorageAsset moveAsset(StorageAsset origin, String destination) throws IOException { - return null; - } - - @Override - public StorageAsset copyAsset(StorageAsset origin, String destination) throws IOException { - return null; - } } diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java index cae8337b3..747f64e30 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java @@ -43,6 +43,7 @@ import org.apache.archiva.repository.features.RemoteIndexFeature; import org.apache.archiva.repository.features.StagingRepositoryFeature; import org.springframework.stereotype.Service; +import java.io.IOException; import java.net.URI; import java.nio.file.Paths; import java.time.Duration; @@ -72,15 +73,18 @@ public class RepositoryProviderMock implements RepositoryProvider } @Override - public EditableManagedRepository createManagedInstance( String id, String name ) - { - return new BasicManagedRepository( id, name , Paths.get("target/repositories")); + public EditableManagedRepository createManagedInstance( String id, String name ) throws IOException { + return BasicManagedRepository.newFilesystemInstance( id, name , Paths.get("target/repositories")); } @Override public EditableRemoteRepository createRemoteInstance( String id, String name ) { - return new BasicRemoteRepository( id, name, Paths.get("target/remotes") ); + try { + return BasicRemoteRepository.newFilesystemInstance( id, name, Paths.get("target/remotes") ); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override @@ -92,7 +96,12 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public ManagedRepository createManagedInstance( ManagedRepositoryConfiguration configuration ) throws RepositoryException { - BasicManagedRepository managedRepository = new BasicManagedRepository( configuration.getId( ), configuration.getName( ) , Paths.get("target/repositories")); + BasicManagedRepository managedRepository = null; + try { + managedRepository = BasicManagedRepository.newFilesystemInstance( configuration.getId( ), configuration.getName( ) , Paths.get("target/repositories")); + } catch (IOException e) { + throw new RepositoryException(e); + } updateManagedInstance( managedRepository, configuration ); return managedRepository; } @@ -139,7 +148,12 @@ 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( ), Paths.get("target/repositories") ); + BasicManagedRepository managedRepository = null; + try { + managedRepository = BasicManagedRepository.newFilesystemInstance( id, configuration.getName( ), Paths.get("target/repositories") ); + } catch (IOException e) { + throw new RepositoryException(e); + } updateManagedInstance( managedRepository, configuration ); return managedRepository; } @@ -147,7 +161,12 @@ public class RepositoryProviderMock implements RepositoryProvider @Override public RemoteRepository createRemoteInstance( RemoteRepositoryConfiguration configuration ) throws RepositoryException { - BasicRemoteRepository remoteRepository = new BasicRemoteRepository( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); + BasicRemoteRepository remoteRepository = null; + try { + remoteRepository = BasicRemoteRepository.newFilesystemInstance( configuration.getId( ), configuration.getName( ), Paths.get("target/remotes") ); + } catch (IOException e) { + throw new RepositoryException(e); + } updateRemoteInstance( remoteRepository, configuration ); return remoteRepository; } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java index e76b92c55..01e429e6d 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java @@ -67,8 +67,6 @@ public class ManagedDefaultRepositoryContent implements ManagedRepositoryContent { - private FilesystemStorage storage; - private FileTypes filetypes; public void setFileTypes(FileTypes fileTypes) { @@ -421,13 +419,6 @@ public class ManagedDefaultRepositoryContent if (repository instanceof EditableManagedRepository) { ((EditableManagedRepository) repository).setContent(this); } - final Path repositoryDir = getRepoDir(); - try { - storage = new FilesystemStorage(repositoryDir, this.lockManager); - } catch (IOException e) { - log.error("Could not initialize the filesystem storage to repository {}: {}", repositoryDir, e.getMessage(), e); - throw new RuntimeException("Fatal error. Could not initialize the filesystem storage for "+repositoryDir+": "+e.getMessage()); - } } } @@ -545,42 +536,4 @@ public class ManagedDefaultRepositoryContent } - @Override - public void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ) throws IOException - { - storage.consumeData(asset, consumerFunction, readLock); - } - - - @Override - public StorageAsset getAsset( String path ) - { - return storage.getAsset(path); - } - - @Override - public StorageAsset addAsset( String path, boolean container ) - { - return storage.addAsset(path, container); - } - - @Override - public void removeAsset( StorageAsset asset ) throws IOException - { - storage.removeAsset(asset); - } - - @Override - public StorageAsset moveAsset( StorageAsset origin, String destination ) throws IOException - { - return storage.moveAsset(origin, destination); - } - - @Override - public StorageAsset copyAsset( StorageAsset origin, String destination ) throws IOException - { - return storage.copyAsset(origin, destination); - } - - } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java index be4756b42..026990e87 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java @@ -19,8 +19,12 @@ package org.apache.archiva.repository.maven2; * under the License. */ +import org.apache.archiva.common.filelock.DefaultFileLockManager; +import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.utils.PathUtil; import org.apache.archiva.repository.*; +import org.apache.archiva.repository.content.FilesystemStorage; +import org.apache.archiva.repository.content.RepositoryStorage; import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo; import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.features.IndexCreationFeature; @@ -65,17 +69,18 @@ public class MavenManagedRepository extends AbstractManagedRepository false ); - public MavenManagedRepository( String id, String name, Path basePath ) + public MavenManagedRepository(String id, String name, FilesystemStorage storage) { - super( RepositoryType.MAVEN, id, name, basePath); + + super( RepositoryType.MAVEN, id, name, storage); this.indexCreationFeature = new IndexCreationFeature(this, this); - setLocation(basePath.resolve(id).toUri()); + setLocation(storage.getAsset("").getFilePath().toUri()); } - public MavenManagedRepository( Locale primaryLocale, String id, String name, Path basePath ) + public MavenManagedRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage ) { - super( primaryLocale, RepositoryType.MAVEN, id, name, basePath ); - setLocation(basePath.resolve(id).toUri()); + super( primaryLocale, RepositoryType.MAVEN, id, name, storage ); + setLocation(storage.getAsset("").getFilePath().toUri()); } @Override @@ -121,22 +126,44 @@ public class MavenManagedRepository extends AbstractManagedRepository @Override public void setLocation( URI location ) { - super.setLocation( location ); + URI previousLocation = super.getLocation(); + Path previousLoc = PathUtil.getPathFromUri(previousLocation); Path newLoc = PathUtil.getPathFromUri( location ); - if (!Files.exists( newLoc )) { - try - { - Files.createDirectories( newLoc ); + if (!newLoc.toAbsolutePath().equals(previousLoc.toAbsolutePath())) { + super.setLocation(location); + if (!Files.exists(newLoc)) { + try { + Files.createDirectories(newLoc); + } catch (IOException e) { + log.error("Could not create directory {}", location, e); + } } - catch ( IOException e ) - { - log.error("Could not create directory {}",location, e); + FilesystemStorage previous = (FilesystemStorage) getStorage(); + try { + FilesystemStorage fs = new FilesystemStorage(newLoc, previous.getFileLockManager()); + setStorage(fs); + } catch (IOException e) { + log.error("Could not create new filesystem storage at {}", newLoc); + try { + Path tmpDir = Files.createTempDirectory("tmp-repo-"+getId()); + FilesystemStorage fs = new FilesystemStorage(tmpDir, previous.getFileLockManager()); + setStorage(fs); + } catch (IOException ex) { + throw new RuntimeException("Could not setup storage for repository "+getId()); + } } } + } @Override public RepositoryRequestInfo getRequestInfo() { return new MavenRepositoryRequestInfo(this); } + + public static MavenManagedRepository newLocalInstance(String id, String name, Path basePath) throws IOException { + FileLockManager lockManager = new DefaultFileLockManager(); + FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); + return new MavenManagedRepository(id, name, storage); + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java index 1933554ac..f3380c0ec 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRemoteRepository.java @@ -1,5 +1,7 @@ package org.apache.archiva.repository.maven2; +import org.apache.archiva.common.filelock.DefaultFileLockManager; +import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.repository.AbstractRemoteRepository; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RemoteRepository; @@ -7,12 +9,14 @@ import org.apache.archiva.repository.RepositoryCapabilities; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.StandardCapabilities; import org.apache.archiva.repository.UnsupportedFeatureException; +import org.apache.archiva.repository.content.FilesystemStorage; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; import org.apache.archiva.repository.features.RepositoryFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.nio.file.Path; import java.util.Locale; @@ -59,16 +63,16 @@ public class MavenRemoteRepository extends AbstractRemoteRepository false ); - public MavenRemoteRepository( String id, String name, Path basePath ) + public MavenRemoteRepository(String id, String name, FilesystemStorage storage) { - super( RepositoryType.MAVEN, id, name, basePath ); + super( RepositoryType.MAVEN, id, name, storage ); this.indexCreationFeature = new IndexCreationFeature(this, this); } - public MavenRemoteRepository( Locale primaryLocale, String id, String name, Path basePath ) + public MavenRemoteRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage ) { - super( primaryLocale, RepositoryType.MAVEN, id, name, basePath ); + super( primaryLocale, RepositoryType.MAVEN, id, name, storage ); this.indexCreationFeature = new IndexCreationFeature(this, this); } @@ -111,4 +115,10 @@ public class MavenRemoteRepository extends AbstractRemoteRepository public String toString() { return super.toString()+", remoteIndexFeature="+remoteIndexFeature.toString()+", indexCreationFeature="+indexCreationFeature.toString(); } + + public static MavenRemoteRepository newLocalInstance(String id, String name, Path basePath) throws IOException { + FileLockManager lockManager = new DefaultFileLockManager(); + FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); + return new MavenRemoteRepository(id, name, storage); + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java index 094d18275..56e65a2bd 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryGroup.java @@ -19,6 +19,7 @@ package org.apache.archiva.repository.maven2; * under the License. */ +import org.apache.archiva.common.filelock.DefaultFileLockManager; import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.repository.*; import org.apache.archiva.repository.content.FilesystemStorage; @@ -47,41 +48,32 @@ public class MavenRepositoryGroup extends AbstractRepositoryGroup implements Edi private final Logger log = LoggerFactory.getLogger(MavenRepositoryGroup.class); - private FileLockManager lockManager; - private FilesystemStorage fsStorage; private IndexCreationFeature indexCreationFeature; - public MavenRepositoryGroup(String id, String name, Path repositoryBase, FileLockManager lockManager) { - super(RepositoryType.MAVEN, id, name, repositoryBase); - this.lockManager = lockManager; + public MavenRepositoryGroup(String id, String name, FilesystemStorage storage) { + super(RepositoryType.MAVEN, id, name, storage); init(); } - public MavenRepositoryGroup(Locale primaryLocale, String id, String name, Path repositoryBase, FileLockManager lockManager) { - super(primaryLocale, RepositoryType.MAVEN, id, name, repositoryBase); - this.lockManager = lockManager; + public MavenRepositoryGroup(Locale primaryLocale, String id, String name, FilesystemStorage storage) { + super(primaryLocale, RepositoryType.MAVEN, id, name, storage); init(); } private Path getRepositoryPath() { - return getRepositoryBase().resolve(getId()); + return getStorage().getAsset("").getFilePath(); } private void init() { setCapabilities(CAPABILITIES); - try { - Path repoPath = getRepositoryPath(); - if (!Files.exists(repoPath)) { - Files.createDirectories(repoPath); - } - fsStorage = new FilesystemStorage(getRepositoryPath(), lockManager); - } catch (IOException e) { - log.error("IOException while initializing repository group with path {}",getRepositoryBase()); - throw new RuntimeException("Fatal error while accessing repository path "+ getRepositoryBase(), e); - } - setStorage(fsStorage); this.indexCreationFeature = new IndexCreationFeature(this, this); addFeature( this.indexCreationFeature ); } + + public static MavenRepositoryGroup newLocalInstance(String id, String name, Path basePath) throws IOException { + FileLockManager lockManager = new DefaultFileLockManager(); + FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); + return new MavenRepositoryGroup(id, name, storage); + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java index 211c2e720..ee21a79f6 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java @@ -23,6 +23,7 @@ import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.configuration.*; import org.apache.archiva.repository.*; import org.apache.archiva.repository.content.FilesystemAsset; +import org.apache.archiva.repository.content.FilesystemStorage; import org.apache.archiva.repository.features.ArtifactCleanupFeature; import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.RemoteIndexFeature; @@ -76,18 +77,51 @@ public class MavenRepositoryProvider implements RepositoryProvider { } @Override - public EditableManagedRepository createManagedInstance(String id, String name) { - return new MavenManagedRepository(id, name, archivaConfiguration.getRepositoryBaseDir()); + public MavenManagedRepository createManagedInstance(String id, String name) { + return createManagedInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir()); + } + + public MavenManagedRepository createManagedInstance(String id, String name, Path baseDir) { + FilesystemStorage storage = null; + try { + storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager); + } catch (IOException e) { + log.error("Could not initialize fileystem for repository {}", id); + throw new RuntimeException(e); + } + return new MavenManagedRepository(id, name, storage); } @Override - public EditableRemoteRepository createRemoteInstance(String id, String name) { - return new MavenRemoteRepository(id, name, archivaConfiguration.getRemoteRepositoryBaseDir()); + public MavenRemoteRepository createRemoteInstance(String id, String name) { + return createRemoteInstance(id, name, archivaConfiguration.getRemoteRepositoryBaseDir()); + } + + public MavenRemoteRepository createRemoteInstance(String id, String name, Path baseDir) { + FilesystemStorage storage = null; + try { + storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager); + } catch (IOException e) { + log.error("Could not initialize fileystem for repository {}", id); + throw new RuntimeException(e); + } + return new MavenRemoteRepository(id, name, storage); } @Override public EditableRepositoryGroup createRepositoryGroup(String id, String name) { - return new MavenRepositoryGroup(id, name, archivaConfiguration.getRepositoryBaseDir(), fileLockManager); + return createRepositoryGroup(id, name, archivaConfiguration.getRepositoryBaseDir()); + } + + public MavenRepositoryGroup createRepositoryGroup(String id, String name, Path baseDir) { + FilesystemStorage storage = null; + try { + storage = new FilesystemStorage(baseDir.resolve(id), fileLockManager); + } catch (IOException e) { + log.error("Could not initialize fileystem for repository {}", id); + throw new RuntimeException(e); + } + return new MavenRepositoryGroup(id, name, storage); } private URI getURIFromString(String uriStr) throws RepositoryException { @@ -121,7 +155,7 @@ public class MavenRepositoryProvider implements RepositoryProvider { @Override public ManagedRepository createManagedInstance(ManagedRepositoryConfiguration cfg) throws RepositoryException { - MavenManagedRepository repo = new MavenManagedRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRepositoryBaseDir()); + MavenManagedRepository repo = createManagedInstance(cfg.getId(), cfg.getName(), Paths.get(cfg.getLocation()).getParent()); updateManagedInstance(repo, cfg); return repo; } @@ -181,7 +215,7 @@ public class MavenRepositoryProvider implements RepositoryProvider { @Override public RemoteRepository createRemoteInstance(RemoteRepositoryConfiguration cfg) throws RepositoryException { - MavenRemoteRepository repo = new MavenRemoteRepository(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir()); + MavenRemoteRepository repo = createRemoteInstance(cfg.getId(), cfg.getName(), archivaConfiguration.getRemoteRepositoryBaseDir()); updateRemoteInstance(repo, cfg); return repo; } @@ -249,8 +283,8 @@ public class MavenRepositoryProvider implements RepositoryProvider { @Override public RepositoryGroup createRepositoryGroup(RepositoryGroupConfiguration configuration) throws RepositoryException { Path repositoryGroupBase = getArchivaConfiguration().getRepositoryGroupBaseDir(); - MavenRepositoryGroup newGrp = new MavenRepositoryGroup(configuration.getId(), configuration.getName(), - repositoryGroupBase, fileLockManager); + MavenRepositoryGroup newGrp = createRepositoryGroup(configuration.getId(), configuration.getName(), + repositoryGroupBase); updateRepositoryGroupInstance(newGrp, configuration); return newGrp; } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/AbstractRepositoryLayerTestCase.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/AbstractRepositoryLayerTestCase.java index 0c2fdbd78..2dce57074 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/AbstractRepositoryLayerTestCase.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/AbstractRepositoryLayerTestCase.java @@ -29,6 +29,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Path; @@ -49,16 +50,14 @@ public abstract class AbstractRepositoryLayerTestCase @Inject protected ApplicationContext applicationContext; - protected MavenManagedRepository createRepository( String id, String name, Path location ) - { - MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent().toAbsolutePath()); + protected MavenManagedRepository createRepository( String id, String name, Path location ) throws IOException { + MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( 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, Paths.get("target/remotes")); + protected MavenRemoteRepository createRemoteRepository( String id, String name, String url ) throws URISyntaxException, IOException { + MavenRemoteRepository repo = MavenRemoteRepository.newLocalInstance(id, name, Paths.get("target/remotes")); repo.setLocation( new URI( url ) ); return repo; } @@ -67,7 +66,7 @@ public abstract class AbstractRepositoryLayerTestCase String layout ) throws Exception { - MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent() ); + MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, location.getParent() ); repo.setLocation( location.toAbsolutePath().toUri() ); repo.setLayout( layout ); @@ -81,7 +80,7 @@ public abstract class AbstractRepositoryLayerTestCase protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout ) throws Exception { - MavenRemoteRepository repo = new MavenRemoteRepository(id, name, Paths.get("target/remotes")); + MavenRemoteRepository repo = MavenRemoteRepository.newLocalInstance(id, name, Paths.get("target/remotes")); repo.setLocation( new URI( url ) ); repo.setLayout( layout ); diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java index 783970784..85ed97d6e 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/content/maven2/MavenRepositoryRequestInfoTest.java @@ -40,6 +40,7 @@ import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import javax.inject.Named; +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; @@ -74,9 +75,8 @@ public class MavenRepositoryRequestInfoTest private MavenRepositoryRequestInfo repoRequest; - protected MavenManagedRepository createRepository( String id, String name, Path location ) - { - MavenManagedRepository repo = new MavenManagedRepository( id, name, location.getParent().toAbsolutePath()); + protected MavenManagedRepository createRepository( String id, String name, Path location ) throws IOException { + MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, location.getParent().toAbsolutePath()); repo.setLocation( location.toAbsolutePath().toUri() ); return repo; } @@ -549,7 +549,7 @@ public class MavenRepositoryRequestInfoTest String layout ) throws Exception { - MavenManagedRepository repo = new MavenManagedRepository( id, name, archivaConfiguration.getRepositoryBaseDir()); + MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, archivaConfiguration.getRepositoryBaseDir()); repo.setLocation( location.toAbsolutePath().toUri() ); repo.setLayout( layout ); diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java index 39396d6d5..3fa8cfa33 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java @@ -36,6 +36,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Files; @@ -217,7 +218,7 @@ public class MavenRepositoryProviderTest @Test public void getManagedConfiguration() throws Exception { - MavenManagedRepository repo = new MavenManagedRepository( "test01", "My Test repo", Paths.get("target/repositories") ); + MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( "test01", "My Test repo", Paths.get("target/repositories") ); repo.setLocation( new URI("file:///this.is/a/test") ); repo.setScanned( true ); @@ -262,7 +263,7 @@ public class MavenRepositoryProviderTest @Test public void getRemoteConfiguration() throws Exception { - MavenRemoteRepository repo = new MavenRemoteRepository( "test01", "My Test repo", Paths.get("target/remotes") ); + MavenRemoteRepository repo = MavenRemoteRepository.newLocalInstance( "test01", "My Test repo", Paths.get("target/remotes") ); repo.setLocation( new URI("https://this.is/a/test") ); repo.setScanned( true ); @@ -296,12 +297,10 @@ public class MavenRepositoryProviderTest } @Test - public void getRepositoryGroupConfiguration() throws RepositoryException, URISyntaxException - { - MavenRepositoryGroup repositoryGroup = new MavenRepositoryGroup("group1","group1",Paths.get("target/groups"), - new DefaultFileLockManager()); - MavenManagedRepository repo1 = new MavenManagedRepository( "test01", "My Test repo", Paths.get("target/repositories") ); - MavenManagedRepository repo2 = new MavenManagedRepository( "test02", "My Test repo", Paths.get("target/repositories") ); + public void getRepositoryGroupConfiguration() throws RepositoryException, URISyntaxException, IOException { + MavenRepositoryGroup repositoryGroup = MavenRepositoryGroup.newLocalInstance("group1","group1",Paths.get("target/groups")); + MavenManagedRepository repo1 = MavenManagedRepository.newLocalInstance( "test01", "My Test repo", Paths.get("target/repositories") ); + MavenManagedRepository repo2 = MavenManagedRepository.newLocalInstance( "test02", "My Test repo", Paths.get("target/repositories") ); repositoryGroup.setDescription(repositoryGroup.getPrimaryLocale(), "Repository group"); diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/metadata/Maven2RepositoryStorageTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/metadata/Maven2RepositoryStorageTest.java index dd4ecd91c..2adc0fc06 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/metadata/Maven2RepositoryStorageTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/metadata/Maven2RepositoryStorageTest.java @@ -29,6 +29,7 @@ import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import javax.inject.Named; +import java.io.IOException; import java.nio.file.Paths; /** @@ -43,21 +44,20 @@ public class Maven2RepositoryStorageTest RepositoryStorage repositoryStorage; @Test - public void testGetLogicalPath() - { + public void testGetLogicalPath() throws IOException { String href = "/repository/internal/org/apache/maven/someartifact.jar"; Assert.assertEquals( "/org/apache/maven/someartifact.jar", - repositoryStorage.getFilePath( href, new MavenManagedRepository( "repo01", "repo01", Paths.get("target/repositories")) ) ); + repositoryStorage.getFilePath( href, MavenManagedRepository.newLocalInstance( "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", Paths.get("target/repositories") ) ) ); + repositoryStorage.getFilePath( href, MavenManagedRepository.newLocalInstance( "repo01", "repo01", Paths.get("target/repositories") ) ) ); href = "repository/internal/org/apache/maven/"; - Assert.assertEquals( "/org/apache/maven/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01", Paths.get("target/repositories")) ) ); + Assert.assertEquals( "/org/apache/maven/", repositoryStorage.getFilePath( href, MavenManagedRepository.newLocalInstance("repo01", "repo01", Paths.get("target/repositories")) ) ); href = "mypath"; - Assert.assertEquals( "/", repositoryStorage.getFilePath( href, new MavenManagedRepository("repo01", "repo01", Paths.get("target/repositories")) ) ); + Assert.assertEquals( "/", repositoryStorage.getFilePath( href, MavenManagedRepository.newLocalInstance("repo01", "repo01", Paths.get("target/repositories")) ) ); } diff --git a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java index a8ace80c1..80f70ac42 100644 --- a/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-scheduler/src/test/java/org/apache/archiva/scheduler/indexing/maven/ArchivaIndexingTaskExecutorTest.java @@ -89,7 +89,7 @@ public class ArchivaIndexingTaskExecutorTest super.setUp(); Path baseDir = Paths.get(System.getProperty("basedir"), "target/test-classes").toAbsolutePath(); - BasicManagedRepository repositoryConfig = new BasicManagedRepository( "test-repo", "Test Repository", baseDir); + BasicManagedRepository repositoryConfig = BasicManagedRepository.newFilesystemInstance( "test-repo", "Test Repository", baseDir); Path repoLocation = baseDir.resolve("test-repo" ); repositoryConfig.setLocation(repoLocation.toUri() ); repositoryConfig.setLayout( "default" ); |