001package org.apache.maven.repository.metadata; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.HashSet; 023import java.util.List; 024import java.util.Set; 025 026import org.apache.maven.artifact.Artifact; 027import org.apache.maven.artifact.factory.ArtifactFactory; 028import org.apache.maven.artifact.repository.ArtifactRepository; 029import org.apache.maven.artifact.versioning.ArtifactVersion; 030import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException; 031import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource; 032import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; 033import org.apache.maven.repository.legacy.metadata.ResolutionGroup; 034import org.codehaus.plexus.component.annotations.Component; 035import org.codehaus.plexus.component.annotations.Requirement; 036 037@Component(role = ArtifactMetadataSource.class) 038public class TestMetadataSource 039 implements ArtifactMetadataSource 040{ 041 @Requirement 042 private ArtifactFactory factory; 043 044 public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories ) 045 throws ArtifactMetadataRetrievalException 046 { 047 Set dependencies = new HashSet(); 048 049 if ( "g".equals( artifact.getArtifactId() ) ) 050 { 051 Artifact a = null; 052 try 053 { 054 a = factory.createBuildArtifact( "org.apache.maven", "h", "1.0", "jar" ); 055 dependencies.add( a ); 056 } 057 catch ( Exception e ) 058 { 059 throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a ); 060 } 061 } 062 063 if ( "i".equals( artifact.getArtifactId() ) ) 064 { 065 Artifact a = null; 066 try 067 { 068 a = factory.createBuildArtifact( "org.apache.maven", "j", "1.0-SNAPSHOT", "jar" ); 069 dependencies.add( a ); 070 } 071 catch ( Exception e ) 072 { 073 throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a ); 074 } 075 } 076 077 078 return new ResolutionGroup( artifact, dependencies, remoteRepositories ); 079 } 080 081 public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories ) 082 throws ArtifactMetadataRetrievalException 083 { 084 throw new UnsupportedOperationException( "Cannot get available versions in this test case" ); 085 } 086 087 public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository ) 088 throws ArtifactMetadataRetrievalException 089 { 090 throw new UnsupportedOperationException( "Cannot get available versions in this test case" ); 091 } 092 093 public ResolutionGroup retrieve( MetadataResolutionRequest request ) 094 throws ArtifactMetadataRetrievalException 095 { 096 return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() ); 097 } 098 099}