in arthur-impl/src/main/java/org/apache/geronimo/arthur/impl/nativeimage/generator/ConfigurationGenerator.java [107:183]
private void updateConfiguration(final DefautContext context) throws IOException {
if (!context.getReflections().isEmpty()) {
ensureWorkingDirectoryExists();
final Path json = workingDirectory.resolve("reflection.arthur.json");
log.info("Creating reflection model '{}'", json);
try (final Writer writer = Files.newBufferedWriter(
json, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) {
jsonSerializer.accept(
context.getReflections().stream()
.collect(groupingBy(ClassReflectionModel::getName))
.values().stream()
.map(this::merge)
.sorted(comparing(ClassReflectionModel::getName))
.collect(toList()),
writer);
}
context.addReflectionConfigFile(json.toAbsolutePath().toString());
}
if (!context.getResources().isEmpty() || !context.getBundles().isEmpty()) {
final ResourcesModel resourcesModel = new ResourcesModel();
if (!context.getResources().isEmpty()) {
resourcesModel.setResources(context.getResources());
}
if (!context.getBundles().isEmpty()) {
resourcesModel.setBundles(context.getBundles());
}
ensureWorkingDirectoryExists();
final Path json = workingDirectory.resolve("resources.arthur.json");
log.info("Creating resources model '{}'", json);
try (final Writer writer = Files.newBufferedWriter(
json, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) {
jsonSerializer.accept(resourcesModel, writer);
}
context.addResourcesConfigFile(json.toAbsolutePath().toString());
}
if (!context.getDynamicProxyModels().isEmpty()) {
final Set<Collection<String>> proxies = context.getDynamicProxyModels().stream()
.map(DynamicProxyModel::getClasses)
.collect(toCollection(LinkedHashSet::new));
ensureWorkingDirectoryExists();
final Path json = workingDirectory.resolve("dynamicproxies.arthur.json");
log.info("Creating dynamic proxy model '{}'", json);
try (final Writer writer = Files.newBufferedWriter(
json, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) {
jsonSerializer.accept(proxies, writer);
}
context.addDynamicProxiesConfigFile(json.toAbsolutePath().toString());
}
if (!context.getDynamicClasses().isEmpty()) {
final Path dynamicClassesDir = workingDirectory.resolve("dynamic_classes");
context.getDynamicClasses().forEach((name, content) -> {
final Path target = dynamicClassesDir.resolve(name.replace('.', '/') + ".class");
if (!Files.exists(target.getParent())) {
try {
Files.createDirectories(target.getParent());
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}
try {
Files.write(target, content, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (final IOException e) {
throw new IllegalStateException(e);
}
});
log.info("Dumped {} generated classes in '{}'", context.getDynamicClasses().size(), dynamicClassesDir);
if (configuration.getClasspath() == null) {
configuration.setClasspath(singletonList(dynamicClassesDir.toString()));
} else {
configuration.setClasspath(Stream.concat(
configuration.getClasspath().stream(),
Stream.of(dynamicClassesDir.toString())
).distinct().collect(toList()));
}
}
}