private static Collection<Artifact> downloadArtifact( PlexusContainer container, String groupId, String artifactId,
String version, File setting )
throws ComponentLookupException, ArtifactNotFoundException, ArtifactResolutionException, IOException
{
ArtifactRepositoryFactory factory =
(ArtifactRepositoryFactory) container.lookup( ArtifactRepositoryFactory.ROLE );
DefaultRepositoryLayout layout =
(DefaultRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, "default" );
ArtifactRepository localRepository =
factory.createArtifactRepository( "local", getLocalRepositoryURL( container, setting ), layout, null, null );
List<ArtifactRepository> remoteRepositories = new ArrayList<ArtifactRepository>();
remoteRepositories.add(
factory.createArtifactRepository( "central", "http://repo1.maven.org/maven2", layout, null, null ) );
//Load extra repositories from active profile
Settings settings = getSettings( container, setting );
List<String> profileIds = settings.getActiveProfiles();
Map<String, Profile> profilesAsMap = settings.getProfilesAsMap();
if ( profileIds != null && !profileIds.isEmpty() )
{
for ( String profileId : profileIds )
{
Profile profile = profilesAsMap.get( profileId );
if ( profile != null )
{
List<Repository> repos = profile.getRepositories();
if ( repos != null && !repos.isEmpty() )
{
for ( Repository repo : repos )
{
remoteRepositories.add( factory.createArtifactRepository( repo.getId(), repo.getUrl(),
layout, null, null ) );
}
}
}
}
}
ArtifactFactory artifactFactory = (ArtifactFactory) container.lookup( ArtifactFactory.ROLE );
Artifact artifact =
artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" );
Artifact dummyArtifact = artifactFactory.createProjectArtifact( "dummy", "dummy", "1.0" );
if ( artifact.isSnapshot() )
{
remoteRepositories.add( factory.createArtifactRepository( "apache.snapshots",
"http://people.apache.org/repo/m2-snapshot-repository",
layout, null, null ) );
}
ArtifactResolver resolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );