From 0ec8d281ef7c64654aa89b2fa814b80fe8b2c7dd Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 23 Mar 2021 12:17:38 -0700 Subject: [PATCH] Align TldPatterns with Tomcat default Update `TldPatterns` to align with the latest default shipped by Tomcat. This commit also introduces a test to ensure that we will remain aligned going forwards. Closes gh-25764 --- gradle.properties | 3 +- .../spring-boot-dependencies/build.gradle | 2 +- spring-boot-project/spring-boot/build.gradle | 22 +++++ .../boot/web/embedded/tomcat/TldPatterns.java | 89 +++++++++++++------ .../web/embedded/tomcat/TldPatternsTests.java | 65 ++++++++++++++ 5 files changed, 151 insertions(+), 30 deletions(-) create mode 100644 spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TldPatternsTests.java diff --git a/gradle.properties b/gradle.properties index e05c37de56..29c84dd690 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,5 @@ org.gradle.caching=true org.gradle.parallel=true org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8 -kotlinVersion=1.3.72 \ No newline at end of file +kotlinVersion=1.3.72 +tomcatVersion=9.0.43 diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 2954768342..01e4d9671c 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1807,7 +1807,7 @@ bom { ] } } - library("Tomcat", "9.0.43") { + library("Tomcat", "${tomcatVersion}") { group("org.apache.tomcat") { modules = [ "tomcat-annotations-api", diff --git a/spring-boot-project/spring-boot/build.gradle b/spring-boot-project/spring-boot/build.gradle index 888b2d92f3..33b616c1b6 100644 --- a/spring-boot-project/spring-boot/build.gradle +++ b/spring-boot-project/spring-boot/build.gradle @@ -9,6 +9,12 @@ plugins { description = "Spring Boot" +def tomcatConfigProperties = "$buildDir/tomcat-config-properties" + +configurations { + tomcatDistribution +} + dependencies { annotationProcessor("org.apache.logging.log4j:log4j-core") @@ -106,6 +112,22 @@ dependencies { exclude group: "javax.annotation", module: "javax.annotation-api" exclude group: "javax.xml.bind", module: "jaxb-api" } + + tomcatDistribution("org.apache.tomcat:tomcat:${tomcatVersion}@zip") +} + +task extractTomcatConfigProperties(type: Sync) { + dependsOn configurations.tomcatDistribution + destinationDir = file(tomcatConfigProperties) + from(zipTree(configurations.tomcatDistribution.incoming.files.singleFile).matching { + include '**/conf/catalina.properties' + }.singleFile) +} + +sourceSets { + test { + output.dir(tomcatConfigProperties, builtBy: "extractTomcatConfigProperties") + } } compileKotlin { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TldPatterns.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TldPatterns.java index 04f5ea587e..35dc5504ab 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TldPatterns.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TldPatterns.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,16 +28,30 @@ import java.util.Set; */ final class TldPatterns { - private static final Set TOMCAT_SKIP; + static final Set TOMCAT_SKIP; static { // Same as Tomcat Set skipPatterns = new LinkedHashSet<>(); - skipPatterns.add("ant-*.jar"); + skipPatterns.add("annotations-api.jar"); + skipPatterns.add("ant-junit*.jar"); + skipPatterns.add("ant-launcher.jar"); + skipPatterns.add("ant.jar"); + skipPatterns.add("asm-*.jar"); skipPatterns.add("aspectj*.jar"); + skipPatterns.add("bootstrap.jar"); + skipPatterns.add("catalina-ant.jar"); + skipPatterns.add("catalina-ha.jar"); + skipPatterns.add("catalina-ssi.jar"); + skipPatterns.add("catalina-storeconfig.jar"); + skipPatterns.add("catalina-tribes.jar"); + skipPatterns.add("catalina.jar"); + skipPatterns.add("cglib-*.jar"); + skipPatterns.add("cobertura-*.jar"); skipPatterns.add("commons-beanutils*.jar"); skipPatterns.add("commons-codec*.jar"); skipPatterns.add("commons-collections*.jar"); + skipPatterns.add("commons-daemon.jar"); skipPatterns.add("commons-dbcp*.jar"); skipPatterns.add("commons-digester*.jar"); skipPatterns.add("commons-fileupload*.jar"); @@ -47,29 +61,59 @@ final class TldPatterns { skipPatterns.add("commons-logging*.jar"); skipPatterns.add("commons-math*.jar"); skipPatterns.add("commons-pool*.jar"); + skipPatterns.add("dom4j-*.jar"); + skipPatterns.add("easymock-*.jar"); + skipPatterns.add("ecj-*.jar"); + skipPatterns.add("el-api.jar"); skipPatterns.add("geronimo-spec-jaxrpc*.jar"); skipPatterns.add("h2*.jar"); - skipPatterns.add("hamcrest*.jar"); + skipPatterns.add("hamcrest-*.jar"); skipPatterns.add("hibernate*.jar"); - skipPatterns.add("jaxb-runtime-*.jar"); - skipPatterns.add("jmx*.jar"); - skipPatterns.add("jmx-tools-*.jar"); + skipPatterns.add("httpclient*.jar"); + skipPatterns.add("icu4j-*.jar"); + skipPatterns.add("jasper-el.jar"); + skipPatterns.add("jasper.jar"); + skipPatterns.add("jaspic-api.jar"); + skipPatterns.add("jaxb-*.jar"); + skipPatterns.add("jaxen-*.jar"); + skipPatterns.add("jdom-*.jar"); + skipPatterns.add("jetty-*.jar"); + skipPatterns.add("jmx-tools.jar"); + skipPatterns.add("jmx.jar"); + skipPatterns.add("jsp-api.jar"); + skipPatterns.add("jstl.jar"); skipPatterns.add("jta*.jar"); skipPatterns.add("junit-*.jar"); - skipPatterns.add("httpclient*.jar"); - skipPatterns.add("log4j-*.jar"); + skipPatterns.add("junit.jar"); + skipPatterns.add("log4j*.jar"); skipPatterns.add("mail*.jar"); - skipPatterns.add("org.hamcrest*.jar"); + skipPatterns.add("objenesis-*.jar"); + skipPatterns.add("oraclepki.jar"); + skipPatterns.add("oro-*.jar"); + skipPatterns.add("servlet-api-*.jar"); + skipPatterns.add("servlet-api.jar"); skipPatterns.add("slf4j*.jar"); - skipPatterns.add("tomcat-embed-core-*.jar"); - skipPatterns.add("tomcat-embed-logging-*.jar"); - skipPatterns.add("tomcat-jdbc-*.jar"); - skipPatterns.add("tomcat-juli-*.jar"); + skipPatterns.add("taglibs-standard-spec-*.jar"); + skipPatterns.add("tagsoup-*.jar"); + skipPatterns.add("tomcat-api.jar"); + skipPatterns.add("tomcat-coyote.jar"); + skipPatterns.add("tomcat-dbcp.jar"); + skipPatterns.add("tomcat-i18n-*.jar"); + skipPatterns.add("tomcat-jdbc.jar"); + skipPatterns.add("tomcat-jni.jar"); + skipPatterns.add("tomcat-juli-adapters.jar"); + skipPatterns.add("tomcat-juli.jar"); + skipPatterns.add("tomcat-util-scan.jar"); + skipPatterns.add("tomcat-util.jar"); + skipPatterns.add("tomcat-websocket.jar"); skipPatterns.add("tools.jar"); + skipPatterns.add("websocket-api.jar"); skipPatterns.add("wsdl4j*.jar"); - skipPatterns.add("xercesImpl-*.jar"); + skipPatterns.add("xercesImpl.jar"); + skipPatterns.add("xml-apis.jar"); skipPatterns.add("xmlParserAPIs-*.jar"); - skipPatterns.add("xml-apis-*.jar"); + skipPatterns.add("xmlParserAPIs.jar"); + skipPatterns.add("xom-*.jar"); TOMCAT_SKIP = Collections.unmodifiableSet(skipPatterns); } @@ -80,17 +124,9 @@ final class TldPatterns { Set skipPatterns = new LinkedHashSet<>(); skipPatterns.add("antlr-*.jar"); skipPatterns.add("aopalliance-*.jar"); - skipPatterns.add("aspectjrt-*.jar"); skipPatterns.add("aspectjweaver-*.jar"); skipPatterns.add("classmate-*.jar"); - skipPatterns.add("dom4j-*.jar"); - skipPatterns.add("ecj-*.jar"); skipPatterns.add("ehcache-core-*.jar"); - skipPatterns.add("hibernate-core-*.jar"); - skipPatterns.add("hibernate-commons-annotations-*.jar"); - skipPatterns.add("hibernate-entitymanager-*.jar"); - skipPatterns.add("hibernate-jpa-2.1-api-*.jar"); - skipPatterns.add("hibernate-validator-*.jar"); skipPatterns.add("hsqldb-*.jar"); skipPatterns.add("jackson-annotations-*.jar"); skipPatterns.add("jackson-core-*.jar"); @@ -102,11 +138,9 @@ final class TldPatterns { skipPatterns.add("jcl-over-slf4j-*.jar"); skipPatterns.add("jdom-*.jar"); skipPatterns.add("jul-to-slf4j-*.jar"); - skipPatterns.add("log4j-over-slf4j-*.jar"); skipPatterns.add("logback-classic-*.jar"); skipPatterns.add("logback-core-*.jar"); skipPatterns.add("rome-*.jar"); - skipPatterns.add("slf4j-api-*.jar"); skipPatterns.add("spring-aop-*.jar"); skipPatterns.add("spring-aspects-*.jar"); skipPatterns.add("spring-beans-*.jar"); @@ -122,7 +156,6 @@ final class TldPatterns { skipPatterns.add("snakeyaml-*.jar"); skipPatterns.add("tomcat-embed-el-*.jar"); skipPatterns.add("validation-api-*.jar"); - skipPatterns.add("xml-apis-*.jar"); ADDITIONAL_SKIP = Collections.unmodifiableSet(skipPatterns); } @@ -135,7 +168,7 @@ final class TldPatterns { DEFAULT_SKIP = Collections.unmodifiableSet(skipPatterns); } - private static final Set TOMCAT_SCAN; + static final Set TOMCAT_SCAN; static { Set scanPatterns = new LinkedHashSet<>(); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TldPatternsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TldPatternsTests.java new file mode 100644 index 0000000000..1041a59b0c --- /dev/null +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TldPatternsTests.java @@ -0,0 +1,65 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.web.embedded.tomcat; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import org.springframework.util.StringUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link TldPatterns}. + * + * @author Phillip Webb + */ +class TldPatternsTests { + + @Test + void tomcatSkipAlignsWithTomcatDefaults() throws IOException { + assertThat(TldPatterns.TOMCAT_SKIP).containsExactlyInAnyOrderElementsOf(getTomcatDefaultJarsToSkip()); + } + + @Test + void tomcatScanAlignsWithTomcatDefaults() throws IOException { + assertThat(TldPatterns.TOMCAT_SCAN).containsExactlyInAnyOrderElementsOf(getTomcatDefaultJarsToScan()); + } + + private Set getTomcatDefaultJarsToSkip() throws IOException { + return getTomcatDefault("tomcat.util.scan.StandardJarScanFilter.jarsToSkip"); + } + + private Set getTomcatDefaultJarsToScan() throws IOException { + return getTomcatDefault("tomcat.util.scan.StandardJarScanFilter.jarsToScan"); + } + + private Set getTomcatDefault(String key) throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + try (InputStream inputStream = classLoader.getResource("catalina.properties").openStream()) { + Properties properties = new Properties(); + properties.load(inputStream); + String jarsToSkip = properties.getProperty(key); + return StringUtils.commaDelimitedListToSet(jarsToSkip); + } + } + +}