private File createArchive(List<Artifact> bundles) throws MojoExecutionException {
ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
File archiveFile = getArchiveFile(outputDirectory, finalName, null);
MavenArchiver archiver = new MavenArchiver();
MavenArchiveConfiguration configuration = new MavenArchiveConfiguration();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(archiveFile);
try {
// include the features XML file
Artifact featureArtifact = factory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), "xml", KarArtifactInstaller.FEATURES_CLASSIFIER);
jarArchiver.addFile(featuresFile, repositoryPath + layout.pathOf(featureArtifact));
for (Artifact artifact : bundles) {
resolver.resolve(artifact, remoteRepos, localRepo);
File localFile = artifact.getFile();
// TODO this may not be reasonable, but... resolved snapshot artifacts have timestamped versions
// which do not work in startup.properties
artifact.setVersion(artifact.getBaseVersion());
String targetFileName = repositoryPath + layout.pathOf(artifact);
jarArchiver.addFile(localFile, targetFileName);
}
if (resourcesDir.isDirectory()) {
archiver.getArchiver().addDirectory(resourcesDir);
}
archiver.createArchive(project, configuration);
return archiveFile;
} catch (Exception e) {
throw new MojoExecutionException("Failed to create kar archive", e);
}