From 5c38ae3549c2706329036402c4a016ae7775bfb4 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Tue, 31 Mar 2020 12:53:49 +1000 Subject: [PATCH 1/3] Issue #4727 setConfigurationDiscovered true per default Signed-off-by: olivier lamy --- .../jetty/annotations/TestAnnotationConfiguration.java | 7 ++++--- .../main/java/org/eclipse/jetty/webapp/WebAppContext.java | 2 +- .../org/eclipse/jetty/webapp/MetaInfConfigurationTest.java | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationConfiguration.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationConfiguration.java index 13753551f7c..2e169e62266 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationConfiguration.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationConfiguration.java @@ -118,25 +118,25 @@ public class TestAnnotationConfiguration @Test public void testAnnotationScanControl() throws Exception { - //check that a 2.5 webapp won't discover annotations + //check that a 2.5 webapp with configurationDiscovered will discover annotations TestableAnnotationConfiguration config25 = new TestableAnnotationConfiguration(); WebAppContext context25 = new WebAppContext(); context25.setClassLoader(Thread.currentThread().getContextClassLoader()); context25.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE); context25.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0); + context25.setConfigurationDiscovered(false); context25.getMetaData().setWebDescriptor(new WebDescriptor(Resource.newResource(web25))); context25.getServletContext().setEffectiveMajorVersion(2); context25.getServletContext().setEffectiveMinorVersion(5); config25.configure(context25); config25.assertAnnotationDiscovery(false); - //check that a 2.5 webapp with configurationDiscovered will discover annotations + //check that a 2.5 webapp discover annotations TestableAnnotationConfiguration config25b = new TestableAnnotationConfiguration(); WebAppContext context25b = new WebAppContext(); context25b.setClassLoader(Thread.currentThread().getContextClassLoader()); context25b.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE); context25b.setAttribute(AnnotationConfiguration.MAX_SCAN_WAIT, 0); - context25b.setConfigurationDiscovered(true); context25b.getMetaData().setWebDescriptor(new WebDescriptor(Resource.newResource(web25))); context25b.getServletContext().setEffectiveMajorVersion(2); context25b.getServletContext().setEffectiveMinorVersion(5); @@ -293,6 +293,7 @@ public class TestAnnotationConfiguration AnnotationConfiguration config = new AnnotationConfiguration(); WebAppContext context = new WebAppContext(); List scis; + context.setConfigurationDiscovered(false); context.setClassLoader(webAppLoader); context.getMetaData().setWebDescriptor(new WebDescriptor(Resource.newResource(web25))); context.getMetaData().setWebInfClassesResources(classes); diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index 5b55d08712f..284d1332247 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -209,7 +209,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL private Map _resourceAliases; private boolean _ownClassLoader = false; - private boolean _configurationDiscovered = false; + private boolean _configurationDiscovered = true; private boolean _allowDuplicateFragmentNames = false; private boolean _throwUnavailableOnStartupException = false; diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/MetaInfConfigurationTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/MetaInfConfigurationTest.java index 599872a30d6..c28aa703713 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/MetaInfConfigurationTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/MetaInfConfigurationTest.java @@ -84,20 +84,20 @@ public class MetaInfConfigurationTest File web31 = MavenTestingUtils.getTestResourceFile("web31.xml"); File web31false = MavenTestingUtils.getTestResourceFile("web31false.xml"); - //test a 2.5 webapp will not look for fragments by default + //test a 2.5 webapp will not look for fragments as manually configured MetaInfConfiguration meta25 = new TestableMetaInfConfiguration(MetaInfConfiguration.__allScanTypes, Arrays.asList(MetaInfConfiguration.METAINF_TLDS, MetaInfConfiguration.METAINF_RESOURCES)); WebAppContext context25 = new WebAppContext(); + context25.setConfigurationDiscovered(false); context25.getMetaData().setWebDescriptor(new WebDescriptor(Resource.newResource(web25))); context25.getServletContext().setEffectiveMajorVersion(2); context25.getServletContext().setEffectiveMinorVersion(5); meta25.preConfigure(context25); - //test a 2.5 webapp will look for fragments if configurationDiscovered==true + //test a 2.5 webapp will look for fragments as configurationDiscovered default true MetaInfConfiguration meta25b = new TestableMetaInfConfiguration(MetaInfConfiguration.__allScanTypes, MetaInfConfiguration.__allScanTypes); WebAppContext context25b = new WebAppContext(); - context25b.setConfigurationDiscovered(true); context25b.getMetaData().setWebDescriptor(new WebDescriptor(Resource.newResource(web25))); context25b.getServletContext().setEffectiveMajorVersion(2); context25b.getServletContext().setEffectiveMinorVersion(5); From e3bab289241f9db54bd498087b6e46762fb505c2 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 1 Apr 2020 12:07:48 +1000 Subject: [PATCH 2/3] document new default behaviour with annotations scanning Signed-off-by: olivier lamy --- .../distribution-guide/annotations/using-annotations.adoc | 5 ++--- .../quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jetty-documentation/src/main/asciidoc/distribution-guide/annotations/using-annotations.adoc b/jetty-documentation/src/main/asciidoc/distribution-guide/annotations/using-annotations.adoc index 93eb15c82ef..765bb61a22a 100644 --- a/jetty-documentation/src/main/asciidoc/distribution-guide/annotations/using-annotations.adoc +++ b/jetty-documentation/src/main/asciidoc/distribution-guide/annotations/using-annotations.adoc @@ -121,9 +121,8 @@ As is the case with annotation scanning, the link:#using-extra-classpath-method[ ____ [NOTE] -As of Jetty-9.4.4, unless the `web.xml` is version 3.0 or greater, only `ServletContainerInitializers` that are on the container classpath will be discovered. -Users wishing to use `ServletContainerInitializers` from within the webapp with older versions of `web.xml` must either upgrade their `web.xml` version, or call `WebAppContext.setConfigurationDiscovered(true)` either programmatically or in xml. -Upgrading the `web.xml` version is preferable. +As of Jetty 10, Annotations will be discovered even for old versions of `web.xml` (2.5). +Users wishing to not use `ServletContainerInitializers` from within the webapp with older versions of `web.xml` must call `WebAppContext.setConfigurationDiscovered(false)` either programmatically or in xml. ____ ===== Controlling the order of ServletContainerInitializer invocation diff --git a/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc b/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc index 0b3653c10c9..fb0da833c5b 100644 --- a/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc +++ b/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc @@ -23,9 +23,14 @@ It is not comprehensive, but covers many of the major changes included in the re ==== Required Java Version -Jetty 10 requires, at a minimum, Java 9 to function. +Jetty 10 requires, at a minimum, Java 11 to function. Items such as the Java Platform Module System (JPMS), which Jetty 10 supports, are not available in earlier versions of Java. +==== ServletContainerInitializers + +As of Jetty 10, Annotations will be discovered even for old versions of `web.xml` (2.5). +Users wishing to not use `ServletContainerInitializers` from within the webapp with older versions of `web.xml` must call `WebAppContext.setConfigurationDiscovered(false)` either programmatically or in xml. + ==== Removed Classes //TODO - Insert major removed/refactored classes from Jetty-9.x.x to Jetty-10.0.x From f14560a22803d1b1ad66072a027564e821c891eb Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 1 Apr 2020 22:11:34 +1000 Subject: [PATCH 3/3] fix documentation Signed-off-by: olivier lamy --- .../distribution-guide/annotations/using-annotations.adoc | 2 +- .../quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jetty-documentation/src/main/asciidoc/distribution-guide/annotations/using-annotations.adoc b/jetty-documentation/src/main/asciidoc/distribution-guide/annotations/using-annotations.adoc index 765bb61a22a..091a68dd4b0 100644 --- a/jetty-documentation/src/main/asciidoc/distribution-guide/annotations/using-annotations.adoc +++ b/jetty-documentation/src/main/asciidoc/distribution-guide/annotations/using-annotations.adoc @@ -122,7 +122,7 @@ As is the case with annotation scanning, the link:#using-extra-classpath-method[ ____ [NOTE] As of Jetty 10, Annotations will be discovered even for old versions of `web.xml` (2.5). -Users wishing to not use `ServletContainerInitializers` from within the webapp with older versions of `web.xml` must call `WebAppContext.setConfigurationDiscovered(false)` either programmatically or in xml. +Users wishing not to use annotations from the webapp classpath must call `WebAppContext.setConfigurationDiscovered(false)` either programmatically or in xml. ____ ===== Controlling the order of ServletContainerInitializer invocation diff --git a/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc b/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc index fb0da833c5b..7b78916a4d2 100644 --- a/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc +++ b/jetty-documentation/src/main/asciidoc/quickstart-guide/upgrading/upgrading-9.4-to.10.0.adoc @@ -29,7 +29,7 @@ Items such as the Java Platform Module System (JPMS), which Jetty 10 supports, a ==== ServletContainerInitializers As of Jetty 10, Annotations will be discovered even for old versions of `web.xml` (2.5). -Users wishing to not use `ServletContainerInitializers` from within the webapp with older versions of `web.xml` must call `WebAppContext.setConfigurationDiscovered(false)` either programmatically or in xml. +Users wishing not to use annotations from the webapp classpath with older versions of `web.xml` must call `WebAppContext.setConfigurationDiscovered(false)` either programmatically or in xml. ==== Removed Classes