Skip to content

Commit b762351

Browse files
committed
check module descriptors hidden inside META-INF/versions folder
1 parent a8ff841 commit b762351

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>io.github.ghackenberg</groupId>
77
<artifactId>jigsaw-maven-plugin</artifactId>
8-
<version>1.0.2</version>
8+
<version>1.1.0</version>
99
<packaging>maven-plugin</packaging>
1010
<name>Maven Java Platform Module System (JPMS) Plugin</name>
1111
<description>Plugin to simplify software linking and packaging on top of the Java Platform Module system (JPMS).</description>

src/main/java/io/github/ghackenberg/maven/plugins/jigsaw/PatchMojo.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.util.Enumeration;
3737
import java.util.HashMap;
3838
import java.util.List;
39+
import java.util.regex.Matcher;
40+
import java.util.regex.Pattern;
3941
import java.util.zip.ZipEntry;
4042
import java.util.zip.ZipFile;
4143

@@ -55,6 +57,12 @@
5557
@Mojo(name = "patch", defaultPhase = LifecyclePhase.PACKAGE)
5658
public class PatchMojo extends BaseMojo {
5759

60+
private static final Pattern PATTERN = Pattern.compile("^META-INF/versions/([0-9]*)/module-info.class$");
61+
62+
private static final String JAVA_VERSION = System.getProperty("java.version");
63+
64+
private static final String JAVA_VERSION_MAJOR = JAVA_VERSION.substring(0, JAVA_VERSION.indexOf('.'));
65+
5866
@Parameter
5967
private boolean ignoreMissingDeps;
6068

@@ -64,6 +72,10 @@ public class PatchMojo extends BaseMojo {
6472
@Override
6573
protected final void run() throws MojoExecutionException, MojoFailureException {
6674

75+
String targetJavaVersion = multiRelease != null ? multiRelease : JAVA_VERSION_MAJOR;
76+
77+
int targetJavaVersionNumber = Integer.parseInt(targetJavaVersion);
78+
6779
File[] jars = modulePath.listFiles(file -> !file.isDirectory() && file.getName().endsWith(".jar"));
6880

6981
for (File jar : jars) {
@@ -73,10 +85,38 @@ protected final void run() throws MojoExecutionException, MojoFailureException {
7385
System.out.println("[" + jar.getName() + "] Checking module info");
7486

7587
try (ZipFile zip = new ZipFile(jar)) {
76-
if (zip.getEntry("module-info.class") != null) {
77-
continue;
88+
Enumeration<? extends ZipEntry> iterator = zip.entries();
89+
90+
boolean found = false;
91+
92+
while (iterator.hasMoreElements()) {
93+
// Get entry
94+
ZipEntry entry = iterator.nextElement();
95+
// Get name
96+
String name = entry.getName();
97+
// Check name
98+
if (name.equals("module-info.class")) {
99+
found = true;
100+
break;
101+
} else {
102+
// Get match
103+
Matcher matcher = PATTERN.matcher(name);
104+
// Check match
105+
if (matcher.find()) {
106+
// Get version
107+
String version = matcher.group(1);
108+
// Parse version
109+
int versionNumber = Integer.parseInt(version);
110+
// Check version
111+
if (versionNumber <= targetJavaVersionNumber) {
112+
found = true;
113+
break;
114+
}
115+
}
116+
}
78117
}
79-
if (zip.getEntry("META-INF/versions/") != null) {
118+
119+
if (found) {
80120
continue;
81121
}
82122
}

0 commit comments

Comments
 (0)