From b91557f0158b4cc093c170256a6103c6fd73c908 Mon Sep 17 00:00:00 2001 From: melloware Date: Thu, 24 Oct 2024 13:56:42 -0400 Subject: [PATCH] MYFACES-4688: 5.0 Quarkus reflection/serialization --- .../quarkus/deployment/MyFacesProcessor.java | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/extensions/quarkus/deployment/src/main/java/org/apache/myfaces/core/extensions/quarkus/deployment/MyFacesProcessor.java b/extensions/quarkus/deployment/src/main/java/org/apache/myfaces/core/extensions/quarkus/deployment/MyFacesProcessor.java index 327d6d27b..15dfc875b 100644 --- a/extensions/quarkus/deployment/src/main/java/org/apache/myfaces/core/extensions/quarkus/deployment/MyFacesProcessor.java +++ b/extensions/quarkus/deployment/src/main/java/org/apache/myfaces/core/extensions/quarkus/deployment/MyFacesProcessor.java @@ -32,6 +32,8 @@ import javax.xml.parsers.DocumentBuilderFactory; import jakarta.el.ELResolver; +import jakarta.el.Expression; +import jakarta.el.ValueExpression; import jakarta.enterprise.inject.Produces; import jakarta.faces.FactoryFinder; import jakarta.faces.annotation.View; @@ -117,6 +119,7 @@ import org.apache.myfaces.view.facelets.tag.LambdaMetadataTargetImpl; import org.apache.myfaces.view.facelets.tag.MethodRule; import org.apache.myfaces.view.facelets.tag.faces.ComponentSupport; +import org.apache.myfaces.view.facelets.tag.faces.FaceletState; import org.apache.myfaces.view.facelets.tag.jstl.fn.JstlFunction; import org.apache.myfaces.webapp.FacesInitializerImpl; import org.apache.myfaces.webapp.MyFacesContainerInitializer; @@ -337,9 +340,8 @@ void buildRecommendedInitParams(BuildProducer initPar { // user config Config config = ConfigProvider.getConfig(); - - Optional projectStage = resolveProjectStage(config); - initParam.produce(new ServletInitParamBuildItem(ProjectStage.PROJECT_STAGE_PARAM_NAME, projectStage.get())); + String projectStage = resolveProjectStage(config); + initParam.produce(new ServletInitParamBuildItem(ProjectStage.PROJECT_STAGE_PARAM_NAME, projectStage)); } @BuildStep @@ -361,7 +363,7 @@ void buildAnnotationProviderIntegration(MyFacesRecorder recorder, CombinedIndexB } } - private Optional resolveProjectStage(Config config) + private String resolveProjectStage(Config config) { Optional projectStage = config.getOptionalValue(ProjectStage.PROJECT_STAGE_PARAM_NAME, String.class); @@ -377,7 +379,7 @@ else if (ConfigUtils.getProfiles().contains(LaunchMode.TEST.getDefaultProfile()) projectStage = Optional.of(ProjectStage.SystemTest.name()); } } - return projectStage; + return projectStage.orElse(ProjectStage.Production.name()); } @BuildStep @@ -442,7 +444,6 @@ void registerForLimitedReflection(MyFacesRecorder recorder, classNames.addAll(collectSubclasses(combinedIndex, Renderer.class.getName())); classNames.addAll(collectSubclasses(combinedIndex, ClientBehaviorRenderer.class.getName())); - classNames.addAll(collectSubclasses(combinedIndex, jakarta.el.ValueExpression.class.getName())); classNames.addAll(collectSubclasses(combinedIndex, SystemEvent.class.getName())); classNames.addAll(collectSubclasses(combinedIndex, FacesContext.class.getName())); classNames.addAll(collectSubclasses(combinedIndex, Application.class.getName())); @@ -495,12 +496,6 @@ void registerForLimitedReflection(MyFacesRecorder recorder, classNames.addAll(collectSubclasses(combinedIndex, factory)); } - classNames.addAll(Arrays.asList( - "jakarta.faces.component._DeltaStateHelper", - "jakarta.faces.component._DeltaStateHelper$InternalMap", - "jakarta.validation.groups.Default", - "jakarta.validation.Validation")); - List> classes = new ArrayList<>(Arrays.asList(ApplicationImplEventManager.class, DefaultWebConfigProviderFactory.class, ErrorPageWriter.class, @@ -529,29 +524,41 @@ void registerForMethodReflection(MyFacesRecorder recorder, BuildProducer classNames = new ArrayList<>(); List> classes = new ArrayList<>(); - classNames.add("jakarta.faces._FactoryFinderProviderFactory"); + // Java Core + classNames.add("java.util.Collections$EmptySet"); classNames.addAll(collectImplementors(combinedIndex, java.util.Collection.class.getName())); classNames.addAll(collectImplementors(combinedIndex, java.time.temporal.TemporalAccessor.class.getName())); classNames.addAll(collectImplementors(combinedIndex, java.util.Map.Entry.class.getName())); classNames.addAll(collectSubclasses(combinedIndex, java.lang.Number.class.getName())); - classNames.add(java.util.Date.class.getName()); - classNames.add(java.util.Calendar.class.getName()); classNames.add(java.lang.Iterable.class.getName()); - classNames.add(java.lang.Throwable.class.getName()); classNames.add(java.lang.String.class.getName()); + classNames.add(java.lang.StringBuffer.class.getName()); + classNames.add(java.lang.Throwable.class.getName()); + classNames.add(java.util.Calendar.class.getName()); + classNames.add(java.util.Date.class.getName()); - classNames.addAll(collectSubclasses(combinedIndex, TagHandler.class.getName())); - classNames.addAll(collectSubclasses(combinedIndex, ConverterHandler.class.getName())); + // Jakarta Faces + classNames.add("jakarta.faces._FactoryFinderProviderFactory"); + classNames.add("jakarta.faces.component._AttachedStateWrapper"); + classNames.add("jakarta.faces.component._DeltaStateHelper"); + classNames.add("jakarta.faces.component._DeltaStateHelper$InternalMap"); + classNames.add("jakarta.faces.context._MyFacesExternalContextHelper"); + classNames.add("jakarta.validation.Validation"); + classNames.add("jakarta.validation.groups.Default"); + classNames.add(jakarta.faces.view.Location.class.getName()); + classNames.addAll(collectImplementors(combinedIndex, Behavior.class.getName())); + classNames.addAll(collectImplementors(combinedIndex, Converter.class.getName())); + classNames.addAll(collectImplementors(combinedIndex, Validator.class.getName())); classNames.addAll(collectSubclasses(combinedIndex, ComponentHandler.class.getName())); - classNames.addAll(collectSubclasses(combinedIndex, ValidatorHandler.class.getName())); - classNames.addAll(collectSubclasses(combinedIndex, UIComponent.class.getName())); + classNames.addAll(collectSubclasses(combinedIndex, ConverterHandler.class.getName())); + classNames.addAll(collectSubclasses(combinedIndex, ValueExpression.class.getName())); classNames.addAll(collectSubclasses(combinedIndex, ELResolver.class.getName())); - classNames.addAll(collectSubclasses(combinedIndex, MethodRule.class.getName())); + classNames.addAll(collectSubclasses(combinedIndex, Expression.class.getName())); classNames.addAll(collectSubclasses(combinedIndex, MetaRuleset.class.getName())); - - classNames.addAll(collectImplementors(combinedIndex, Converter.class.getName())); - classNames.addAll(collectImplementors(combinedIndex, Validator.class.getName())); - classNames.addAll(collectImplementors(combinedIndex, Behavior.class.getName())); + classNames.addAll(collectSubclasses(combinedIndex, MethodRule.class.getName())); + classNames.addAll(collectSubclasses(combinedIndex, TagHandler.class.getName())); + classNames.addAll(collectSubclasses(combinedIndex, UIComponent.class.getName())); + classNames.addAll(collectSubclasses(combinedIndex, ValidatorHandler.class.getName())); // Register CDI produced servlet objects for EL #{session} and #{request} classes.addAll(Arrays.asList( @@ -559,12 +566,14 @@ void registerForMethodReflection(MyFacesRecorder recorder, BuildProducer reflectiveClass) - { + ReflectiveClassBuildItem.builder(classNames.toArray(new String[0])) + .methods().fields().serialization().build()); reflectiveClass.produce( - ReflectiveClassBuildItem.builder("jakarta.faces.context._MyFacesExternalContextHelper") - .methods(true).fields(true).build()); + ReflectiveClassBuildItem.builder(classes.toArray(new Class[0])) + .methods().fields().serialization().build()); } @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) @@ -787,7 +788,7 @@ else if (ai.target().asMethod().returnType().kind() == Type.Kind.PARAMETERIZED_T types.removeIf(Objects::isNull); // collect all public types from getters and fields - List temp = new ArrayList(); + List temp = new ArrayList<>(); types.forEach(ci -> collectPublicTypes(ci, temp, combinedIndex)); types.addAll(temp);