From d495b86f132028ff5912d03e7b9b6ed7dc54cd93 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Sat, 4 Feb 2023 11:48:26 -0300 Subject: [PATCH] Ignore missing AWT library if missing - This is a workaround until https://github.com/oracle/graal/issues/4124 is fixed --- .../poi/deployment/POIProcessor.java | 6 ++++ .../runtime/graal/SheetUtilSubstitution.java | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 runtime/src/main/java/io/quarkiverse/poi/runtime/graal/SheetUtilSubstitution.java diff --git a/deployment/src/main/java/io/quarkiverse/poi/deployment/POIProcessor.java b/deployment/src/main/java/io/quarkiverse/poi/deployment/POIProcessor.java index 46f19c4..eba07e0 100644 --- a/deployment/src/main/java/io/quarkiverse/poi/deployment/POIProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/poi/deployment/POIProcessor.java @@ -12,6 +12,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.IndexDependencyBuildItem; import io.quarkus.deployment.builditem.NativeImageFeatureBuildItem; +import io.quarkus.deployment.builditem.SystemPropertyBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; class POIProcessor { @@ -34,6 +35,11 @@ void indexTransitiveDependencies(BuildProducer index) index.produce(new IndexDependencyBuildItem("org.apache.poi", "poi-ooxml-full")); } + @BuildStep + SystemPropertyBuildItem ignoreMissingFontSystem() { + return new SystemPropertyBuildItem("org.apache.poi.ss.ignoreMissingFontSystem", "true"); + } + @BuildStep void registerXMLBeansClassesForReflection(CombinedIndexBuildItem combinedIndexBuildItem, BuildProducer reflectiveClass) { diff --git a/runtime/src/main/java/io/quarkiverse/poi/runtime/graal/SheetUtilSubstitution.java b/runtime/src/main/java/io/quarkiverse/poi/runtime/graal/SheetUtilSubstitution.java new file mode 100644 index 0000000..0e4f35f --- /dev/null +++ b/runtime/src/main/java/io/quarkiverse/poi/runtime/graal/SheetUtilSubstitution.java @@ -0,0 +1,34 @@ +package io.quarkiverse.poi.runtime.graal; + +import java.text.AttributedString; + +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.SheetUtil; +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.Platforms; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; + +@TargetClass(SheetUtil.class) +@Platforms(Platform.MACOS.class) +public final class SheetUtilSubstitution { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias) + public static int DEFAULT_CHAR_WIDTH = 5; + + @Substitute + public static int getDefaultCharWidth(final Workbook wb) { + return DEFAULT_CHAR_WIDTH; + } + + @Substitute + private static double getCellWidth(int defaultCharWidth, int colspan, + CellStyle style, double minWidth, AttributedString str) { + return defaultCharWidth; + } +}