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.Dependency;
26 import org.apache.archiva.metadata.model.ProjectMetadata;
27 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
28 import org.apache.archiva.metadata.model.ProjectVersionReference;
29 import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
30 import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver;
33 * @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver"
35 public class DefaultMetadataResolver
36 implements MetadataResolver
41 private MetadataRepository metadataRepository;
44 * FIXME: this needs to be configurable based on storage type, and availability of proxy module
45 * ... could be a different type since we need methods to modify the storage metadata, which would also allow more
46 * appropriate methods to pass in the already determined repository configuration, for example, instead of the ID
48 * @plexus.requirement role-hint="maven2"
50 private StorageMetadataResolver storageResolver;
52 public ProjectMetadata getProject( String repoId, String namespace, String projectId )
55 return metadataRepository.getProject( repoId, namespace, projectId );
58 public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
59 String projectVersion )
60 throws MetadataResolverException
62 ProjectVersionMetadata metadata =
63 metadataRepository.getProjectVersion( repoId, namespace, projectId, projectVersion );
64 // TODO: do we want to detect changes as well by comparing timestamps? isProjectVersionNewerThan(updated)
65 // in such cases we might also remove/update stale metadata, including adjusting plugin-based facets
66 if ( metadata == null )
68 metadata = storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion );
69 if ( metadata != null )
71 // FIXME: make this a more generic post-processing that plugins can take advantage of
72 // eg. maven projects should be able to process parent here
73 if ( !metadata.getDependencies().isEmpty() )
75 ProjectVersionReference ref = new ProjectVersionReference();
76 ref.setNamespace( namespace );
77 ref.setProjectId( projectId );
78 ref.setProjectVersion( projectVersion );
79 ref.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
80 for ( Dependency dependency : metadata.getDependencies() )
82 metadataRepository.updateProjectReference( repoId, dependency.getGroupId(),
83 dependency.getArtifactId(), dependency.getVersion(),
87 metadataRepository.updateProjectVersion( repoId, namespace, projectId, metadata );
93 public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
94 String projectVersion )
97 return metadataRepository.getArtifactVersions( repoId, namespace, projectId, projectVersion );
100 public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
101 String projectVersion )
103 // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
104 // not passed to the storage mechanism as resolving references would require iterating all artifacts
105 return metadataRepository.getProjectReferences( repoId, namespace, projectId, projectVersion );
108 public Collection<String> getRootNamespaces( String repoId )
110 Collection<String> namespaces = metadataRepository.getRootNamespaces( repoId );
111 Collection<String> storageNamespaces =
112 storageResolver.getRootNamespaces( repoId, new ExcludesFilter<String>( namespaces ) );
113 if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
115 for ( String n : storageNamespaces )
117 metadataRepository.updateNamespace( repoId, n );
119 namespaces = new ArrayList<String>( namespaces );
120 namespaces.addAll( storageNamespaces );
125 public Collection<String> getNamespaces( String repoId, String namespace )
127 Collection<String> namespaces = metadataRepository.getNamespaces( repoId, namespace );
128 Collection<String> exclusions = new ArrayList<String>( namespaces );
129 exclusions.addAll( metadataRepository.getProjects( repoId, namespace ) );
130 Collection<String> storageNamespaces =
131 storageResolver.getNamespaces( repoId, namespace, new ExcludesFilter<String>( exclusions ) );
132 if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
134 for ( String n : storageNamespaces )
136 metadataRepository.updateNamespace( repoId, namespace + "." + n );
138 namespaces = new ArrayList<String>( namespaces );
139 namespaces.addAll( storageNamespaces );
144 public Collection<String> getProjects( String repoId, String namespace )
146 Collection<String> projects = metadataRepository.getProjects( repoId, namespace );
147 Collection<String> exclusions = new ArrayList<String>( projects );
148 exclusions.addAll( metadataRepository.getNamespaces( repoId, namespace ) );
149 Collection<String> storageProjects =
150 storageResolver.getProjects( repoId, namespace, new ExcludesFilter<String>( exclusions ) );
151 if ( storageProjects != null && !storageProjects.isEmpty() )
153 for ( String projectId : storageProjects )
155 ProjectMetadata projectMetadata = storageResolver.getProject( repoId, namespace, projectId );
156 if ( projectMetadata != null )
158 metadataRepository.updateProject( repoId, projectMetadata );
161 projects = new ArrayList<String>( projects );
162 projects.addAll( storageProjects );
167 public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
168 throws MetadataResolverException
170 Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId );
171 Collection<String> storageProjectVersions = storageResolver.getProjectVersions( repoId, namespace, projectId,
172 new ExcludesFilter<String>(
174 if ( storageProjectVersions != null && !storageProjectVersions.isEmpty() )
176 for ( String projectVersion : storageProjectVersions )
178 ProjectVersionMetadata versionMetadata =
179 storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion );
180 if ( versionMetadata != null )
182 metadataRepository.updateProjectVersion( repoId, namespace, projectId, versionMetadata );
185 projectVersions = new ArrayList<String>( projectVersions );
186 projectVersions.addAll( storageProjectVersions );
188 return projectVersions;