Skip to content

Commit

Permalink
Tidy iCal extension native workaround for absence of com.github.erosb…
Browse files Browse the repository at this point in the history
…:json-sKema

Fixes #5099
  • Loading branch information
jamesnetherton committed Jul 31, 2023
1 parent d11a8b8 commit 3c41262
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -62,21 +62,13 @@ void nativeResources(
}

@BuildStep
void registerWsSecurityReflectionItems(CombinedIndexBuildItem combinedIndexBuildItem,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> 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<RuntimeInitializedClassBuildItem> runtimeInitializedClass) {
runtimeInitializedClass
.produce(new RuntimeInitializedClassBuildItem("net.fortuna.ical4j.validate.schema.JsonSchemaValidator"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,36 @@
*/
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;
import net.fortuna.ical4j.model.property.StructuredData;
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<StructuredData> 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.<init>(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;
}
}
}

0 comments on commit 3c41262

Please sign in to comment.