From 7c0b0387a3a53d8ce2677092f02046e39103be60 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 21 Apr 2020 18:40:17 +0200 Subject: [PATCH] Removing API methods for repository content --- .../repository/ManagedRepositoryContent.java | 49 ------------- .../mock/ManagedRepositoryContentMock.java | 18 ----- .../mock/ManagedRepositoryContentMock.java | 18 ----- .../mock/ManagedRepositoryContentMock.java | 18 ----- .../ManagedDefaultRepositoryContent.java | 69 ------------------- .../services/DefaultRepositoriesService.java | 25 ++++++- 6 files changed, 22 insertions(+), 175 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java index 08e91d461..3ba9fddb8 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java @@ -312,19 +312,6 @@ public interface ManagedRepositoryContent extends RepositoryContent */ VersionedReference toVersion( ArtifactReference artifactReference); - /** - * Returns a artifact reference for the given coordinates. - * @param groupId the group id - * @param artifactId the artifact id - * @param version the version - * @param type the type - * @param classifier the classifier - * @return a artifact reference object - */ - ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier); - - - /** * Delete from the managed repository all files / directories associated with the @@ -391,26 +378,6 @@ public interface ManagedRepositoryContent extends RepositoryContent */ String getId(); - /** - *

- * Gather up the list of related artifacts to the ArtifactReference provided. - * If type and / or classifier of the reference is set, this returns only a list of artifacts that is directly - * related to the given artifact, like checksums. - * If type and classifier is null it will return the same artifacts as - * {@link #getRelatedArtifacts(VersionedReference)} - *

- *

- * NOTE: Some layouts (such as maven 1 "legacy") are not compatible with this query. - *

- * - * @param reference the reference to work off of. - * @return the list of ArtifactReferences for related artifacts, if - * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository. - * @see #getRelatedArtifacts(VersionedReference) - */ - List getRelatedArtifacts( ArtifactReference reference ) - throws ContentNotFoundException, LayoutException, ContentAccessException; - /** *

* Gather up the list of related artifacts to the ArtifactReference provided. @@ -430,22 +397,6 @@ public interface ManagedRepositoryContent extends RepositoryContent throws ContentNotFoundException, LayoutException, ContentAccessException; - - - - - - /** - * Returns all the assets that belong to a given artifact type. The list returned contain - * all the files that correspond to the given artifact reference. - * This method is the same as {@link #getRelatedArtifacts(ArtifactReference)} but may also return - * e.g. hash files. - * - * @param reference - * @return - */ - List getRelatedAssets(ArtifactReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException; - /** * Returns all artifacts that belong to a given version * @param reference the version reference diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java index 0b3b50789..977bad2ed 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java @@ -63,12 +63,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return null; } - @Override - public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier ) - { - return null; - } - @Override public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException { @@ -218,24 +212,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return null; } - @Override - public List getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public List getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException { return null; } - @Override - public List getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public List getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException { diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java index 4317cf78f..92e025886 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java @@ -79,12 +79,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return null; } - @Override - public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier ) - { - return null; - } - @Override public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException { @@ -229,24 +223,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return repository.getId(); } - @Override - public List getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public List getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException { return null; } - @Override - public List getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public List getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException { 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 4b04b1e3d..68e006247 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 @@ -83,12 +83,6 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return null; } - @Override - public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier ) - { - return null; - } - @Override public void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException { @@ -233,24 +227,12 @@ public class ManagedRepositoryContentMock implements ManagedRepositoryContent return repository.getId(); } - @Override - public List getRelatedArtifacts( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public List getRelatedArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException { return null; } - @Override - public List getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public List getArtifacts( VersionedReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException { diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java index bc8b2e5f8..b6852c7ad 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java @@ -20,7 +20,6 @@ package org.apache.archiva.repository.maven.content; import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.utils.FileUtils; -import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.metadata.maven.MavenMetadataReader; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; @@ -927,11 +926,6 @@ public class ManagedDefaultRepositoryContent return toVersion( artifactReference.getGroupId( ), artifactReference.getArtifactId( ), artifactReference.getVersion( ) ); } - @Override - public ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier) { - return new ArtifactReference( ).groupId( groupId ).artifactId( artifactId ).version( version ).type( type ).classifier( classifier ); - } - @Override public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException @@ -1154,69 +1148,6 @@ public class ManagedDefaultRepositoryContent } - @Override - public List getRelatedArtifacts( ArtifactReference reference ) - throws ContentNotFoundException, LayoutException, ContentAccessException - { - if ( StringUtils.isEmpty( reference.getType() ) && StringUtils.isEmpty( reference.getClassifier() ) ) { - return getRelatedArtifacts( toVersion( reference ) ); - } - - StorageAsset artifactFile = toFile( reference ); - StorageAsset repoDir = artifactFile.getParent(); - String ext; - if (!artifactFile.isContainer()) { - ext = StringUtils.substringAfterLast( artifactFile.getName(), "."); - } else { - ext = ""; - } - - if ( !repoDir.exists()) - { - throw new ContentNotFoundException( - "Unable to get related artifacts using a non-existant directory: " + repoDir.getPath() ); - } - - if ( !repoDir.isContainer() ) - { - throw new ContentNotFoundException( - "Unable to get related artifacts using a non-directory: " + repoDir.getPath() ); - } - - // First gather up the versions found as artifacts in the managed repository. - - try (Stream stream = repoDir.list().stream() ) { - return stream.filter( - asset -> !asset.isContainer()) - .map(path -> { - try { - return toArtifactReference(path.getPath()); - } catch (LayoutException e) { - log.debug( "Not processing file that is not an artifact: {}", e.getMessage() ); - return null; - } - }).filter(Objects::nonNull).filter(getChecker( reference, ext )).collect(Collectors.toList()); - } catch (RuntimeException e) { - Throwable cause = e.getCause( ); - if (cause!=null) { - if (cause instanceof LayoutException) { - throw (LayoutException)cause; - } else - { - throw new ContentAccessException( cause.getMessage( ), cause ); - } - } else { - throw new ContentAccessException( e.getMessage( ), e ); - } - } - } - - @Override - public List getRelatedAssets( ArtifactReference reference ) throws ContentNotFoundException, LayoutException, ContentAccessException - { - return null; - } - @Override public String getRepoRoot() { diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java index 1cc78b252..8d0a77b08 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java @@ -51,6 +51,8 @@ import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.RepositoryType; +import org.apache.archiva.repository.content.ItemNotFoundException; +import org.apache.archiva.repository.content.base.ArchivaItemSelector; import org.apache.archiva.repository.storage.fs.FsStorageUtil; import org.apache.archiva.repository.storage.RepositoryStorage; import org.apache.archiva.repository.storage.StorageAsset; @@ -787,6 +789,16 @@ public class DefaultRepositoriesService artifactReference.setClassifier( artifact.getClassifier() ); artifactReference.setType( artifact.getType() ); + ArchivaItemSelector selector = ArchivaItemSelector.builder( ) + .withNamespace( artifact.getGroupId( ) ) + .withProjectId( artifact.getArtifactId( ) ) + .withVersion( artifact.getVersion( ) ) + .withClassifier( artifact.getClassifier( ) ) + .withArtifactId( artifact.getArtifactId( ) ) + .withType( artifact.getType( ) ) + .includeRelatedArtifacts() + .build( ); + MetadataRepository metadataRepository = repositorySession.getRepository(); String path = repository.toMetadataPath( ref ); @@ -798,9 +810,16 @@ public class DefaultRepositoriesService throw new ArchivaRestServiceException( "You must configure a type/packaging when using classifier", 400, null ); } - List artifacts = repository.getRelatedArtifacts( artifactReference ); - for (ArtifactReference aRef : artifacts ) { - repository.deleteArtifact( aRef ); + List artifactItems = repository.getArtifacts( selector ); + for ( org.apache.archiva.repository.content.Artifact aRef : artifactItems ) { + try + { + repository.deleteItem( aRef ); + } + catch ( ItemNotFoundException e ) + { + log.error( "Could not delete item, seems to be deleted by other thread. {}, {} ", aRef, e.getMessage( ) ); + } } } -- 2.39.5