This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from Trivadis/feature/issue-177-improve-loggi…
…ng-native-image Feature/issue 177 - Improve logging capabilities of standalone image and native image creation
- Loading branch information
Showing
11 changed files
with
904 additions
and
159 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ hs_err_pid* | |
.project | ||
.classpath | ||
**/.settings | ||
.vscode | ||
|
||
# IntelliJ | ||
**/.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...lone/src/main/java/com/trivadis/plsql/formatter/RuntimeReflectionRegistrationFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.trivadis.plsql.formatter; | ||
|
||
import org.graalvm.nativeimage.hosted.Feature; | ||
import org.graalvm.nativeimage.hosted.RuntimeReflection; | ||
import org.reflections.Reflections; | ||
import org.reflections.scanners.Scanners; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.util.Set; | ||
|
||
@SuppressWarnings("unused") | ||
public class RuntimeReflectionRegistrationFeature implements Feature { | ||
private static final String[] SKIP_CLASS_NAMES = { | ||
"oracle.dbtools.util.Closeables", | ||
}; | ||
|
||
private static void register(String packageName, boolean includeSubPackages, ClassLoader classLoader) { | ||
Reflections reflections = new Reflections(packageName); | ||
Set<String> allClassNames = reflections.getAll(Scanners.SubTypes); | ||
// allClassNames contains also inner classes | ||
for (String className : allClassNames) { | ||
if (className.startsWith((packageName))) { | ||
if (includeSubPackages || (!className.substring(packageName.length() + 1).contains("."))) { | ||
if (validClass(className)) { | ||
registerClass(className, classLoader); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static boolean validClass(String className) { | ||
for (String skipClassName : SKIP_CLASS_NAMES) { | ||
if (className.startsWith(skipClassName)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private static void registerClass(String className, ClassLoader classLoader) { | ||
try { | ||
Class<?> clazz = Class.forName(className, false, classLoader); | ||
// calling getClass() on a clazz throws an Exception when not found on the classpath | ||
RuntimeReflection.register(clazz.getClass()); | ||
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { | ||
RuntimeReflection.register(constructor); | ||
} | ||
for (Method method : clazz.getDeclaredMethods()) { | ||
RuntimeReflection.register((method)); | ||
} | ||
for (Field field : clazz.getDeclaredFields()) { | ||
RuntimeReflection.register(field); | ||
} | ||
} catch (Throwable t) { | ||
// ignore | ||
} | ||
} | ||
|
||
public void beforeAnalysis(BeforeAnalysisAccess access) { | ||
ClassLoader classLoader = access.getApplicationClassLoader(); | ||
// register all classes in a package | ||
register("oracle.dbtools.app", true, classLoader); | ||
register("oracle.dbtools.arbori", true, classLoader); | ||
register("oracle.dbtools.parser", true, classLoader); | ||
register("oracle.dbtools.raptor", false, classLoader); | ||
register("oracle.dbtools.util", true, classLoader); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
.../resources/META-INF/native-image/com.trivadis.plsql.formatter/tvdformat/proxy-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[ | ||
[], | ||
["java.util.function.Predicate"] | ||
] |
Oops, something went wrong.