From 4b5be0143c7f46866971d21dca85ad70d4789142 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 19 Oct 2012 22:47:19 +0000 Subject: [PATCH] [MRM-1701] metadatas are not removed when a snapshot is purged. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1400323 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/AbstractRepositoryPurge.java | 89 ++++++++++++++++++- .../services/DefaultRepositoriesService.java | 3 - .../src/main/webapp/js/redback/user.js | 4 +- 3 files changed, 88 insertions(+), 8 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java index 736099db1..27b3871cf 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java @@ -20,16 +20,24 @@ package org.apache.archiva.consumers.core.repository; */ import org.apache.archiva.audit.AuditEvent; +import org.apache.archiva.common.utils.VersionUtil; +import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataRepositoryException; +import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.archiva.model.ArtifactReference; +import org.apache.archiva.repository.ContentNotFoundException; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.FilenameFilter; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -39,7 +47,7 @@ import java.util.Set; public abstract class AbstractRepositoryPurge implements RepositoryPurge { - protected Logger log = LoggerFactory.getLogger( AbstractRepositoryPurge.class ); + protected Logger log = LoggerFactory.getLogger( getClass() ); protected final ManagedRepositoryContent repository; @@ -83,7 +91,82 @@ public abstract class AbstractRepositoryPurge // TODO: this needs to be logged artifactFile.delete(); - //repository.deleteArtifact( reference ); + try + { + repository.deleteArtifact( reference ); + } + catch ( ContentNotFoundException e ) + { + log.warn( "skip error deleting artifact {}: {}", reference, e.getMessage() ); + } + + try + { + metadataRepository.removeProjectVersion( repository.getId(), reference.getGroupId(), + reference.getArtifactId(), reference.getVersion() ); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "skip error removeProjectVersion artifact {}: {}", reference, e.getMessage() ); + } + + boolean snapshotVersion = VersionUtil.isSnapshot( reference.getVersion() ); + + try + { + if ( snapshotVersion ) + { + String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() ); + Collection artifacts = + metadataRepository.getArtifacts( repository.getId(), reference.getGroupId(), + reference.getArtifactId(), baseVersion ); + // cleanup snapshots metadata + for ( ArtifactMetadata artifactMetadata : artifacts ) + { + + // TODO: mismatch between artifact (snapshot) version and project (base) version here + if ( artifactMetadata.getVersion().equals( reference.getVersion() ) ) + { + if ( StringUtils.isNotBlank( reference.getClassifier() ) ) + { + + // cleanup facet which contains classifier information + MavenArtifactFacet mavenArtifactFacet = + (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID ); + + if ( StringUtils.equals( reference.getClassifier(), + mavenArtifactFacet.getClassifier() ) ) + { + artifactMetadata.removeFacet( MavenArtifactFacet.FACET_ID ); + String groupId = reference.getGroupId(), artifactId = reference.getArtifactId(), + version = reference.getVersion(); + MavenArtifactFacet mavenArtifactFacetToCompare = new MavenArtifactFacet(); + mavenArtifactFacetToCompare.setClassifier( reference.getClassifier() ); + metadataRepository.removeArtifact( repository.getId(), groupId, artifactId, + version, mavenArtifactFacetToCompare ); + metadataRepository.save(); + } + + } + else + { + metadataRepository.removeArtifact( artifactMetadata, VersionUtil.getBaseVersion( + reference.getVersion() ) ); + } + + } + } + } + } + catch ( MetadataResolutionException e ) + { + log.warn( "skip error deleting metadata {}: {}", reference, e.getMessage() ); + } + catch ( MetadataRepositoryException e ) + { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + repositorySession.save(); triggerAuditEvent( repository.getRepository().getId(), ArtifactReference.toKey( reference ), 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 798f47b59..f0b79575e 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 @@ -766,9 +766,6 @@ public class DefaultRepositoriesService artifactMetadata.removeFacet( MavenArtifactFacet.FACET_ID ); String groupId = artifact.getGroupId(), artifactId = artifact.getArtifactId(), version = artifact.getVersion(); - //metadataRepository.updateArtifact( repositoryId, groupId, artifactId, version, - // artifactMetadata ); - // String repositoryId, String namespace, String project, String version, String projectId, MetadataFacet metadataFacet MavenArtifactFacet mavenArtifactFacetToCompare = new MavenArtifactFacet(); mavenArtifactFacetToCompare.setClassifier( artifact.getClassifier() ); metadataRepository.removeArtifact( repositoryId, groupId, artifactId, version, diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js index e1b3fe7c3..83f966eb9 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js @@ -77,7 +77,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid) { this.modified=ko.observable(false); this.rememberme=false; - this.password=null; + this.logged=false; this.remove = function() { @@ -413,7 +413,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid) { // FIXME check validated user.rememberme=window.redbackModel.rememberme; if(user.rememberme){ - user.password=window.redbackModel.password; + user.password(window.redbackModel.password); } $.log("user.rememberme:"+(user.rememberme)); reccordLoginCookie(user);