Skip to content

Commit

Permalink
fix issue #124: merge META-INF/services/* from all mergedModule JARs
Browse files Browse the repository at this point in the history
  • Loading branch information
siordache committed Mar 15, 2020
1 parent 65abfdf commit 0369de4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ class PrepareMergedJarsDirTaskImpl extends BaseTaskImpl<PrepareMergedJarsDirTask
if(jars.empty) return
LOGGER.info("Merging content into ${td.mergedJarsDir}...")

TreeMap<String, String> services = [:]
jars.each { jar ->
project.delete(td.tmpJarsDirPath)
project.copy {
from project.zipTree(jar)
into td.tmpJarsDirPath
exclude 'module-info.class', 'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/SIG-*'
exclude 'module-info.class', 'META-INF/services/*', 'META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/SIG-*'
exclude { hasInvalidName(it) }
}

appendServices(services, jar)

def versionedDir = Util.getVersionedDir(new File(td.tmpJarsDirPath), td.jvmVersion)
if(versionedDir?.directory) {
project.copy {
Expand All @@ -92,6 +96,7 @@ class PrepareMergedJarsDirTaskImpl extends BaseTaskImpl<PrepareMergedJarsDirTask
project.ant.move file: td.tmpJarsDirPath, tofile: td.mergedJarsDir
}
}
writeServiceFiles(services)
Util.createManifest(td.mergedJarsDir, false)
}

Expand All @@ -111,4 +116,22 @@ class PrepareMergedJarsDirTaskImpl extends BaseTaskImpl<PrepareMergedJarsDirTask
}
return invalid
}

@CompileDynamic
void appendServices(Map<String, String> services, File jar) {
def svcFiles = project.zipTree(jar).matching {
include 'META-INF/services/*'
}
svcFiles?.files?.each { f ->
def oldText = services[f.name] ?: ''
if(oldText && !oldText.endsWith('\n')) oldText += '\n'
services[f.name] = oldText + f.text
}
}

void writeServiceFiles(Map<String, String> services) {
services.each { name, text ->
new File("$td.mergedJarsDir/META-INF/services/$name").write(text)
}
}
}
16 changes: 14 additions & 2 deletions src/test/groovy/org/beryx/jlink/SuggestMergedModuleInfoSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ class SuggestMergedModuleInfoSpec extends Specification {
"requires 'java.logging';",
"requires 'java.scripting';",
"requires 'java.xml';",
"requires 'java.datatransfer';",
"requires 'java.management';",
"uses 'org.apache.logging.log4j.spi.Provider';",
"provides 'javax.annotation.processing.Processor' with 'org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor';",
"provides 'javax.imageio.spi.ImageReaderSpi' with 'com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi', 'com.twelvemonkeys.imageio.plugins.tiff.BigTIFFImageReaderSpi', 'com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderSpi';",
"provides 'javax.imageio.spi.ImageWriterSpi' with 'com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterSpi', 'com.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriterSpi';",

]
static Set<String> GROOVY_DIRECTIVES = GROOVY_DIRECTIVES_CONSTRAINT + [
"requires 'java.rmi';",
Expand All @@ -48,6 +52,7 @@ class SuggestMergedModuleInfoSpec extends Specification {
]

static Set<String> KOTLIN_DIRECTIVES_CONSTRAINT = [
'requires("java.datatransfer");',
'requires("java.management");',
'requires("java.naming");',
'requires("java.logging");',
Expand All @@ -57,13 +62,15 @@ class SuggestMergedModuleInfoSpec extends Specification {
'requires("java.desktop");',
'uses("org.apache.logging.log4j.spi.Provider");',
'provides("javax.annotation.processing.Processor").with("org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor");',
'provides("javax.imageio.spi.ImageReaderSpi").with("com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi", "com.twelvemonkeys.imageio.plugins.tiff.BigTIFFImageReaderSpi", "com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderSpi");',
'provides("javax.imageio.spi.ImageWriterSpi").with("com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterSpi", "com.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriterSpi");',
]
static Set<String> KOTLIN_DIRECTIVES = KOTLIN_DIRECTIVES_CONSTRAINT + [
'requires("java.rmi");',
'requires("java.compiler");',
'uses("org.apache.logging.log4j.message.ThreadDumpMessage.ThreadInfoFactory");',
'provides("org.apache.logging.log4j.spi.Provider").with("org.apache.logging.log4j.core.impl.Log4jProvider");',
'provides("org.apache.logging.log4j.message.ThreadDumpMessage.ThreadInfoFactory").with("org.apache.logging.log4j.core.message.ExtendedThreadInfoFactory");'
'provides("org.apache.logging.log4j.message.ThreadDumpMessage.ThreadInfoFactory").with("org.apache.logging.log4j.core.message.ExtendedThreadInfoFactory");',
]

static Set<String> JAVA_DIRECTIVES_CONSTRAINT = [
Expand All @@ -73,9 +80,12 @@ class SuggestMergedModuleInfoSpec extends Specification {
"requires java.logging;",
"requires java.scripting;",
"requires java.xml;",
"requires java.datatransfer;",
"requires java.management;",
"uses org.apache.logging.log4j.spi.Provider;",
"provides javax.annotation.processing.Processor with org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor;",
"provides javax.imageio.spi.ImageReaderSpi with com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi, com.twelvemonkeys.imageio.plugins.tiff.BigTIFFImageReaderSpi, com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderSpi;",
"provides javax.imageio.spi.ImageWriterSpi with com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterSpi, com.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriterSpi;",
]
static Set<String> JAVA_DIRECTIVES = JAVA_DIRECTIVES_CONSTRAINT + [
"requires java.rmi;",
Expand Down Expand Up @@ -145,6 +155,8 @@ class SuggestMergedModuleInfoSpec extends Specification {
int endPos = taskOutput.indexOf(blockEnd, startPos)
assert endPos >= 0
def content = taskOutput.substring(startPos, endPos)
content.lines().map{it.trim()}.filter{!it.empty}.collect(Collectors.toList())
content = content.lines().map{it.trim()}.filter{!it.empty}.collect(Collectors.joining('\n'))
content = content.replace(',\n', ', ')
content.lines().collect(Collectors.toList())
}
}
2 changes: 2 additions & 0 deletions src/test/resources/hello-log4j-2.9.0/build.additive.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {
compile "org.apache.logging.log4j:log4j-core:$log4jVersion"
compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion"
compile "javax.xml.bind:jaxb-api:2.3.0"
compile 'com.twelvemonkeys.imageio:imageio-jpeg:3.5'
compile 'com.twelvemonkeys.imageio:imageio-tiff:3.5'
}

mainClassName = 'org.beryx.modular.hello.Hello'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dependencies {
implementation("org.apache.logging.log4j:log4j-core:$log4jVersion")
implementation("org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion")
implementation("javax.xml.bind:jaxb-api:2.3.0")
implementation("com.twelvemonkeys.imageio:imageio-jpeg:3.5")
implementation("com.twelvemonkeys.imageio:imageio-tiff:3.5")
}

application {
Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/hello-log4j-2.9.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {
compile "org.apache.logging.log4j:log4j-core:$log4jVersion"
compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion"
compile "javax.xml.bind:jaxb-api:2.3.0"
compile 'com.twelvemonkeys.imageio:imageio-jpeg:3.5'
compile 'com.twelvemonkeys.imageio:imageio-tiff:3.5'
}

mainClassName = 'org.beryx.modular.hello.Hello'
Expand All @@ -38,12 +40,18 @@ jlink {
mergedModule {
requires 'java.naming';
requires 'java.xml';
requires 'java.datatransfer';
requires 'java.management';
requires 'java.scripting';
requires 'java.desktop';

uses 'org.apache.logging.log4j.spi.Provider';
provides 'org.apache.logging.log4j.spi.Provider' with 'org.apache.logging.log4j.core.impl.Log4jProvider';
provides 'javax.imageio.spi.ImageReaderSpi' with 'com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi',
'com.twelvemonkeys.imageio.plugins.tiff.BigTIFFImageReaderSpi',
'com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderSpi';
provides 'javax.imageio.spi.ImageWriterSpi' with 'com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterSpi',
'com.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriterSpi';
}
}

Expand Down

0 comments on commit 0369de4

Please sign in to comment.