123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package org.apache.archiva.web.webtest.memory;
-
- /*
- * 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.ProjectVersionMetadata;
- import org.apache.archiva.metadata.model.ProjectVersionReference;
- import org.apache.archiva.metadata.repository.MetadataResolver;
- import org.apache.archiva.metadata.repository.RepositorySession;
-
- import java.util.Collection;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.LinkedHashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
-
- public class TestMetadataResolver
- implements MetadataResolver
- {
- private Map<String, ProjectVersionMetadata> projectVersions = new HashMap<>();
-
- private Map<String, List<ArtifactMetadata>> artifacts = new HashMap<>();
-
- private Map<String, List<ProjectVersionReference>> references =
- new HashMap<String, List<ProjectVersionReference>>();
-
- private Map<String, List<String>> namespaces = new HashMap<>();
-
- private Map<String, Collection<String>> projectsInNamespace = new HashMap<>();
-
- private Map<String, Collection<String>> versionsInProject = new HashMap<>();
-
- @Override
- public ProjectVersionMetadata resolveProjectVersion( RepositorySession repositorySession, String repoId,
- String namespace, String projectId, String projectVersion )
- {
- return projectVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
- }
-
- @Override
- public Collection<ProjectVersionReference> resolveProjectReferences( RepositorySession repositorySession,
- String repoId, String namespace,
- String projectId, String projectVersion )
- {
- Collection<ProjectVersionReference> projectVersionReferences =
- references.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
- return projectVersionReferences;
- }
-
- @Override
- public Collection<String> resolveRootNamespaces( RepositorySession repositorySession, String repoId )
- {
- return resolveNamespaces( repositorySession, repoId, null );
- }
-
- @Override
- public Collection<String> resolveNamespaces( RepositorySession repositorySession, String repoId,
- String baseNamespace )
- {
- Set<String> namespaces = new LinkedHashSet<String>();
- int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
- for ( String namespace : this.namespaces.get( repoId ) )
- {
- if ( baseNamespace == null || namespace.startsWith( baseNamespace + "." ) )
- {
- int i = namespace.indexOf( '.', fromIndex );
- if ( i >= 0 )
- {
- namespaces.add( namespace.substring( fromIndex, i ) );
- }
- else
- {
- namespaces.add( namespace.substring( fromIndex ) );
- }
- }
- }
- return namespaces;
- }
-
- @Override
- public Collection<String> resolveProjects( RepositorySession repositorySession, String repoId, String namespace )
- {
- Collection<String> list = projectsInNamespace.get( namespace );
- return list != null ? list : Collections.<String>emptyList();
- }
-
- @Override
- public Collection<String> resolveProjectVersions( RepositorySession repositorySession, String repoId,
- String namespace, String projectId )
- {
- Collection<String> list = versionsInProject.get( namespace + ":" + projectId );
- return list != null ? list : Collections.<String>emptyList();
- }
-
- @Override
- public Collection<ArtifactMetadata> resolveArtifacts( RepositorySession repositorySession, String repoId,
- String namespace, String projectId, String projectVersion )
- {
- List<ArtifactMetadata> artifacts =
- this.artifacts.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
- return ( artifacts != null ? artifacts : Collections.<ArtifactMetadata>emptyList() );
- }
-
- public void setProjectVersion( String repoId, String namespace, String projectId,
- ProjectVersionMetadata versionMetadata )
- {
- projectVersions.put( createMapKey( repoId, namespace, projectId, versionMetadata.getId() ), versionMetadata );
-
- Collection<String> projects = projectsInNamespace.get( namespace );
- if ( projects == null )
- {
- projects = new LinkedHashSet<String>();
- projectsInNamespace.put( namespace, projects );
- }
- projects.add( projectId );
-
- String key = namespace + ":" + projectId;
- Collection<String> versions = versionsInProject.get( key );
- if ( versions == null )
- {
- versions = new LinkedHashSet<String>();
- versionsInProject.put( key, versions );
- }
- versions.add( versionMetadata.getId() );
- }
-
- public void setArtifacts( String repoId, String namespace, String projectId, String projectVersion,
- List<ArtifactMetadata> artifacts )
- {
- this.artifacts.put( createMapKey( repoId, namespace, projectId, projectVersion ), artifacts );
- }
-
- private String createMapKey( String repoId, String namespace, String projectId, String projectVersion )
- {
- return repoId + ":" + namespace + ":" + projectId + ":" + projectVersion;
- }
-
- public void setProjectReferences( String repoId, String namespace, String projectId, String projectVersion,
- List<ProjectVersionReference> references )
- {
- this.references.put( createMapKey( repoId, namespace, projectId, projectVersion ), references );
- }
-
- public void setNamespaces( String repoId, List<String> namespaces )
- {
- this.namespaces.put( repoId, namespaces );
- }
- }
|