From 4658cf42c2b15d3f7d5a0d128d89a38280a5836d Mon Sep 17 00:00:00 2001 From: Tobias Schulte Date: Tue, 1 Aug 2017 09:44:57 +0200 Subject: [PATCH] fix(SignJars): works with Java 8u141 The gradle-jnlp-plugin removes all named entries `.*-Digest` and some main attributes of the MANIFEST.MF to prevent some type of errors. In doing this, it does alter the manifest of the original jar file to create a new jar file. But it seems, that 8u141 does has an issue with this. The SignJarsTask now creates a new Manifest instead of copying the original one. Closes #42 --- .../gliderpilot/gradle/jnlp/SignJarsTask.groovy | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gradle-jnlp-plugin/src/main/groovy/de/gliderpilot/gradle/jnlp/SignJarsTask.groovy b/gradle-jnlp-plugin/src/main/groovy/de/gliderpilot/gradle/jnlp/SignJarsTask.groovy index 582ccef..f05b1d9 100644 --- a/gradle-jnlp-plugin/src/main/groovy/de/gliderpilot/gradle/jnlp/SignJarsTask.groovy +++ b/gradle-jnlp-plugin/src/main/groovy/de/gliderpilot/gradle/jnlp/SignJarsTask.groovy @@ -22,10 +22,7 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.incremental.IncrementalTaskInputs -import java.util.jar.JarEntry -import java.util.jar.JarFile -import java.util.jar.JarOutputStream -import java.util.jar.Manifest +import java.util.jar.* class SignJarsTask extends AbstractCopyJarsTask { @@ -70,7 +67,15 @@ class SignJarsTask extends AbstractCopyJarsTask { File output = new File(into, newName(input.name)) logger.info("Copying " + input + " to " + output) JarFile jarFile = new JarFile(input) - Manifest manifest = jarFile.manifest ?: new Manifest() + Manifest manifest = new Manifest() + if (jarFile.manifest) { + // new Manifest(jarFile.manifest) does not create new named attributes, but reuses them. This causes + // problems, since we are altering the named attributes + manifest.mainAttributes.putAll(jarFile.manifest.mainAttributes) + jarFile.manifest.entries.each { key, attributes -> + manifest.entries.put(key, new Attributes(attributes)) + } + } def removeManifestEntries = { pattern, attributes -> def keysToRemove = attributes.keySet().findAll { key -> key.toString() ==~ "(?i)${pattern}" } attributes.keySet().removeAll(keysToRemove)