Skip to content

Commit

Permalink
Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Hammad committed Oct 21, 2024
1 parent 999c5df commit 90545ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11, 17 ]
java: [ 8, 11, 17, 21 ]
steps:
- uses: actions/checkout@v4
- name: Setup java
Expand Down
34 changes: 23 additions & 11 deletions src/main/java/org/dvare/dynamic/compiler/DynamicCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ public void addCompilerOption(DynamicCompilerOption compilerOption, String compi
options.add(compilerOptionVaule);
}

public static boolean isJava9OrAbove() {
String version = System.getProperty("java.version");
if (version.startsWith("1.8")) {
return false;
}
int majorVersion = Integer.parseInt(version.split("\\.")[0]);
return majorVersion >= 9;
}

public Map<String, Class<?>> build() throws DynamicCompilerException {

errors.clear();
Expand All @@ -153,17 +162,9 @@ public Map<String, Class<?>> build() throws DynamicCompilerException {
}

try {
Class.forName("com.sun.tools.sjavac.Module");
options.add(DynamicCompilerOption.ADD_EXPORTS.toString());
options.add("java.base/java.lang=ALL-UNNAMED");
options.add(DynamicCompilerOption.ADD_EXPORTS.toString());
options.add("java.base/java.util=ALL-UNNAMED");
options.add(DynamicCompilerOption.ADD_EXPORTS.toString());
options.add("java.base/java.io=ALL-UNNAMED");
options.add(DynamicCompilerOption.ADD_EXPORTS.toString());
options.add("java.base/java.net=ALL-UNNAMED");


if (isJava9OrAbove()) {
importBaseModule();
}
} catch (Exception ignored) {
}

Expand Down Expand Up @@ -213,6 +214,17 @@ public Map<String, Class<?>> build() throws DynamicCompilerException {

}

private void importBaseModule() {
options.add(DynamicCompilerOption.ADD_EXPORTS.toString());
options.add("java.base/java.lang=ALL-UNNAMED");
options.add(DynamicCompilerOption.ADD_EXPORTS.toString());
options.add("java.base/java.util=ALL-UNNAMED");
options.add(DynamicCompilerOption.ADD_EXPORTS.toString());
options.add("java.base/java.io=ALL-UNNAMED");
options.add(DynamicCompilerOption.ADD_EXPORTS.toString());
options.add("java.base/java.net=ALL-UNNAMED");
}


private List<String> diagnosticToString(List<Diagnostic<? extends JavaFileObject>> diagnostics) {

Expand Down

0 comments on commit 90545ed

Please sign in to comment.