From 9662b559a51efa9224cfcc56c1277520d3c2a8ca Mon Sep 17 00:00:00 2001 From: arjantijms Date: Thu, 7 Sep 2017 18:05:19 +0200 Subject: [PATCH] #4270 Removed forgotten 2.3 switch based on faces-config Updated tests and tested with base set of tests and default permutation. --- api/.gitignore | 1 + .../faces/application/ApplicationImpl.java | 30 +++++++++++++++---- .../cdi/InjectInitParameterMapBean.java | 5 ++-- .../src/main/webapp/WEB-INF/faces-config.xml | 7 ----- .../src/main/webapp/WEB-INF/glassfish-web.xml | 8 +---- .../cdi/src/main/webapp/WEB-INF/web.xml | 27 +++++------------ .../main/webapp/injectInitParameterMap.xhtml | 4 +-- .../faces/test/javaee8/cdi/Issue3793IT.java | 8 ++--- .../faces/test/javaee8/cdi/Spec1389IT.java | 4 +-- 9 files changed, 45 insertions(+), 49 deletions(-) create mode 100644 api/.gitignore delete mode 100644 test/javaee8/cdi/src/main/webapp/WEB-INF/faces-config.xml diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/api/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/jsf-ri/src/main/java/com/sun/faces/application/ApplicationImpl.java b/jsf-ri/src/main/java/com/sun/faces/application/ApplicationImpl.java index e1e4ab166b..6490afa5fc 100644 --- a/jsf-ri/src/main/java/com/sun/faces/application/ApplicationImpl.java +++ b/jsf-ri/src/main/java/com/sun/faces/application/ApplicationImpl.java @@ -89,6 +89,7 @@ import javax.faces.validator.Validator; import com.sun.faces.RIConstants; +import com.sun.faces.cdi.CdiExtension; import com.sun.faces.cdi.CdiUtils; import com.sun.faces.component.search.CompositeSearchKeywordResolver; import com.sun.faces.component.search.SearchKeywordResolverImplAll; @@ -105,8 +106,14 @@ import com.sun.faces.component.search.SearchKeywordResolverImplThis; import com.sun.faces.config.WebConfiguration; import com.sun.faces.config.WebConfiguration.WebContextInitParameter; + +import static com.sun.faces.cdi.CdiUtils.getBeanReference; import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.DateTimeConverterUsesSystemTimezone; import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.RegisterConverterPropertyEditors; +import static com.sun.faces.util.Util.getCdiBeanManager; +import static com.sun.faces.util.Util.getFacesConfigXmlVersion; +import static com.sun.faces.util.Util.getWebXmlVersion; + import com.sun.faces.el.ELUtils; import com.sun.faces.el.FacesCompositeELResolver; import com.sun.faces.el.PropertyResolverImpl; @@ -543,12 +550,10 @@ public void addELResolver(ELResolver resolver) { MessageUtils.ILLEGAL_ATTEMPT_SETTING_APPLICATION_ARTIFACT_ID, "ELResolver")); } - FacesContext facesContext = FacesContext.getCurrentInstance(); - if (Util.getFacesConfigXmlVersion(facesContext).equals("2.3") || - Util.getWebXmlVersion(facesContext).equals("4.0")) { + if (isJsf23()) { javax.enterprise.inject.spi.BeanManager beanManager = - Util.getCdiBeanManager(facesContext); + getCdiBeanManager(FacesContext.getCurrentInstance()); if (beanManager != null && !resolver.equals(beanManager.getELResolver())) { elResolvers.add(resolver); @@ -2700,10 +2705,25 @@ private String getFacesConfigXmlVersion(FacesContext facesContext) { * @return true if we are, false otherwise. */ private boolean isJsf23() { + if (isJsf23 == null) { + FacesContext facesContext = FacesContext.getCurrentInstance(); - isJsf23 = getFacesConfigXmlVersion(facesContext).equals("2.3"); + + BeanManager beanManager = getCdiBeanManager(facesContext); + + if (beanManager == null) { + // TODO: use version enum and >= + if (getFacesConfigXmlVersion(facesContext).equals("2.3") || getWebXmlVersion(facesContext).equals("4.0")) { + throw new FacesException("Unable to find CDI BeanManager"); + } + isJsf23 = false; + } else { + isJsf23 = getBeanReference(beanManager, CdiExtension.class).isAddBeansForJSFImplicitObjects(); + } + } + return isJsf23; } diff --git a/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/InjectInitParameterMapBean.java b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/InjectInitParameterMapBean.java index ad40ad62e7..f75191d62c 100644 --- a/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/InjectInitParameterMapBean.java +++ b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/InjectInitParameterMapBean.java @@ -15,9 +15,8 @@ public class InjectInitParameterMapBean { private Map initParameterMap; public String getInitParameterValue() { - // javax.faces.ENABLE_CDI_RESOLVER_CHAIN set in web.xml, should be true - // otherwise injection will not resolve - return initParameterMap.get("javax.faces.ENABLE_CDI_RESOLVER_CHAIN"); + // MY_TEST_PARAMETER set in web.xml, should be available + return initParameterMap.get("MY_TEST_PARAMETER"); } } diff --git a/test/javaee8/cdi/src/main/webapp/WEB-INF/faces-config.xml b/test/javaee8/cdi/src/main/webapp/WEB-INF/faces-config.xml deleted file mode 100644 index 728c76d0bf..0000000000 --- a/test/javaee8/cdi/src/main/webapp/WEB-INF/faces-config.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - diff --git a/test/javaee8/cdi/src/main/webapp/WEB-INF/glassfish-web.xml b/test/javaee8/cdi/src/main/webapp/WEB-INF/glassfish-web.xml index 8e06a462f8..58452a0911 100644 --- a/test/javaee8/cdi/src/main/webapp/WEB-INF/glassfish-web.xml +++ b/test/javaee8/cdi/src/main/webapp/WEB-INF/glassfish-web.xml @@ -1,11 +1,5 @@ - + /test-javaee8-cdi - - - - Keep a copy of the generated servlet class' java code. - - diff --git a/test/javaee8/cdi/src/main/webapp/WEB-INF/web.xml b/test/javaee8/cdi/src/main/webapp/WEB-INF/web.xml index 4157b08bc1..fa1bfb7237 100644 --- a/test/javaee8/cdi/src/main/webapp/WEB-INF/web.xml +++ b/test/javaee8/cdi/src/main/webapp/WEB-INF/web.xml @@ -42,10 +42,10 @@ --> - + + javax.faces.PROJECT_STAGE ${webapp.projectStage} @@ -66,21 +66,10 @@ javax.faces.FACELETS_LIBRARIES /WEB-INF/injectBehavior.taglib.xml + - javax.faces.ENABLE_CDI_RESOLVER_CHAIN - true + MY_TEST_PARAMETER + IS_THERE - - Faces Servlet - javax.faces.webapp.FacesServlet - 1 - - - Faces Servlet - *.xhtml - /faces/* - - - faces/index.xhtml - + diff --git a/test/javaee8/cdi/src/main/webapp/injectInitParameterMap.xhtml b/test/javaee8/cdi/src/main/webapp/injectInitParameterMap.xhtml index ed5e2a62d5..a03f26920e 100644 --- a/test/javaee8/cdi/src/main/webapp/injectInitParameterMap.xhtml +++ b/test/javaee8/cdi/src/main/webapp/injectInitParameterMap.xhtml @@ -7,8 +7,8 @@ Init parameter Map test - + - ENABLE_CDI_RESOLVER_CHAIN:#{injectInitParameterMapBean.initParameterValue} + MY_TEST_PARAMETER:#{injectInitParameterMapBean.initParameterValue} \ No newline at end of file diff --git a/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Issue3793IT.java b/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Issue3793IT.java index 27bf1252a2..3496f00108 100644 --- a/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Issue3793IT.java +++ b/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Issue3793IT.java @@ -66,14 +66,14 @@ public void setUp() { @After public void tearDown() { - webClient.closeAllWindows(); + webClient.close(); } @Test - @JsfTest(value = JsfVersion.JSF_2_3_0_M01, - excludes = {WEBLOGIC_12_1_4, WEBLOGIC_12_2_1}) + @JsfTest(value = JsfVersion.JSF_2_3_0_M01, excludes = { WEBLOGIC_12_1_4, WEBLOGIC_12_2_1 }) public void testFacesConfig23() throws Exception { HtmlPage page = webClient.getPage(webUrl + "faces/mojarraFacesConfigVersion.xhtml"); - assertTrue(page.asXml().contains("2.3")); + + assertTrue(!page.asXml().contains("2.3")); } } diff --git a/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Spec1389IT.java b/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Spec1389IT.java index b3f49fd71f..eac362dcaf 100644 --- a/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Spec1389IT.java +++ b/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Spec1389IT.java @@ -80,9 +80,9 @@ public void tearDown() { public void testInjectInitParameterMap() throws Exception { HtmlPage page = webClient.getPage(webUrl + "injectInitParameterMap.xhtml"); - + // Init parameter value should be printed on the page - assertTrue(page.asXml().contains("ENABLE_CDI_RESOLVER_CHAIN:true")); + assertTrue(page.asXml().contains("MY_TEST_PARAMETER:IS_THERE")); } }