Skip to content

Commit

Permalink
Native work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Oct 8, 2024
1 parent e7f83b7 commit d0ac2f7
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 24 deletions.
4 changes: 0 additions & 4 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
<groupId>io.quarkiverse.jasperreports</groupId>
<artifactId>quarkus-jasperreports</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-xalan-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.quarkiverse.jasperreports.deployment;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import io.quarkiverse.jasperreports.XalanTransformerFactory;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.nativeimage.ExcludeConfigBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;

class XalanNativeImageProcessor {
private static final String TRANSFORMER_FACTORY_SERVICE_FILE_PATH = "META-INF/services/javax.xml.transform.TransformerFactory";

@BuildStep
List<ReflectiveClassBuildItem> reflectiveClasses() {
return Arrays.asList(
ReflectiveClassBuildItem.builder(io.quarkiverse.jasperreports.XalanTransformerFactory.class.getName(),
"org.apache.xalan.xsltc.dom.ObjectFactory",
"org.apache.xalan.xsltc.dom.XSLTCDTMManager",
"org.apache.xalan.xsltc.trax.ObjectFactory",
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl",
"org.apache.xml.dtm.ObjectFactory",
"org.apache.xml.dtm.ref.DTMManagerDefault",
"org.apache.xml.serializer.OutputPropertiesFactory",
"org.apache.xml.serializer.CharInfo",
"org.apache.xml.utils.FastStringBuffer").methods().build(),
ReflectiveClassBuildItem.builder("org.apache.xml.serializer.ToHTMLStream",
"org.apache.xml.serializer.ToTextStream",
"org.apache.xml.serializer.ToXMLStream").build());
}

@BuildStep
List<NativeImageResourceBundleBuildItem> resourceBundles() {
return Arrays.asList(
new NativeImageResourceBundleBuildItem("org.apache.xalan.xsltc.compiler.util.ErrorMessages"),
new NativeImageResourceBundleBuildItem("org.apache.xml.serializer.utils.SerializerMessages"),
new NativeImageResourceBundleBuildItem("org.apache.xml.serializer.XMLEntities"),
new NativeImageResourceBundleBuildItem("org.apache.xml.res.XMLErrorResources"));
}

@BuildStep
void resources(BuildProducer<NativeImageResourceBuildItem> resource) {

Stream.of(
"html",
"text",
"xml",
"unknown")
.map(s -> "org/apache/xml/serializer/output_" + s + ".properties")
.map(NativeImageResourceBuildItem::new)
.forEach(resource::produce);

}

@BuildStep
void installTransformerFactory(
BuildProducer<ExcludeConfigBuildItem> excludeConfig,
BuildProducer<ServiceProviderBuildItem> serviceProvider) {

excludeConfig
.produce(new ExcludeConfigBuildItem("xalan\\.xalan-.*\\.jar", "/" + TRANSFORMER_FACTORY_SERVICE_FILE_PATH));
serviceProvider.produce(new ServiceProviderBuildItem("javax.xml.transform.TransformerFactory",
XalanTransformerFactory.class.getName()));

}

}
23 changes: 11 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<!-- Dependency Versions -->
<version.quarkus>3.15.1</version.quarkus>
<version.quarkus-poi>2.0.6</version.quarkus-poi>
<version.quarkus-camel>3.15.0</version.quarkus-camel>
<version.xalan>2.7.2</version.xalan>
<version.jasperreports>7.0.1</version.jasperreports>
</properties>
<dependencyManagement>
Expand All @@ -60,16 +60,6 @@
<artifactId>quarkus-poi-deployment</artifactId>
<version>${version.quarkus-poi}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-xalan</artifactId>
<version>${version.quarkus-camel}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-xalan-deployment</artifactId>
<version>${version.quarkus-camel}</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
Expand Down Expand Up @@ -105,7 +95,16 @@
<artifactId>jasperreports-annotation-processors</artifactId>
<version>${version.jasperreports}</version>
</dependency>

<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>${version.xalan}</version>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>serializer</artifactId>
<version>${version.xalan}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
Expand Down
8 changes: 0 additions & 8 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
<groupId>io.quarkiverse.poi</groupId>
<artifactId>quarkus-poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-xalan</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>commons-logging-jboss-logging</artifactId>
Expand Down Expand Up @@ -77,10 +73,6 @@
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-xalan</artifactId>
<exclusions>
<exclusion>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package io.quarkiverse.jasperreports;

import javax.xml.transform.ErrorListener;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TemplatesHandler;
import javax.xml.transform.sax.TransformerHandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.XMLFilter;

/**
* A {@link TransformerFactory} delegating to a {@link TransformerFactory} created via
* {@code TransformerFactory.newInstance("org.apache.xalan.xsltc.trax.TransformerFactoryImpl", Thread.currentThread().getContextClassLoader())}
*/
public final class XalanTransformerFactory extends SAXTransformerFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(XalanTransformerFactory.class);

private final SAXTransformerFactory delegate;

public XalanTransformerFactory() {
final SAXTransformerFactory factory = (SAXTransformerFactory) TransformerFactory.newInstance(
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl",
Thread.currentThread().getContextClassLoader());
try {
factory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (TransformerException e) {
LOGGER.warn("Unsupported TransformerFactory feature " + javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING);
}

this.delegate = factory;
}

@Override
public Transformer newTransformer(Source source) throws TransformerConfigurationException {
return delegate.newTransformer(source);
}

@Override
public Transformer newTransformer() throws TransformerConfigurationException {
return delegate.newTransformer();
}

@Override
public Templates newTemplates(Source source) throws TransformerConfigurationException {
return delegate.newTemplates(source);
}

@Override
public Source getAssociatedStylesheet(Source source, String media, String title, String charset)
throws TransformerConfigurationException {
return delegate.getAssociatedStylesheet(source, media, title, charset);
}

@Override
public void setURIResolver(URIResolver resolver) {
delegate.setURIResolver(resolver);
}

@Override
public URIResolver getURIResolver() {
return delegate.getURIResolver();
}

@Override
public void setFeature(String name, boolean value) throws TransformerConfigurationException {
delegate.setFeature(name, value);
}

@Override
public boolean getFeature(String name) {
return delegate.getFeature(name);
}

@Override
public void setAttribute(String name, Object value) {
delegate.setAttribute(name, value);
}

@Override
public Object getAttribute(String name) {
return delegate.getAttribute(name);
}

@Override
public void setErrorListener(ErrorListener listener) {
delegate.setErrorListener(listener);
}

@Override
public ErrorListener getErrorListener() {
return delegate.getErrorListener();
}

@Override
public TransformerHandler newTransformerHandler(Source source) throws TransformerConfigurationException {
return delegate.newTransformerHandler(source);
}

@Override
public TransformerHandler newTransformerHandler(Templates templates) throws TransformerConfigurationException {
return delegate.newTransformerHandler(templates);
}

@Override
public TransformerHandler newTransformerHandler() throws TransformerConfigurationException {
return delegate.newTransformerHandler();
}

@Override
public TemplatesHandler newTemplatesHandler() throws TransformerConfigurationException {
return delegate.newTemplatesHandler();
}

@Override
public XMLFilter newXMLFilter(Source source) throws TransformerConfigurationException {
return delegate.newXMLFilter(source);
}

@Override
public XMLFilter newXMLFilter(Templates templates) throws TransformerConfigurationException {
return delegate.newXMLFilter(templates);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.jasperreports.graal;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

@TargetClass(className = "org.apache.xalan.xsltc.trax.TemplatesImpl")
final class TemplatesImplSubstitution {

@TargetClass(className = "org.apache.xalan.xsltc.trax.TemplatesImpl", innerClass = "TransletClassLoader")
static final class TransletClassLoader {
@Substitute
Class defineClass(final byte[] b) {
throw new UnsupportedOperationException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkiverse.jasperreports.XalanTransformerFactory

0 comments on commit d0ac2f7

Please sign in to comment.