// If we have a system scoped artifact then we do not want any searching in local or remote repositories
// and we want artifact resolution to only return the system scoped artifact itself.
//
if ( artifact.getScope() != null && artifact.getScope().equals( Artifact.SCOPE_SYSTEM ) )
{
return new ResolutionGroup( null, null, null );
}
ResolutionGroup cached =
cache.get( artifact, request.isResolveManagedVersions(), request.getLocalRepository(),
request.getRemoteRepositories() );
if ( cached != null )
{
// if the POM has no file, we cached a missing artifact, only return the cached data if no update forced
if ( !request.isForceUpdate() || hasFile( cached.getPomArtifact() ) )
{
return cached;
}
}
List<Dependency> dependencies;
List<Dependency> managedDependencies = null;
List<ArtifactRepository> pomRepositories = null;
Artifact pomArtifact;
Artifact relocatedArtifact = null;
//TODO: Not even sure this is really required as the project will be cached in the builder, we'll see this
// is currently the biggest hotspot
if ( artifact instanceof ArtifactWithDependencies )
{
pomArtifact = artifact;
dependencies = ( (ArtifactWithDependencies) artifact ).getDependencies();
managedDependencies = ( (ArtifactWithDependencies) artifact ).getManagedDependencies();
}
else
{
ProjectRelocation rel = retrieveRelocatedProject( artifact, request );
if ( rel == null )
{
return null;
}
pomArtifact = rel.pomArtifact;
relocatedArtifact = rel.relocatedArtifact;
if ( rel.project == null )
{
// When this happens we have a Maven 1.x POM, or some invalid POM. There is still a pile of
// shit in the Maven 2.x repository that should have never found its way into the repository
// but it did.
dependencies = Collections.emptyList();
}
else
{
dependencies = rel.project.getDependencies();
DependencyManagement depMngt = rel.project.getDependencyManagement();
managedDependencies = ( depMngt != null ) ? depMngt.getDependencies() : null;
pomRepositories = rel.project.getRemoteArtifactRepositories();
}
}
Set<Artifact> artifacts = Collections.<Artifact>emptySet();
if ( !artifact.getArtifactHandler().isIncludesDependencies() )
{
artifacts = new LinkedHashSet<Artifact>();
for ( Dependency dependency : dependencies )
{
Artifact dependencyArtifact = createDependencyArtifact( dependency, artifact, pomArtifact );
if ( dependencyArtifact != null )
{
artifacts.add( dependencyArtifact );
}
}
}
Map<String, Artifact> managedVersions = null;
if ( managedDependencies != null && request.isResolveManagedVersions() )
{
managedVersions = new HashMap<String, Artifact>();
for ( Dependency managedDependency : managedDependencies )
{
Artifact managedArtifact = createDependencyArtifact( managedDependency, null, pomArtifact );
managedVersions.put( managedDependency.getManagementKey(), managedArtifact );
}
}
List<ArtifactRepository> aggregatedRepositories =
aggregateRepositories( request.getRemoteRepositories(), pomRepositories );
ResolutionGroup result =
new ResolutionGroup( pomArtifact, relocatedArtifact, artifacts, managedVersions, aggregatedRepositories );
cache.put( artifact, request.isResolveManagedVersions(), request.getLocalRepository(),
request.getRemoteRepositories(), result );
return result;