diff options
author | Olivier Lamy <olamy@apache.org> | 2012-10-11 22:42:00 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-10-11 22:42:00 +0000 |
commit | 092a635e39f0329c59d23745cdd93fdd000516e4 (patch) | |
tree | cafb88f3ec9d789fdb1ff209d4ce065dcb90a83a /archiva-modules | |
parent | db43bb93394bd38dde8b01a3b5927648c2ac9a91 (diff) | |
download | archiva-092a635e39f0329c59d23745cdd93fdd000516e4.tar.gz archiva-092a635e39f0329c59d23745cdd93fdd000516e4.zip |
do some cleanup if metadatarepository still contains versions when deleting
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1397342 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
3 files changed, 60 insertions, 5 deletions
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 012d1c263..798f47b59 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 @@ -725,6 +725,25 @@ public class DefaultRepositoriesService log.debug( "artifacts: {}", artifacts ); + if ( artifacts.isEmpty() ) + { + if ( !snapshotVersion ) + { + // verify metata repository doesn't contains anymore the version + Collection<String> projectVersions = + metadataRepository.getProjectVersions( repositoryId, artifact.getGroupId(), + artifact.getArtifactId() ); + + if ( projectVersions.contains( artifact.getVersion() ) ) + { + log.warn( "artifact not found when deleted but version still here ! so force cleanup" ); + metadataRepository.removeProjectVersion( repositoryId, artifact.getGroupId(), + artifact.getArtifactId(), artifact.getVersion() ); + } + + } + } + for ( ArtifactMetadata artifactMetadata : artifacts ) { @@ -785,8 +804,6 @@ public class DefaultRepositoriesService triggerAuditEvent( repositoryId, path, AuditEvent.REMOVE_FILE ); } } - - } catch ( ContentNotFoundException e ) { diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index 37b705188..442ff6d14 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -112,11 +112,10 @@ public interface MetadataRepository throws MetadataRepositoryException; /** - * * @param repositoryId - * @param namespace (groupId for maven ) - * @since 1.4-M3 + * @param namespace (groupId for maven ) * @throws MetadataRepositoryException + * @since 1.4-M3 */ void removeNamespace( String repositoryId, String namespace ) throws MetadataRepositoryException; @@ -160,6 +159,18 @@ public interface MetadataRepository Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) throws MetadataResolutionException; + /** + * + * @param repoId + * @param namespace + * @param projectId + * @param projectVersion + * @since 1.4-M4 + * @throws MetadataResolutionException + */ + void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataRepositoryException; + Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, String projectVersion ) throws MetadataResolutionException; diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 6dd78efe5..47f23eb6b 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -1047,6 +1047,33 @@ public class JcrMetadataRepository } + + public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataRepositoryException + { + try + { + + String path = getProjectPath( repoId, namespace, projectId ); + Node root = getJcrSession().getRootNode(); + + Node nodeAtPath = root.getNode( path ); + + for ( Node node : JcrUtils.getChildNodes( nodeAtPath ) ) + { + if ( node.isNodeType( PROJECT_VERSION_NODE_TYPE ) && StringUtils.equals( projectVersion, + node.getName() ) ) + { + node.remove(); + } + } + } + catch ( RepositoryException e ) + { + throw new MetadataRepositoryException( e.getMessage(), e ); + } + } + public void removeArtifact( String repositoryId, String namespace, String projectId, String projectVersion, String id ) throws MetadataRepositoryException |