1 package org.apache.archiva.metadata.repository;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.Collection;
24 import org.apache.archiva.metadata.model.Dependency;
25 import org.apache.archiva.metadata.model.ProjectMetadata;
26 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
27 import org.apache.archiva.metadata.model.ProjectVersionReference;
30 * @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver"
32 public class DefaultMetadataResolver
33 implements MetadataResolver
38 private MetadataRepository metadataRepository;
41 * FIXME: this needs to be configurable based on storage type, and availability of proxy module
42 * ... could be a different type since we need methods to modify the storage metadata, which would also allow more
43 * appropriate methods to pass in the already determined repository configuration, for example, instead of the ID
45 * @plexus.requirement role-hint="maven2"
47 private MetadataResolver storageResolver;
49 public ProjectMetadata getProject( String repoId, String namespace, String projectId )
52 return metadataRepository.getProject( repoId, namespace, projectId );
55 public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
56 String projectVersion )
57 throws MetadataResolverException
59 ProjectVersionMetadata metadata =
60 metadataRepository.getProjectVersion( repoId, namespace, projectId, projectVersion );
61 // TODO: do we want to detect changes as well by comparing timestamps? isProjectVersionNewerThan(updated)
62 // in such cases we might also remove/update stale metadata, including adjusting plugin-based facets
63 if ( metadata == null )
65 metadata = storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion );
66 if ( metadata != null )
68 // FIXME: make this a more generic post-processing that plugins can take advantage of
69 // eg. maven projects should be able to process parent here
70 if ( !metadata.getDependencies().isEmpty() )
72 ProjectVersionReference ref = new ProjectVersionReference();
73 ref.setNamespace( namespace );
74 ref.setProjectId( projectId );
75 ref.setProjectVersion( projectVersion );
76 ref.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
77 for ( Dependency dependency : metadata.getDependencies() )
79 metadataRepository.updateProjectReference( repoId, dependency.getGroupId(),
80 dependency.getArtifactId(), dependency.getVersion(),
84 metadataRepository.updateProjectVersion( repoId, namespace, projectId, metadata );
90 public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
91 String projectVersion )
94 return metadataRepository.getArtifactVersions( repoId, namespace, projectId, projectVersion );
97 public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
98 String projectVersion )
100 // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
101 // not passed to the storage mechanism as resolving references would require iterating all artifacts
102 return metadataRepository.getProjectReferences( repoId, namespace, projectId, projectVersion );
105 public Collection<String> getRootNamespaces( String repoId )
107 // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
108 // not passed to the storage mechanism as resolving references would require iterating all groups
109 return metadataRepository.getRootNamespaces( repoId );
112 public Collection<String> getNamespaces( String repoId, String namespace )
114 // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
115 // not passed to the storage mechanism as resolving references would require iterating all groups
116 return metadataRepository.getNamespaces( repoId, namespace );
119 public Collection<String> getProjects( String repoId, String namespace )
121 // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
122 // not passed to the storage mechanism as resolving references would require iterating all projects
123 return metadataRepository.getProjects( repoId, namespace );
126 public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
128 // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
129 // not passed to the storage mechanism as resolving references would require iterating all versions
130 return metadataRepository.getProjectVersions( repoId, namespace, projectId );