From 5b17cacb1f49a0b4a4397acb146df8986a597e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 10 Oct 2022 12:19:45 +0200 Subject: [PATCH] Remove spring.xml.ignore flag usages This commit is a follow-up of spring-projects/spring-framework#29277. See gh-32653 --- .../boot/BeanDefinitionLoader.java | 6 +-- .../logging/logback/LogbackLoggingSystem.java | 6 +-- .../IgnoringXmlBeanDefinitionLoaderTests.java | 50 ------------------- 3 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 spring-boot-project/spring-boot/src/test/java/org/springframework/boot/IgnoringXmlBeanDefinitionLoaderTests.java diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java index 7534915ec6..fc4dc368c4 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java @@ -34,7 +34,6 @@ import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; -import org.springframework.core.SpringProperties; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @@ -61,9 +60,6 @@ import org.springframework.util.StringUtils; */ class BeanDefinitionLoader { - // Static final field to facilitate code removal by Graal - private static final boolean XML_ENABLED = !SpringProperties.getFlag("spring.xml.ignore"); - private static final Pattern GROOVY_CLOSURE_PATTERN = Pattern.compile(".*\\$_.*closure.*"); private final Object[] sources; @@ -89,7 +85,7 @@ class BeanDefinitionLoader { Assert.notEmpty(sources, "Sources must not be empty"); this.sources = sources; this.annotatedReader = new AnnotatedBeanDefinitionReader(registry); - this.xmlReader = (XML_ENABLED ? new XmlBeanDefinitionReader(registry) : null); + this.xmlReader = new XmlBeanDefinitionReader(registry); this.groovyReader = (isGroovyPresent() ? new GroovyBeanDefinitionReader(registry) : null); this.scanner = new ClassPathBeanDefinitionScanner(registry); this.scanner.addExcludeFilter(new ClassExcludeFilter(sources)); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java index 39df27a15f..44da84cc5c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java @@ -52,7 +52,6 @@ import org.springframework.boot.logging.LoggingSystem; import org.springframework.boot.logging.LoggingSystemFactory; import org.springframework.boot.logging.LoggingSystemProperties; import org.springframework.core.Ordered; -import org.springframework.core.SpringProperties; import org.springframework.core.annotation.Order; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; @@ -74,9 +73,6 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem { private static final String BRIDGE_HANDLER = "org.slf4j.bridge.SLF4JBridgeHandler"; - // Static final field to facilitate code removal by Graal - private static final boolean XML_ENABLED = !SpringProperties.getFlag("spring.xml.ignore"); - private static final String CONFIGURATION_FILE_PROPERTY = "logback.configurationFile"; private static final LogLevels LEVELS = new LogLevels<>(); @@ -237,7 +233,7 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem { private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext, URL url) throws JoranException { - if (XML_ENABLED && url.toString().endsWith("xml")) { + if (url.toString().endsWith("xml")) { JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext); configurator.setContext(loggerContext); configurator.doConfigure(url); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/IgnoringXmlBeanDefinitionLoaderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/IgnoringXmlBeanDefinitionLoaderTests.java deleted file mode 100644 index 4713977792..0000000000 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/IgnoringXmlBeanDefinitionLoaderTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2012-2020 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; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.boot.testsupport.classpath.ForkedClassPath; -import org.springframework.context.support.StaticApplicationContext; - -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - -@ForkedClassPath -class IgnoringXmlBeanDefinitionLoaderTests { - - @BeforeAll - static void ignoreXml() { - System.setProperty("spring.xml.ignore", "true"); - } - - @AfterAll - static void enableXml() { - System.clearProperty("spring.xml.ignore"); - } - - @Test - void whenXmlSupportIsDisabledXmlSourcesAreRejected() { - assertThatExceptionOfType(BeanDefinitionStoreException.class) - .isThrownBy(() -> new BeanDefinitionLoader(new StaticApplicationContext(), - "classpath:org/springframework/boot/sample-beans.xml").load()) - .withMessage("Cannot load XML bean definitions when XML support is disabled"); - } - -}