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();
}
}
Aggregations