]> source.dussan.org Git - archiva.git/commitdiff
Removing old API methods
authorMartin Stockhammer <martin_s@apache.org>
Wed, 3 Jun 2020 08:46:34 +0000 (10:46 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Wed, 3 Jun 2020 08:46:34 +0000 (10:46 +0200)
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/mock/ManagedRepositoryContentMock.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/repository/mock/ManagedRepositoryContentMock.java
archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java

index 069730689e928f9039ff0cef1ddcdd44a0f1cd3f..fe58824a3f46bfcfcdd796f5fc24f0e427fe4eac 100644 (file)
@@ -34,6 +34,7 @@ import org.apache.archiva.repository.BaseRepositoryContentLayout;
 import org.apache.archiva.repository.ReleaseScheme;
 import org.apache.archiva.repository.RepositoryRegistry;
 import org.apache.archiva.metadata.audit.RepositoryListener;
+import org.apache.archiva.repository.content.ItemNotFoundException;
 import org.apache.archiva.repository.content.ItemSelector;
 import org.apache.archiva.repository.content.Project;
 import org.apache.archiva.repository.content.Version;
@@ -108,7 +109,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge
                 return;
             }
 
-            ItemSelector selector = ArchivaItemSelector.builder( )
+            ItemSelector projectSelector = ArchivaItemSelector.builder( )
                 .withNamespace( artifactRef.getGroupId( ) )
                 .withProjectId( artifactRef.getArtifactId( ) )
                 .build();
@@ -124,7 +125,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge
                 if ( repo.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ))
                 {
                     BaseRepositoryContentLayout repoContent = repo.getContent().getLayout( BaseRepositoryContentLayout.class );
-                    Project proj = repoContent.getProject( selector );
+                    Project proj = repoContent.getProject( projectSelector );
                     for ( Version version : repoContent.getVersions( proj ) )
                     {
                         if ( !VersionUtil.isSnapshot( version.getVersion() ) )
@@ -144,13 +145,21 @@ public class CleanupReleasedSnapshotsRepositoryPurge
             versionRef.setGroupId( artifactRef.getGroupId( ) );
             versionRef.setArtifactId( artifactRef.getArtifactId( ) );
 
+            ArchivaItemSelector.Builder versionSelectorBuilder = ArchivaItemSelector.builder( )
+                .withNamespace( artifactRef.getGroupId( ) )
+                .withProjectId( artifactRef.getArtifactId( ) )
+                .withArtifactId( artifactRef.getArtifactId( ) );
+
             MetadataRepository metadataRepository = repositorySession.getRepository( );
 
             if ( releasedVersions.contains( VersionUtil.getReleaseVersion( artifactRef.getVersion( ) ) ) )
             {
-                versionRef.setVersion( artifactRef.getVersion( ) );
-                layout.deleteVersion( versionRef );
-
+                ArchivaItemSelector selector = versionSelectorBuilder.withVersion( artifactRef.getVersion( ) ).build( );
+                Version version = layout.getVersion( selector );
+                if (version.exists())
+                {
+                    repository.deleteItem( version );
+                }
                 for ( RepositoryListener listener : listeners )
                 {
                     listener.deleteArtifact( metadataRepository, repository.getId( ), artifactRef.getGroupId( ),
@@ -172,10 +181,6 @@ public class CleanupReleasedSnapshotsRepositoryPurge
         {
             log.debug( "Not processing file that is not an artifact: {}", e.getMessage( ) );
         }
-        catch ( ContentNotFoundException e )
-        {
-            throw new RepositoryPurgeException( e.getMessage( ), e );
-        }
         catch ( MetadataRepositoryException e )
         {
             log.error( "Could not remove metadata during cleanup of released snapshots of {}", path, e );
@@ -184,6 +189,10 @@ public class CleanupReleasedSnapshotsRepositoryPurge
         {
             e.printStackTrace( );
         }
+        catch ( ItemNotFoundException e )
+        {
+            log.error( "Could not find item to delete {}",e.getMessage( ), e );
+        }
     }
 
 
@@ -211,15 +220,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge
         {
             // Ignore. (Just means we have no snapshot versions left to reference).
         }
-        catch ( RepositoryMetadataException e )
-        {
-            // Ignore.
-        }
-        catch ( IOException e )
-        {
-            // Ignore.
-        }
-        catch ( LayoutException e )
+        catch ( RepositoryMetadataException | IOException | LayoutException e )
         {
             // Ignore.
         }
@@ -228,21 +229,10 @@ public class CleanupReleasedSnapshotsRepositoryPurge
         {
             metadataTools.updateMetadata( repository, projectRef );
         }
-        catch ( ContentNotFoundException e )
+        catch ( ContentNotFoundException | RepositoryMetadataException | IOException | LayoutException e )
         {
             // Ignore. (Just means we have no snapshot versions left to reference).
         }
-        catch ( RepositoryMetadataException e )
-        {
-            // Ignore.
-        }
-        catch ( IOException e )
-        {
-            // Ignore.
-        }
-        catch ( LayoutException e )
-        {
-            // Ignore.
-        }
+
     }
 }
index bd1e2933cf32e43d90579dd616a4f6b3f54884fc..2fc7aee975d56957178d0baa54811e0be5cf2374 100644 (file)
@@ -290,18 +290,6 @@ public interface BaseRepositoryContentLayout extends ManagedRepositoryContentLay
     VersionedReference toVersion( ArtifactReference artifactReference);
 
 
-    /**
-     * Delete from the managed repository all files / directories associated with the
-     * provided version reference.
-     *
-     * @param reference the version reference to delete.
-     * @throws ContentNotFoundException
-     */
-    void deleteVersion( VersionedReference reference )
-        throws ContentNotFoundException, ContentAccessException;
-
-
-
     /**
      * delete a specified artifact from the repository
      *
@@ -395,13 +383,5 @@ public interface BaseRepositoryContentLayout extends ManagedRepositoryContentLay
      */
     StorageAsset toFile( VersionedReference reference );
 
-    /**
-     * Given an {@link ArtifactReference}, return the file reference to the artifact.
-     *
-     * @param reference the artifact reference to use.
-     * @return the relative path to the artifact.
-     */
-    StorageAsset toFile( ArtifactReference reference );
-
 
 }
index ae32b0ee9d0609e13c7a2b2c59a263b628e231e9..c10c6c319a7606a047987c59c9e33eec472799fc 100644 (file)
@@ -149,13 +149,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
     }
 
 
-    @Override
-    public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
-    {
-
-    }
-
-
     @Override
     public Version getVersion( ItemSelector versionCoordinates ) throws ContentAccessException, IllegalArgumentException
     {
@@ -392,12 +385,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
         return null;
     }
 
-    @Override
-    public StorageAsset toFile( ArtifactReference reference )
-    {
-        return null;
-    }
-
     @Override
     public String toPath( ArtifactReference reference )
     {
index 604c70b21f9f7a04105dfc7491c9cb3995433fbf..d7d9ab46b100fbf6fbdd15426a32d3134fc0c5f2 100644 (file)
@@ -307,12 +307,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
         return null;
     }
 
-    @Override
-    public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
-    {
-
-    }
-
     @Override
     public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
     {
@@ -585,12 +579,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
     }
 
 
-    @Override
-    public StorageAsset toFile( ArtifactReference reference )
-    {
-        return getRepoRootAsset().resolve(refs.get(reference));
-    }
-
     private String formatAsDirectory( String directory )
     {
         return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
index 970645139b604b59c627ca0b8ac62cb5dec56169..ae4a88950295e6bf8b0607c788d2ac745d136efc 100644 (file)
@@ -328,12 +328,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
         }
     }
 
-    @Override
-    public void deleteVersion( VersionedReference reference ) throws ContentNotFoundException, ContentAccessException
-    {
-
-    }
-
     @Override
     public void deleteArtifact( ArtifactReference artifactReference ) throws ContentNotFoundException, ContentAccessException
     {
@@ -607,12 +601,6 @@ public class ManagedRepositoryContentMock implements BaseRepositoryContentLayout
     }
 
 
-    @Override
-    public StorageAsset toFile( ArtifactReference reference )
-    {
-        return getRepoRootAsset().resolve( refs.get(reference));
-    }
-
     private String formatAsDirectory( String directory )
     {
         return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
index 032c531d7ac36869c2790141225ce95fe15e4276..3e195c22691da1636c7e5019b80f26ddf1602a16 100644 (file)
@@ -1342,35 +1342,6 @@ public class ManagedDefaultRepositoryContent
     }
 
 
-    @Override
-    public void deleteVersion( VersionedReference ref ) throws ContentNotFoundException, ContentAccessException
-    {
-        final String path = toPath( ref );
-        final Path deleteTarget = getRepoDir( ).resolve( path );
-        if ( !Files.exists( deleteTarget ) )
-        {
-            log.warn( "Version path for repository {} does not exist: {}", getId( ), deleteTarget );
-            throw new ContentNotFoundException( "Version not found for repository " + getId( ) + ": " + path );
-        }
-        if ( Files.isDirectory( deleteTarget ) )
-        {
-            try
-            {
-                org.apache.archiva.common.utils.FileUtils.deleteDirectory( deleteTarget );
-            }
-            catch ( IOException e )
-            {
-                log.error( "Could not delete file path {}: {}", deleteTarget, e.getMessage( ), e );
-                throw new ContentAccessException( "Error while trying to delete path " + path + " from repository " + getId( ) + ": " + e.getMessage( ), e );
-            }
-        }
-        else
-        {
-            log.warn( "Version path for repository {} is not a directory {}", getId( ), deleteTarget );
-            throw new ContentNotFoundException( "Version path for repository " + getId( ) + " is not directory: " + path );
-        }
-    }
-
     @Override
     public void deleteProject( ProjectReference ref )
         throws ContentNotFoundException, ContentAccessException
@@ -1689,12 +1660,6 @@ public class ManagedDefaultRepositoryContent
     }
 
 
-    @Override
-    public StorageAsset toFile( ArtifactReference reference )
-    {
-        return repository.getAsset( toPath( reference ) );
-    }
-
     @Override
     public StorageAsset toFile( VersionedReference reference )
     {
index e4728f2aaa477553a0aa197d4041988461feca47..746bbb8d7b7e1ae77343e3620ca518f575a6480d 100644 (file)
@@ -521,24 +521,6 @@ public class ManagedDefaultRepositoryContentTest
     }
 
 
-    @Test
-    public void testDeleteVersion() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
-    {
-        Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
-        assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
-        assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
-        assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
-        assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
-        assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
-
-        VersionedReference ref = new VersionedReference( ).groupId( "org.apache.maven" ).artifactId( "samplejar" ).version( "1.0" );
-
-        repoContent.deleteVersion( ref );
-
-        assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
-
-    }
-
     @Test
     public void testDeleteProject() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
     {