From cd7e06a922b42a4417284351746080377581e2ee Mon Sep 17 00:00:00 2001 From: Melloware Date: Tue, 29 Oct 2024 08:20:07 -0400 Subject: [PATCH] Fix #271: MimeTypes UberJar handling (#272) --- .../deployment/MimeTypesProcessor.java | 68 +++++++++++++++++++ .../deployment/PrimeFacesProcessor.java | 4 -- 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 quarkus-primefaces/deployment/src/main/java/io/quarkiverse/primefaces/deployment/MimeTypesProcessor.java diff --git a/quarkus-primefaces/deployment/src/main/java/io/quarkiverse/primefaces/deployment/MimeTypesProcessor.java b/quarkus-primefaces/deployment/src/main/java/io/quarkiverse/primefaces/deployment/MimeTypesProcessor.java new file mode 100644 index 0000000..588b894 --- /dev/null +++ b/quarkus-primefaces/deployment/src/main/java/io/quarkiverse/primefaces/deployment/MimeTypesProcessor.java @@ -0,0 +1,68 @@ +package io.quarkiverse.primefaces.deployment; + +import java.util.List; + +import io.quarkus.deployment.IsNormal; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.IndexDependencyBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem; +import io.quarkus.deployment.pkg.builditem.UberJarMergedResourceBuildItem; + +/** + * The {@code MimeTypesProcessor} class provides build steps to handle transitive dependencies and resources + * required for MIME type handling in a Quarkus environment. + *

+ * This processor extends {@link AbstractJandexProcessor} and uses Quarkus build steps to: + *

+ */ +class MimeTypesProcessor extends AbstractJandexProcessor { + + /** + * Registers transitive dependencies to be indexed for Jandex processing. + *

+ * This step produces an {@link IndexDependencyBuildItem} for the "mime-types" library, ensuring + * that relevant classes are indexed by Jandex for use in the Quarkus build process. + * + * @param index the build producer for {@link IndexDependencyBuildItem} instances + */ + @BuildStep + void indexTransitiveDependencies(BuildProducer index) { + index.produce(new IndexDependencyBuildItem("org.overviewproject", "mime-types")); + } + + /** + * Produces {@link UberJarMergedResourceBuildItem}s for each specified service file to be included in the Uber JAR. + *

+ * This build step is only executed in "normal" mode and registers each of the listed services + * in the {@code META-INF/services} directory, which allows the Uber JAR to load specific service implementations. + * + * @param producer the build producer for creating {@link UberJarMergedResourceBuildItem} instances + */ + @BuildStep(onlyIf = IsNormal.class) + void uberJarServiceLoaders(BuildProducer producer) { + List serviceFiles = List.of("java.nio.file.spi.FileTypeDetector"); + + for (String serviceFile : serviceFiles) { + producer.produce(new UberJarMergedResourceBuildItem("META-INF/services/" + serviceFile)); + } + } + + /** + * Produces a {@link NativeImageResourceBundleBuildItem} to include the MIME type cache resource + * in native images. + *

+ * This ensures that MIME type information is available in native images, which is required for + * applications using the "mime-types" library for file type detection. + * + * @param resourceBundleBuildItem the build producer for {@link NativeImageResourceBundleBuildItem} instances + */ + @BuildStep + void mimeTypeResourceBuildItems(BuildProducer resourceBundleBuildItem) { + resourceBundleBuildItem.produce(new NativeImageResourceBundleBuildItem("mime.cache")); + } +} \ No newline at end of file diff --git a/quarkus-primefaces/deployment/src/main/java/io/quarkiverse/primefaces/deployment/PrimeFacesProcessor.java b/quarkus-primefaces/deployment/src/main/java/io/quarkiverse/primefaces/deployment/PrimeFacesProcessor.java index 3021eeb..0e4b39d 100644 --- a/quarkus-primefaces/deployment/src/main/java/io/quarkiverse/primefaces/deployment/PrimeFacesProcessor.java +++ b/quarkus-primefaces/deployment/src/main/java/io/quarkiverse/primefaces/deployment/PrimeFacesProcessor.java @@ -46,7 +46,6 @@ NativeImageFeatureBuildItem nativeImageFeature() { void indexTransitiveDependencies(BuildProducer index) { index.produce(new IndexDependencyBuildItem("com.googlecode.owasp-java-html-sanitizer", "owasp-java-html-sanitizer")); index.produce(new IndexDependencyBuildItem("io.nayuki", "qrcodegen")); - index.produce(new IndexDependencyBuildItem("org.overviewproject", "mime-types")); index.produce(new IndexDependencyBuildItem("org.primefaces", "primefaces")); index.produce(new IndexDependencyBuildItem("software.xdev", "chartjs-java-model")); } @@ -116,9 +115,6 @@ void substrateResourceBuildItems(BuildProducer nat resourceBundleBuildItem.produce(new NativeImageResourceBundleBuildItem("org.primefaces.Messages_sv")); resourceBundleBuildItem.produce(new NativeImageResourceBundleBuildItem("org.primefaces.Messages_tr")); resourceBundleBuildItem.produce(new NativeImageResourceBundleBuildItem("org.primefaces.Messages_zh")); - - // mime types - resourceBundleBuildItem.produce(new NativeImageResourceBundleBuildItem("mime.cache")); } @BuildStep