From: Martin Stockhammer Date: Wed, 3 Jun 2020 08:46:34 +0000 (+0200) Subject: Removing old API methods X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b9dd7edf9eac052e4400fd37e12b3e123b8b9f55;p=archiva.git Removing old API methods --- diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index 069730689..fe58824a3 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -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. - } + } } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java index bd1e2933c..2fc7aee97 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java @@ -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 ); - } 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 ae32b0ee9..c10c6c319 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 @@ -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 ) { 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 604c70b21..d7d9ab46b 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 @@ -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 ); 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 970645139..ae4a88950 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 @@ -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 ); 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 032c531d7..3e195c226 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 @@ -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 ) { diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java index e4728f2aa..746bbb8d7 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java @@ -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 {