From 2c0289b01137a749a3a84716e94146aa6fe5900f Mon Sep 17 00:00:00 2001 From: airsquared <36649395+airsquared@users.noreply.github.com> Date: Sun, 24 Sep 2023 02:29:54 -0700 Subject: [PATCH] Read module-info.class anywhere in jar file (#224) --- .../impl/CreateMergedModuleTaskImpl.groovy | 25 +++++++++++-------- .../jlink/util/SourceCodeConstants.groovy | 17 ++++++------- .../jlink/SuggestMergedModuleInfoSpec.groovy | 3 +++ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/groovy/org/beryx/jlink/impl/CreateMergedModuleTaskImpl.groovy b/src/main/groovy/org/beryx/jlink/impl/CreateMergedModuleTaskImpl.groovy index ae378bde..d51f5527 100644 --- a/src/main/groovy/org/beryx/jlink/impl/CreateMergedModuleTaskImpl.groovy +++ b/src/main/groovy/org/beryx/jlink/impl/CreateMergedModuleTaskImpl.groovy @@ -27,6 +27,7 @@ import org.gradle.api.Project import org.gradle.api.file.CopySpec import org.gradle.api.logging.Logger import org.gradle.api.logging.Logging +import org.gradle.process.internal.ExecException import java.lang.module.ModuleFinder import java.lang.module.ModuleReference @@ -136,16 +137,20 @@ class CreateMergedModuleTaskImpl extends BaseTaskImpl entries = zipFile.entries(); entries.hasMoreElements();) { - ZipEntry entry = entries.nextElement(); - if(entry.getName().equals(prefix + "module-info.class")) { - InputStream entryStream = zipFile.getInputStream(entry); - return ModuleDescriptor.read(entryStream); - } + var x = zipFile.stream().filter(entry -> entry.getName().endsWith("module-info.class")).findFirst(); + if (x.isPresent()) { + return ModuleDescriptor.read(zipFile.getInputStream(x.get())); + } else { + return null; } - return null; } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/test/groovy/org/beryx/jlink/SuggestMergedModuleInfoSpec.groovy b/src/test/groovy/org/beryx/jlink/SuggestMergedModuleInfoSpec.groovy index 74545c81..aec7af71 100644 --- a/src/test/groovy/org/beryx/jlink/SuggestMergedModuleInfoSpec.groovy +++ b/src/test/groovy/org/beryx/jlink/SuggestMergedModuleInfoSpec.groovy @@ -37,6 +37,7 @@ class SuggestMergedModuleInfoSpec extends Specification { "requires 'java.xml';", "requires 'java.desktop';", "requires 'java.datatransfer';", + "requires 'org.apache.logging.log4j';", "provides 'javax.annotation.processing.Processor' with 'org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor';", "provides 'javax.imageio.spi.ImageWriterSpi' with 'com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriterSpi', 'com.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriterSpi';", "provides 'javax.imageio.spi.ImageReaderSpi' with 'com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReaderSpi', 'com.twelvemonkeys.imageio.plugins.tiff.BigTIFFImageReaderSpi', 'com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderSpi';", @@ -59,6 +60,7 @@ class SuggestMergedModuleInfoSpec extends Specification { 'requires("java.sql");', 'requires("java.xml");', 'requires("java.desktop");', + 'requires("org.apache.logging.log4j");', '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");', @@ -80,6 +82,7 @@ class SuggestMergedModuleInfoSpec extends Specification { "requires java.xml;", "requires java.datatransfer;", "requires java.management;", + "requires org.apache.logging.log4j;", "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;",