Search in sources :

Example 56 with ArchiverException

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 57 with ArchiverException

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);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 58 with ArchiverException

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;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) File(java.io.File)

Example 59 with ArchiverException

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);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) File(java.io.File)

Example 60 with ArchiverException

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);
        }
    }
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) File(java.io.File) TarArchiver(org.codehaus.plexus.archiver.tar.TarArchiver) TarGzArchiver(org.eclipse.tycho.plugins.tar.TarGzArchiver) Archiver(org.codehaus.plexus.archiver.Archiver)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)99 File (java.io.File)69 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)54 IOException (java.io.IOException)48 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)28 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)18 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)15 MavenArchiver (org.apache.maven.archiver.MavenArchiver)14 Artifact (org.apache.maven.artifact.Artifact)14 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)14 Archiver (org.codehaus.plexus.archiver.Archiver)8 Resource (org.apache.maven.model.Resource)7 IncludeExcludeFileSelector (org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 DefaultFileSet (org.codehaus.plexus.archiver.util.DefaultFileSet)6 ArrayList (java.util.ArrayList)5 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)5 MavenProject (org.apache.maven.project.MavenProject)5 FileInputStream (java.io.FileInputStream)4 FileWriter (java.io.FileWriter)4