Search in sources :

Example 1 with IncludeExcludeFileSelector

use of org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector in project maven-plugins by apache.

the class AbstractJavadocMojo method copyAdditionalJavadocResources.

/**
     * Method that copy additional Javadoc resources from given artifacts.
     *
     * @param anOutputDirectory the output directory
     * @throws MavenReportException if any
     * @see #resourcesArtifacts
     */
private void copyAdditionalJavadocResources(File anOutputDirectory) throws MavenReportException {
    Set<ResourcesArtifact> resourcesArtifacts = collectResourcesArtifacts();
    if (isEmpty(resourcesArtifacts)) {
        return;
    }
    UnArchiver unArchiver;
    try {
        unArchiver = archiverManager.getUnArchiver("jar");
    } catch (NoSuchArchiverException e) {
        throw new MavenReportException("Unable to extract resources artifact. " + "No archiver for 'jar' available.", e);
    }
    for (ResourcesArtifact item : resourcesArtifacts) {
        Artifact artifact;
        try {
            artifact = createAndResolveArtifact(item);
        } catch (ArtifactResolverException e) {
            throw new MavenReportException("Unable to resolve artifact:" + item, e);
        }
        unArchiver.setSourceFile(artifact.getFile());
        unArchiver.setDestDirectory(anOutputDirectory);
        // remove the META-INF directory from resource artifact
        IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
        selectors[0].setExcludes(new String[] { "META-INF/**" });
        unArchiver.setFileSelectors(selectors);
        getLog().info("Extracting contents of resources artifact: " + artifact.getArtifactId());
        try {
            unArchiver.extract();
        } catch (ArchiverException e) {
            throw new MavenReportException("Extraction of resources failed. Artifact that failed was: " + artifact.getArtifactId(), e);
        }
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) IncludeExcludeFileSelector(org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with IncludeExcludeFileSelector

use of org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector 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 3 with IncludeExcludeFileSelector

use of org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector 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)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)3 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)3 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)3 IncludeExcludeFileSelector (org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector)3 Artifact (org.apache.maven.artifact.Artifact)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 File (java.io.File)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 ResourcesArtifact (org.apache.maven.plugin.javadoc.options.ResourcesArtifact)1 TagletArtifact (org.apache.maven.plugin.javadoc.options.TagletArtifact)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)1 ZipUnArchiver (org.codehaus.plexus.archiver.zip.ZipUnArchiver)1