if (artifacts != null)
{
for (int ctr = 0; ctr < artifacts.length; ctr++)
{
final CartridgeArtifact cartridgeArtifact = artifacts[ctr];
final Artifact artifact = this.resolveArtifact(cartridgeArtifact);
if (artifact != null)
{
final String path = cartridgeArtifact.getPath();
if (path == null || path.trim().length() == 0)
{
throw new MojoFailureException("Please specify the 'path' for the cartridge artifact [" +
cartridgeArtifact.getGroupId() + ":" + cartridgeArtifact.getArtifactId() + ":" +
cartridgeArtifact.getType() + "]");
}
final File destinationDirectory = new File(outputDirectory,
cartridgeArtifact.getPath());
final File artifactFile = artifact.getFile();
final String artifactPath =
artifactFile != null
? StringUtils.replace(
artifact.getFile().toString().replaceAll(
".*(\\\\|/)",
""),
'-' + artifact.getVersion(),
"") : null;
if (artifactPath != null)
{
FileUtils.copyFile(
artifactFile,
new File(
destinationDirectory,
artifactPath));
}
}
}
}
final File cartridgeFile = new File(buildDirectory, this.finalName + ".jar");
final Artifact artifact = this.project.getArtifact();
final MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(this.jarArchiver);
archiver.setOutputFile(cartridgeFile);
archiver.getArchiver().addDirectory(
outputDirectory,
OUTPUT_INCLUDES,
null);
archiver.createArchive(
this.project,
this.archive);
artifact.setFile(cartridgeFile);
}
catch (final Throwable throwable)
{
throw new MojoExecutionException("An error occured while packaging this cartridge", throwable);
}