Search in sources :

Example 1 with SimpleFilter

use of org.apache.maven.plugins.shade.filter.SimpleFilter in project maven-plugins by apache.

the class ShadeMojo method getFilters.

private List<Filter> getFilters() throws MojoExecutionException {
    List<Filter> filters = new ArrayList<Filter>();
    List<SimpleFilter> simpleFilters = new ArrayList<SimpleFilter>();
    if (this.filters != null && this.filters.length > 0) {
        Map<Artifact, ArtifactId> artifacts = new HashMap<Artifact, ArtifactId>();
        artifacts.put(project.getArtifact(), new ArtifactId(project.getArtifact()));
        for (Artifact artifact : project.getArtifacts()) {
            artifacts.put(artifact, new ArtifactId(artifact));
        }
        for (ArchiveFilter filter : this.filters) {
            ArtifactId pattern = new ArtifactId(filter.getArtifact());
            Set<File> jars = new HashSet<File>();
            for (Map.Entry<Artifact, ArtifactId> entry : artifacts.entrySet()) {
                if (entry.getValue().matches(pattern)) {
                    Artifact artifact = entry.getKey();
                    jars.add(artifact.getFile());
                    if (createSourcesJar) {
                        File file = resolveArtifactSources(artifact);
                        if (file != null) {
                            jars.add(file);
                        }
                    }
                }
            }
            if (jars.isEmpty()) {
                getLog().info("No artifact matching filter " + filter.getArtifact());
                continue;
            }
            simpleFilters.add(new SimpleFilter(jars, filter.getIncludes(), filter.getExcludes()));
        }
    }
    filters.addAll(simpleFilters);
    if (minimizeJar) {
        getLog().info("Minimizing jar " + project.getArtifact());
        try {
            filters.add(new MinijarFilter(project, getLog(), simpleFilters));
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to analyze class dependencies", e);
        }
    }
    return filters;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) SimpleFilter(org.apache.maven.plugins.shade.filter.SimpleFilter) Filter(org.apache.maven.plugins.shade.filter.Filter) MinijarFilter(org.apache.maven.plugins.shade.filter.MinijarFilter) SimpleFilter(org.apache.maven.plugins.shade.filter.SimpleFilter) MinijarFilter(org.apache.maven.plugins.shade.filter.MinijarFilter) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Artifact (org.apache.maven.artifact.Artifact)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 Filter (org.apache.maven.plugins.shade.filter.Filter)1 MinijarFilter (org.apache.maven.plugins.shade.filter.MinijarFilter)1 SimpleFilter (org.apache.maven.plugins.shade.filter.SimpleFilter)1