Search in sources :

Example 6 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project midpoint by Evolveum.

the class SchemaDistMojo method unpack.

private void unpack(ArtifactItem artifactItem, File destDir) throws MojoExecutionException {
    Artifact artifact = artifactItem.getArtifact();
    File file = artifact.getFile();
    if (file == null) {
        throw new MojoExecutionException("No file for artifact " + artifact);
    }
    if (file.isDirectory()) {
        try {
            FileUtils.copyDirectory(file, destDir);
        } catch (IOException e) {
            throw new MojoExecutionException("Error copying directory " + file + " to " + destDir + ": " + e.getMessage(), e);
        }
    } else {
        try {
            UnArchiver unArchiver = archiverManager.getUnArchiver(artifact.getType());
            unArchiver.setSourceFile(file);
            unArchiver.setDestDirectory(destDir);
            if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
                // Create the selectors that will filter
                // based on include/exclude parameters
                // MDEP-47
                IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
                if (StringUtils.isNotEmpty(excludes)) {
                    selectors[0].setExcludes(excludes.split(","));
                }
                if (StringUtils.isNotEmpty(includes)) {
                    selectors[0].setIncludes(includes.split(","));
                }
                unArchiver.setFileSelectors(selectors);
            }
            unArchiver.extract();
        } catch (ArchiverException | NoSuchArchiverException e) {
            throw new MojoExecutionException("Error unpacking file: " + file + " to: " + destDir + "\r\n" + e.toString(), e);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IncludeExcludeFileSelector(org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) Artifact(org.apache.maven.artifact.Artifact) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 7 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException 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 8 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException 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 9 with NoSuchArchiverException

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

the class AbstractDependencyMojo method unpack.

protected void unpack(Artifact artifact, String type, File location, String includes, String excludes, String encoding) throws MojoExecutionException {
    File file = artifact.getFile();
    try {
        logUnpack(file, location, includes, excludes);
        location.mkdirs();
        if (!location.exists()) {
            throw new MojoExecutionException("Location to write unpacked files to could not be created: " + location);
        }
        if (file.isDirectory()) {
            // usual case is a future jar packaging, but there are special cases: classifier and other packaging
            throw new MojoExecutionException("Artifact has not been packaged yet. When used on reactor artifact, " + "unpack should be executed after packaging: see MDEP-98.");
        }
        UnArchiver unArchiver;
        try {
            unArchiver = archiverManager.getUnArchiver(type);
            getLog().debug("Found unArchiver by type: " + unArchiver);
        } catch (NoSuchArchiverException e) {
            unArchiver = archiverManager.getUnArchiver(file);
            getLog().debug("Found unArchiver by extension: " + unArchiver);
        }
        if (encoding != null && unArchiver instanceof ZipUnArchiver) {
            ((ZipUnArchiver) unArchiver).setEncoding(encoding);
            getLog().info("Unpacks '" + type + "' with encoding '" + encoding + "'.");
        }
        unArchiver.setUseJvmChmod(useJvmChmod);
        unArchiver.setIgnorePermissions(ignorePermissions);
        unArchiver.setSourceFile(file);
        unArchiver.setDestDirectory(location);
        if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
            // Create the selectors that will filter
            // based on include/exclude parameters
            // MDEP-47
            IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
            if (StringUtils.isNotEmpty(excludes)) {
                selectors[0].setExcludes(excludes.split(","));
            }
            if (StringUtils.isNotEmpty(includes)) {
                selectors[0].setIncludes(includes.split(","));
            }
            unArchiver.setFileSelectors(selectors);
        }
        if (this.silent) {
            silenceUnarchiver(unArchiver);
        }
        unArchiver.extract();
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("Unknown archiver type", e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Error unpacking file: " + file + " to: " + location + "\r\n" + e.toString(), e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IncludeExcludeFileSelector(org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ZipUnArchiver(org.codehaus.plexus.archiver.zip.ZipUnArchiver) File(java.io.File) ZipUnArchiver(org.codehaus.plexus.archiver.zip.ZipUnArchiver) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 10 with NoSuchArchiverException

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

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)12 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)12 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 File (java.io.File)6 IOException (java.io.IOException)3 Artifact (org.apache.maven.artifact.Artifact)3 IncludeExcludeFileSelector (org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector)3 Archiver (org.codehaus.plexus.archiver.Archiver)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)1 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)1 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)1 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)1 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)1