This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit 7c0b0387a3a53d8ce2677092f02046e39103be60
Author: Martin Stockhammer <[email protected]>
AuthorDate: Tue Apr 21 18:40:17 2020 +0200

    Removing API methods for repository content
---
 .../repository/ManagedRepositoryContent.java       | 49 ---------------
 .../mock/ManagedRepositoryContentMock.java         | 18 ------
 .../scanner/mock/ManagedRepositoryContentMock.java | 18 ------
 .../mock/ManagedRepositoryContentMock.java         | 18 ------
 .../content/ManagedDefaultRepositoryContent.java   | 69 ----------------------
 .../rest/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 08e91d4..3ba9fdd 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
@@ -394,26 +381,6 @@ public interface ManagedRepositoryContent extends 
RepositoryContent
     /**
      * <p>
      * 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 <code>null</code> it will return the same 
artifacts as 
-     * {@link #getRelatedArtifacts(VersionedReference)}
-     * </p>
-     * <p>
-     * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not 
compatible with this query.
-     * </p>
-     *
-     * @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<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
-        throws ContentNotFoundException, LayoutException, 
ContentAccessException;
-
-    /**
-     * <p>
-     * Gather up the list of related artifacts to the ArtifactReference 
provided.
      * This typically includes the pom files, and those things with
      * classifiers (such as doc, source code, test libs, etc...). Even if the 
classifier
      * is set in the artifact reference, it may return artifacts with 
different classifiers.
@@ -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<StorageAsset> 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 0b3b507..977bad2 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
@@ -64,12 +64,6 @@ public class ManagedRepositoryContentMock implements 
ManagedRepositoryContent
     }
 
     @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
     {
 
@@ -219,24 +213,12 @@ public class ManagedRepositoryContentMock implements 
ManagedRepositoryContent
     }
 
     @Override
-    public List<ArtifactReference> getRelatedArtifacts( ArtifactReference 
reference ) throws ContentNotFoundException, LayoutException, 
ContentAccessException
-    {
-        return null;
-    }
-
-    @Override
     public List<ArtifactReference> getRelatedArtifacts( VersionedReference 
reference ) throws ContentNotFoundException, LayoutException, 
ContentAccessException
     {
         return null;
     }
 
     @Override
-    public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) 
throws ContentNotFoundException, LayoutException, ContentAccessException
-    {
-        return null;
-    }
-
-    @Override
     public List<ArtifactReference> getArtifacts( VersionedReference reference 
) throws ContentNotFoundException, LayoutException, ContentAccessException
     {
         return null;
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 4317cf7..92e0258 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
@@ -80,12 +80,6 @@ public class ManagedRepositoryContentMock implements 
ManagedRepositoryContent
     }
 
     @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
     {
 
@@ -230,24 +224,12 @@ public class ManagedRepositoryContentMock implements 
ManagedRepositoryContent
     }
 
     @Override
-    public List<ArtifactReference> getRelatedArtifacts( ArtifactReference 
reference ) throws ContentNotFoundException, LayoutException, 
ContentAccessException
-    {
-        return null;
-    }
-
-    @Override
     public List<ArtifactReference> getRelatedArtifacts( VersionedReference 
reference ) throws ContentNotFoundException, LayoutException, 
ContentAccessException
     {
         return null;
     }
 
     @Override
-    public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) 
throws ContentNotFoundException, LayoutException, ContentAccessException
-    {
-        return null;
-    }
-
-    @Override
     public List<ArtifactReference> getArtifacts( VersionedReference reference 
) throws ContentNotFoundException, LayoutException, ContentAccessException
     {
         return null;
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 4b04b1e..68e0062 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
@@ -84,12 +84,6 @@ public class ManagedRepositoryContentMock implements 
ManagedRepositoryContent
     }
 
     @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
     {
 
@@ -234,24 +228,12 @@ public class ManagedRepositoryContentMock implements 
ManagedRepositoryContent
     }
 
     @Override
-    public List<ArtifactReference> getRelatedArtifacts( ArtifactReference 
reference ) throws ContentNotFoundException, LayoutException, 
ContentAccessException
-    {
-        return null;
-    }
-
-    @Override
     public List<ArtifactReference> getRelatedArtifacts( VersionedReference 
reference ) throws ContentNotFoundException, LayoutException, 
ContentAccessException
     {
         return null;
     }
 
     @Override
-    public List<StorageAsset> getRelatedAssets( ArtifactReference reference ) 
throws ContentNotFoundException, LayoutException, ContentAccessException
-    {
-        return null;
-    }
-
-    @Override
     public List<ArtifactReference> getArtifacts( VersionedReference reference 
) throws ContentNotFoundException, LayoutException, ContentAccessException
     {
         return null;
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 bc8b2e5..b6852c7 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
@@ -1155,69 +1149,6 @@ public class ManagedDefaultRepositoryContent
     }
 
     @Override
-    public List<ArtifactReference> 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<? extends StorageAsset> 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<StorageAsset> getRelatedAssets( ArtifactReference reference ) 
throws ContentNotFoundException, LayoutException, ContentAccessException
-    {
-        return null;
-    }
-
-    @Override
     public String getRepoRoot()
     {
         return convertUriToPath( repository.getLocation() );
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 1cc78b2..8d0a77b 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<ArtifactReference> artifacts = 
repository.getRelatedArtifacts( artifactReference );
-                for (ArtifactReference aRef : artifacts ) {
-                    repository.deleteArtifact( aRef );
+                List<? extends org.apache.archiva.repository.content.Artifact> 
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( ) );
+                    }
                 }
 
             }

Reply via email to