From f6d87c18b460665703b2ae44e91b60571a61c9d1 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 8 Jul 2010 05:53:27 +0000 Subject: [PATCH] [MRM-980] Add getArtifacts() method to be able to retrieve all artifacts in a repository Submitted by: Patti Arachchige Eshan Sudharaka git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-MRM-980@961576 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/TestMetadataRepository.java | 4 ++ .../memory/TestMetadataRepository.java | 4 ++ .../repository/TestMetadataRepository.java | 3 ++ .../repository/MetadataRepository.java | 2 + .../AbstractMetadataRepositoryTest.java | 11 +++++ .../repository/TestMetadataRepository.java | 3 ++ .../file/FileMetadataRepository.java | 40 +++++++++++++++++-- 7 files changed, 63 insertions(+), 4 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index 26393052b..60ebf4ee7 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -159,4 +159,8 @@ public class TestMetadataRepository { return null; //To change body of implemented methods use File | Settings | File Templates. } + + public List getArtifacts(String repositoryId){ + return null; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java index cd7ef6a0d..164922604 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java @@ -199,4 +199,8 @@ public class TestMetadataRepository { return artifacts; } + + public List getArtifacts(String repositoryId){ + return artifacts; + } } \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index 26393052b..d5dae295c 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -159,4 +159,7 @@ public class TestMetadataRepository { return null; //To change body of implemented methods use File | Settings | File Templates. } + public List getArtifacts(String repositoryId){ + return null; + } } 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 823129212..cc7c513fc 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 @@ -75,4 +75,6 @@ public interface MetadataRepository * @param repositoryId the repository to delete */ void deleteRepository( String repositoryId ); + + List getArtifacts(String repositoryId); } diff --git a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java index ca59dcc56..fd8362f48 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java +++ b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java @@ -484,6 +484,17 @@ public abstract class AbstractMetadataRepositoryTest Date upper = new Date( artifact.getWhenGathered().getTime() - 10000 ); assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ).isEmpty() ); + } + + public void testGetArtifactsByRepoId() + { + repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE ); + repository.updateProject( TEST_REPO_ID, createProject() ); + ArtifactMetadata artifact = createArtifact(); + repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); + assertFalse( repository.getArtifacts(TEST_REPO_ID).isEmpty()); + + } public void testGetNamespacesWithSparseDepth() 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 ea51c9e31..932152b68 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 @@ -114,4 +114,7 @@ public class TestMetadataRepository { //To change body of implemented methods use File | Settings | File Templates. } + public List getArtifacts(String repositoryId){ + return null; + } } \ No newline at end of file diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index aca1bace7..eab85f297 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -140,7 +140,7 @@ public class FileMetadataRepository { properties.remove( name ); } - + // clear the facet contents so old properties are no longer written clearMetadataFacetProperties( versionMetadata, properties ); } @@ -227,7 +227,7 @@ public class FileMetadataRepository } } } - + private void clearMetadataFacetProperties( ProjectVersionMetadata versionMetadata, Properties properties ) { List propsToRemove = new ArrayList(); @@ -242,7 +242,7 @@ public class FileMetadataRepository } } } - + for( Object key : propsToRemove ) { properties.remove( key ); @@ -577,7 +577,7 @@ public class FileMetadataRepository properties.remove( "artifact:sha1:" + id ); properties.remove( "artifact:version:" + id ); properties.remove( "artifact:facetIds:" + id ); - + String prefix = "artifact:facet:" + id + ":"; for ( Object key : new ArrayList( properties.keySet() ) ) { @@ -1075,4 +1075,36 @@ public class FileMetadataRepository return artifact1.getWhenGathered().compareTo( artifact2.getWhenGathered() ); } } + + public List getArtifacts( String repoId ) + { + + List artifacts = new ArrayList(); + for ( String ns : getRootNamespaces( repoId ) ) + { + getArtifacts( artifacts, repoId, ns ); + } + return artifacts; + } + + private void getArtifacts( List artifacts, String repoId, String ns ) + { + for ( String namespace : getNamespaces( repoId, ns ) ) + { + getArtifacts( artifacts, repoId, ns + "." + namespace ); + } + + for ( String project : getProjects( repoId, ns ) ) + { + for ( String version : getProjectVersions( repoId, ns, project ) ) + { + for ( ArtifactMetadata artifact : getArtifacts( repoId, ns, project, version ) ) + { + + artifacts.add( artifact ); + + } + } + } + } } -- 2.39.5