diff --git a/src/main/groovy/org/beryx/jlink/impl/PrepareMergedJarsDirTaskImpl.groovy b/src/main/groovy/org/beryx/jlink/impl/PrepareMergedJarsDirTaskImpl.groovy index 0ce21bec..f25c0dba 100644 --- a/src/main/groovy/org/beryx/jlink/impl/PrepareMergedJarsDirTaskImpl.groovy +++ b/src/main/groovy/org/beryx/jlink/impl/PrepareMergedJarsDirTaskImpl.groovy @@ -71,14 +71,18 @@ class PrepareMergedJarsDirTaskImpl extends BaseTaskImpl 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 { @@ -92,6 +96,7 @@ class PrepareMergedJarsDirTaskImpl extends BaseTaskImpl 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 services) { + services.each { name, text -> + new File("$td.mergedJarsDir/META-INF/services/$name").write(text) + } + } } diff --git a/src/test/groovy/org/beryx/jlink/SuggestMergedModuleInfoSpec.groovy b/src/test/groovy/org/beryx/jlink/SuggestMergedModuleInfoSpec.groovy index e1f72bfb..1e73f43e 100644 --- a/src/test/groovy/org/beryx/jlink/SuggestMergedModuleInfoSpec.groovy +++ b/src/test/groovy/org/beryx/jlink/SuggestMergedModuleInfoSpec.groovy @@ -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 GROOVY_DIRECTIVES = GROOVY_DIRECTIVES_CONSTRAINT + [ "requires 'java.rmi';", @@ -48,6 +52,7 @@ class SuggestMergedModuleInfoSpec extends Specification { ] static Set KOTLIN_DIRECTIVES_CONSTRAINT = [ + 'requires("java.datatransfer");', 'requires("java.management");', 'requires("java.naming");', 'requires("java.logging");', @@ -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 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 JAVA_DIRECTIVES_CONSTRAINT = [ @@ -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 JAVA_DIRECTIVES = JAVA_DIRECTIVES_CONSTRAINT + [ "requires java.rmi;", @@ -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()) } } diff --git a/src/test/resources/hello-log4j-2.9.0/build.additive.gradle b/src/test/resources/hello-log4j-2.9.0/build.additive.gradle index c87c7389..dd5248ed 100644 --- a/src/test/resources/hello-log4j-2.9.0/build.additive.gradle +++ b/src/test/resources/hello-log4j-2.9.0/build.additive.gradle @@ -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' diff --git a/src/test/resources/hello-log4j-2.9.0/build.additive.gradle.kts b/src/test/resources/hello-log4j-2.9.0/build.additive.gradle.kts index 12786af7..f80789f6 100644 --- a/src/test/resources/hello-log4j-2.9.0/build.additive.gradle.kts +++ b/src/test/resources/hello-log4j-2.9.0/build.additive.gradle.kts @@ -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 { diff --git a/src/test/resources/hello-log4j-2.9.0/build.gradle b/src/test/resources/hello-log4j-2.9.0/build.gradle index bad177af..e7dbd948 100644 --- a/src/test/resources/hello-log4j-2.9.0/build.gradle +++ b/src/test/resources/hello-log4j-2.9.0/build.gradle @@ -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' @@ -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'; } }