001 package org.apache.maven.artifact.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
022 import java.util.HashSet;
023 import java.util.List;
024 import java.util.Set;
025
026 import org.apache.maven.artifact.Artifact;
027 import org.apache.maven.artifact.factory.ArtifactFactory;
028 import org.apache.maven.artifact.repository.ArtifactRepository;
029 import org.apache.maven.artifact.versioning.ArtifactVersion;
030 import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
031 import org.codehaus.plexus.component.annotations.Component;
032 import org.codehaus.plexus.component.annotations.Requirement;
033
034 @Component(role = ArtifactMetadataSource.class, hint="test")
035 public class TestMetadataSource
036 implements ArtifactMetadataSource
037 {
038 @Requirement
039 private ArtifactFactory factory;
040
041 public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
042 throws ArtifactMetadataRetrievalException
043 {
044 Set dependencies = new HashSet();
045
046 if ( "g".equals( artifact.getArtifactId() ) )
047 {
048 Artifact a = null;
049 try
050 {
051 a = factory.createBuildArtifact( "org.apache.maven", "h", "1.0", "jar" );
052 dependencies.add( a );
053 }
054 catch ( Exception e )
055 {
056 throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a );
057 }
058 }
059
060 if ( "i".equals( artifact.getArtifactId() ) )
061 {
062 Artifact a = null;
063 try
064 {
065 a = factory.createBuildArtifact( "org.apache.maven", "j", "1.0-SNAPSHOT", "jar" );
066 dependencies.add( a );
067 }
068 catch ( Exception e )
069 {
070 throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a );
071 }
072 }
073
074
075 return new ResolutionGroup( artifact, dependencies, remoteRepositories );
076 }
077
078 public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
079 throws ArtifactMetadataRetrievalException
080 {
081 throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
082 }
083
084 public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
085 throws ArtifactMetadataRetrievalException
086 {
087 throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
088 }
089
090 public ResolutionGroup retrieve( MetadataResolutionRequest request )
091 throws ArtifactMetadataRetrievalException
092 {
093 return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
094 }
095
096 public List<ArtifactVersion> retrieveAvailableVersions( MetadataResolutionRequest request )
097 throws ArtifactMetadataRetrievalException
098 {
099 return retrieveAvailableVersions( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
100 }
101
102 }