diff --git a/extensions/ical/deployment/src/main/java/org/apache/camel/quarkus/component/ical/deployment/IcalProcessor.java b/extensions/ical/deployment/src/main/java/org/apache/camel/quarkus/component/ical/deployment/IcalProcessor.java index 989dd7cd8cc8..5ae52c557c7b 100644 --- a/extensions/ical/deployment/src/main/java/org/apache/camel/quarkus/component/ical/deployment/IcalProcessor.java +++ b/extensions/ical/deployment/src/main/java/org/apache/camel/quarkus/component/ical/deployment/IcalProcessor.java @@ -20,13 +20,13 @@ 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.NativeImageResourceDirectoryBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; -import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; +import net.fortuna.ical4j.model.TimeZoneLoader; +import net.fortuna.ical4j.util.MapTimeZoneCache; class IcalProcessor { @@ -62,21 +62,13 @@ void nativeResources( } @BuildStep - void registerWsSecurityReflectionItems(CombinedIndexBuildItem combinedIndexBuildItem, - BuildProducer reflectiveClass) { + void registerForReflection(BuildProducer reflectiveClass) { reflectiveClass - .produce(ReflectiveClassBuildItem.builder("net.fortuna.ical4j.util.MapTimeZoneCache").methods(true).build()); + .produce(ReflectiveClassBuildItem.builder(MapTimeZoneCache.class).build()); } @BuildStep - IndexDependencyBuildItem registerDependencyForIndex() { - return new IndexDependencyBuildItem("org.mnode.ical4j", "ical4j"); + RuntimeReinitializedClassBuildItem runtimeReinitializedClasses() { + return new RuntimeReinitializedClassBuildItem(TimeZoneLoader.class.getName()); } - - @BuildStep - void runtimeInitializedClasses(BuildProducer runtimeInitializedClass) { - runtimeInitializedClass - .produce(new RuntimeInitializedClassBuildItem("net.fortuna.ical4j.validate.schema.JsonSchemaValidator")); - } - } diff --git a/extensions/ical/runtime/src/main/java/org/apache/camel/quarkus/component/ical/deployment/SchemaValidatorFactorySubst.java b/extensions/ical/runtime/src/main/java/org/apache/camel/quarkus/component/ical/deployment/SchemaValidatorFactorySubst.java index e3f6e3447a7c..dfa063ecabda 100644 --- a/extensions/ical/runtime/src/main/java/org/apache/camel/quarkus/component/ical/deployment/SchemaValidatorFactorySubst.java +++ b/extensions/ical/runtime/src/main/java/org/apache/camel/quarkus/component/ical/deployment/SchemaValidatorFactorySubst.java @@ -16,6 +16,8 @@ */ package org.apache.camel.quarkus.component.ical.deployment; +import java.util.function.BooleanSupplier; + import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import net.fortuna.ical4j.model.parameter.Schema; @@ -23,17 +25,27 @@ import net.fortuna.ical4j.validate.Validator; import net.fortuna.ical4j.validate.schema.SchemaValidatorFactory; -@TargetClass(value = SchemaValidatorFactory.class) +/** + * Cuts out paths to optional JsonSchemaValidator. Only required if STRUCTURED-DATA elements are present + * in the calendar definition. See RFC 9073. + */ +@TargetClass(value = SchemaValidatorFactory.class, onlyWith = IsJsonSkemaAbsent.class) final class SchemaValidatorFactorySubstitutions { - @Substitute public static Validator newInstance(Schema schema) { - //see https://github.com/apache/camel-quarkus/issues/5099 for more details - //Method causes error (it is unclear to me, why it is happening): - //UnresolvedElementException: Discovered unresolved method during parsing: net.fortuna.ical4j.validate.schema.JsonSchemaValidator.(java.net.URL). - // This error is reported at image build time because class net.fortuna.ical4j.validate.schema.SchemaValidatorFactory - // is registered for linking at image build time by command line + throw new UnsupportedOperationException( + "iCalendar JSON schema validation is unavailable. Add com.github.erosb:json-sKema to the application classpath"); + } +} - throw new RuntimeException("Feature is not supported."); +final class IsJsonSkemaAbsent implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + try { + Class.forName("com.github.erosb.jsonsKema.Schema", false, Thread.currentThread().getContextClassLoader()); + return false; + } catch (ClassNotFoundException e) { + return true; + } } }