Search in sources :

Example 41 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.

the class ManifestCreationFinalizer method finalizeArchiveCreation.

@Override
public void finalizeArchiveCreation(final Archiver archiver) {
    if (archiveConfiguration != null) {
        try {
            Manifest manifest;
            final File manifestFile = archiveConfiguration.getManifestFile();
            if (manifestFile != null) {
                Reader manifestFileReader = null;
                try {
                    manifestFileReader = new InputStreamReader(new FileInputStream(manifestFile), "UTF-8");
                    manifest = new Manifest(manifestFileReader);
                    manifestFileReader.close();
                    manifestFileReader = null;
                } catch (final FileNotFoundException e) {
                    throw new ArchiverException("Manifest not found: " + e.getMessage(), e);
                } catch (final IOException e) {
                    throw new ArchiverException("Error processing manifest: " + e.getMessage(), e);
                } finally {
                    IOUtil.close(manifestFileReader);
                }
            } else {
                manifest = mavenArchiver.getManifest(session, project, archiveConfiguration);
            }
            if ((manifest != null) && (archiver instanceof JarArchiver)) {
                final JarArchiver jarArchiver = (JarArchiver) archiver;
                jarArchiver.addConfiguredManifest(manifest);
            }
        } catch (final ManifestException e) {
            throw new ArchiverException("Error creating manifest: " + e.getMessage(), e);
        } catch (final DependencyResolutionRequiredException e) {
            throw new ArchiverException("Dependencies were not resolved: " + e.getMessage(), e);
        }
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) InputStreamReader(java.io.InputStreamReader) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Manifest(org.codehaus.plexus.archiver.jar.Manifest) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) FileInputStream(java.io.FileInputStream)

Example 42 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.

the class DefaultAssemblyArchiver method configureArchiver.

private void configureArchiver(final Archiver archiver, final AssemblerConfigurationSource configSource) {
    Xpp3Dom config;
    try {
        config = Xpp3DomBuilder.build(new StringReader(configSource.getArchiverConfig()));
    } catch (final XmlPullParserException e) {
        throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
    } catch (final IOException e) {
        throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
    }
    getLogger().debug("Configuring archiver: '" + archiver.getClass().getName() + "' -->");
    try {
        configureComponent(archiver, config, configSource);
    } catch (final ComponentConfigurationException e) {
        throw new ArchiverException("Failed to configure archiver: " + archiver.getClass().getName(), e);
    } catch (final ComponentLookupException e) {
        throw new ArchiverException("Failed to lookup configurator for setup of archiver: " + archiver.getClass().getName(), e);
    }
    getLogger().debug("-- end configuration --");
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) StringReader(java.io.StringReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Example 43 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.

the class AbstractWarMojoTest method createArchive.

protected void createArchive(final File directory, final File destinationFile) {
    try {
        // WarArchiver archiver = new WarArchiver();
        Archiver archiver = new JarArchiver();
        archiver.setUseJvmChmod(true);
        archiver.setDestFile(destinationFile);
        archiver.addDirectory(directory);
        // archiver.setWebxml( new File(directory, "WEB-INF/web.xml"));
        // create archive
        archiver.createArchive();
    } catch (ArchiverException e) {
        e.printStackTrace();
        fail("Failed to create overlay archive " + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected exception " + e.getMessage());
    }
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) Archiver(org.codehaus.plexus.archiver.Archiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver)

Example 44 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.

the class AssemblyFileUtilsTest method testUnpack_ShouldSetSourceAndDestinationAndCallExtract.

public void testUnpack_ShouldSetSourceAndDestinationAndCallExtract() throws IOException, ArchiveExpansionException, NoSuchArchiverException {
    EasyMockSupport mockManager = new EasyMockSupport();
    File source = fileManager.createTempFile();
    File destDir = fileManager.createTempDir();
    UnArchiver unarchiver = mockManager.createMock(UnArchiver.class);
    ArchiverManager archiverManager = mockManager.createMock(ArchiverManager.class);
    try {
        expect(archiverManager.getUnArchiver(source)).andReturn(unarchiver);
    } catch (NoSuchArchiverException e) {
        fail("Should never happen.");
    }
    unarchiver.setSourceFile(source);
    unarchiver.setDestDirectory(destDir);
    try {
        unarchiver.extract();
    } catch (ArchiverException e) {
        fail("Should never happen.");
    }
    mockManager.replayAll();
    AssemblyFileUtils.unpack(source, destDir, archiverManager);
    mockManager.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) File(java.io.File) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 45 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-plugins by apache.

the class EjbMojo method generateEjb.

private File generateEjb() throws MojoExecutionException {
    File jarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClassifier());
    getLog().info("Building EJB " + jarName + " with EJB version " + ejbVersion);
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(jarFile);
    File deploymentDescriptor = new File(sourceDirectory, ejbJar);
    checkEJBVersionCompliance(deploymentDescriptor);
    try {
        List<String> defaultExcludes = Lists.newArrayList(ejbJar, "**/package.html");
        List<String> defaultIncludes = DEFAULT_INCLUDES_LIST;
        IncludesExcludes ie = new IncludesExcludes(Collections.<String>emptyList(), excludes, defaultIncludes, defaultExcludes);
        archiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes());
        // FIXME: We should be able to filter more than just the deployment descriptor?
        if (deploymentDescriptor.exists()) {
            // EJB-34 Filter ejb-jar.xml
            if (filterDeploymentDescriptor) {
                filterDeploymentDescriptor(deploymentDescriptor);
            }
            archiver.getArchiver().addFile(deploymentDescriptor, ejbJar);
        }
        // create archive
        archiver.createArchive(session, project, archive);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
    } catch (ManifestException e) {
        throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
    } catch (MavenFilteringException e) {
        throw new MojoExecutionException("There was a problem filtering the deployment descriptor: " + e.getMessage(), e);
    }
    return jarFile;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

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