]> source.dussan.org Git - archiva.git/commitdiff
prevent overzealous deletion of snapshot versions in the same artifact that may not...
authorBrett Porter <brett@apache.org>
Mon, 3 Oct 2011 07:18:10 +0000 (07:18 +0000)
committerBrett Porter <brett@apache.org>
Mon, 3 Oct 2011 07:18:10 +0000 (07:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1178312 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java

index c504ad0ce215442d405263a8cc84494a1dacadc7..45d62658ef9ead49b16a24e0f2e906472adbd143 100644 (file)
@@ -116,19 +116,25 @@ public class CleanupReleasedSnapshotsRepositoryPurge
             reference.setGroupId( artifactRef.getGroupId() );
             reference.setArtifactId( artifactRef.getArtifactId() );
 
-            // Gather up all of the versions.
-            List<String> allVersions = new ArrayList<String>( repository.getVersions( reference ) );
+            // Gether the released versions
+            List<String> releasedVersions = new ArrayList<String>();
 
             List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
             for ( ManagedRepository repo : repos )
             {
-                if ( repo.isReleases() && !repo.getId().equals( repository.getId() ) )
+                if ( repo.isReleases() )
                 {
                     try
                     {
                         ManagedRepositoryContent repoContent =
                             repoContentFactory.getManagedRepositoryContent( repo.getId() );
-                        allVersions.addAll( repoContent.getVersions( reference ) );
+                        for ( String version : repoContent.getVersions( reference ) )
+                        {
+                            if ( !VersionUtil.isSnapshot( version ) )
+                            {
+                                releasedVersions.add( version );
+                            }
+                        }
                     }
                     catch ( RepositoryNotFoundException e )
                     {
@@ -141,25 +147,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge
                 }
             }
 
-            // Split the versions into released and snapshots.
-            List<String> releasedVersions = new ArrayList<String>();
-            List<String> snapshotVersions = new ArrayList<String>();
-
-            for ( String version : allVersions )
-            {
-                if ( VersionUtil.isSnapshot( version ) )
-                {
-                    snapshotVersions.add( version );
-                }
-                else
-                {
-                    releasedVersions.add( version );
-                }
-            }
-
-            Collections.sort( allVersions, VersionComparator.getInstance() );
             Collections.sort( releasedVersions, VersionComparator.getInstance() );
-            Collections.sort( snapshotVersions, VersionComparator.getInstance() );
 
             // Now clean out any version that is earlier than the highest released version.
             boolean needsMetadataUpdate = false;
@@ -168,28 +156,22 @@ public class CleanupReleasedSnapshotsRepositoryPurge
             versionRef.setGroupId( artifactRef.getGroupId() );
             versionRef.setArtifactId( artifactRef.getArtifactId() );
 
-            ArchivaArtifact artifact =
-                new ArchivaArtifact( artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion(),
-                                     artifactRef.getClassifier(), artifactRef.getType(), repository.getId() );
-
             MetadataRepository metadataRepository = repositorySession.getRepository();
-            for ( String version : snapshotVersions )
-            {
-                if ( releasedVersions.contains( VersionUtil.getReleaseVersion( version ) ) )
-                {
-                    versionRef.setVersion( version );
-                    repository.deleteVersion( versionRef );
 
-                    // FIXME: looks incomplete, might not delete related metadata?
-                    for ( RepositoryListener listener : listeners )
-                    {
-                        listener.deleteArtifact( metadataRepository, repository.getId(), artifact.getGroupId(),
-                                                 artifact.getArtifactId(), artifact.getVersion(),
-                                                 artifactFile.getName() );
-                    }
+            if ( releasedVersions.contains( VersionUtil.getReleaseVersion( artifactRef.getVersion() ) ) )
+            {
+                versionRef.setVersion( artifactRef.getVersion() );
+                repository.deleteVersion( versionRef );
 
-                    needsMetadataUpdate = true;
+                // FIXME: looks incomplete, might not delete related metadata?
+                for ( RepositoryListener listener : listeners )
+                {
+                    listener.deleteArtifact( metadataRepository, repository.getId(), artifactRef.getGroupId(),
+                                             artifactRef.getArtifactId(), artifactRef.getVersion(),
+                                             artifactFile.getName() );
                 }
+
+                needsMetadataUpdate = true;
             }
 
             if ( needsMetadataUpdate )