From 5c166688a997f1980a0c2c7a3f466eda630f1e49 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 3 Oct 2011 07:18:10 +0000 Subject: [PATCH] prevent overzealous deletion of snapshot versions in the same artifact that may not be part of the currently scanned file git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1178312 13f79535-47bb-0310-9956-ffa450edef68 --- ...eanupReleasedSnapshotsRepositoryPurge.java | 62 +++++++------------ 1 file changed, 22 insertions(+), 40 deletions(-) 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 c504ad0ce..45d62658e 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 @@ -116,19 +116,25 @@ public class CleanupReleasedSnapshotsRepositoryPurge reference.setGroupId( artifactRef.getGroupId() ); reference.setArtifactId( artifactRef.getArtifactId() ); - // Gather up all of the versions. - List allVersions = new ArrayList( repository.getVersions( reference ) ); + // Gether the released versions + List releasedVersions = new ArrayList(); List 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 releasedVersions = new ArrayList(); - List snapshotVersions = new ArrayList(); - - 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 ) -- 2.39.5