Skip to content

Commit 84e0363

Browse files
[MENFORCER-440] Fix pattern for Java 8 version
1 parent 4bbf7cd commit 84e0363

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/version/RequireJavaVersion.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
@Named("requireJavaVersion")
4343
public final class RequireJavaVersion extends AbstractVersionEnforcer {
4444

45-
private static final Pattern JDK8_VERSION_PATTERN = Pattern.compile("([\\[(,]?)(1\\.8|8)([]),]?)");
45+
private static final Pattern JDK8_VERSION_PATTERN = Pattern.compile("([\\d.]+)");
4646

4747
/**
4848
* Display the normalized JDK version.
@@ -57,11 +57,20 @@ public void setVersion(String theVersion) {
5757
return;
5858
}
5959

60+
if (!theVersion.contains("8")) {
61+
super.setVersion(theVersion);
62+
return;
63+
}
64+
6065
Matcher matcher = JDK8_VERSION_PATTERN.matcher(theVersion);
6166

6267
StringBuffer result = new StringBuffer();
6368
while (matcher.find()) {
64-
matcher.appendReplacement(result, "$11.8$3");
69+
if ("8".equals(matcher.group(1))) {
70+
matcher.appendReplacement(result, "1.8");
71+
} else {
72+
matcher.appendReplacement(result, "$1");
73+
}
6574
}
6675
matcher.appendTail(result);
6776

enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/version/TestRequireJavaVersion.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,24 @@ static Stream<Arguments> fixJava8ShortVersion() {
140140
return Stream.of(
141141
Arguments.of("1.8", "1.8"),
142142
Arguments.of("8", "1.8"),
143+
Arguments.of(".8", ".8"),
144+
Arguments.of("8.", "8."),
143145
Arguments.of("8,)", "1.8,)"),
144146
Arguments.of("[8,)", "[1.8,)"),
145147
Arguments.of("(1.7,8]", "(1.7,1.8]"),
146148
Arguments.of("[1.8,)", "[1.8,)"),
147149
Arguments.of("(1.8,8]", "(1.8,1.8]"),
150+
Arguments.of("(8,8]", "(1.8,1.8]"),
148151
Arguments.of("(8,)", "(1.8,)"),
149152
Arguments.of("[8]", "[1.8]"),
150-
Arguments.of("(9,11],[8]", "(9,11],[1.8]"));
153+
Arguments.of("(9,11],[8]", "(9,11],[1.8]"),
154+
Arguments.of("(11.0.18", "(11.0.18"),
155+
Arguments.of("(15.1.8", "(15.1.8"),
156+
Arguments.of("(15.1.2", "(15.1.2"),
157+
Arguments.of("18", "18"),
158+
Arguments.of("18.", "18."),
159+
Arguments.of(".18", ".18"),
160+
Arguments.of("38", "38"));
151161
}
152162

153163
@ParameterizedTest

0 commit comments

Comments
 (0)