Skip to content

Commit

Permalink
Java version check: only check >=11 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-ka authored Feb 22, 2024
1 parent f0f5949 commit 50936b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
23 changes: 10 additions & 13 deletions .github/workflows/build_standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ jobs:
path: ./out
if-no-files-found: error

validate_java_8:
validate_java_11:
runs-on: ubuntu-latest
needs:
- build

steps:
- name: Download build
uses: actions/download-artifact@v2
Expand All @@ -57,18 +56,17 @@ jobs:
path: ./out
- name: Grant execute permission for cm
run: chmod +x ./out/bin/cm
- name: Set up JDK 8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 8
java-version: 11
- name: Execute to check if Java version is compatible
run: ./out/bin/cm

validate_java_11:
validate_java_17:
runs-on: ubuntu-latest
needs:
- build

steps:
- name: Download build
uses: actions/download-artifact@v2
Expand All @@ -77,18 +75,17 @@ jobs:
path: ./out
- name: Grant execute permission for cm
run: chmod +x ./out/bin/cm
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Execute to check if Java version is compatible
run: ./out/bin/cm

validate_java_17:
validate_java_21:
runs-on: ubuntu-latest
needs:
- build

steps:
- name: Download build
uses: actions/download-artifact@v2
Expand All @@ -97,9 +94,9 @@ jobs:
path: ./out
- name: Grant execute permission for cm
run: chmod +x ./out/bin/cm
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21
- name: Execute to check if Java version is compatible
run: ./out/bin/cm || if [ $? != 1 ]; then exit -1; fi
run: ./out/bin/cm
8 changes: 4 additions & 4 deletions src/main/java/org/contextmapper/cli/ContextMapperCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class ContextMapperCLI {

private static final List<String> REQUIRED_JAVA_VERSIONS = Collections.unmodifiableList(Arrays.asList("11", "17"));
private static final int REQUIRED_JAVA_VERSION = 11;
private static final String VALIDATE_COMMAND = "validate";
private static final String GENERATE_COMMAND = "generate";

Expand All @@ -38,12 +38,12 @@ public ContextMapperCLI() {
}

public static void main(String[] args) {
String javaVersion = System.getProperty("java.version");
int javaVersion = Runtime.version().feature();

if (REQUIRED_JAVA_VERSIONS.stream().anyMatch(javaVersion::startsWith)) {
if (Runtime.version().feature() >= REQUIRED_JAVA_VERSION) {
new ContextMapperCLI().run(args);
} else {
System.out.printf("Invalid Java version '%s', please set JAVA_HOME to major version '%s'%n", javaVersion, String.join("' or '", REQUIRED_JAVA_VERSIONS));
System.out.printf("Invalid Java version '%s' (>=%s is required).", javaVersion, REQUIRED_JAVA_VERSION);
System.exit(1);
}
}
Expand Down

0 comments on commit 50936b4

Please sign in to comment.