Browse Source

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
tags/archiva-1.4-M4
Olivier Lamy 11 years ago
parent
commit
092a635e39

+ 19
- 2
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java 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 )
{

+ 14
- 3
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java 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;

+ 27
- 0
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java 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

Loading…
Cancel
Save