// Create directory if not existing
this.outputFile.getParentFile().mkdirs();
// Build artifacts from modules
if (this.modules == null) {
throw new MojoExecutionException("No modules element has been set");
}
// Create list
List<Artifact> artifacts = new ArrayList<Artifact>();
// for each module, build artifact.
for (Module module : this.modules) {
String groupId = module.getGroupId();
String artifactId = module.getArtifactId();
String type = module.getType();
String version = module.getVersion();
String classifier = module.getClassifier();
if (groupId == null) {
throw new MojoExecutionException("No groupdId set for module '" + module + "'");
}
if (artifactId == null) {
throw new MojoExecutionException("No artifactId set for module '" + module + "'");
}
if (type == null) {
getLog().debug("No type set for module '" + module + "', assume it is jar type");
type = "jar";
module.setType(type);
}
if (version == null) {
// try to find version with dependency management
DependencyManagement dependencyManagement = this.project.getDependencyManagement();
if (dependencyManagement != null) {
// try to find a version for this component
List<Dependency> dependencies = dependencyManagement.getDependencies();
if (dependencies != null) {
for (Dependency dependency : dependencies) {
getLog().debug("Dependency = " + dependency);
if (groupId.equals(dependency.getGroupId()) && artifactId.equals(dependency.getArtifactId())
&& type.equals(dependency.getType())) {
getLog().debug("Using version of dependency management" + dependency.getVersion());
version = dependency.getVersion();
break;
}
}
}
}
if (version == null) {
throw new MojoExecutionException("No version set for module '" + module + "'");
}
}
Artifact artifact = null;
if (classifier != null) {
artifact = this.artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
} else {
artifact = this.artifactFactory.createBuildArtifact(groupId, artifactId, version, type);
}
getLog().debug("Built Artifact = " + artifact);
// now resolve this artifact
try {
this.artifactResolver.resolve(artifact, this.repositories, this.localRepository);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Cannot resolve artifact '" + artifactId + "'.", e);
} catch (ArtifactNotFoundException e) {
throw new MojoExecutionException("Artifact '" + artifactId + "' not found.", e);
}
// Add artifact
artifacts.add(artifact);
}
FileWriter fileWriter = null;
try {
// Create file writer
try {
fileWriter = new FileWriter(this.outputFile);
} catch (IOException e) {
throw new MojoExecutionException("Cannot create a file on '" + this.outputFile + "'", e);
}
// Write the name of the files
for (Artifact artifact : artifacts) {
try {
getLog().debug("Writing " + artifact.getFile().getName());
fileWriter.write(artifact.getFile().getName());
fileWriter.write("\n");
} catch (IOException e) {
throw new MojoExecutionException("Cannot write the line for Artifact '" + artifact + "' in the file '"
+ this.outputFile + "'", e);
}
}
} finally {
// close file writer