Search in sources :

Example 1 with ManifestResourceTransformer

use of org.apache.maven.plugins.shade.resource.ManifestResourceTransformer in project maven-plugins by apache.

the class DefaultShader method shade.

public void shade(ShadeRequest shadeRequest) throws IOException, MojoExecutionException {
    Set<String> resources = new HashSet<String>();
    ResourceTransformer manifestTransformer = null;
    List<ResourceTransformer> transformers = new ArrayList<ResourceTransformer>(shadeRequest.getResourceTransformers());
    for (Iterator<ResourceTransformer> it = transformers.iterator(); it.hasNext(); ) {
        ResourceTransformer transformer = it.next();
        if (transformer instanceof ManifestResourceTransformer) {
            manifestTransformer = transformer;
            it.remove();
        }
    }
    RelocatorRemapper remapper = new RelocatorRemapper(shadeRequest.getRelocators());
    // noinspection ResultOfMethodCallIgnored
    shadeRequest.getUberJar().getParentFile().mkdirs();
    JarOutputStream out = null;
    try {
        out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(shadeRequest.getUberJar())));
        goThroughAllJarEntriesForManifestTransformer(shadeRequest, resources, manifestTransformer, out);
        // CHECKSTYLE_OFF: MagicNumber
        Multimap<String, File> duplicates = HashMultimap.create(10000, 3);
        // CHECKSTYLE_ON: MagicNumber
        shadeJars(shadeRequest, resources, transformers, remapper, out, duplicates);
        // CHECKSTYLE_OFF: MagicNumber
        Multimap<Collection<File>, String> overlapping = HashMultimap.create(20, 15);
        for (String clazz : duplicates.keySet()) {
            Collection<File> jarz = duplicates.get(clazz);
            if (jarz.size() > 1) {
                overlapping.put(jarz, clazz);
            }
        }
        // Log a summary of duplicates
        logSummaryOfDuplicates(overlapping);
        if (overlapping.keySet().size() > 0) {
            showOverlappingWarning();
        }
        for (ResourceTransformer transformer : transformers) {
            if (transformer.hasTransformedResource()) {
                transformer.modifyOutputStream(out);
            }
        }
        out.close();
        out = null;
    } finally {
        IOUtil.close(out);
    }
    for (Filter filter : shadeRequest.getFilters()) {
        filter.finished();
    }
}
Also used : ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) Filter(org.apache.maven.plugins.shade.filter.Filter) FileOutputStream(java.io.FileOutputStream) Collection(java.util.Collection) ManifestResourceTransformer(org.apache.maven.plugins.shade.resource.ManifestResourceTransformer) ResourceTransformer(org.apache.maven.plugins.shade.resource.ResourceTransformer) ManifestResourceTransformer(org.apache.maven.plugins.shade.resource.ManifestResourceTransformer) BufferedOutputStream(java.io.BufferedOutputStream) JarFile(java.util.jar.JarFile) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 JarFile (java.util.jar.JarFile)1 JarOutputStream (java.util.jar.JarOutputStream)1 Filter (org.apache.maven.plugins.shade.filter.Filter)1 ManifestResourceTransformer (org.apache.maven.plugins.shade.resource.ManifestResourceTransformer)1 ResourceTransformer (org.apache.maven.plugins.shade.resource.ResourceTransformer)1