Skip to content

Commit 8c50f6c

Browse files
committed
fix: github-api in native image
1 parent d957af9 commit 8c50f6c

File tree

5 files changed

+47
-43
lines changed

5 files changed

+47
-43
lines changed

Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ RUN jar -xvf ${ARTIFACT_JAR_PATTERN}
3939
RUN native-image \
4040
--initialize-at-build-time=`cat ./InitializeAtBuildTime | tr '\n' ','` \
4141
--initialize-at-run-time=`cat ./InitializeAtRunTime | tr '\n' ','` \
42-
-H:ReflectionConfigurationResources=META-INF/native-image/github-api-native-test-custom-definitions/reflect-config.json \
4342
--no-fallback \
4443
--enable-https \
4544
--install-exit-handlers \

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<artifactId>bridge-method-injector</artifactId>
5151
<version>${bridge-method-injector.version}</version>
5252
</dependency>
53+
5354
</dependencies>
5455

5556
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package github.api.nat.test.aot;
2+
3+
import org.springframework.aot.hint.MemberCategory;
4+
import org.springframework.aot.hint.RuntimeHints;
5+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
6+
import org.springframework.aot.hint.TypeReference;
7+
8+
import java.io.File;
9+
import java.io.FileInputStream;
10+
import java.io.IOException;
11+
import java.util.Arrays;
12+
import java.util.jar.JarEntry;
13+
import java.util.jar.JarInputStream;
14+
import java.util.logging.Level;
15+
import java.util.logging.Logger;
16+
17+
public class GitHubRuntimeHints implements RuntimeHintsRegistrar {
18+
19+
private static final Logger LOGGER = Logger.getLogger(GitHubRuntimeHints.class.getName());
20+
21+
@Override
22+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
23+
Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator)).forEach(classpathEntry -> {
24+
// If the classpathEntry is no jar skip it
25+
if (!classpathEntry.endsWith(".jar")) {
26+
return;
27+
}
28+
29+
try (JarInputStream is = new JarInputStream(new FileInputStream(classpathEntry))) {
30+
JarEntry entry;
31+
while ((entry = is.getNextJarEntry()) != null) {
32+
if (entry.getName().endsWith(".class") && entry.getName().startsWith("org/kohsuke/github")) {
33+
String githubApiClassName = entry.getName().replace("/", ".");
34+
String githubApiClassNameWithoutClass = githubApiClassName.substring(0, githubApiClassName.length() - 6);
35+
LOGGER.log(Level.INFO, "Registered class " + githubApiClassNameWithoutClass + " for reflections and serialization.");
36+
hints.reflection().registerType(TypeReference.of(githubApiClassNameWithoutClass), MemberCategory.values());
37+
hints.serialization().registerType(TypeReference.of(githubApiClassName));
38+
}
39+
}
40+
} catch (IOException e) {
41+
LOGGER.log(Level.INFO, "Error while reading jars", e);
42+
}
43+
});
44+
}
45+
}

src/main/resources/META-INF/native-image/github-api-native-test-custom-definitions/reflect-config.json

-42
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=github.api.nat.test.aot.GitHubRuntimeHints

0 commit comments

Comments
 (0)