Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ public void accept(PluginDescriptor pluginDescriptor) {
}

boolean matchesVersion(String requiredVersion, String currentVersion) {
// Java 8 is consistent: it will always say "1.8...". Users are not consistent.
if (!requiredVersion.contains("1.8") && currentVersion.startsWith("1.8")) {
currentVersion = currentVersion.substring(2);
}
VersionConstraint constraint;
try {
constraint = versionScheme.parseVersionConstraint(requiredVersion.equals("8") ? "1.8" : requiredVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two lines above you substring currentVersion here it's about requiredVersion. Is it intended or are you accidently mixing variables?

constraint = versionScheme.parseVersionConstraint(requiredVersion);
} catch (InvalidVersionSpecificationException e) {
throw new IllegalArgumentException("Invalid 'requiredJavaVersion' given in plugin descriptor", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,22 @@ public class MavenPluginJavaPrerequisiteCheckerTest {
public void testMatchesVersion() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Parameterized tests here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the change as you asked, but now fails with checkstyle:

Error:  src/test/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteCheckerTest.java:[67,19] (design) VisibilityModifier: Variable 'requiredVersion' must be private and have accessor methods.
Error:  src/test/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteCheckerTest.java:[70,19] (design) VisibilityModifier: Variable 'currentVersion' must be private and have accessor methods.
Error:  src/test/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteCheckerTest.java:[73,20] (design) VisibilityModifier: Variable 'expected' must be private and have accessor methods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly the two are not aligned: as if I make field private or just non-public, I get

Cannot set parameter 'requiredVersion'. Ensure that the field 'requiredVersion' is public.

So one want this, other want that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do it simple, you can try to add suppress for checkstyle, by the way I'm working on move test to JUnit 5 in #11547

MavenPluginJavaPrerequisiteChecker checker = new MavenPluginJavaPrerequisiteChecker();
assertTrue(checker.matchesVersion("8", "1.8"));
assertTrue(checker.matchesVersion("[8,)", "1.8"));
assertTrue(checker.matchesVersion("(,8]", "1.8"));
assertFalse(checker.matchesVersion("(,8)", "1.8"));
assertTrue(checker.matchesVersion("8", "9.0.1+11"));
assertTrue(checker.matchesVersion("[8,)", "9.0.1+11"));
assertFalse(checker.matchesVersion("(,8]", "9.0.1+11"));
assertFalse(checker.matchesVersion("(,8)", "9.0.1+11"));
assertTrue(checker.matchesVersion("1.8", "1.8"));
assertTrue(checker.matchesVersion("[1.8,)", "1.8"));
assertTrue(checker.matchesVersion("(,1.8]", "1.8"));
assertFalse(checker.matchesVersion("(,1.8)", "1.8"));
assertTrue(checker.matchesVersion("1.8", "9.0.1+11"));
assertTrue(checker.matchesVersion("[1.8,)", "9.0.1+11"));
assertFalse(checker.matchesVersion("(,1.8]", "9.0.1+11"));
assertFalse(checker.matchesVersion("(,1.8)", "9.0.1+11"));

assertTrue(checker.matchesVersion("1.0", "1.8"));
assertTrue(checker.matchesVersion("1.8", "9.0.1+11"));
assertFalse(checker.matchesVersion("[1.0,2],[3,4]", "2.1"));
Expand Down
Loading