final FileWriter fileWriter = new FileWriter(classpathFile);
final XMLWriter writer = new PrettyPrintXMLWriter(fileWriter);
writer.startElement("classpath");
final Set projectArtifactIds = new LinkedHashSet();
for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
{
final MavenProject project = (MavenProject)iterator.next();
final Artifact projectArtifact =
artifactFactory.createArtifact(
project.getGroupId(),
project.getArtifactId(),
project.getVersion(),
null,
project.getPackaging());
projectArtifactIds.add(projectArtifact.getId());
}
// - write the source roots for the root project (if they are any)
this.writeSourceRoots(this.project, rootDirectory, writer);
final Set allArtifacts = new LinkedHashSet(this.project.createArtifacts(
artifactFactory,
null,
null));
for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
{
final MavenProject project = (MavenProject)iterator.next();
this.writeSourceRoots(project, rootDirectory, writer);
final Set artifacts = project.createArtifacts(
artifactFactory,
null,
null);
// - get the direct dependencies
for (final Iterator artifactIterator = artifacts.iterator(); artifactIterator.hasNext();)
{
final Artifact artifact = (Artifact)artifactIterator.next();
// - don't attempt to resolve the artifact if its part of the project (we
// infer this if it has the same id has one of the projects or is in
// the same groupId).
if (!projectArtifactIds.contains(artifact.getId()) &&
!project.getGroupId().equals(artifact.getGroupId()))
{
artifactResolver.resolve(
artifact,
project.getRemoteArtifactRepositories(),
localRepository);
allArtifacts.add(artifact);
}
else
{
allArtifacts.add(artifact);
}
}
}
// - remove the project artifacts
for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
{
final MavenProject project = (MavenProject)iterator.next();
final Artifact projectArtifact = project.getArtifact();
if (projectArtifact != null)
{
for (final Iterator artifactIterator = allArtifacts.iterator(); artifactIterator.hasNext();)
{
final Artifact artifact = (Artifact)artifactIterator.next();
final String projectId = projectArtifact.getArtifactId();
final String projectGroupId = projectArtifact.getGroupId();
final String artifactId = artifact.getArtifactId();
final String groupId = artifact.getGroupId();
if (artifactId.equals(projectId) && groupId.equals(projectGroupId))
{
artifactIterator.remove();
}
}
}
}
// - now we resolve transitively, if we have the flag on
if (resolveTransitiveDependencies)
{
final Artifact rootProjectArtifact =
artifactFactory.createArtifact(
this.project.getGroupId(),
this.project.getArtifactId(),
this.project.getVersion(),
null,
this.project.getPackaging());
final OrArtifactFilter filter = new OrArtifactFilter();
filter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE));
filter.add(new ScopeArtifactFilter(Artifact.SCOPE_PROVIDED));
filter.add(new ScopeArtifactFilter(Artifact.SCOPE_TEST));
final ArtifactResolutionResult result =
artifactResolver.resolveTransitively(
allArtifacts,
rootProjectArtifact,
localRepository,
remoteRepositories,
artifactMetadataSource,
filter);
allArtifacts.clear();
allArtifacts.addAll(result.getArtifacts());
}
final List allArtifactPaths = new ArrayList(allArtifacts);
for (final ListIterator iterator = allArtifactPaths.listIterator(); iterator.hasNext();)
{