Search in sources :

Example 6 with Archiver

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

the class DefaultAssemblyArchiver method createArchiver.

/**
     * Creates the necessary archiver to build the distribution file.
     *
     * @param format                Archive format
     * @param includeBaseDir        the base directory for include.
     * @param finalName             The final name.
     * @param configSource          {@link AssemblerConfigurationSource}
     * @param containerHandlers     The list of {@link ContainerDescriptorHandler}
     * @param recompressZippedFiles recompress zipped files.
     * @param mergeManifestMode     how to handle already existing Manifest files
     * @return archiver Archiver generated
     * @throws org.codehaus.plexus.archiver.ArchiverException
     * @throws org.codehaus.plexus.archiver.manager.NoSuchArchiverException
     */
protected Archiver createArchiver(final String format, final boolean includeBaseDir, final String finalName, final AssemblerConfigurationSource configSource, final List<ContainerDescriptorHandler> containerHandlers, boolean recompressZippedFiles, String mergeManifestMode) throws NoSuchArchiverException {
    Archiver archiver;
    if ("txz".equals(format) || "tgz".equals(format) || "tbz2".equals(format) || format.startsWith("tar")) {
        archiver = createTarArchiver(format, TarLongFileMode.valueOf(configSource.getTarLongFileMode()));
    } else if ("war".equals(format)) {
        archiver = createWarArchiver();
    } else {
        archiver = archiverManager.getArchiver(format);
    }
    if (archiver instanceof AbstractZipArchiver) {
        ((AbstractZipArchiver) archiver).setRecompressAddedZips(recompressZippedFiles);
    }
    final List<FileSelector> extraSelectors = new ArrayList<FileSelector>();
    final List<ArchiveFinalizer> extraFinalizers = new ArrayList<ArchiveFinalizer>();
    if (archiver instanceof JarArchiver) {
        if (mergeManifestMode != null) {
            ((JarArchiver) archiver).setFilesetmanifest(JarArchiver.FilesetManifestConfig.valueOf(mergeManifestMode));
        }
        extraSelectors.add(new JarSecurityFileSelector());
        extraFinalizers.add(new ManifestCreationFinalizer(configSource.getMavenSession(), configSource.getProject(), configSource.getJarArchiveConfiguration()));
    }
    if (configSource.getArchiverConfig() != null) {
        configureArchiver(archiver, configSource);
    }
    String prefix = "";
    if (includeBaseDir) {
        prefix = finalName;
    }
    archiver = new AssemblyProxyArchiver(prefix, archiver, containerHandlers, extraSelectors, extraFinalizers, configSource.getWorkingDirectory(), getLogger());
    if (configSource.isDryRun()) {
        archiver = new DryRunArchiver(archiver, getLogger());
    }
    archiver.setUseJvmChmod(configSource.isUpdateOnly());
    archiver.setIgnorePermissions(configSource.isIgnorePermissions());
    archiver.setForced(!configSource.isUpdateOnly());
    return archiver;
}
Also used : AssemblyProxyArchiver(org.apache.maven.plugins.assembly.archive.archiver.AssemblyProxyArchiver) FileSelector(org.codehaus.plexus.components.io.fileselectors.FileSelector) JarSecurityFileSelector(org.codehaus.plexus.archiver.filters.JarSecurityFileSelector) ArrayList(java.util.ArrayList) JarSecurityFileSelector(org.codehaus.plexus.archiver.filters.JarSecurityFileSelector) DryRunArchiver(org.codehaus.plexus.archiver.diags.DryRunArchiver) ArchiveFinalizer(org.codehaus.plexus.archiver.ArchiveFinalizer) AssemblyProxyArchiver(org.apache.maven.plugins.assembly.archive.archiver.AssemblyProxyArchiver) AbstractZipArchiver(org.codehaus.plexus.archiver.zip.AbstractZipArchiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) TarArchiver(org.codehaus.plexus.archiver.tar.TarArchiver) Archiver(org.codehaus.plexus.archiver.Archiver) DryRunArchiver(org.codehaus.plexus.archiver.diags.DryRunArchiver) WarArchiver(org.codehaus.plexus.archiver.war.WarArchiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) AbstractZipArchiver(org.codehaus.plexus.archiver.zip.AbstractZipArchiver)

Example 7 with Archiver

use of org.codehaus.plexus.archiver.Archiver 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)

Aggregations

Archiver (org.codehaus.plexus.archiver.Archiver)7 JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)5 File (java.io.File)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)3 FileSelector (org.codehaus.plexus.components.io.fileselectors.FileSelector)3 AssemblyProxyArchiver (org.apache.maven.plugins.assembly.archive.archiver.AssemblyProxyArchiver)2 DryRunArchiver (org.codehaus.plexus.archiver.diags.DryRunArchiver)2 TrackingArchiver (org.codehaus.plexus.archiver.diags.TrackingArchiver)2 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)2 TarArchiver (org.codehaus.plexus.archiver.tar.TarArchiver)2 WarArchiver (org.codehaus.plexus.archiver.war.WarArchiver)2 AbstractZipArchiver (org.codehaus.plexus.archiver.zip.AbstractZipArchiver)2 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)2 EasyMockSupport (org.easymock.classextension.EasyMockSupport)2 Test (org.junit.Test)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 AssemblyArchiverPhase (org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase)1 DependencyResolutionException (org.apache.maven.plugins.assembly.artifact.DependencyResolutionException)1