diff --git a/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/JasperReportsProcessor.java b/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/JasperReportsProcessor.java index 55a08b1..6031aeb 100644 --- a/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/JasperReportsProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/jasperreports/deployment/JasperReportsProcessor.java @@ -1,17 +1,27 @@ package io.quarkiverse.jasperreports.deployment; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; import java.util.stream.Stream; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; +import org.jboss.logging.Logger; + import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.IndexDependencyBuildItem; 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.RuntimeInitializedPackageBuildItem; import io.quarkus.deployment.pkg.builditem.UberJarMergedResourceBuildItem; class JasperReportsProcessor { - + private static final Logger LOGGER = Logger.getLogger("JasperReports"); private static final String FEATURE = "jasperreports"; private static final String EXTENSIONS_FILE = "jasperreports_extension.properties"; @@ -25,24 +35,20 @@ UberJarMergedResourceBuildItem mergeResource() { return new UberJarMergedResourceBuildItem(EXTENSIONS_FILE); } + @BuildStep + void indexTransitiveDependencies(BuildProducer index) { + index.produce(new IndexDependencyBuildItem("net.sf.jasperreports", "jasperreports")); + index.produce(new IndexDependencyBuildItem("net.sf.jasperreports", "jasperreports-fonts")); + index.produce(new IndexDependencyBuildItem("org.apache.xmlgraphics", "batik-bridge")); + index.produce(new IndexDependencyBuildItem("com.ibm.icu", "icu4j")); + index.produce(new IndexDependencyBuildItem("com.drewnoakes", "metadata-extractor")); + } + @BuildStep void runtimeInitializedClasses(BuildProducer runtimeInitializedPackages) { //@formatter:off Stream.of( - javax.swing.plaf.metal.MetalIconFactory.class.getPackageName(), - net.sf.jasperreports.data.http.HttpDataService.class.getPackageName(), - net.sf.jasperreports.engine.SimpleReportContext.class.getPackageName(), - net.sf.jasperreports.engine.design.JRAbstractCompiler.class.getPackageName(), - net.sf.jasperreports.engine.export.JRXlsExporter.class.getPackageName(), - net.sf.jasperreports.engine.export.oasis.JROdtExporter.class.getPackageName(), - net.sf.jasperreports.engine.export.ooxml.DocxRunHelper.class.getPackageName(), - net.sf.jasperreports.engine.fonts.AwtFontManager.class.getPackageName(), - net.sf.jasperreports.engine.print.JRPrinterAWT.class.getPackageName(), - net.sf.jasperreports.engine.type.ColorEnum.class.getPackageName(), - net.sf.jasperreports.engine.util.ExifUtil.class.getPackageName(), - net.sf.jasperreports.engine.util.json.DefaultJsonQLExecuter.class.getPackageName(), - net.sf.jasperreports.renderers.AbstractSvgDataToGraphics2DRenderer.class.getPackageName(), - net.sf.jasperreports.renderers.util.SvgFontProcessor.class.getPackageName() + javax.swing.plaf.metal.MetalIconFactory.class.getPackageName() ) .map(RuntimeInitializedPackageBuildItem::new) .forEach(runtimeInitializedPackages::produce); @@ -64,4 +70,61 @@ void substrateResourceBuildItems(BuildProducer nat resourceBundleBuildItem.produce(new NativeImageResourceBundleBuildItem("metadata_messages")); resourceBundleBuildItem.produce(new NativeImageResourceBundleBuildItem("metadata_messages-defaults")); } + + @BuildStep + void registerForReflection(BuildProducer reflectiveClass, + CombinedIndexBuildItem combinedIndex) { + + final List classNames = new ArrayList<>(); + // All utilities + classNames.addAll(collectClassesInPackage(combinedIndex, + net.sf.jasperreports.renderers.util.RendererUtil.class.getPackageName())); + classNames.addAll( + collectClassesInPackage(combinedIndex, net.sf.jasperreports.engine.util.ExifUtil.class.getPackageName())); + classNames.addAll(collectClassesInPackage(combinedIndex, + net.sf.jasperreports.engine.util.json.DefaultJsonQLExecuter.class.getPackageName())); + classNames.addAll(collectClassesInPackage(combinedIndex, + net.sf.jasperreports.renderers.WrappingSvgDataToGraphics2DRenderer.class.getPackageName())); + + reflectiveClass.produce( + ReflectiveClassBuildItem.builder(classNames.toArray(new String[0])).constructors().methods().fields() + .serialization() + .build()); + } + + public List collectClassesInPackage(CombinedIndexBuildItem combinedIndex, String packageName) { + final List classes = new ArrayList<>(); + final List packages = new ArrayList<>(combinedIndex.getIndex().getSubpackages(packageName)); + packages.add(DotName.createSimple(packageName)); + for (DotName aPackage : packages) { + final List packageClasses = combinedIndex.getIndex() + .getClassesInPackage(aPackage) + .stream() + .map(ClassInfo::toString) + .toList(); + classes.addAll(packageClasses); + } + LOGGER.tracef("%s Classes: %s", packageName, classes); + return classes; + } + + private List collectSubclasses(CombinedIndexBuildItem combinedIndex, String className) { + List classes = combinedIndex.getIndex() + .getAllKnownSubclasses(DotName.createSimple(className)) + .stream() + .map(ClassInfo::toString) + .collect(Collectors.toList()); + classes.add(className); + return classes; + } + + public List collectImplementors(CombinedIndexBuildItem combinedIndex, String className) { + List classes = combinedIndex.getIndex() + .getAllKnownImplementors(DotName.createSimple(className)) + .stream() + .map(ClassInfo::toString) + .collect(Collectors.toList()); + classes.add(className); + return classes; + } } \ No newline at end of file diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index c9553a8..6c9bfce 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -15,7 +15,7 @@ io.quarkus - quarkus-resteasy-reactive + quarkus-rest io.quarkiverse.jasperreports diff --git a/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperReportsResource.java b/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperReportsResource.java index 23822cc..31876ee 100644 --- a/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperReportsResource.java +++ b/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperReportsResource.java @@ -40,6 +40,7 @@ import net.sf.jasperreports.engine.design.JasperDesign; import net.sf.jasperreports.engine.export.HtmlExporter; import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRRtfExporter; import net.sf.jasperreports.engine.export.JRXmlExporter; import net.sf.jasperreports.engine.fill.JRFiller; import net.sf.jasperreports.engine.fill.SimpleJasperReportSource; @@ -155,6 +156,22 @@ public byte[] html() throws JRException { return outputStream.toByteArray(); } + @POST + @Path("rtf") + public byte[] rtf() throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + JRRtfExporter exporter = new JRRtfExporter(); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleWriterExporterOutput(outputStream)); + + exporter.exportReport(); + Log.info("RTF creation time : " + (System.currentTimeMillis() - start)); + return outputStream.toByteArray(); + } + // @POST // @Path("print") // public void print() throws JRException { @@ -182,27 +199,7 @@ public byte[] html() throws JRException { // // return outputStream.toByteArray(); // } - // - // @POST - // @Path("rtf") - // public byte[] rtf() throws JRException { - // long start = System.currentTimeMillis(); - // - // JasperPrint jasperPrint = fill(); - // - // JRRtfExporter exporter = new JRRtfExporter(); - // - // exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); - // - // ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - // exporter.setExporterOutput(new SimpleWriterExporterOutput(outputStream)); - // - // exporter.exportReport(); - // - // Log.info("RTF creation time : " + (System.currentTimeMillis() - start)); - // - // return outputStream.toByteArray(); - // } + // // @@ -329,4 +326,4 @@ public byte[] html() throws JRException { // // return outputStream.toByteArray(); // } -} +} \ No newline at end of file diff --git a/integration-tests/src/test/java/io/quarkiverse/jasperreports/it/JasperReportsResourceTest.java b/integration-tests/src/test/java/io/quarkiverse/jasperreports/it/JasperReportsResourceTest.java index 1ea16cc..c02fdd4 100644 --- a/integration-tests/src/test/java/io/quarkiverse/jasperreports/it/JasperReportsResourceTest.java +++ b/integration-tests/src/test/java/io/quarkiverse/jasperreports/it/JasperReportsResourceTest.java @@ -38,6 +38,14 @@ void testExportHTML() { .statusCode(200); } + @Test + void testExportRTF() { + given() + .when().post("/jasperreports/rtf") + .then() + .statusCode(200); + } + // @Test // void testExportPDF() { // given() @@ -46,13 +54,7 @@ void testExportHTML() { // .statusCode(200); // } // - // @Test - // void testExportRTF() { - // given() - // .when().post("/jasperreports/rtf") - // .then() - // .statusCode(200); - // } + // // diff --git a/pom.xml b/pom.xml index 5f45ed3..1c626e1 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ 2.0.6 6.21.3 - 1.2.0 + 2.0.0 diff --git a/runtime/pom.xml b/runtime/pom.xml index 9d2b090..3e2ed87 100644 --- a/runtime/pom.xml +++ b/runtime/pom.xml @@ -63,6 +63,36 @@ ${version.jaxen} + + com.ibm.icu + icu4j + 75.1 + + + + org.apache.xmlgraphics + batik-bridge + 1.17 + + + + antlr + antlr + 2.7.5 + + + + org.mozilla + rhino + 1.7.15 + + + + com.drewnoakes + metadata-extractor + 2.19.0 + + org.apache.commons commons-collections4