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.ArrayList;
23 import java.util.Collection;
25 import org.apache.archiva.metadata.model.ArtifactMetadata;
26 import org.apache.archiva.metadata.model.Dependency;
27 import org.apache.archiva.metadata.model.ProjectMetadata;
28 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
29 import org.apache.archiva.metadata.model.ProjectVersionReference;
30 import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
31 import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver;
34 * @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver"
36 public class DefaultMetadataResolver
37 implements MetadataResolver
42 private MetadataRepository metadataRepository;
45 * FIXME: this needs to be configurable based on storage type, and availability of proxy module
46 * ... could be a different type since we need methods to modify the storage metadata, which would also allow more
47 * appropriate methods to pass in the already determined repository configuration, for example, instead of the ID
49 * @plexus.requirement role-hint="maven2"
51 private StorageMetadataResolver storageResolver;
53 public ProjectMetadata getProject( String repoId, String namespace, String projectId )
56 return metadataRepository.getProject( repoId, namespace, projectId );
59 public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
60 String projectVersion )
61 throws MetadataResolverException
63 ProjectVersionMetadata metadata =
64 metadataRepository.getProjectVersion( repoId, namespace, projectId, projectVersion );
65 // TODO: do we want to detect changes as well by comparing timestamps? isProjectVersionNewerThan(updated)
66 // in such cases we might also remove/update stale metadata, including adjusting plugin-based facets
67 if ( metadata == null )
69 metadata = storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion );
70 if ( metadata != null )
72 // FIXME: make this a more generic post-processing that plugins can take advantage of
73 // eg. maven projects should be able to process parent here
74 if ( !metadata.getDependencies().isEmpty() )
76 ProjectVersionReference ref = new ProjectVersionReference();
77 ref.setNamespace( namespace );
78 ref.setProjectId( projectId );
79 ref.setProjectVersion( projectVersion );
80 ref.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
81 for ( Dependency dependency : metadata.getDependencies() )
83 metadataRepository.updateProjectReference( repoId, dependency.getGroupId(),
84 dependency.getArtifactId(), dependency.getVersion(),
88 metadataRepository.updateProjectVersion( repoId, namespace, projectId, metadata );
94 public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
95 String projectVersion )
98 return metadataRepository.getArtifactVersions( repoId, namespace, projectId, projectVersion );
101 public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
102 String projectVersion )
104 // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
105 // not passed to the storage mechanism as resolving references would require iterating all artifacts
106 return metadataRepository.getProjectReferences( repoId, namespace, projectId, projectVersion );
109 public Collection<String> getRootNamespaces( String repoId )
111 Collection<String> namespaces = metadataRepository.getRootNamespaces( repoId );
112 Collection<String> storageNamespaces =
113 storageResolver.getRootNamespaces( repoId, new ExcludesFilter<String>( namespaces ) );
114 if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
116 for ( String n : storageNamespaces )
118 metadataRepository.updateNamespace( repoId, n );
120 namespaces = new ArrayList<String>( namespaces );
121 namespaces.addAll( storageNamespaces );
126 public Collection<String> getNamespaces( String repoId, String namespace )
128 Collection<String> namespaces = metadataRepository.getNamespaces( repoId, namespace );
129 Collection<String> exclusions = new ArrayList<String>( namespaces );
130 exclusions.addAll( metadataRepository.getProjects( repoId, namespace ) );
131 Collection<String> storageNamespaces =
132 storageResolver.getNamespaces( repoId, namespace, new ExcludesFilter<String>( exclusions ) );
133 if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
135 for ( String n : storageNamespaces )
137 metadataRepository.updateNamespace( repoId, namespace + "." + n );
139 namespaces = new ArrayList<String>( namespaces );
140 namespaces.addAll( storageNamespaces );
145 public Collection<String> getProjects( String repoId, String namespace )
147 Collection<String> projects = metadataRepository.getProjects( repoId, namespace );
148 Collection<String> exclusions = new ArrayList<String>( projects );
149 exclusions.addAll( metadataRepository.getNamespaces( repoId, namespace ) );
150 Collection<String> storageProjects =
151 storageResolver.getProjects( repoId, namespace, new ExcludesFilter<String>( exclusions ) );
152 if ( storageProjects != null && !storageProjects.isEmpty() )
154 for ( String projectId : storageProjects )
156 ProjectMetadata projectMetadata = storageResolver.getProject( repoId, namespace, projectId );
157 if ( projectMetadata != null )
159 metadataRepository.updateProject( repoId, projectMetadata );
162 projects = new ArrayList<String>( projects );
163 projects.addAll( storageProjects );
168 public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
169 throws MetadataResolverException
171 Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId );
172 Collection<String> storageProjectVersions = storageResolver.getProjectVersions( repoId, namespace, projectId,
173 new ExcludesFilter<String>(
175 if ( storageProjectVersions != null && !storageProjectVersions.isEmpty() )
177 for ( String projectVersion : storageProjectVersions )
179 ProjectVersionMetadata versionMetadata =
180 storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion );
181 if ( versionMetadata != null )
183 metadataRepository.updateProjectVersion( repoId, namespace, projectId, versionMetadata );
186 projectVersions = new ArrayList<String>( projectVersions );
187 projectVersions.addAll( storageProjectVersions );
189 return projectVersions;
192 public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
193 String projectVersion )
195 Collection<ArtifactMetadata> artifacts =
196 metadataRepository.getArtifacts( repoId, namespace, projectId, projectVersion );
197 Collection<ArtifactMetadata> storageArtifacts =
198 storageResolver.getArtifacts( repoId, namespace, projectId, projectVersion,
199 new ExcludesFilter<String>( createArtifactIdList( artifacts ) ) );
200 if ( storageArtifacts != null && !storageArtifacts.isEmpty() )
202 for ( ArtifactMetadata artifact : storageArtifacts )
204 metadataRepository.updateArtifact( repoId, namespace, projectId, projectVersion, artifact );
206 artifacts = new ArrayList<ArtifactMetadata>( artifacts );
207 artifacts.addAll( storageArtifacts );
212 private Collection<String> createArtifactIdList( Collection<ArtifactMetadata> artifacts )
214 Collection<String> artifactIds = new ArrayList<String>();
215 for ( ArtifactMetadata artifact : artifacts )
217 artifactIds.add( artifact.getId() );