ArtifactRepository localRepo = createLocalArtifactRepository();
log( "Using local repository: " + localRepo.getBasedir(), Project.MSG_VERBOSE );
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
List dependencies = this.dependencies;
Pom pom = buildPom( projectBuilder, localRepo );
if ( pom != null )
{
if ( !dependencies.isEmpty() )
{
throw new BuildException( "You cannot specify both dependencies and a pom in the dependencies task" );
}
dependencies = pom.getDependencies();
for ( Iterator i = pom.getRepositories().iterator(); i.hasNext(); )
{
Repository pomRepository = (Repository) i.next();
addRemoteRepository( createAntRemoteRepository( pomRepository ) );
}
}
else
{
// we have to have some sort of Pom object in order to satisfy the requirements for building the
// originating Artifact below...
pom = createDummyPom();
}
if ( dependencies.isEmpty() )
{
log( "There were no dependencies specified", Project.MSG_WARN );
}
log( "Resolving dependencies...", Project.MSG_VERBOSE );
WagonManager wagonManager = (WagonManager) lookup( WagonManager.ROLE );
wagonManager.setDownloadMonitor( new AntDownloadMonitor() );
ArtifactResolutionResult result;
Set artifacts;
List remoteArtifactRepositories = createRemoteArtifactRepositories();
try
{
artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, null );
Artifact pomArtifact = artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom
.getVersion(), pom.getPackaging() );
List listeners = Collections.singletonList( new AntResolutionListener( getProject(), verbose ) );
// TODO: managed dependencies
Map managedDependencies = Collections.EMPTY_MAP;
ArtifactFilter filter = null;
if ( useScope != null )
{
filter = new ScopeArtifactFilter( useScope );
}
if ( type != null )
{
TypeArtifactFilter typeArtifactFilter = new TypeArtifactFilter( type );
if ( filter != null )
{
AndArtifactFilter andFilter = new AndArtifactFilter();
andFilter.add( filter );
andFilter.add( typeArtifactFilter );
filter = andFilter;
}
else
{
filter = typeArtifactFilter;
}
}
result = resolver.resolveTransitively( artifacts, pomArtifact, managedDependencies, localRepo,
remoteArtifactRepositories, metadataSource, filter, listeners );
}
catch ( ArtifactResolutionException e )
{
throw new BuildException( "Unable to resolve artifact: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new BuildException( "Dependency not found: " + e.getMessage(), e );
}
catch ( InvalidDependencyVersionException e )
{
throw new BuildException( e.getMessage(), e );
}
/*
MANTTASKS-37: Do what other ant tasks do and just override the path id.
if ( pathId != null && getProject().getReference( pathId ) != null )
{
throw new BuildException( "Reference ID " + pathId + " already exists" );
}
if ( filesetId != null && getProject().getReference( filesetId ) != null )
{
throw new BuildException( "Reference ID " + filesetId + " already exists" );
}
if ( sourcesFilesetId != null && getProject().getReference( sourcesFilesetId ) != null )
{
throw new BuildException( "Reference ID " + sourcesFilesetId + " already exists" );
}
*/
FileList fileList = new FileList();
fileList.setDir( getLocalRepository().getPath() );
FileSet fileSet = new FileSet();
fileSet.setProject( getProject() );
fileSet.setDir( fileList.getDir( getProject() ) );
FileList sourcesFileList = new FileList();
sourcesFileList.setDir( getLocalRepository().getPath() );
FileSet sourcesFileSet = new FileSet();
sourcesFileSet.setDir( sourcesFileList.getDir( getProject() ) );
Set versions = new HashSet();
if ( result.getArtifacts().isEmpty() )
{
fileSet.createExclude().setName( "**/**" );
}
else
{
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
artifact.isSnapshot(); // MNG-2961: DefaultArtifact getBaseVersion is changed to "xxxx-SNAPSHOT" only if you first call isSnapshot()
String filename = localRepo.pathOf( artifact );
FileList.FileName file = new FileList.FileName();
file.setName( filename );
fileList.addConfiguredFile( file );
fileSet.createInclude().setName( filename );
versions.add( artifact.getBaseVersion() );
if ( sourcesFilesetId != null )
{
log( "Resolving dependencies sources...", Project.MSG_VERBOSE );
// get sources
Artifact sourcesArtifact =
artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), "java-source", "sources" );
if ( sourcesArtifact != null )
{
try
{