{
projects.add(this.getRootProject());
final Set artifacts = new LinkedHashSet();
for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
{
final MavenProject project = (MavenProject)iterator.next();
final Artifact artifact =
this.artifactFactory.createArtifact(
project.getGroupId(),
project.getArtifactId(),
project.getVersion(),
null,
project.getPackaging());
final String artifactPath = this.localRepository.pathOf(artifact);
final String artifactFileName = artifactPath.replaceAll(
".*(\\\\|/+)",
"");
final String repositoryDirectoryPath =
artifactPath.substring(
0,
artifactPath.indexOf(artifactFileName));
final Build build = project.getBuild();
final File workDirectory = new File(build.getDirectory());
final File distributionDirectory =
new File(new File(
directory,
this.artifactDirectory), repositoryDirectoryPath);
if (workDirectory.exists())
{
final String finalName = build.getFinalName();
final String[] names = workDirectory.list();
if (names != null)
{
final int numberOfArtifacts = names.length;
for (int ctr = 0; ctr < numberOfArtifacts; ctr++)
{
final String name = names[ctr];
if (name.indexOf(finalName) != -1 && !name.equals(finalName))
{
final File distributionFile = new File(distributionDirectory, name);
this.bundleFile(
artifact,
new File(
workDirectory,
name),
distributionFile);
}
}
}
}
else
{
this.artifactResolver.resolve(
artifact,
this.project.getRemoteArtifactRepositories(),
this.localRepository);
}
// - bundle the POM
final File repositoryPom =
this.constructPom(
new File(
this.localRepository.getBasedir(),
repositoryDirectoryPath),
artifact);
final File distributionPom = this.constructPom(
distributionDirectory,
artifact);
this.bundleFile(
artifact,
repositoryPom,
distributionPom);
artifacts.addAll(project.createArtifacts(
artifactFactory,
null,
null));
}
final ArtifactResolutionResult result =
this.artifactResolver.resolveTransitively(
artifacts,
this.project.getArtifact(),
this.project.getRemoteArtifactRepositories(),
this.localRepository,
this.artifactMetadataSource);
artifacts.addAll(result.getArtifacts());
// - 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 = artifacts.iterator(); artifactIterator.hasNext();)
{
final Artifact artifact = (Artifact)artifactIterator.next();