diff options
author | Brett Porter <brett@apache.org> | 2010-12-22 08:31:56 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2010-12-22 08:31:56 +0000 |
commit | c63e2a3f776db2d2bc1aff70834e2ad905e86042 (patch) | |
tree | 622337eeaa5f1310c1819ce138a3494fc4a69215 /archiva-modules/metadata | |
parent | f9cd1037d1170cbdc93d6596d2b948f9164bf911 (diff) | |
download | archiva-c63e2a3f776db2d2bc1aff70834e2ad905e86042.tar.gz archiva-c63e2a3f776db2d2bc1aff70834e2ad905e86042.zip |
[MRM-1327] refactor the repository API to make each concern clearer. Storage, resolver and metadata repository are separate interfaces. Rename methods on the resolver and the storage to be clearer of their intent
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1051788 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/metadata')
6 files changed, 139 insertions, 111 deletions
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java index 9fd802db9..7e4e22830 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java @@ -25,7 +25,7 @@ import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.repository.filter.ExcludesFilter; -import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver; +import org.apache.archiva.metadata.repository.storage.RepositoryStorage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,19 +50,12 @@ public class DefaultMetadataResolver * * @plexus.requirement role-hint="maven2" */ - private StorageMetadataResolver storageResolver; + private RepositoryStorage repositoryStorage; private static final Logger log = LoggerFactory.getLogger( DefaultMetadataResolver.class ); - public ProjectMetadata getProject( String repoId, String namespace, String projectId ) - throws MetadataResolutionException - { - // TODO: intercept - return metadataRepository.getProject( repoId, namespace, projectId ); - } - - public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, - String projectVersion ) + public ProjectVersionMetadata resolveProjectVersion( String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException { ProjectVersionMetadata metadata = metadataRepository.getProjectVersion( repoId, namespace, projectId, @@ -74,7 +67,7 @@ public class DefaultMetadataResolver // may then work here and be more efficient than always trying again) if ( metadata == null || metadata.isIncomplete() ) { - metadata = storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion ); + metadata = repositoryStorage.readProjectVersionMetadata( repoId, namespace, projectId, projectVersion ); if ( metadata != null ) { if ( log.isDebugEnabled() ) @@ -117,16 +110,8 @@ public class DefaultMetadataResolver return metadata; } - public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, - String projectVersion ) - throws MetadataResolutionException - { - // TODO: intercept - return metadataRepository.getArtifactVersions( repoId, namespace, projectId, projectVersion ); - } - - public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId, - String projectVersion ) + public Collection<ProjectVersionReference> resolveProjectReferences( String repoId, String namespace, + String projectId, String projectVersion ) throws MetadataResolutionException { // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario? @@ -134,11 +119,11 @@ public class DefaultMetadataResolver return metadataRepository.getProjectReferences( repoId, namespace, projectId, projectVersion ); } - public Collection<String> getRootNamespaces( String repoId ) + public Collection<String> resolveRootNamespaces( String repoId ) throws MetadataResolutionException { Collection<String> namespaces = metadataRepository.getRootNamespaces( repoId ); - Collection<String> storageNamespaces = storageResolver.getRootNamespaces( repoId, new ExcludesFilter<String>( + Collection<String> storageNamespaces = repositoryStorage.listRootNamespaces( repoId, new ExcludesFilter<String>( namespaces ) ); if ( storageNamespaces != null && !storageNamespaces.isEmpty() ) { @@ -163,15 +148,15 @@ public class DefaultMetadataResolver return namespaces; } - public Collection<String> getNamespaces( String repoId, String namespace ) + public Collection<String> resolveNamespaces( String repoId, String namespace ) throws MetadataResolutionException { Collection<String> namespaces = metadataRepository.getNamespaces( repoId, namespace ); Collection<String> exclusions = new ArrayList<String>( namespaces ); exclusions.addAll( metadataRepository.getProjects( repoId, namespace ) ); - Collection<String> storageNamespaces = storageResolver.getNamespaces( repoId, namespace, - new ExcludesFilter<String>( - exclusions ) ); + Collection<String> storageNamespaces = repositoryStorage.listNamespaces( repoId, namespace, + new ExcludesFilter<String>( + exclusions ) ); if ( storageNamespaces != null && !storageNamespaces.isEmpty() ) { if ( log.isDebugEnabled() ) @@ -195,14 +180,14 @@ public class DefaultMetadataResolver return namespaces; } - public Collection<String> getProjects( String repoId, String namespace ) + public Collection<String> resolveProjects( String repoId, String namespace ) throws MetadataResolutionException { Collection<String> projects = metadataRepository.getProjects( repoId, namespace ); Collection<String> exclusions = new ArrayList<String>( projects ); exclusions.addAll( metadataRepository.getNamespaces( repoId, namespace ) ); - Collection<String> storageProjects = storageResolver.getProjects( repoId, namespace, new ExcludesFilter<String>( - exclusions ) ); + Collection<String> storageProjects = repositoryStorage.listProjects( repoId, namespace, + new ExcludesFilter<String>( exclusions ) ); if ( storageProjects != null && !storageProjects.isEmpty() ) { if ( log.isDebugEnabled() ) @@ -211,7 +196,7 @@ public class DefaultMetadataResolver } for ( String projectId : storageProjects ) { - ProjectMetadata projectMetadata = storageResolver.getProject( repoId, namespace, projectId ); + ProjectMetadata projectMetadata = repositoryStorage.readProjectMetadata( repoId, namespace, projectId ); if ( projectMetadata != null ) { try @@ -230,13 +215,13 @@ public class DefaultMetadataResolver return projects; } - public Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) + public Collection<String> resolveProjectVersions( String repoId, String namespace, String projectId ) throws MetadataResolutionException { Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId ); - Collection<String> storageProjectVersions = storageResolver.getProjectVersions( repoId, namespace, projectId, - new ExcludesFilter<String>( - projectVersions ) ); + Collection<String> storageProjectVersions = repositoryStorage.listProjectVersions( repoId, namespace, projectId, + new ExcludesFilter<String>( + projectVersions ) ); if ( storageProjectVersions != null && !storageProjectVersions.isEmpty() ) { if ( log.isDebugEnabled() ) @@ -247,9 +232,10 @@ public class DefaultMetadataResolver { try { - ProjectVersionMetadata versionMetadata = storageResolver.getProjectVersion( repoId, namespace, - projectId, - projectVersion ); + ProjectVersionMetadata versionMetadata = repositoryStorage.readProjectVersionMetadata( repoId, + namespace, + projectId, + projectVersion ); if ( versionMetadata != null ) { metadataRepository.updateProjectVersion( repoId, namespace, projectId, versionMetadata ); @@ -271,17 +257,18 @@ public class DefaultMetadataResolver return projectVersions; } - public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, - String projectVersion ) + public Collection<ArtifactMetadata> resolveArtifacts( String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException { Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts( repoId, namespace, projectId, projectVersion ); - Collection<ArtifactMetadata> storageArtifacts = storageResolver.getArtifacts( repoId, namespace, projectId, - projectVersion, - new ExcludesFilter<String>( - createArtifactIdList( - artifacts ) ) ); + Collection<ArtifactMetadata> storageArtifacts = repositoryStorage.readArtifactsMetadata( repoId, namespace, + projectId, + projectVersion, + new ExcludesFilter<String>( + createArtifactIdList( + artifacts ) ) ); if ( storageArtifacts != null && !storageArtifacts.isEmpty() ) { if ( log.isDebugEnabled() ) 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 130dc7300..f43fbc4fb 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 @@ -30,7 +30,6 @@ import java.util.Date; import java.util.List; public interface MetadataRepository - extends MetadataResolver { /** * Update metadata for a particular project in the metadata repository, or create it if it does not already exist. @@ -81,7 +80,7 @@ public interface MetadataRepository List<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String checksum ) throws MetadataRepositoryException; - void deleteArtifact( String repositoryId, String namespace, String project, String version, String id ) + void removeArtifact( String repositoryId, String namespace, String project, String version, String id ) throws MetadataRepositoryException; /** @@ -89,9 +88,49 @@ public interface MetadataRepository * * @param repositoryId the repository to delete */ - void deleteRepository( String repositoryId ) + void removeRepository( String repositoryId ) throws MetadataRepositoryException; List<ArtifactMetadata> getArtifacts( String repositoryId ) throws MetadataRepositoryException; + + ProjectMetadata getProject( String repoId, String namespace, String projectId ) + throws MetadataResolutionException; + + ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataResolutionException; + + Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataResolutionException; + + /** + * Retrieve project references from the metadata repository. Note that this is not built into the content model for + * a project version as a reference may be present (due to reverse-lookup of dependencies) before the actual + * project is, and we want to avoid adding a stub model to the content repository. + * + * @param repoId the repository ID to look within + * @param namespace the namespace of the project to get references to + * @param projectId the identifier of the project to get references to + * @param projectVersion the version of the project to get references to + * @return a list of project references + */ + Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId, + String projectVersion ) + throws MetadataResolutionException; + + Collection<String> getRootNamespaces( String repoId ) + throws MetadataResolutionException; + + Collection<String> getNamespaces( String repoId, String namespace ) + throws MetadataResolutionException; + + Collection<String> getProjects( String repoId, String namespace ) + throws MetadataResolutionException; + + Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) + throws MetadataResolutionException; + + Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, + String projectVersion ) + throws MetadataResolutionException; } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java index 6de4ad562..4815ceb79 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java @@ -20,7 +20,6 @@ package org.apache.archiva.metadata.repository; */ import org.apache.archiva.metadata.model.ArtifactMetadata; -import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; @@ -28,13 +27,8 @@ import java.util.Collection; public interface MetadataResolver { - ProjectMetadata getProject( String repoId, String namespace, String projectId ) - throws MetadataResolutionException; - - ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) - throws MetadataResolutionException; - - Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ) + ProjectVersionMetadata resolveProjectVersion( String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException; /** @@ -48,23 +42,23 @@ public interface MetadataResolver * @param projectVersion the version of the project to get references to * @return a list of project references */ - Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId, - String projectVersion ) + Collection<ProjectVersionReference> resolveProjectReferences( String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException; - Collection<String> getRootNamespaces( String repoId ) + Collection<String> resolveRootNamespaces( String repoId ) throws MetadataResolutionException; - Collection<String> getNamespaces( String repoId, String namespace ) + Collection<String> resolveNamespaces( String repoId, String namespace ) throws MetadataResolutionException; - Collection<String> getProjects( String repoId, String namespace ) + Collection<String> resolveProjects( String repoId, String namespace ) throws MetadataResolutionException; - Collection<String> getProjectVersions( String repoId, String namespace, String projectId ) + Collection<String> resolveProjectVersions( String repoId, String namespace, String projectId ) throws MetadataResolutionException; - Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, - String projectVersion ) + Collection<ArtifactMetadata> resolveArtifacts( String repoId, String namespace, String projectId, + String projectVersion ) throws MetadataResolutionException; } diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryStorage.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryStorage.java new file mode 100644 index 000000000..e780ec473 --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryStorage.java @@ -0,0 +1,52 @@ +package org.apache.archiva.metadata.repository.storage; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.model.ProjectMetadata; +import org.apache.archiva.metadata.model.ProjectVersionMetadata; +import org.apache.archiva.metadata.repository.MetadataResolutionException; +import org.apache.archiva.metadata.repository.filter.Filter; + +import java.util.Collection; + +public interface RepositoryStorage +{ + ProjectMetadata readProjectMetadata( String repoId, String namespace, String projectId ) + throws MetadataResolutionException; + + ProjectVersionMetadata readProjectVersionMetadata( String repoId, String namespace, String projectId, + String projectVersion ) + throws MetadataResolutionException; + + Collection<String> listRootNamespaces( String repoId, Filter<String> filter ); + + Collection<String> listNamespaces( String repoId, String namespace, Filter<String> filter ); + + Collection<String> listProjects( String repoId, String namespace, Filter<String> filter ); + + Collection<String> listProjectVersions( String repoId, String namespace, String projectId, Filter<String> filter ); + + Collection<ArtifactMetadata> readArtifactsMetadata( String repoId, String namespace, String projectId, + String projectVersion, Filter<String> filter ); + + // TODO: reconsider this API, do we want to expose storage format in the form of a path? + ArtifactMetadata readArtifactMetadataFromPath( String repoId, String path ); +} diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/StorageMetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/StorageMetadataResolver.java deleted file mode 100644 index 771bd4266..000000000 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/StorageMetadataResolver.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.apache.archiva.metadata.repository.storage; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.model.ArtifactMetadata; -import org.apache.archiva.metadata.repository.MetadataResolver; -import org.apache.archiva.metadata.repository.filter.Filter; - -import java.util.Collection; - -public interface StorageMetadataResolver - extends MetadataResolver -{ - Collection<String> getRootNamespaces( String repoId, Filter<String> filter ); - - Collection<String> getNamespaces( String repoId, String namespace, Filter<String> filter ); - - Collection<String> getProjects( String repoId, String namespace, Filter<String> filter ); - - Collection<String> getProjectVersions( String repoId, String namespace, String projectId, Filter<String> filter ); - - Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, String projectVersion, - Filter<String> filter ); - - // TODO: reconsider this API, do we want to expose storage format in the form of a path? - ArtifactMetadata getArtifactForPath( String repoId, String path ); -} 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 643df1817..f9f13c1b4 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 @@ -873,7 +873,7 @@ public abstract class AbstractMetadataRepositoryTest assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) ); - repository.deleteArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() ); + repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() ); assertTrue( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() ); @@ -909,7 +909,7 @@ public abstract class AbstractMetadataRepositoryTest assertEquals( expected, actual ); - repository.deleteRepository( TEST_REPO_ID ); + repository.removeRepository( TEST_REPO_ID ); assertTrue( repository.getArtifacts( TEST_REPO_ID ).isEmpty() ); assertTrue( repository.getRootNamespaces( TEST_REPO_ID ).isEmpty() ); |