This is an automated email from the ASF dual-hosted git repository. pkarwasz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 485848e4d32833db9ab0724ee1403bec5c7ab502 Author: Piotr P. Karwasz <[email protected]> AuthorDate: Sat Oct 15 10:42:40 2022 +0200 Adapt `log4j-script` tests to the module path This requires correcting some module descriptor errors and a dirty trick consisting of copying `target/classes` to `target/test-classes` just before Surefire runs. Surefire is not able to patch the `target/test-classes` module with `target/classes`. --- log4j-script/pom.xml | 39 +++++++++++++++++++ .../src/main/{java => module}/module-info.java | 29 ++++++++------ .../src/{main => test}/java/module-info.java | 45 ++++++++++++++++------ .../filter/ScriptFileFilterPropertiesTest.java | 3 +- .../log4j/script/filter/ScriptFileFilterTest.java | 3 +- .../log4j/script/filter/ScriptFilterTest.java | 3 +- .../log4j/script/filter/ScriptRefFilterTest.java | 3 +- .../log4j/script/layout/PatternSelectorTest.java | 12 +++--- 8 files changed, 105 insertions(+), 32 deletions(-) diff --git a/log4j-script/pom.xml b/log4j-script/pom.xml index 84c419ca9a..a42a6fb6c2 100644 --- a/log4j-script/pom.xml +++ b/log4j-script/pom.xml @@ -106,6 +106,23 @@ <build> <plugins> + <!-- For Eclipse users' sake we move the module descriptor to a separate source folder --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${project.basedir}/src/main/module</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> @@ -131,6 +148,28 @@ </execution> </executions> </plugin> + <!-- Workaround Surefire 3.0.0-M7 limitation: it does not add the main classes with 'patch-module' --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>shade-test-module</id> + <phase>process-test-classes</phase> + <goals> + <goal>copy-resources</goal> + </goals> + <configuration> + <outputDirectory>${project.build.testOutputDirectory}</outputDirectory> + <resources> + <resource> + <directory>${project.build.outputDirectory}</directory> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> </plugins> </build> <reporting> diff --git a/log4j-script/src/main/java/module-info.java b/log4j-script/src/main/module/module-info.java similarity index 67% copy from log4j-script/src/main/java/module-info.java copy to log4j-script/src/main/module/module-info.java index dd8719ace5..0fa939f95e 100644 --- a/log4j-script/src/main/java/module-info.java +++ b/log4j-script/src/main/module/module-info.java @@ -1,5 +1,3 @@ -import org.apache.logging.log4j.plugins.model.PluginService; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -16,23 +14,32 @@ import org.apache.logging.log4j.plugins.model.PluginService; * See the license for the specific language governing permissions and * limitations under the license. */ -module org.apache.logging.log4j.script { +import org.apache.logging.log4j.core.script.ScriptManagerFactory; +import org.apache.logging.log4j.plugins.model.PluginService; +import org.apache.logging.log4j.script.factory.ScriptManagerFactoryImpl; +import org.apache.logging.log4j.script.plugins.Log4jPlugins; +module org.apache.logging.log4j.script { exports org.apache.logging.log4j.script; exports org.apache.logging.log4j.script.appender; + opens org.apache.logging.log4j.script.appender to + org.apache.logging.log4j.core; exports org.apache.logging.log4j.script.appender.rolling.action; exports org.apache.logging.log4j.script.config.arbiter; + opens org.apache.logging.log4j.script.config.arbiter to + org.apache.logging.log4j.core; + opens org.apache.logging.log4j.script.config.builder to + org.apache.logging.log4j.core; exports org.apache.logging.log4j.script.filter; exports org.apache.logging.log4j.script.layout; + opens org.apache.logging.log4j.script.layout to + org.apache.logging.log4j.core; - opens org.apache.logging.log4j.script.appender; - opens org.apache.logging.log4j.script.config.arbiter to org.apache.logging.log4j.core; - opens org.apache.logging.log4j.script.layout to org.apache.logging.log4j.core; - - requires java.scripting; requires org.apache.logging.log4j; - requires org.apache.logging.log4j.plugins; requires org.apache.logging.log4j.core; - provides PluginService with org.apache.logging.log4j.script.plugins.Log4jPlugins; - provides org.apache.logging.log4j.core.script.ScriptManagerFactory with org.apache.logging.log4j.script.factory.ScriptManagerFactoryImpl; + requires org.apache.logging.log4j.plugins; + requires java.scripting; + + provides PluginService with Log4jPlugins; + provides ScriptManagerFactory with ScriptManagerFactoryImpl; } diff --git a/log4j-script/src/main/java/module-info.java b/log4j-script/src/test/java/module-info.java similarity index 51% rename from log4j-script/src/main/java/module-info.java rename to log4j-script/src/test/java/module-info.java index dd8719ace5..6679170185 100644 --- a/log4j-script/src/main/java/module-info.java +++ b/log4j-script/src/test/java/module-info.java @@ -1,5 +1,3 @@ -import org.apache.logging.log4j.plugins.model.PluginService; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -16,23 +14,48 @@ import org.apache.logging.log4j.plugins.model.PluginService; * See the license for the specific language governing permissions and * limitations under the license. */ -module org.apache.logging.log4j.script { +import org.apache.logging.log4j.core.script.ScriptManagerFactory; +import org.apache.logging.log4j.plugins.model.PluginService; +import org.apache.logging.log4j.script.factory.ScriptManagerFactoryImpl; +import org.apache.logging.log4j.script.plugins.Log4jPlugins; +module org.apache.logging.log4j.script { exports org.apache.logging.log4j.script; exports org.apache.logging.log4j.script.appender; + opens org.apache.logging.log4j.script.appender to + org.junit.platform.commons, + org.apache.logging.log4j.core; + exports org.apache.logging.log4j.script.appender.rolling to + junit; exports org.apache.logging.log4j.script.appender.rolling.action; + exports org.apache.logging.log4j.script.appender.routing to + junit; + exports org.apache.logging.log4j.script.config to + org.junit.platform.commons; exports org.apache.logging.log4j.script.config.arbiter; + opens org.apache.logging.log4j.script.config.arbiter to + org.apache.logging.log4j.core; + exports org.apache.logging.log4j.script.config.builder to + org.junit.platform.commons; + opens org.apache.logging.log4j.script.config.builder to + org.apache.logging.log4j.core; exports org.apache.logging.log4j.script.filter; exports org.apache.logging.log4j.script.layout; + opens org.apache.logging.log4j.script.layout to + org.apache.logging.log4j.core; - opens org.apache.logging.log4j.script.appender; - opens org.apache.logging.log4j.script.config.arbiter to org.apache.logging.log4j.core; - opens org.apache.logging.log4j.script.layout to org.apache.logging.log4j.core; - - requires java.scripting; requires org.apache.logging.log4j; - requires org.apache.logging.log4j.plugins; requires org.apache.logging.log4j.core; - provides PluginService with org.apache.logging.log4j.script.plugins.Log4jPlugins; - provides org.apache.logging.log4j.core.script.ScriptManagerFactory with org.apache.logging.log4j.script.factory.ScriptManagerFactoryImpl; + requires org.apache.logging.log4j.core.test; + requires org.apache.logging.log4j.plugins; + requires org.apache.logging.log4j.test; + requires java.scripting; + requires junit; + requires org.assertj.core; + requires org.junit.jupiter.api; + requires org.junitpioneer; + requires org.hamcrest; + + provides PluginService with Log4jPlugins; + provides ScriptManagerFactory with ScriptManagerFactoryImpl; } diff --git a/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFileFilterPropertiesTest.java b/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFileFilterPropertiesTest.java index ef093544a7..c3ba45fac2 100644 --- a/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFileFilterPropertiesTest.java +++ b/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFileFilterPropertiesTest.java @@ -17,10 +17,11 @@ package org.apache.logging.log4j.script.filter; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; +import org.apache.logging.log4j.core.test.junit.ReconfigurationPolicy; import org.apache.logging.log4j.script.factory.ScriptManagerFactoryImpl; import org.junitpioneer.jupiter.SetSystemProperty; @SetSystemProperty(key = ScriptManagerFactoryImpl.SCRIPT_LANGUAGES, value = "Groovy, Javascript") -@LoggerContextSource("log4j-scriptFile-filters.properties") +@LoggerContextSource(value = "log4j-scriptFile-filters.properties", reconfigure = ReconfigurationPolicy.BEFORE_EACH) public class ScriptFileFilterPropertiesTest extends AbstractScriptFilterTest { } diff --git a/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFileFilterTest.java b/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFileFilterTest.java index 3785e2d2bb..b0dd11cc29 100644 --- a/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFileFilterTest.java +++ b/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFileFilterTest.java @@ -17,10 +17,11 @@ package org.apache.logging.log4j.script.filter; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; +import org.apache.logging.log4j.core.test.junit.ReconfigurationPolicy; import org.apache.logging.log4j.script.factory.ScriptManagerFactoryImpl; import org.junitpioneer.jupiter.SetSystemProperty; @SetSystemProperty(key = ScriptManagerFactoryImpl.SCRIPT_LANGUAGES, value = "Groovy, Javascript") -@LoggerContextSource("log4j-scriptFile-filters.xml") +@LoggerContextSource(value = "log4j-scriptFile-filters.xml", reconfigure = ReconfigurationPolicy.BEFORE_EACH) public class ScriptFileFilterTest extends AbstractScriptFilterTest { } diff --git a/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFilterTest.java b/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFilterTest.java index 4e9742f627..62adc9ec16 100644 --- a/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFilterTest.java +++ b/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptFilterTest.java @@ -17,10 +17,11 @@ package org.apache.logging.log4j.script.filter; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; +import org.apache.logging.log4j.core.test.junit.ReconfigurationPolicy; import org.apache.logging.log4j.script.factory.ScriptManagerFactoryImpl; import org.junitpioneer.jupiter.SetSystemProperty; @SetSystemProperty(key = ScriptManagerFactoryImpl.SCRIPT_LANGUAGES, value = "Groovy, Javascript") -@LoggerContextSource("log4j-script-filters.xml") +@LoggerContextSource(value = "log4j-script-filters.xml", reconfigure = ReconfigurationPolicy.BEFORE_EACH) public class ScriptFilterTest extends AbstractScriptFilterTest { } diff --git a/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptRefFilterTest.java b/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptRefFilterTest.java index 23551b3722..d29b624b2e 100644 --- a/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptRefFilterTest.java +++ b/log4j-script/src/test/java/org/apache/logging/log4j/script/filter/ScriptRefFilterTest.java @@ -17,10 +17,11 @@ package org.apache.logging.log4j.script.filter; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; +import org.apache.logging.log4j.core.test.junit.ReconfigurationPolicy; import org.apache.logging.log4j.script.factory.ScriptManagerFactoryImpl; import org.junitpioneer.jupiter.SetSystemProperty; @SetSystemProperty(key = ScriptManagerFactoryImpl.SCRIPT_LANGUAGES, value = "Groovy, Javascript") -@LoggerContextSource("log4j-scriptRef-filters.xml") +@LoggerContextSource(value = "log4j-scriptRef-filters.xml", reconfigure = ReconfigurationPolicy.BEFORE_EACH) public class ScriptRefFilterTest extends AbstractScriptFilterTest { } diff --git a/log4j-script/src/test/java/org/apache/logging/log4j/script/layout/PatternSelectorTest.java b/log4j-script/src/test/java/org/apache/logging/log4j/script/layout/PatternSelectorTest.java index f641583fb4..842e56f904 100644 --- a/log4j-script/src/test/java/org/apache/logging/log4j/script/layout/PatternSelectorTest.java +++ b/log4j-script/src/test/java/org/apache/logging/log4j/script/layout/PatternSelectorTest.java @@ -19,20 +19,20 @@ package org.apache.logging.log4j.script.layout; import java.util.List; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.core.test.junit.Named; -import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.core.test.appender.ListAppender; +import org.apache.logging.log4j.core.test.junit.LoggerContextSource; +import org.apache.logging.log4j.core.test.junit.Named; +import org.apache.logging.log4j.core.test.junit.ReconfigurationPolicy; import org.apache.logging.log4j.script.factory.ScriptManagerFactoryImpl; import org.apache.logging.log4j.util.Strings; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledForJreRange; -import org.junit.jupiter.api.condition.JRE; import org.junitpioneer.jupiter.SetSystemProperty; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; @SetSystemProperty(key = ScriptManagerFactoryImpl.SCRIPT_LANGUAGES, value = "bsh, Javascript") -@LoggerContextSource("log4j-patternSelector.xml") +@LoggerContextSource(value = "log4j-patternSelector.xml", reconfigure = ReconfigurationPolicy.BEFORE_EACH) public class PatternSelectorTest { @Test
