Skip to content

Commit

Permalink
fix(SignJars): works with Java 8u141
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tschulte committed Aug 1, 2017
1 parent d59bf9e commit 4658cf4
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4658cf4

Please sign in to comment.