Search in sources :

Example 46 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 47 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 48 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 49 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project sling by apache.

the class PreparePackageMojo method unpack.

private void unpack(File source, File destination) throws MojoExecutionException {
    getLog().info("Unpacking " + source.getPath() + " to\n  " + destination.getPath());
    try {
        destination.mkdirs();
        UnArchiver unArchiver = archiverManager.getUnArchiver(source);
        unArchiver.setSourceFile(source);
        unArchiver.setDestDirectory(destination);
        unArchiver.extract();
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("Unable to find archiver for " + source.getPath(), e);
    } catch (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 50 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)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)50 File (java.io.File)33 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)25 IOException (java.io.IOException)24 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)17 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)9 Artifact (org.apache.maven.artifact.Artifact)8 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)8 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)7 MavenArchiver (org.apache.maven.archiver.MavenArchiver)6 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)5 ArrayList (java.util.ArrayList)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Archiver (org.codehaus.plexus.archiver.Archiver)3 JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2