use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.
the class PreparePackageMojo method pack.
private void pack(File sourceDir, File destination) throws MojoExecutionException {
getLog().info("Packing " + sourceDir.getPath() + " to\n " + destination.getPath());
try {
destination.getParentFile().mkdirs();
jarArchiver.setDestFile(destination);
jarArchiver.addDirectory(sourceDir);
jarArchiver.setManifest(new File(sourceDir, "META-INF/MANIFEST.MF".replace('/', File.separatorChar)));
jarArchiver.createArchive();
} catch (IOException e) {
throw new MojoExecutionException("Unable to pack " + sourceDir.getPath(), e);
} catch (ArchiverException e) {
throw new MojoExecutionException("Unable to pack " + sourceDir.getPath(), e);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.
the class AttachBundleListMojo method executeWithArtifacts.
@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
FileWriter fw = null;
try {
this.outputFile.getParentFile().mkdirs();
fw = new FileWriter(outputFile);
writer.write(fw, getInitializedBundleList());
projectHelper.attachArtifact(project, AttachPartialBundleListMojo.TYPE, AttachPartialBundleListMojo.CLASSIFIER, outputFile);
} catch (IOException e) {
throw new MojoExecutionException("Unable to output effective bundle list", e);
} finally {
if (fw != null) {
try {
fw.close();
} catch (IOException e) {
}
}
}
this.getLog().info("Attaching bundle list configuration");
try {
this.attachConfigurations();
} catch (final IOException ioe) {
throw new MojoExecutionException("Unable to attach configuration.", ioe);
} catch (final ArchiverException ioe) {
throw new MojoExecutionException("Unable to attach configuration.", ioe);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.
the class AttachPartialBundleListMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
final BundleList initializedBundleList;
if (bundleListFile.exists()) {
try {
initializedBundleList = readBundleList(bundleListFile);
} catch (IOException e) {
throw new MojoExecutionException("Unable to read bundle list file", e);
} catch (XmlPullParserException e) {
throw new MojoExecutionException("Unable to read bundle list file", e);
}
} else {
throw new MojoFailureException(String.format("Bundle list file %s does not exist.", bundleListFile.getAbsolutePath()));
}
interpolateProperties(initializedBundleList, this.project, this.mavenSession);
final BundleListXpp3Writer writer = new BundleListXpp3Writer();
try {
this.bundleListOutput.getParentFile().mkdirs();
writer.write(new FileWriter(bundleListOutput), initializedBundleList);
} catch (IOException e) {
throw new MojoExecutionException("Unable to write bundle list", e);
}
// if this project is a partial bundle list, it's the main artifact
if (project.getPackaging().equals(PARTIAL)) {
project.getArtifact().setFile(bundleListOutput);
} else {
// otherwise attach it as an additional artifact
projectHelper.attachArtifact(project, TYPE, CLASSIFIER, bundleListOutput);
}
this.getLog().info("Attaching bundle list configuration");
try {
this.attachConfigurations();
} catch (final IOException ioe) {
throw new MojoExecutionException("Unable to attach configuration.", ioe);
} catch (final ArchiverException ioe) {
throw new MojoExecutionException("Unable to attach configuration.", ioe);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.
the class CreateBundleJarMojo method addBundles.
private void addBundles() throws MojoExecutionException {
BundleList bundles = getInitializedBundleList();
for (StartLevel level : bundles.getStartLevels()) {
for (Bundle bundle : level.getBundles()) {
Artifact artifact = getArtifact(new ArtifactDefinition(bundle, level.getStartLevel()));
final String destFileName = getPathForArtifact(level.getStartLevel(), bundle.getRunModes(), artifact.getFile().getName());
try {
jarArchiver.addFile(artifact.getFile(), destFileName);
} catch (ArchiverException e) {
throw new MojoExecutionException("Unable to add file to bundle jar file: " + artifact.getFile().getAbsolutePath(), e);
}
}
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project aries by apache.
the class EsaMojo method addDependenciesToArchive.
/**
* add the dependencies to the archive depending on the configuration of <archiveContent />
*/
private void addDependenciesToArchive() throws MojoExecutionException {
try {
Set<Artifact> artifacts = null;
switch(EsaContent.valueOf(archiveContent)) {
case none:
getLog().info("archiveContent=none: subsystem archive will not contain any bundles.");
break;
case content:
// only include the direct dependencies in the archive
artifacts = project.getDependencyArtifacts();
break;
case all:
// include direct and transitive dependencies in the archive
artifacts = project.getArtifacts();
break;
default:
throw new MojoExecutionException("Invalid configuration for <archiveContent/>. Valid values are none, content and all.");
}
if (artifacts != null) {
// Explicitly add self to bundle set (used when pom packaging
// type != "esa" AND a file is present (no point to add to
// zip archive without file)
final Artifact selfArtifact = project.getArtifact();
if (!"esa".equals(selfArtifact.getType()) && selfArtifact.getFile() != null) {
getLog().info("Explicitly adding artifact[" + selfArtifact.getGroupId() + ", " + selfArtifact.getId() + ", " + selfArtifact.getScope() + "]");
artifacts.add(project.getArtifact());
}
artifacts = selectArtifactsInCompileOrRuntimeScope(artifacts);
artifacts = selectNonJarArtifactsAndBundles(artifacts);
int cnt = 0;
for (Artifact artifact : artifacts) {
if (!artifact.isOptional()) /*&& filter.include(artifact)*/
{
getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
zipArchiver.addFile(artifact.getFile(), artifact.getArtifactId() + "-" + artifact.getVersion() + "." + (artifact.getType() == null ? "jar" : artifact.getType()));
cnt++;
}
}
getLog().info(String.format("Added %s artifacts to subsystem subsystem archive.", cnt));
}
} catch (ArchiverException e) {
throw new MojoExecutionException("Error copying esa dependencies", e);
}
}
Aggregations