1 package org.apache.archiva.metadata.repository.memory;
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;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.LinkedHashSet;
26 import java.util.List;
30 import org.apache.archiva.metadata.model.ArtifactMetadata;
31 import org.apache.archiva.metadata.model.ProjectMetadata;
32 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
33 import org.apache.archiva.metadata.model.ProjectVersionReference;
34 import org.apache.archiva.metadata.repository.MetadataResolver;
36 public class TestMetadataResolver
37 implements MetadataResolver
39 private Map<String, ProjectVersionMetadata> projectVersions = new HashMap<String, ProjectVersionMetadata>();
41 private Map<String, List<String>> artifactVersions = new HashMap<String, List<String>>();
43 private Map<String, List<ProjectVersionReference>> references =
44 new HashMap<String, List<ProjectVersionReference>>();
46 private List<String> namespaces;
48 private Map<String, Collection<String>> projectsInNamespace = new HashMap<String, Collection<String>>();
50 private Map<String, Collection<String>> versionsInProject = new HashMap<String, Collection<String>>();
52 public ProjectMetadata getProject( String repoId, String namespace, String projectId )
54 ProjectMetadata metadata = new ProjectMetadata();
55 metadata.setNamespace( namespace );
56 metadata.setId( projectId );
60 public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
61 String projectVersion )
63 return projectVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
66 public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
67 String projectVersion )
69 List<String> versions = artifactVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
70 return ( versions != null ? versions : Collections.<String>emptyList() );
73 public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
74 String projectVersion )
76 return references.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
79 public Collection<String> getRootNamespaces( String repoId )
81 return getNamespaces( null );
84 private Collection<String> getNamespaces( String baseNamespace )
86 Set<String> namespaces = new LinkedHashSet<String>();
87 int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
88 for ( String namespace : this.namespaces )
90 if ( baseNamespace == null || namespace.startsWith( baseNamespace + "." ) )
92 int i = namespace.indexOf( '.', fromIndex );
95 namespaces.add( namespace.substring( fromIndex, i ) );
99 namespaces.add( namespace.substring( fromIndex ) );
106 public Collection<String> getNamespaces( String repoId, String namespace )
108 return getNamespaces( namespace );
111 public Collection<String> getProjects( String repoId, String namespace )
113 Collection<String> list = projectsInNamespace.get( namespace );
114 return list != null ? list : Collections.<String>emptyList();
117 public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
119 Collection<String> list = versionsInProject.get( namespace + ":" + projectId );
120 return list != null ? list : Collections.<String>emptyList();
123 public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
124 String projectVersion )
126 return null; //To change body of implemented methods use File | Settings | File Templates.
129 public void setProjectVersion( String repoId, String namespace, String projectId,
130 ProjectVersionMetadata versionMetadata )
132 projectVersions.put( createMapKey( repoId, namespace, projectId, versionMetadata.getId() ), versionMetadata );
134 Collection<String> projects = projectsInNamespace.get( namespace );
135 if ( projects == null )
137 projects = new LinkedHashSet<String>();
138 projectsInNamespace.put( namespace, projects );
140 projects.add( projectId );
142 String key = namespace + ":" + projectId;
143 Collection<String> versions = versionsInProject.get( key );
144 if ( versions == null )
146 versions = new LinkedHashSet<String>();
147 versionsInProject.put( key, versions );
149 versions.add( versionMetadata.getId() );
152 public void setArtifactVersions( String repoId, String namespace, String projectId, String projectVersion,
153 List<String> versions )
155 artifactVersions.put( createMapKey( repoId, namespace, projectId, projectVersion ), versions );
158 private String createMapKey( String repoId, String namespace, String projectId, String projectVersion )
160 return repoId + ":" + namespace + ":" + projectId + ":" + projectVersion;
163 public void setProjectReferences( String repoId, String namespace, String projectId, String projectVersion,
164 List<ProjectVersionReference> references )
166 this.references.put( createMapKey( repoId, namespace, projectId, projectVersion ), references );
169 public void setNamespaces( List<String> namespaces )
171 this.namespaces = namespaces;