Skip to content

Commit

Permalink
Adds support to detect Maven 4 beta versions (#798)
Browse files Browse the repository at this point in the history
* Adds support to detect Maven 4 beta versions

* source format

---------

Co-authored-by: Benoit GUERIN <[email protected]>
  • Loading branch information
froque and bguerin authored May 29, 2024
1 parent b57d3dd commit 89bec7a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MavenVersion {

public static MavenVersion fromString(String str) {
try {
String[] parts = str.split("\\.");
String[] parts = str.split("[.\\-]");
return new MavenVersion(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
} catch (Exception ex) {
throw new IllegalArgumentException("'" + str + "' is not a valid maven version", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class MavenVersionUtils {

public static Predicate<String> containsMavenVersion() {
return string -> string != null && string.matches("Apache Maven \\d+\\.\\d+\\.\\d+ \\(.*\\)");
return string -> string != null && string.matches("Apache Maven \\d+\\.\\d+\\.\\d+(.*) \\(.*\\)");
}

public static MavenVersion parseMavenVersion(String outputLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public void should_detect_maven_version() {
assertThat(MavenVersionUtils.containsMavenVersion()
.test("Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)"))
.isTrue();

assertThat(MavenVersionUtils.containsMavenVersion()
.test("Apache Maven 4.0.0-beta-3 (e92f645c2749eb2a4f5a8843cf01e7441e4b559f)"))
.isTrue();
}

@Test
Expand All @@ -30,5 +34,7 @@ public void should_parse_maven_version() {
.isEqualTo(new MavenVersion(3, 8, 8));
assertThat(MavenVersionUtils.parseMavenVersion("Apache Maven 3.6.1")).isEqualTo(new MavenVersion(3, 6, 1));
assertThat(MavenVersionUtils.parseMavenVersion("Apache Maven 3.5.4")).isEqualTo(new MavenVersion(3, 5, 4));
assertThat(MavenVersionUtils.parseMavenVersion("Apache Maven 4.0.0-beta-3"))
.isEqualTo(new MavenVersion(4, 0, 0));
}
}

0 comments on commit 89bec7a

Please sign in to comment.