Skip to content

Commit d58c3a8

Browse files
authored
Merge pull request #10 from KyleAure/main
2 parents e049cb4 + 110afbe commit d58c3a8

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

.github/workflows/CI.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Java CI with Gradle
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
strategy:
13+
matrix:
14+
java-version: [ '17', '18', '19', '20', '21' ]
15+
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout project
20+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
21+
22+
# Gradle java toolchain cannot find early release images, need to preload until GA is available
23+
- name: Preload JDK 21
24+
if: ${{ matrix.java-version == '21' }}
25+
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
26+
with:
27+
java-version: '21-ea'
28+
distribution: 'temurin'
29+
30+
- name: Set up JDK 11
31+
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
32+
with:
33+
java-version: '11'
34+
distribution: 'temurin'
35+
cache: gradle
36+
37+
- name: Build application
38+
run: |
39+
./gradlew io.openliberty.java.internal_fat_${{ matrix.java-version }}:build
40+
41+
- name: Verify application
42+
run: |
43+
./.github/workflows/scripts/verifyArtifact.sh ${{ matrix.java-version }}
44+
45+
- name: Upload application
46+
uses: actions/upload-artifact@013d2b89baa2f354c5ffec54c68bec4ab39a2534 #v3.1.2
47+
with:
48+
name: Applications
49+
path: io.openliberty.java.internal_fat_${{ matrix.java-version }}/build/libs/io.openliberty.java.internal_fat_${{ matrix.java-version }}.war
50+
if-no-files-found: error
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class ClassVersionChecker {
5+
6+
private static final HashMap<String, Integer> majorCodeMap = new HashMap<>();
7+
8+
public static void main(String[] args) throws IOException {
9+
if (args.length != 2) {
10+
throw new RuntimeException("Expected exactly 2 arguments");
11+
}
12+
13+
//Adapted from https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.1
14+
majorCodeMap.put("1.0.2", 45);
15+
majorCodeMap.put("1.1", 45);
16+
majorCodeMap.put("1.2", 46);
17+
majorCodeMap.put("1.3", 47);
18+
majorCodeMap.put("1.4", 48);
19+
majorCodeMap.put("5.0", 49);
20+
majorCodeMap.put("6", 50);
21+
majorCodeMap.put("7", 51);
22+
majorCodeMap.put("8", 52);
23+
majorCodeMap.put("9", 53);
24+
majorCodeMap.put("10", 54);
25+
majorCodeMap.put("11", 55);
26+
majorCodeMap.put("12", 56);
27+
majorCodeMap.put("13", 57);
28+
majorCodeMap.put("14", 58);
29+
majorCodeMap.put("15", 59);
30+
majorCodeMap.put("16", 60);
31+
majorCodeMap.put("17", 61);
32+
majorCodeMap.put("18", 62);
33+
majorCodeMap.put("19", 63);
34+
majorCodeMap.put("20", 64);
35+
majorCodeMap.put("21", 65);
36+
37+
String filename = args[0];
38+
int expected = majorCodeMap.get(args[1]);
39+
40+
checkClassVersion(filename, expected);
41+
}
42+
43+
private static void checkClassVersion(String filename, int expected) throws IOException {
44+
try ( DataInputStream in = new DataInputStream(new FileInputStream(filename)) ) {
45+
int magic = in.readInt();
46+
47+
if(magic != 0xcafebabe) {
48+
System.out.println(filename + " is not a valid class!");
49+
}
50+
51+
int minor = in.readUnsignedShort();
52+
int major = in.readUnsignedShort();
53+
54+
System.out.println("Major version: " + major);
55+
System.out.println("Minor version: " + minor);
56+
57+
if(expected != major) {
58+
System.out.println("Expected major version of " + expected + " but got " + major);
59+
System.exit(1); //Failing execution
60+
}
61+
}
62+
}
63+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
if [ $# -ne 1 ]; then
4+
echo "Exactly one argument is required"
5+
exit 0
6+
fi
7+
8+
JAVA_VERSION=$1
9+
SUB_PROJECT=$PWD/io.openliberty.java.internal_fat_$JAVA_VERSION
10+
TEST_CLASS=$SUB_PROJECT/build/classes/java/main/io/openliberty/java/internal/TestApp.class
11+
12+
13+
echo "Checking class"
14+
SCRIPTS=$PWD/.github/workflows/scripts/
15+
pushd $SCRIPTS &> /dev/null
16+
java ClassVersionChecker.java $TEST_CLASS $JAVA_VERSION
17+
popd &> /dev/null
18+
echo "--------------------"

gradlew

100644100755
File mode changed.

0 commit comments

Comments
 (0)