Skip to content

Commit 5d2a253

Browse files
launcher 2.6.2: properly detect MPS 2025.1 vs 2025.2
1 parent 0bf1309 commit 5d2a253

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

launcher/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
66
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 2.6.2
9+
10+
### Fixed
11+
12+
- MPS 2025.1 vs 2025.2 detection logic should now work properly.
13+
814
## 2.6.1
915

1016
### Fixed

launcher/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version.launcher=2.6.1
1+
version.launcher=2.6.2

launcher/src/main/java/de/itemis/mps/gradle/launcher/MpsVersionDetection.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,34 @@ public static Provider<String> fromMpsHome(ProjectLayout layout, ProviderFactory
3434
throw new GradleException("Could not read mps.build.number property from file " + buildPropertiesFile.getAsFile());
3535
}
3636

37-
return buildNumberToVersion(buildNumber);
37+
String buildNumberWithoutPrefix = buildNumber.replaceFirst("^\\p{Alpha}+-", "");
38+
return buildNumberToVersion(buildNumberWithoutPrefix);
3839
});
3940
}
4041

4142
private static String buildNumberToVersion(String buildNumber) {
42-
String buildNumberWithoutPrefix = buildNumber.replaceFirst("^\\p{Alpha}+-", "");
43-
if (buildNumberWithoutPrefix.compareTo("251.23774.10000") >= 0 && buildNumberWithoutPrefix.compareTo("252") < 0) {
44-
// 251.23774.10000 and above are pre-releases of 2025.2
45-
return "2025.2";
43+
if (!Character.isDigit(buildNumber.charAt(0))) {
44+
throw new IllegalArgumentException("build number must start with a digit");
4645
}
4746

48-
return buildNumberWithoutPrefix.replaceFirst("^(\\d{2})(\\d)\\..*", "20$1.$2");
47+
if (buildNumber.startsWith("251.23774.")) {
48+
// 251.23774.10000 and above are actually pre-releases of 2025.2
49+
String suffix = buildNumber.substring("251.23774.".length());
50+
int suffixAsInt;
51+
try {
52+
suffixAsInt = Integer.parseInt(suffix);
53+
} catch (NumberFormatException nfe) {
54+
// Something unknown in the number, treat it as 2025.1
55+
return "2025.1";
56+
}
57+
58+
if (suffixAsInt >= 10000) {
59+
return "2025.2";
60+
} else {
61+
return "2025.1";
62+
}
63+
}
64+
65+
return buildNumber.replaceFirst("^(\\d{2})(\\d)\\..*", "20$1.$2");
4966
}
5067
}

launcher/src/test/java/de/itemis/mps/gradle/launcher/MpsVersionDetectionTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ public void readsVersionFromBuildProperties(@TempDir File tempDir) throws IOExce
2828
project.provider(() -> mpsDir)).get());
2929
}
3030

31+
@Test
32+
public void version251(@TempDir File tempDir) throws IOException {
33+
final Project project = ProjectBuilder.builder().withProjectDir(tempDir).build();
34+
35+
File mpsDir = new File(tempDir, "build/mps");
36+
File buildProperties = new File(mpsDir, "build.properties");
37+
38+
FileUtils.writeStringToFile(buildProperties, "mps.build.number=MPS-251.23774.541\n",
39+
StandardCharsets.ISO_8859_1);
40+
41+
assertEquals("2025.1", MpsVersionDetection.fromMpsHome(project.getLayout(), project.getProviders(),
42+
project.provider(() -> mpsDir)).get());
43+
}
44+
3145
@Test
3246
public void prereleaseOf252(@TempDir File tempDir) throws IOException {
3347
final Project project = ProjectBuilder.builder().withProjectDir(tempDir).build();

0 commit comments

Comments
 (0)