aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-06-05 21:42:02 +0000
committerOlivier Lamy <olamy@apache.org>2012-06-05 21:42:02 +0000
commitea5ddd09615bd26400024da1b8de70b592391c58 (patch)
tree4ce87e7ced70243007271425de5964152d8a1e0c /archiva-modules
parent25e650b0b4dc368ff6492711e24df6e5edc9b07c (diff)
downloadarchiva-ea5ddd09615bd26400024da1b8de70b592391c58.tar.gz
archiva-ea5ddd09615bd26400024da1b8de70b592391c58.zip
improve MetadataRepository api to be able to remove an artifact with MetadataFacet use case deleting a maven artifact with a classifier
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1346609 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/mock/MockRepositorySessionFactory.java8
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockRepositorySessionFactory.java8
-rw-r--r--archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/mock/MockRepositorySessionFactory.java18
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java11
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java89
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java39
-rw-r--r--archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/FacetedMetadata.java6
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java13
-rw-r--r--archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java19
-rw-r--r--archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java39
-rw-r--r--archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java8
-rw-r--r--archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java19
-rw-r--r--archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java56
13 files changed, 297 insertions, 36 deletions
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/mock/MockRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/mock/MockRepositorySessionFactory.java
index fa175d670..5a6c40042 100644
--- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/mock/MockRepositorySessionFactory.java
+++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/mock/MockRepositorySessionFactory.java
@@ -63,6 +63,14 @@ public class MockRepositorySessionFactory
{
return new MetadataRepository( )
{
+
+ public void removeArtifact( String repositoryId, String namespace, String project,
+ String projectVersion, String projectId, MetadataFacet metadataFacet )
+ throws MetadataRepositoryException
+ {
+
+ }
+
public void updateProject( String repositoryId, ProjectMetadata project )
throws MetadataRepositoryException
{
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockRepositorySessionFactory.java
index f753ce9ea..649343209 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockRepositorySessionFactory.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockRepositorySessionFactory.java
@@ -63,6 +63,14 @@ public class MockRepositorySessionFactory
{
return new MetadataRepository( )
{
+
+ public void removeArtifact( String repositoryId, String namespace, String project,
+ String projectVersion, String projectId, MetadataFacet metadataFacet )
+ throws MetadataRepositoryException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
public void updateProject( String repositoryId, ProjectMetadata project )
throws MetadataRepositoryException
{
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/mock/MockRepositorySessionFactory.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/mock/MockRepositorySessionFactory.java
index 063fa4b4b..37290708a 100644
--- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/mock/MockRepositorySessionFactory.java
+++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/mock/MockRepositorySessionFactory.java
@@ -63,30 +63,38 @@ public class MockRepositorySessionFactory
{
return new MetadataRepository()
{
+
+ public void removeArtifact( String repositoryId, String namespace, String project,
+ String projectVersion, String projectId, MetadataFacet metadataFacet )
+ throws MetadataRepositoryException
+ {
+
+ }
+
public void updateProject( String repositoryId, ProjectMetadata project )
throws MetadataRepositoryException
{
- //To change body of implemented methods use File | Settings | File Templates.
+
}
public void updateArtifact( String repositoryId, String namespace, String projectId,
String projectVersion, ArtifactMetadata artifactMeta )
throws MetadataRepositoryException
{
- //To change body of implemented methods use File | Settings | File Templates.
+
}
public void updateProjectVersion( String repositoryId, String namespace, String projectId,
ProjectVersionMetadata versionMetadata )
throws MetadataRepositoryException
{
- //To change body of implemented methods use File | Settings | File Templates.
+
}
public void updateNamespace( String repositoryId, String namespace )
throws MetadataRepositoryException
{
- //To change body of implemented methods use File | Settings | File Templates.
+
}
public List<String> getMetadataFacets( String repositoryId, String facetId )
@@ -104,7 +112,7 @@ public class MockRepositorySessionFactory
public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
throws MetadataRepositoryException
{
- //To change body of implemented methods use File | Settings | File Templates.
+
}
public void removeMetadataFacets( String repositoryId, String facetId )
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
index b82ee5d16..06509af11 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
@@ -129,4 +129,15 @@ public interface RepositoriesService
Boolean isAuthorizedToDeleteArtifacts( @PathParam( "repositoryId" ) String repoId )
throws ArchivaRestServiceException;
+ @Path( "deleteGroupId" )
+ @GET
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+ @RedbackAuthorization( noPermission = true )
+ /**
+ * <b>permissions are checked in impl</b>
+ * @since 1.4-M3
+ */
+ Boolean deleteGroupId( @QueryParam( "groupId" ) String groupId )
+ throws ArchivaRestServiceException;
+
}
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 6ee2cec2a..d49f6efca 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
@@ -37,6 +37,7 @@ 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.RepositorySessionFactory;
+import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.VersionedReference;
@@ -669,6 +670,10 @@ public class DefaultRepositoriesService
ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
+ MetadataRepository metadataRepository = repositorySession.getRepository();
+
+ String path = repository.toMetadataPath( ref );
+
if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
{
if ( StringUtils.isBlank( artifact.getPackaging() ) )
@@ -684,45 +689,73 @@ public class DefaultRepositoriesService
artifactReference.setType( artifact.getPackaging() );
repository.deleteArtifact( artifactReference );
- // TODO cleanup facet which contains classifier information
- return Boolean.TRUE;
}
-
- String path = repository.toMetadataPath( ref );
- int index = path.lastIndexOf( '/' );
- path = path.substring( 0, index );
- File targetPath = new File( repoConfig.getLocation(), path );
-
- if ( !targetPath.exists() )
+ else
{
- throw new ContentNotFoundException(
- artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() );
- }
- // TODO: this should be in the storage mechanism so that it is all tied together
- // delete from file system
- repository.deleteVersion( ref );
+ int index = path.lastIndexOf( '/' );
+ path = path.substring( 0, index );
+ File targetPath = new File( repoConfig.getLocation(), path );
- File metadataFile = getMetadata( targetPath.getAbsolutePath() );
- ArchivaRepositoryMetadata metadata = getMetadata( metadataFile );
+ if ( !targetPath.exists() )
+ {
+ throw new ContentNotFoundException(
+ artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() );
+ }
- updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, artifact );
+ // TODO: this should be in the storage mechanism so that it is all tied together
+ // delete from file system
+ repository.deleteVersion( ref );
- MetadataRepository metadataRepository = repositorySession.getRepository();
+ File metadataFile = getMetadata( targetPath.getAbsolutePath() );
+ ArchivaRepositoryMetadata metadata = getMetadata( metadataFile );
+ updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, artifact );
+ }
Collection<ArtifactMetadata> artifacts =
metadataRepository.getArtifacts( repositoryId, artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion() );
for ( ArtifactMetadata artifactMetadata : artifacts )
{
+
// TODO: mismatch between artifact (snapshot) version and project (base) version here
if ( artifactMetadata.getVersion().equals( artifact.getVersion() ) )
{
- metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(),
- artifactMetadata.getNamespace(), artifactMetadata.getProject(),
- artifact.getVersion(), artifactMetadata.getId() );
+ if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
+ {
+ if ( StringUtils.isBlank( artifact.getPackaging() ) )
+ {
+ throw new ArchivaRestServiceException(
+ "You must configure a type/packaging when using classifier", 400, null );
+ }
+ // cleanup facet which contains classifier information
+ MavenArtifactFacet mavenArtifactFacet =
+ (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+
+ if ( StringUtils.equals( artifact.getClassifier(), mavenArtifactFacet.getClassifier() ) )
+ {
+ 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,
+ mavenArtifactFacetToCompare );
+ metadataRepository.save();
+ }
+ }
+ else
+ {
+ metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(),
+ artifactMetadata.getNamespace(),
+ artifactMetadata.getProject(), artifact.getVersion(),
+ artifactMetadata.getId() );
+ }
// TODO: move into the metadata repository proper - need to differentiate attachment of
// repository metadata to an artifact
for ( RepositoryListener listener : listeners )
@@ -736,11 +769,8 @@ public class DefaultRepositoriesService
}
}
- repositorySession.save();
- repositorySession.close();
}
-
catch ( ContentNotFoundException e )
{
throw new ArchivaRestServiceException( "Artifact does not exist: " + e.getMessage(), 400, e );
@@ -766,13 +796,20 @@ public class DefaultRepositoriesService
throw new ArchivaRestServiceException( "RepositoryAdmin exception: " + e.getMessage(), 500, e );
}
finally
-
{
+ repositorySession.save();
+
repositorySession.close();
}
return Boolean.TRUE;
}
+ public Boolean deleteGroupId( String groupId )
+ throws ArchivaRestServiceException
+ {
+ return true;
+ }
+
public Boolean isAuthorizedToDeleteArtifacts( String repoId )
throws ArchivaRestServiceException
{
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
index 4ecdddbe7..59fcbbd65 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
@@ -22,13 +22,14 @@ package org.apache.archiva.rest.services;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.common.utils.FileUtil;
import org.apache.archiva.rest.api.model.Artifact;
+import org.apache.archiva.rest.api.model.BrowseResult;
+import org.apache.archiva.rest.api.model.BrowseResultEntry;
import org.apache.archiva.rest.api.model.VersionsList;
import org.apache.archiva.rest.api.services.BrowseService;
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
import org.apache.archiva.rest.api.services.RepositoriesService;
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
import org.fest.assertions.Assertions;
-import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
@@ -189,7 +190,6 @@ public class RepositoriesServiceTest
}
@Test
- @Ignore
public void deleteArtifactWithClassifier()
throws Exception
{
@@ -232,9 +232,15 @@ public class RepositoriesServiceTest
artifacts =
browseService.getArtifactDownloadInfos( "commons-logging", "commons-logging", "1.0.1", SOURCE_REPO_ID );
- Assertions.assertThat( artifacts ).isNotNull().isEmpty();
+ log.info( "artifact: {}", artifacts );
+
+ Assertions.assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 2 );
+
+ versionsList = browseService.getVersionsList( "commons-logging", "commons-logging", SOURCE_REPO_ID );
- Assertions.assertThat( versionsList.getVersions() ).isNotNull().isNotEmpty().hasSize( 5 );
+ log.info( "versionsList: {}", versionsList );
+
+ Assertions.assertThat( versionsList.getVersions() ).isNotNull().isNotEmpty().hasSize( 6 );
}
finally
@@ -245,6 +251,31 @@ public class RepositoriesServiceTest
@Test
+ public void deleteGroupId()
+ throws Exception
+ {
+ initSourceTargetRepo();
+ try
+ {
+ BrowseService browseService = getBrowseService( authorizationHeader, false );
+
+ BrowseResult browseResult = browseService.browseGroupId( "org.apache.karaf.features", SOURCE_REPO_ID );
+
+ assertNotNull( browseResult );
+
+ Assertions.assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isNotEmpty().contains(
+ new BrowseResultEntry( "org.apache.karaf.features.org.apache.karaf.features.command", true ),
+ new BrowseResultEntry( "org.apache.karaf.features.org.apache.karaf.features.core", true ) );
+
+ log.info( "browseResult: {}", browseResult );
+ }
+ finally
+ {
+ cleanRepos();
+ }
+ }
+
+ @Test
public void authorizedToDeleteArtifacts()
throws Exception
{
diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/FacetedMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/FacetedMetadata.java
index 387813e36..e2261a199 100644
--- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/FacetedMetadata.java
+++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/FacetedMetadata.java
@@ -19,7 +19,6 @@ package org.apache.archiva.metadata.model;
* under the License.
*/
-import javax.xml.bind.annotation.XmlElement;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -56,6 +55,11 @@ public abstract class FacetedMetadata
return this.facets.get( facetId );
}
+ public MetadataFacet removeFacet( String facetId )
+ {
+ return this.facets.remove( facetId );
+ }
+
/**
* Get all the facets available on this metadata.
*
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
index 4ab65c642..60e536357 100644
--- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
@@ -80,6 +80,19 @@ public interface MetadataRepository
throws MetadataRepositoryException;
/**
+ * @param repositoryId
+ * @param namespace
+ * @param project
+ * @param version
+ * @param metadataFacet will remove artifacts which have this {@link MetadataFacet} using equals
+ * @throws MetadataRepositoryException
+ * @since 1.4-M3
+ */
+ void removeArtifact( String repositoryId, String namespace, String project, String version,
+ MetadataFacet metadataFacet )
+ throws MetadataRepositoryException;
+
+ /**
* Delete a repository's metadata. This includes all associated metadata facets.
*
* @param repositoryId the repository to delete
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java
index aa330385d..6e72fdcd7 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java
@@ -20,6 +20,7 @@ package org.apache.archiva.metadata.repository.storage.maven2;
*/
import org.apache.archiva.metadata.model.MetadataFacet;
+import org.apache.commons.lang.StringUtils;
import java.util.HashMap;
import java.util.Map;
@@ -118,4 +119,22 @@ public class MavenArtifactFacet
this.buildNumber = Integer.parseInt( buildNumber );
}
}
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( !( o instanceof MavenArtifactFacet ) )
+ {
+ return false;
+ }
+
+ MavenArtifactFacet that = (MavenArtifactFacet) o;
+
+ return StringUtils.equals( that.getClassifier(), this.classifier );
+ }
+
}
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
index 83fe1693e..93826d8d1 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
@@ -118,4 +118,43 @@ public class MavenProjectFacet
this.parent = parent;
}
}
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( !( o instanceof MavenProjectFacet ) )
+ {
+ return false;
+ }
+
+ MavenProjectFacet that = (MavenProjectFacet) o;
+
+ if ( !artifactId.equals( that.artifactId ) )
+ {
+ return false;
+ }
+ if ( !groupId.equals( that.groupId ) )
+ {
+ return false;
+ }
+ if ( !packaging.equals( that.packaging ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = groupId.hashCode();
+ result = 31 * result + artifactId.hashCode();
+ result = 31 * result + packaging.hashCode();
+ return result;
+ }
}
diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
index 3d5760765..24a0a5d44 100644
--- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
+++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
@@ -198,4 +198,12 @@ public class TestMetadataRepository
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
+
+
+ public void removeArtifact( String repositoryId, String namespace, String project, String projectVersion,
+ String projectId, MetadataFacet metadataFacet )
+ throws MetadataRepositoryException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
} \ No newline at end of file
diff --git a/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
index ad483d5ec..e3de5fd40 100644
--- a/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
+++ b/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
@@ -35,8 +35,10 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.model.Scm;
import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.NotImplementedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -635,6 +637,23 @@ public class FileMetadataRepository
}
}
+ /**
+ * FIXME implements this !!!!
+ * @param repositoryId
+ * @param namespace
+ * @param project
+ * @param projectVersion
+ * @param projectId
+ * @param metadataFacet will remove artifacts which have this {@link MetadataFacet} using equals
+ * @throws MetadataRepositoryException
+ */
+ public void removeArtifact( String repositoryId, String namespace, String project, String projectVersion,
+ String projectId, MetadataFacet metadataFacet )
+ throws MetadataRepositoryException
+ {
+ throw new NotImplementedException( "not implemented" );
+ }
+
public void removeRepository( String repoId )
{
File dir = getDirectory( repoId );
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 b0acf2950..ab1b1cbd6 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
@@ -194,6 +194,27 @@ public class JcrMetadataRepository
node.setProperty( "version", artifactMeta.getVersion() );
+ // iterate over available facets to update/add/remove from the artifactMetadata
+ for ( String facetId : metadataFacetFactories.keySet() )
+ {
+ MetadataFacet metadataFacet = artifactMeta.getFacet( facetId );
+ if ( node.hasNode( facetId ) )
+ {
+ node.getNode( facetId ).remove();
+ }
+ if ( metadataFacet != null )
+ {
+ // recreate, to ensure properties are removed
+ Node n = node.addNode( facetId );
+ n.addMixin( FACET_NODE_TYPE );
+
+ for ( Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet() )
+ {
+ n.setProperty( entry.getKey(), entry.getValue() );
+ }
+ }
+ }
+ /*
for ( MetadataFacet facet : artifactMeta.getFacetList() )
{
if ( node.hasNode( facet.getFacetId() ) )
@@ -210,6 +231,7 @@ public class JcrMetadataRepository
n.setProperty( entry.getKey(), entry.getValue() );
}
}
+ */
}
catch ( RepositoryException e )
{
@@ -1011,6 +1033,40 @@ public class JcrMetadataRepository
}
}
+ public void removeArtifact( String repositoryId, String namespace, String project, String projectVersion,
+ MetadataFacet metadataFacet )
+ throws MetadataRepositoryException
+ {
+ try
+ {
+ Node root = getJcrSession().getRootNode();
+ String path = getProjectVersionPath( repositoryId, namespace, project, projectVersion );
+
+ if ( root.hasNode( path ) )
+ {
+ Node node = root.getNode( path );
+
+ for ( Node n : JcrUtils.getChildNodes( node ) )
+ {
+ if ( n.isNodeType( ARTIFACT_NODE_TYPE ) )
+ {
+ ArtifactMetadata artifactMetadata = getArtifactFromNode( repositoryId, n );
+ log.debug( "artifactMetadata: {}", artifactMetadata );
+ MetadataFacet metadataFacetToRemove = artifactMetadata.getFacet( metadataFacet.getFacetId() );
+ if ( metadataFacetToRemove != null && metadataFacet.equals( metadataFacetToRemove ) )
+ {
+ n.remove();
+ }
+ }
+ }
+ }
+ }
+ catch ( RepositoryException e )
+ {
+ throw new MetadataRepositoryException( e.getMessage(), e );
+ }
+ }
+
public Collection<ArtifactMetadata> getArtifacts( String repositoryId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException