Search in sources :

Example 1 with Archiver

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

the class AssemblyProxyArchiverTest method addFile_NoPerms_CallAcceptFilesOnlyOnce.

@Test
public void addFile_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
    EasyMockSupport mm = new EasyMockSupport();
    final Archiver delegate = mm.createMock(Archiver.class);
    delegate.addFile((File) anyObject(), (String) anyObject());
    EasyMock.expectLastCall().anyTimes();
    delegate.setForced(true);
    EasyMock.expectLastCall().anyTimes();
    final CounterSelector counter = new CounterSelector(true);
    final List<FileSelector> selectors = new ArrayList<FileSelector>();
    selectors.add(counter);
    mm.replayAll();
    final AssemblyProxyArchiver archiver = new AssemblyProxyArchiver("", delegate, null, selectors, null, new File("."), new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    archiver.setForced(true);
    final File inputFile = fileManager.createTempFile();
    archiver.addFile(inputFile, "file.txt");
    assertEquals(1, counter.getCount());
    mm.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) FileSelector(org.codehaus.plexus.components.io.fileselectors.FileSelector) ArrayList(java.util.ArrayList) TrackingArchiver(org.codehaus.plexus.archiver.diags.TrackingArchiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) Archiver(org.codehaus.plexus.archiver.Archiver) File(java.io.File) Test(org.junit.Test)

Example 2 with Archiver

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

the class DefaultAssemblyArchiver method createArchive.

/**
     * {@inheritDoc}
     */
@Override
public File createArchive(final Assembly assembly, final String fullName, final String format, final AssemblerConfigurationSource configSource, boolean recompressZippedFiles, String mergeManifestMode) throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException {
    validate(assembly);
    String filename = fullName;
    if (!configSource.isIgnoreDirFormatExtensions() || !format.startsWith("dir")) {
        filename += "." + format;
    }
    AssemblyFileUtils.verifyTempDirectoryAvailability(configSource.getTemporaryRootDirectory());
    final File outputDirectory = configSource.getOutputDirectory();
    final File destFile = new File(outputDirectory, filename);
    try {
        final String finalName = configSource.getFinalName();
        final String specifiedBasedir = assembly.getBaseDirectory();
        String basedir = finalName;
        if (specifiedBasedir != null) {
            basedir = AssemblyFormatUtils.getOutputDirectory(specifiedBasedir, finalName, configSource, AssemblyFormatUtils.moduleProjectInterpolator(configSource.getProject()), AssemblyFormatUtils.artifactProjectInterpolator(null));
        }
        final List<ContainerDescriptorHandler> containerHandlers = selectContainerDescriptorHandlers(assembly.getContainerDescriptorHandlers(), configSource);
        final Archiver archiver = createArchiver(format, assembly.isIncludeBaseDirectory(), basedir, configSource, containerHandlers, recompressZippedFiles, mergeManifestMode);
        archiver.setDestFile(destFile);
        for (AssemblyArchiverPhase phase : sortedPhases()) {
            phase.execute(assembly, archiver, configSource);
        }
        archiver.createArchive();
    } catch (final ArchiverException e) {
        throw new ArchiveCreationException("Error creating assembly archive " + assembly.getId() + ": " + e.getMessage(), e);
    } catch (final IOException e) {
        throw new ArchiveCreationException("Error creating assembly archive " + assembly.getId() + ": " + e.getMessage(), e);
    } catch (final NoSuchArchiverException e) {
        throw new ArchiveCreationException("Unable to obtain archiver for extension '" + format + "', for assembly: '" + assembly.getId() + "'", e);
    } catch (final DependencyResolutionException e) {
        throw new ArchiveCreationException("Unable to resolve dependencies for assembly '" + assembly.getId() + "'", e);
    }
    return destFile;
}
Also used : ContainerDescriptorHandler(org.apache.maven.plugins.assembly.filter.ContainerDescriptorHandler) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) DependencyResolutionException(org.apache.maven.plugins.assembly.artifact.DependencyResolutionException) IOException(java.io.IOException) File(java.io.File) 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) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) AssemblyArchiverPhase(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase)

Example 3 with Archiver

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

the class ResourcesBundleMojo method doExecute.

/**
     * Assemble a new {@link org.apache.maven.plugin.javadoc.options.JavadocOptions JavadocOptions} instance that
     * contains the configuration options in this
     * mojo, which are a subset of those provided in derivatives of the {@link AbstractJavadocMojo}
     * class (most of the javadoc mojos, in other words). Then, bundle the contents of the
     * <code>javadocDirectory</code> along with the assembled JavadocOptions instance (serialized to
     * META-INF/maven/javadoc-options.xml) into a project attachment for installation/deployment.
     *
     * {@inheritDoc}
     * @see org.apache.maven.plugin.Mojo#execute()
     */
public void doExecute() throws MojoExecutionException, MojoFailureException {
    try {
        buildJavadocOptions();
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to generate javadoc-options file: " + e.getMessage(), e);
    }
    Archiver archiver;
    try {
        archiver = archiverManager.getArchiver("jar");
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("Failed to retrieve jar archiver component from manager.", e);
    }
    File optionsFile = getJavadocOptionsFile();
    File bundleFile = new File(getProject().getBuild().getDirectory(), finalName + "-" + getAttachmentClassifier() + ".jar");
    try {
        archiver.addFile(optionsFile, BUNDLE_OPTIONS_PATH);
        File javadocDir = getJavadocDirectory();
        if (javadocDir.exists() && javadocDir.isDirectory()) {
            archiver.addDirectory(javadocDir, RESOURCES_DIR_PATH + "/");
        }
        archiver.setDestFile(bundleFile);
        archiver.createArchive();
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Failed to assemble javadoc-resources bundle archive. Reason: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to assemble javadoc-resources bundle archive. Reason: " + e.getMessage(), e);
    }
    projectHelper.attachArtifact(getProject(), bundleFile, getAttachmentClassifier());
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) Archiver(org.codehaus.plexus.archiver.Archiver) File(java.io.File) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 4 with Archiver

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

the class AssemblyProxyArchiverTest method addDirectory_NoPerms_CallAcceptFilesOnlyOnce.

@Test
public void addDirectory_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
    final Archiver delegate = new JarArchiver();
    final File output = fileManager.createTempFile();
    delegate.setDestFile(output);
    final CounterSelector counter = new CounterSelector(true);
    final List<FileSelector> selectors = new ArrayList<FileSelector>();
    selectors.add(counter);
    final AssemblyProxyArchiver archiver = new AssemblyProxyArchiver("", delegate, null, selectors, null, new File("."), new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    archiver.setForced(true);
    final File dir = fileManager.createTempDir();
    FileUtils.cleanDirectory(dir);
    fileManager.createFile(dir, "file.txt", "This is a test.");
    archiver.addDirectory(dir);
    archiver.createArchive();
    assertEquals(1, counter.getCount());
}
Also used : ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) FileSelector(org.codehaus.plexus.components.io.fileselectors.FileSelector) ArrayList(java.util.ArrayList) TrackingArchiver(org.codehaus.plexus.archiver.diags.TrackingArchiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) Archiver(org.codehaus.plexus.archiver.Archiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) File(java.io.File) Test(org.junit.Test)

Example 5 with Archiver

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

the class AddDirectoryTaskTest method setUp.

public void setUp() {
    fileManager = new TestFileManager("ArchiveAssemblyUtils.test.", "");
    mockManager = new EasyMockSupport();
    archiver = mockManager.createMock(Archiver.class);
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) TestFileManager(org.apache.maven.plugins.assembly.testutils.TestFileManager) Archiver(org.codehaus.plexus.archiver.Archiver)

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