use of io.quarkus.deployment.builditem.GeneratedNativeImageClassBuildItem in project camel-quarkus by apache.
the class XalanNativeImageProcessor method installTransformerFactory.
@BuildStep
void installTransformerFactory(BuildProducer<GeneratedNativeImageClassBuildItem> nativeImageClass, BuildProducer<GeneratedResourceBuildItem> generatedResources) {
final String serviceProviderFileContent = XalanTransformerFactory.class.getName() + "\n";
/* This is primarily for the JVM mode */
generatedResources.produce(new GeneratedResourceBuildItem(TRANSFORMER_FACTORY_SERVICE_FILE_PATH, serviceProviderFileContent.getBytes(StandardCharsets.UTF_8)));
/* A low level way to embed only our service file in the native image.
* There are at least two META-INF/services/javax.xml.transform.TransformerFactory files
* in the class path: ours and the one from xalan.jar. As of GraalVM 19.3.1-java8, 19.3.1-java11,
* 20.0.0-java8 and 20.0.0-java11, there is no way to ensure that ServiceProviderBuildItem
* or NativeImageResourceBuildItem will pick the service file preferred by us.
* We are thus forced to use this low level mechanism to ensure that.
*/
final ClassCreator file = new ClassCreator(new ClassOutput() {
@Override
public void write(String s, byte[] bytes) {
nativeImageClass.produce(new GeneratedNativeImageClassBuildItem(s, bytes));
}
}, getClass().getName() + "AutoFeature", null, Object.class.getName(), Feature.class.getName());
file.addAnnotation("com.oracle.svm.core.annotate.AutomaticFeature");
final MethodCreator beforeAn = file.getMethodCreator("beforeAnalysis", "V", Feature.BeforeAnalysisAccess.class.getName());
final TryBlock overallCatch = beforeAn.tryBlock();
overallCatch.invokeStaticMethod(ofMethod(ResourceUtils.class, "registerResources", void.class, String.class, String.class), overallCatch.load(TRANSFORMER_FACTORY_SERVICE_FILE_PATH), overallCatch.load(serviceProviderFileContent));
final CatchBlockCreator print = overallCatch.addCatch(Throwable.class);
print.invokeVirtualMethod(ofMethod(Throwable.class, "printStackTrace", void.class), print.getCaughtException());
beforeAn.returnValue(null);
file.close();
}
Aggregations