src/main/java/de/unixwork/uwproj/CompatibilityCheck.java

Sun, 12 Jan 2025 16:28:08 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 12 Jan 2025 16:28:08 +0100
changeset 135
9afe68b15c66
parent 121
155cd224b51d
permissions
-rw-r--r--

improve toolchain detection to also get the wordsize and stdc version, issue #439, issue #508

120
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 package de.unixwork.uwproj;
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 public class CompatibilityCheck {
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 private CompatibilityCheck() {}
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 private static int[] versionParts(String ver) {
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 if (ver.isBlank()) return new int[]{0,0,0};
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 final var partStrings = ver.split("\\.");
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 try {
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 return new int[]{
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 partStrings.length > 0 ? Integer.parseInt(partStrings[0]) : 0,
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 partStrings.length > 1 ? Integer.parseInt(partStrings[1]) : 0,
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 partStrings.length > 2 ? Integer.parseInt(partStrings[2]) : 0
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 };
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 } catch (NumberFormatException e) {
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 return new int[]{0,0,0};
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 }
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 }
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 public static void check(String expected, String actual) throws CompatibilityException {
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 final var expectedVer = versionParts(expected);
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 final var actualVer = versionParts(actual);
121
155cd224b51d fix incorrect compatibility check for major versions
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
24 if (expectedVer[0] != actualVer[0] || expectedVer[1] > actualVer[1]) {
120
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 if (actual.isBlank()) actual = "unspecified";
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 throw new CompatibilityException("Expected project file version '" + expected + "' but got '" + actual + "'.");
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 }
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 }
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 public static class CompatibilityException extends Exception {
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 public CompatibilityException(String message) {
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 super(message);
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 }
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 }
0e3827ebc6e4 add compatibility check - resolves #477
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 }

mercurial