do some cleanup if metadatarepository still contains versions when deleting

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1397342 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-10-11 22:42:00 +00:00
parent db43bb9339
commit 092a635e39
3 changed files with 60 additions and 5 deletions

View 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 )
{

View 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;

View 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