]> source.dussan.org Git - archiva.git/commitdiff
do some cleanup if metadatarepository still contains versions when deleting
authorOlivier Lamy <olamy@apache.org>
Thu, 11 Oct 2012 22:42:00 +0000 (22:42 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 11 Oct 2012 22:42:00 +0000 (22:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1397342 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java

index 012d1c26335c11bddef38aad542adbc76fc2beda..798f47b59ac28e01bf67c595bb718a5d3ca38bf9 100644 (file)
@@ -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 )
         {
index 37b7051883fc1b062079196ed16041b9e40ccfe3..442ff6d145dd6e61f24239dbda403a5393bb7bee 100644 (file)
@@ -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;
index 6dd78efe50c6ef8eb0dd53cecdf671ac50b29771..47f23eb6bfe705390d8c44c539cbcd26561baf88 100644 (file)
@@ -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