use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.
the class PreparePackageMojo method unpack.
/**
* Unpack a file
*/
private void unpack(final File source, final File destination) throws MojoExecutionException {
getLog().debug("Unpacking " + source.getPath() + " to\n " + destination.getPath());
try {
destination.mkdirs();
final UnArchiver unArchiver = archiverManager.getUnArchiver(source);
unArchiver.setSourceFile(source);
unArchiver.setDestDirectory(destination);
unArchiver.extract();
} catch (final NoSuchArchiverException e) {
throw new MojoExecutionException("Unable to find archiver for " + source.getPath(), e);
} catch (final ArchiverException e) {
throw new MojoExecutionException("Unable to unpack " + source.getPath(), e);
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.
the class AbstractUsingBundleListMojo method extractConfiguration.
private void extractConfiguration(final Artifact artifact) throws MojoExecutionException, IOException {
// check for configuration artifact
Artifact cfgArtifact = null;
try {
cfgArtifact = getArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), AttachPartialBundleListMojo.CONFIG_TYPE, AttachPartialBundleListMojo.CONFIG_CLASSIFIER);
} catch (final MojoExecutionException ignore) {
// we just ignore this
}
if (cfgArtifact != null) {
getLog().info(String.format("Merging settings from partial bundle list %s:%s:%s", cfgArtifact.getGroupId(), cfgArtifact.getArtifactId(), cfgArtifact.getVersion()));
// extract
zipUnarchiver.setSourceFile(cfgArtifact.getFile());
try {
this.tmpOutputDir.mkdirs();
zipUnarchiver.setDestDirectory(this.tmpOutputDir);
zipUnarchiver.extract();
final File slingDir = new File(this.tmpOutputDir, "sling");
this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_PROPS), 0);
this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_WEBAPP_PROPS), 1);
this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_STANDALONE_PROPS), 2);
this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_BOOTSTRAP), 0);
this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_WEBAPP_BOOTSTRAP), 1);
this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_STANDALONE_BOOTSTRAP), 2);
// and now configurations
final File configDir = new File(this.tmpOutputDir, "config");
if (configDir.exists()) {
if (this.overlayConfigDir == null) {
this.tempConfigDir.mkdirs();
this.overlayConfigDir = this.tempConfigDir;
}
final String[] defaultExcludes = FileUtils.getDefaultExcludes();
String[] excludes;
if (this.configExcludes != null) {
excludes = new String[defaultExcludes.length + this.configExcludes.length];
System.arraycopy(defaultExcludes, 0, excludes, 0, defaultExcludes.length);
System.arraycopy(this.configExcludes, 0, excludes, defaultExcludes.length, this.configExcludes.length);
} else {
excludes = defaultExcludes;
}
String[] includes = null;
if (this.configIncludes != null) {
includes = this.configIncludes;
}
copyDirectory(configDir, this.overlayConfigDir, includes, excludes);
}
} catch (final ArchiverException ae) {
throw new MojoExecutionException("Unable to extract configuration archive.", ae);
} finally {
// and delete at the end
FileUtils.deleteDirectory(this.tmpOutputDir);
}
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.
the class CreateBundleJarMojo method createJARFile.
private File createJARFile() throws MojoExecutionException {
File jarFile = new File(outputDirectory, jarName + "-" + CLASSIFIER + "." + JAR);
jarArchiver.setDestFile(jarFile);
addBundles();
addResources();
try {
jarArchiver.createArchive();
} catch (ArchiverException e) {
throw new MojoExecutionException("Unable to create bundle jar file", e);
} catch (IOException e) {
throw new MojoExecutionException("Unable to create bundle jar file", e);
}
return jarFile;
}
use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.
the class CreateBundleJarMojo method addResources.
private void addResources(Resource resource) throws MojoExecutionException {
getLog().info(String.format("Adding resources [%s] to [%s]", resource.getDirectory(), resource.getTargetPath()));
String[] fileNames = getFilesToCopy(resource);
for (int i = 0; i < fileNames.length; i++) {
String targetFileName = fileNames[i];
if (resource.getTargetPath() != null) {
targetFileName = resource.getTargetPath() + File.separator + targetFileName;
}
try {
jarArchiver.addFile(new File(resource.getDirectory(), fileNames[i]), targetFileName);
} catch (ArchiverException e) {
throw new MojoExecutionException("Unable to add resources to JAR file", e);
}
}
}
use of org.codehaus.plexus.archiver.ArchiverException in project tycho by eclipse.
the class ProductArchiverMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
ProductConfig config = getProductConfig();
if (!config.uniqueAttachIds()) {
throw new MojoFailureException("Artifact file names for the archived products are not unique. " + "Configure the attachId or select a subset of products. Current configuration: " + config.getProducts());
}
for (Product product : config.getProducts()) {
for (TargetEnvironment env : getEnvironments()) {
String format = getArchiveFormat(env);
ProductArchiver productArchiver = productArchivers.get(format);
if (productArchiver == null) {
throw new MojoExecutionException("Unknown or unsupported archive format os=" + env.getOs() + " format=" + format);
}
File productArchive = new File(getProductsBuildDirectory(), getArchiveFileName(product) + "-" + getOsWsArch(env, '.') + "." + format);
try {
final File sourceDir = getProductMaterializeDirectory(product, env);
if (TAR_GZ_ARCHIVE_FORMAT.equals(format) && !"plexus".equals(getSession().getUserProperties().getProperty("tycho.tar"))) {
getLog().debug("Using commons-compress tar");
createCommonsCompressTarGz(productArchive, sourceDir);
} else {
Archiver archiver = productArchiver.getArchiver();
archiver.setDestFile(productArchive);
DefaultFileSet fileSet = new DefaultFileSet(sourceDir);
fileSet.setUsingDefaultExcludes(false);
archiver.addFileSet(fileSet);
archiver.createArchive();
}
} catch (ArchiverException e) {
throw new MojoExecutionException("Error packing product", e);
} catch (IOException e) {
throw new MojoExecutionException("Error packing product", e);
}
final String artifactClassifier = getArtifactClassifier(product, env);
helper.attachArtifact(getProject(), format, artifactClassifier, productArchive);
}
}
}
Aggregations