aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-repository-admin
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-07-28 15:24:13 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-07-28 15:24:13 +0200
commitbb3b074aaf5a2be0d81c950ecf1588fe8efa3316 (patch)
tree8f165780e4d81cfdb6ed4a73c40fbed3a6f39a69 /archiva-modules/archiva-base/archiva-repository-admin
parent8e4acdc82a875ca32e39eb216b879c002d228de3 (diff)
downloadarchiva-bb3b074aaf5a2be0d81c950ecf1588fe8efa3316.tar.gz
archiva-bb3b074aaf5a2be0d81c950ecf1588fe8efa3316.zip
Refactoring to StorageAsset access
Diffstat (limited to 'archiva-modules/archiva-base/archiva-repository-admin')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java4
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java14
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java24
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java15
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java5
5 files changed, 39 insertions, 23 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java
index 8cef4f30b..e98e8321a 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/group/RepositoryGroupAdmin.java
@@ -21,8 +21,8 @@ package org.apache.archiva.admin.model.group;
import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.RepositoryGroup;
+import org.apache.archiva.repository.storage.StorageAsset;
-import java.nio.file.Path;
import java.util.List;
import java.util.Map;
@@ -75,5 +75,5 @@ public interface RepositoryGroupAdmin
Map<String, List<String>> getRepositoryToGroupMap()
throws RepositoryAdminException;
- Path getMergedIndexDirectory(String repositoryGroupId );
+ StorageAsset getMergedIndexDirectory(String repositoryGroupId );
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java
index 757aa12a8..39919a88e 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java
@@ -29,11 +29,11 @@ import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.metadata.model.facets.AuditEvent;
import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler;
-import org.apache.archiva.repository.EditableRepository;
import org.apache.archiva.repository.EditableRepositoryGroup;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.features.IndexCreationFeature;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,9 +47,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -112,9 +109,14 @@ public class DefaultRepositoryGroupAdmin
@Override
- public Path getMergedIndexDirectory( String repositoryGroupId )
+ public StorageAsset getMergedIndexDirectory(String repositoryGroupId )
{
- return groupsDirectory.resolve( repositoryGroupId );
+ org.apache.archiva.repository.RepositoryGroup group = repositoryRegistry.getRepositoryGroup(repositoryGroupId);
+ if (group!=null) {
+ return group.getFeature(IndexCreationFeature.class).get().getLocalIndexPath();
+ } else {
+ return null;
+ }
}
@Override
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java
index 064045de9..1bd7e4c10 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java
@@ -19,7 +19,7 @@ package org.apache.archiva.admin.mock;
* under the License.
*/
-import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.configuration.ArchivaConfiguration;
@@ -40,10 +40,12 @@ import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.UnsupportedRepositoryTypeException;
-import org.apache.archiva.repository.content.FilesystemAsset;
-import org.apache.archiva.repository.content.StorageAsset;
+import org.apache.archiva.repository.storage.FilesystemAsset;
+import org.apache.archiva.repository.storage.FilesystemStorage;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.features.IndexCreationFeature;
import org.apache.archiva.repository.features.RemoteIndexFeature;
+import org.apache.archiva.repository.storage.StorageUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactContextProducer;
@@ -143,7 +145,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
private Path getIndexPath( ArchivaIndexingContext ctx )
{
- return PathUtil.getPathFromUri( ctx.getPath( ) );
+ return ctx.getPath( ).getFilePath();
}
@FunctionalInterface
@@ -378,9 +380,9 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
@Override
public void addArtifactsToIndex( final ArchivaIndexingContext context, final Collection<URI> artifactReference ) throws IndexUpdateFailedException
{
- final URI ctxUri = context.getPath();
+ final StorageAsset ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
- Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
+ Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.getFilePath().toUri().resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.addArtifactsToIndex(artifacts, indexingContext);
} catch (IOException e) {
@@ -394,9 +396,9 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
@Override
public void removeArtifactsFromIndex( ArchivaIndexingContext context, Collection<URI> artifactReference ) throws IndexUpdateFailedException
{
- final URI ctxUri = context.getPath();
+ final StorageAsset ctxUri = context.getPath();
executeUpdateFunction(context, indexingContext -> {
- Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
+ Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.getFilePath().toUri().resolve(r)).toFile())).collect(Collectors.toList());
try {
indexer.deleteArtifactsFromIndex(artifacts, indexingContext);
} catch (IOException e) {
@@ -455,7 +457,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
log.warn("Index close failed");
}
try {
- FileUtils.deleteDirectory(Paths.get(context.getPath()));
+ StorageUtil.deleteRecursively(context.getPath());
} catch (IOException e) {
throw new IndexUpdateFailedException("Could not delete index files");
}
@@ -530,6 +532,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
URI indexDir = icf.getIndexPath();
String indexPath = indexDir.getPath();
Path indexDirectory = null;
+ FilesystemStorage filesystemStorage = (FilesystemStorage) repo.getAsset("").getStorage();
if ( ! StringUtils.isEmpty(indexDir.toString( ) ) )
{
@@ -538,6 +541,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
if ( indexDirectory.isAbsolute( ) )
{
indexPath = indexDirectory.getFileName().toString();
+ filesystemStorage = new FilesystemStorage(indexDirectory.getParent(), new DefaultFileLockManager());
}
else
{
@@ -554,7 +558,7 @@ public class ArchivaIndexManagerMock implements ArchivaIndexManager {
{
Files.createDirectories( indexDirectory );
}
- return new FilesystemAsset( indexPath, indexDirectory);
+ return new FilesystemAsset( filesystemStorage, indexPath, indexDirectory);
}
private IndexingContext createRemoteContext(RemoteRepository remoteRepository ) throws IOException
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java
index 3bed60293..4b4528bc8 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MavenIndexContextMock.java
@@ -19,8 +19,12 @@ package org.apache.archiva.admin.mock;
* under the License.
*/
+import org.apache.archiva.common.filelock.DefaultFileLockManager;
import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.repository.Repository;
+import org.apache.archiva.repository.storage.FilesystemAsset;
+import org.apache.archiva.repository.storage.FilesystemStorage;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.maven.index.context.IndexingContext;
import java.io.IOException;
@@ -38,10 +42,16 @@ public class MavenIndexContextMock implements ArchivaIndexingContext {
private IndexingContext delegate;
private Repository repository;
+ private FilesystemStorage filesystemStorage;
MavenIndexContextMock(Repository repository, IndexingContext delegate) {
this.delegate = delegate;
this.repository = repository;
+ try {
+ this.filesystemStorage = new FilesystemStorage(delegate.getIndexDirectoryFile().toPath(), new DefaultFileLockManager());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
@@ -56,8 +66,9 @@ public class MavenIndexContextMock implements ArchivaIndexingContext {
}
@Override
- public URI getPath() {
- return delegate.getIndexDirectoryFile().toURI();
+ public StorageAsset getPath() {
+ return
+ new FilesystemAsset(filesystemStorage, "", delegate.getIndexDirectoryFile().toPath());
}
@Override
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java
index 4cb8ca78d..6222e7c51 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockMergedRemoteIndexesScheduler.java
@@ -21,10 +21,9 @@ package org.apache.archiva.admin.mock;
import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler;
import org.apache.archiva.repository.RepositoryGroup;
+import org.apache.archiva.repository.storage.StorageAsset;
import org.springframework.stereotype.Service;
-import java.nio.file.Path;
-
/**
* @author Olivier Lamy
*/
@@ -34,7 +33,7 @@ public class MockMergedRemoteIndexesScheduler
{
@Override
- public void schedule( RepositoryGroup repositoryGroup, Path directory )
+ public void schedule(RepositoryGroup repositoryGroup, StorageAsset directory )
{
// no op
}