[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
This commit is contained in:
Olivier Lamy 2012-10-19 22:47:19 +00:00
parent 0b41e0e326
commit 4b5be0143c
3 changed files with 88 additions and 8 deletions

View File

@ -20,16 +20,24 @@ package org.apache.archiva.consumers.core.repository;
*/ */
import org.apache.archiva.audit.AuditEvent; 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.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.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.model.ArtifactReference;
import org.apache.archiva.repository.ContentNotFoundException;
import org.apache.archiva.repository.ManagedRepositoryContent; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -39,7 +47,7 @@ import java.util.Set;
public abstract class AbstractRepositoryPurge public abstract class AbstractRepositoryPurge
implements RepositoryPurge implements RepositoryPurge
{ {
protected Logger log = LoggerFactory.getLogger( AbstractRepositoryPurge.class ); protected Logger log = LoggerFactory.getLogger( getClass() );
protected final ManagedRepositoryContent repository; protected final ManagedRepositoryContent repository;
@ -83,7 +91,82 @@ public abstract class AbstractRepositoryPurge
// TODO: this needs to be logged // TODO: this needs to be logged
artifactFile.delete(); 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<ArtifactMetadata> 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(); repositorySession.save();
triggerAuditEvent( repository.getRepository().getId(), ArtifactReference.toKey( reference ), triggerAuditEvent( repository.getRepository().getId(), ArtifactReference.toKey( reference ),

View File

@ -766,9 +766,6 @@ public class DefaultRepositoriesService
artifactMetadata.removeFacet( MavenArtifactFacet.FACET_ID ); artifactMetadata.removeFacet( MavenArtifactFacet.FACET_ID );
String groupId = artifact.getGroupId(), artifactId = artifact.getArtifactId(), version = String groupId = artifact.getGroupId(), artifactId = artifact.getArtifactId(), version =
artifact.getVersion(); 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(); MavenArtifactFacet mavenArtifactFacetToCompare = new MavenArtifactFacet();
mavenArtifactFacetToCompare.setClassifier( artifact.getClassifier() ); mavenArtifactFacetToCompare.setClassifier( artifact.getClassifier() );
metadataRepository.removeArtifact( repositoryId, groupId, artifactId, version, metadataRepository.removeArtifact( repositoryId, groupId, artifactId, version,

View File

@ -77,7 +77,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid) {
this.modified=ko.observable(false); this.modified=ko.observable(false);
this.rememberme=false; this.rememberme=false;
this.password=null;
this.logged=false; this.logged=false;
this.remove = function() { this.remove = function() {
@ -413,7 +413,7 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid) {
// FIXME check validated // FIXME check validated
user.rememberme=window.redbackModel.rememberme; user.rememberme=window.redbackModel.rememberme;
if(user.rememberme){ if(user.rememberme){
user.password=window.redbackModel.password; user.password(window.redbackModel.password);
} }
$.log("user.rememberme:"+(user.rememberme)); $.log("user.rememberme:"+(user.rememberme));
reccordLoginCookie(user); reccordLoginCookie(user);