From eeed20ed3604a898910b347cecd19a6d8793e210 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 1 Jun 2012 23:48:01 +0000 Subject: fix an issue with not removing project version when removing an artifact from Metadatarepository git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1345397 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugins/metadata-store-file/pom.xml | 5 ++ archiva-modules/plugins/metadata-store-jcr/pom.xml | 5 ++ .../repository/jcr/JcrMetadataRepository.java | 53 ++++++++++++++-------- .../repository/jcr/JcrMetadataRepositoryTest.java | 1 + 4 files changed, 46 insertions(+), 18 deletions(-) (limited to 'archiva-modules/plugins') diff --git a/archiva-modules/plugins/metadata-store-file/pom.xml b/archiva-modules/plugins/metadata-store-file/pom.xml index fd50666e1..951c2e0b4 100644 --- a/archiva-modules/plugins/metadata-store-file/pom.xml +++ b/archiva-modules/plugins/metadata-store-file/pom.xml @@ -70,6 +70,11 @@ spring-test test + + org.easytesting + fest-assert + test + diff --git a/archiva-modules/plugins/metadata-store-jcr/pom.xml b/archiva-modules/plugins/metadata-store-jcr/pom.xml index ea7932b41..218bb3923 100644 --- a/archiva-modules/plugins/metadata-store-jcr/pom.xml +++ b/archiva-modules/plugins/metadata-store-jcr/pom.xml @@ -73,6 +73,11 @@ spring-test test + + org.easytesting + fest-assert + test + diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 0ad272528..b0acf2950 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -35,6 +35,7 @@ import org.apache.archiva.metadata.model.Scm; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.MetadataResolutionException; +import org.apache.commons.lang.StringUtils; import org.apache.jackrabbit.commons.JcrUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -615,24 +616,6 @@ public class JcrMetadataRepository return artifacts; } - public void removeArtifact( String repositoryId, String namespace, String projectId, String projectVersion, - String id ) - throws MetadataRepositoryException - { - try - { - Node root = getJcrSession().getRootNode(); - String path = getArtifactPath( repositoryId, namespace, projectId, projectVersion, id ); - if ( root.hasNode( path ) ) - { - root.getNode( path ).remove(); - } - } - catch ( RepositoryException e ) - { - throw new MetadataRepositoryException( e.getMessage(), e ); - } - } public void removeRepository( String repositoryId ) throws MetadataRepositoryException @@ -994,6 +977,40 @@ public class JcrMetadataRepository return getNodeNames( getProjectPath( repositoryId, namespace, projectId ), PROJECT_VERSION_NODE_TYPE ); } + public void removeArtifact( String repositoryId, String namespace, String projectId, String projectVersion, + String id ) + throws MetadataRepositoryException + { + try + { + Node root = getJcrSession().getRootNode(); + String path = getArtifactPath( repositoryId, namespace, projectId, projectVersion, id ); + if ( root.hasNode( path ) ) + { + root.getNode( path ).remove(); + } + + // remove version + + path = getProjectPath( repositoryId, namespace, projectId ); + + Node nodeAtPath = root.getNode( path ); + + for ( Node node : JcrUtils.getChildNodes( nodeAtPath ) ) + { + if ( node.isNodeType( PROJECT_VERSION_NODE_TYPE ) && StringUtils.equals( node.getName(), + projectVersion ) ) + { + node.remove(); + } + } + } + catch ( RepositoryException e ) + { + throw new MetadataRepositoryException( e.getMessage(), e ); + } + } + public Collection getArtifacts( String repositoryId, String namespace, String projectId, String projectVersion ) throws MetadataResolutionException diff --git a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java index 365135943..1123eb30a 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java @@ -77,6 +77,7 @@ public class JcrMetadataRepositoryTest this.repository = jcrMetadataRepository; } + @After public void tearDown() throws Exception -- cgit v1.2.3