This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch main-j17 in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit a3180fab17afa8630a8a1087aa7f5459be8ae706 Author: Volkan Yazıcı <[email protected]> AuthorDate: Fri Dec 1 22:41:43 2023 +0100 Initial cherry-pick for upgrading the compiler baseline to Java 17 --- .github/workflows/build.yaml | 4 -- .github/workflows/codeql-analysis.yaml | 2 - .github/workflows/merge-dependabot.yaml | 4 -- .java-version | 2 +- BUILDING.adoc | 2 +- log4j-1.2-api/pom.xml | 42 ++++++++++++++++++++ log4j-core-test/pom.xml | 21 ++++++---- .../log4j/core/net/UrlConnectionFactoryTest.java | 6 ++- ...Test.java => DatePatternConverterTestBase.java} | 45 ++++++++++------------ .../DatePatternConverterWithThreadLocalsTest.java | 30 +++++++++++++++ ...atePatternConverterWithoutThreadLocalsTest.java | 29 ++++++++++++++ log4j-layout-jackson-xml/pom.xml | 42 ++++++++++++++++++++ log4j-osgi-test/pom.xml | 39 +++++++++++++++++++ log4j-parent/pom.xml | 12 +++--- pom.xml | 8 ++-- 15 files changed, 232 insertions(+), 56 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a5cb0b9724..46d1c2ec0a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -40,7 +40,6 @@ jobs: if: github.actor != 'dependabot[bot]' uses: apache/logging-parent/.github/workflows/build-reusable.yaml@main with: - java-version: 11 site-enabled: true deploy-snapshot: @@ -51,8 +50,6 @@ jobs: secrets: NEXUS_USER: ${{ secrets.NEXUS_USER }} NEXUS_PW: ${{ secrets.NEXUS_PW }} - with: - java-version: 11 deploy-release: needs: build @@ -69,6 +66,5 @@ jobs: permissions: contents: write with: - java-version: 11 project-id: log4j site-enabled: true diff --git a/.github/workflows/codeql-analysis.yaml b/.github/workflows/codeql-analysis.yaml index 6792f262c5..91fbdd8ba3 100644 --- a/.github/workflows/codeql-analysis.yaml +++ b/.github/workflows/codeql-analysis.yaml @@ -31,8 +31,6 @@ jobs: analyze: uses: apache/logging-parent/.github/workflows/codeql-analysis-reusable.yaml@main - with: - java-version: 11 # Permissions required to publish Security Alerts permissions: actions: read diff --git a/.github/workflows/merge-dependabot.yaml b/.github/workflows/merge-dependabot.yaml index b4d0adc9ff..8e528992d2 100644 --- a/.github/workflows/merge-dependabot.yaml +++ b/.github/workflows/merge-dependabot.yaml @@ -31,14 +31,10 @@ jobs: build: if: github.repository == 'apache/logging-log4j2' && github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]' uses: apache/logging-parent/.github/workflows/build-reusable.yaml@main - with: - java-version: 11 merge-dependabot: needs: build uses: apache/logging-parent/.github/workflows/merge-dependabot-reusable.yaml@main - with: - java-version: 11 permissions: contents: write # to push changelog commits pull-requests: write # to close the PR diff --git a/.java-version b/.java-version index b4de394767..98d9bcb75a 100644 --- a/.java-version +++ b/.java-version @@ -1 +1 @@ -11 +17 diff --git a/BUILDING.adoc b/BUILDING.adoc index cc2576545e..dd83c8c21d 100644 --- a/BUILDING.adoc +++ b/BUILDING.adoc @@ -18,7 +18,7 @@ [#requirements] == Requirements -* JDK 11+ +* JDK 17+ * A modern Linux, OSX, or Windows host [#building] diff --git a/log4j-1.2-api/pom.xml b/log4j-1.2-api/pom.xml index 95ff919fd6..bb0cce6091 100644 --- a/log4j-1.2-api/pom.xml +++ b/log4j-1.2-api/pom.xml @@ -132,6 +132,8 @@ <build> <plugins> + + <!-- Enable Log4j plugin processing --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> @@ -145,6 +147,46 @@ </annotationProcessorPaths> </configuration> </plugin> + </plugins> </build> + + <profiles> + + <!-- Fixes incompatible with Java 8 --> + <profile> + + <id>java8-incompat-fixes</id> + + <!-- CI uses Java 8 for running tests. + Hence, we assume CI=Java8 and apply our changes elsewhere. + + One might think why not activate using `<jdk>[16,)` instead? + This doesn't work, since the match is not against "the JDK running tests", but "the JDK running Maven". + These two JDKs can differ due to Maven Toolchains. + See `java8-tests` profile in `/pom.xml` for details. --> + <activation> + <property> + <name>!env.CI</name> + </property> + </activation> + + <!-- Illegal access is disabled by default in Java 16 due to JEP-396. + We are relaxing it for tests. --> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>--add-opens java.base/java.io=ALL-UNNAMED</argLine> + </configuration> + </plugin> + </plugins> + </build> + + </profile> + + </profiles> + </project> diff --git a/log4j-core-test/pom.xml b/log4j-core-test/pom.xml index d111d8dfbe..ec7e071ee0 100644 --- a/log4j-core-test/pom.xml +++ b/log4j-core-test/pom.xml @@ -276,6 +276,13 @@ <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> + <!-- JEP-335 has deprecated the built-in JavaScript engine (Nashorn) in Java 11, and JEP-372 removed it in Java 15. + We are adding it back for tests that use JavaScript. --> + <dependency> + <groupId>org.openjdk.nashorn</groupId> + <artifactId>nashorn-core</artifactId> + <scope>test</scope> + </dependency> <!-- SLF4J tests --> <dependency> <groupId>org.slf4j</groupId> @@ -313,6 +320,7 @@ <build> <plugins> + <!-- Enable Log4j plugin processing --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> @@ -350,14 +358,11 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> - <argLine> - <!-- - ~ Allow environment modification: - ~ https://junit-pioneer.org/docs/environment-variables/#warnings-for-reflective-access - --> - --add-opens java.base/java.util=ALL-UNNAMED - --add-opens java.base/java.lang=ALL-UNNAMED - </argLine> + <!-- Illegal access is disabled by default in Java 16 due to JEP-396. + We are relaxing it for tests. --> + <argLine>--add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.net=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED</argLine> <runOrder>random</runOrder> <systemPropertyVariables> <Web.isWebApp>false</Web.isWebApp> diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/UrlConnectionFactoryTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/UrlConnectionFactoryTest.java index 315aa816e4..59e8a7e517 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/UrlConnectionFactoryTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/UrlConnectionFactoryTest.java @@ -57,7 +57,10 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.parallel.Isolated; +import org.junitpioneer.jupiter.RetryingTest; /** * Tests the UrlConnectionFactory @@ -142,7 +145,8 @@ public class UrlConnectionFactoryTest { } } - @Test + @RetryingTest(maxAttempts = 5, suspendForMs = 1000) + @DisabledOnOs(value = OS.WINDOWS, disabledReason = "Fails frequently on Windows (#2011)") public void testNoJarFileLeak() throws Exception { ConfigurationSourceTest.prepareJarConfigURL(); final URL url = new File("target/test-classes/jarfile.jar").toURI().toURL(); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTestBase.java similarity index 94% rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java rename to log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTestBase.java index 5b83fea6c9..d84599d4dd 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTestBase.java @@ -16,13 +16,11 @@ */ package org.apache.logging.log4j.core.pattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.text.SimpleDateFormat; -import java.util.Arrays; import java.util.Calendar; -import java.util.Collection; import java.util.Date; import java.util.TimeZone; import org.apache.logging.log4j.core.AbstractLogEvent; @@ -33,14 +31,11 @@ import org.apache.logging.log4j.core.time.internal.format.FixedDateFormat; import org.apache.logging.log4j.core.time.internal.format.FixedDateFormat.FixedTimeZoneFormat; import org.apache.logging.log4j.util.Constants; import org.apache.logging.log4j.util.Strings; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Test; -@RunWith(Parameterized.class) -public class DatePatternConverterTest { +abstract class DatePatternConverterTestBase { - private static class MyLogEvent extends AbstractLogEvent { + private static final class MyLogEvent extends AbstractLogEvent { @Override public Instant getInstant() { @@ -82,13 +77,10 @@ public class DatePatternConverterTest { private static final String[] ISO8601_FORMAT_OPTIONS = {ISO8601}; - @Parameterized.Parameters(name = "threadLocalEnabled={0}") - public static Collection<Object[]> data() { - return Arrays.asList(new Object[][] {{Boolean.TRUE}, {Boolean.FALSE}}); - } + private final boolean threadLocalsEnabled; - public DatePatternConverterTest(final Boolean threadLocalEnabled) { - Constants.setThreadLocalsEnabled(threadLocalEnabled); + DatePatternConverterTestBase(final boolean threadLocalsEnabled) { + this.threadLocalsEnabled = threadLocalsEnabled; } private static Date date(final int year, final int month, final int date) { @@ -106,6 +98,11 @@ public class DatePatternConverterTest { return seconds + "nnnnnnnnn".substring(0, precision) + remainder; } + @Test + void testThreadLocalsConstant() { + assertEquals(threadLocalsEnabled, Constants.isThreadLocalsEnabled()); + } + @Test public void testFormatDateStringBuilderDefaultPattern() { assertDatePattern(null, date(2001, 1, 1), "2001-02-01 14:15:16,123"); @@ -390,9 +387,9 @@ public class DatePatternConverterTest { final String expected = milliBuilder.append(tz).toString(); assertEquals( - "format = " + format + ", pattern = " + pattern + ", precisePattern = " + precisePattern, expected, - preciseBuilder.toString()); + preciseBuilder.toString(), + "format = " + format + ", pattern = " + pattern + ", precisePattern = " + precisePattern); // System.out.println(preciseOptions[0] + ": " + precise); } } @@ -416,7 +413,7 @@ public class DatePatternConverterTest { if (pattern.endsWith("n") || pattern.matches(".+n+X*") || pattern.matches(".+n+Z*") - || pattern.indexOf("SSS") < 0) { + || !pattern.contains("SSS")) { // ignore patterns that already have precise time formats // ignore patterns that do not use seconds. continue; @@ -438,15 +435,13 @@ public class DatePatternConverterTest { milliBuilder.length() - timeZoneFormat.getLength(), milliBuilder.length()) : Strings.EMPTY; milliBuilder.setLength(milliBuilder.length() - truncateLen); // truncate millis - final String expected = milliBuilder - .append("987123456".substring(0, i)) - .append(tz) - .toString(); + final String expected = + milliBuilder.append("987123456", 0, i).append(tz).toString(); assertEquals( - "format = " + format + ", pattern = " + pattern + ", precisePattern = " + precisePattern, expected, - preciseBuilder.toString()); + preciseBuilder.toString(), + "format = " + format + ", pattern = " + pattern + ", precisePattern = " + precisePattern); // System.out.println(preciseOptions[0] + ": " + precise); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithThreadLocalsTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithThreadLocalsTest.java new file mode 100644 index 0000000000..e116120a97 --- /dev/null +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithThreadLocalsTest.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you 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 + * + * http://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.apache.logging.log4j.core.pattern; + +import org.apache.logging.log4j.test.junit.SetTestProperty; +import org.apache.logging.log4j.test.junit.UsingTestProperties; + +@SetTestProperty(key = "log4j2.is.webapp", value = "false") +@SetTestProperty(key = "log4j2.enable.threadlocals", value = "true") +@UsingTestProperties +class DatePatternConverterWithThreadLocalsTest extends DatePatternConverterTestBase { + + DatePatternConverterWithThreadLocalsTest() { + super(true); + } +} diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithoutThreadLocalsTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithoutThreadLocalsTest.java new file mode 100644 index 0000000000..1559e28efb --- /dev/null +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithoutThreadLocalsTest.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you 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 + * + * http://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.apache.logging.log4j.core.pattern; + +import org.apache.logging.log4j.test.junit.SetTestProperty; +import org.apache.logging.log4j.test.junit.UsingTestProperties; + +@SetTestProperty(key = "log4j2.enable.threadlocals", value = "false") +@UsingTestProperties +class DatePatternConverterWithoutThreadLocalsTest extends DatePatternConverterTestBase { + + DatePatternConverterWithoutThreadLocalsTest() { + super(false); + } +} diff --git a/log4j-layout-jackson-xml/pom.xml b/log4j-layout-jackson-xml/pom.xml index fc6be11c8a..763d4dd17c 100644 --- a/log4j-layout-jackson-xml/pom.xml +++ b/log4j-layout-jackson-xml/pom.xml @@ -92,6 +92,8 @@ <build> <plugins> + + <!-- Enable Log4j plugin processing --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> @@ -105,6 +107,46 @@ </annotationProcessorPaths> </configuration> </plugin> + </plugins> </build> + + <profiles> + + <!-- Fixes incompatible with Java 8 --> + <profile> + + <id>java8-incompat-fixes</id> + + <!-- CI uses Java 8 for running tests. + Hence, we assume CI=Java8 and apply our changes elsewhere. + + One might think why not activate using `<jdk>[16,)` instead? + This doesn't work, since the match is not against "the JDK running tests", but "the JDK running Maven". + These two JDKs can differ due to Maven Toolchains. + See `java8-tests` profile in `/pom.xml` for details. --> + <activation> + <property> + <name>!env.CI</name> + </property> + </activation> + + <!-- Illegal access is disabled by default in Java 16 due to JEP-396. + We are relaxing it for tests. --> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine> + </configuration> + </plugin> + </plugins> + </build> + + </profile> + + </profiles> + </project> diff --git a/log4j-osgi-test/pom.xml b/log4j-osgi-test/pom.xml index 59747b2806..485aaeedaf 100644 --- a/log4j-osgi-test/pom.xml +++ b/log4j-osgi-test/pom.xml @@ -201,4 +201,43 @@ </plugins> </build> + + <profiles> + + <!-- Fixes incompatible with Java 8 --> + <profile> + + <id>java8-incompat-fixes</id> + + <!-- CI uses Java 8 for running tests. + Hence, we assume CI=Java8 and apply our changes elsewhere. + + One might think why not activate using `<jdk>[16,)` instead? + This doesn't work, since the match is not against "the JDK running tests", but "the JDK running Maven". + These two JDKs can differ due to Maven Toolchains. + See `java8-tests` profile in `/pom.xml` for details. --> + <activation> + <property> + <name>!env.CI</name> + </property> + </activation> + + <!-- Illegal access is disabled by default in Java 16 due to JEP-396. + We are relaxing it for tests. --> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>--add-opens java.base/java.net=ALL-UNNAMED</argLine> + </configuration> + </plugin> + </plugins> + </build> + + </profile> + + </profiles> + </project> diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml index 7c1b7a305d..e3a2829a1c 100644 --- a/log4j-parent/pom.xml +++ b/log4j-parent/pom.xml @@ -44,12 +44,6 @@ <!-- ================= Common properties ================= --> - <maven.compiler.release>11</maven.compiler.release> - <maven.compiler.source>${maven.compiler.release}</maven.compiler.source> - <maven.compiler.target>${maven.compiler.release}</maven.compiler.target> - - <!-- JDK version of the main Maven process (used in ASF parent POM) --> - <minimalJavaBuildVersion>[11,12)</minimalJavaBuildVersion> <!-- TODO: fix errors and reenable SpotBugs --> <spotbugs.skip>true</spotbugs.skip> <!-- TODO: re-enable BND Baseline --> @@ -748,6 +742,12 @@ <version>${opentest4j.version}</version> </dependency> + <dependency> + <groupId>org.openjdk.nashorn</groupId> + <artifactId>nashorn-core</artifactId> + <version>${nashorn.version}</version> + </dependency> + <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.framework</artifactId> diff --git a/pom.xml b/pom.xml index 1cba6b9f1b..6aee31fe84 100644 --- a/pom.xml +++ b/pom.xml @@ -308,10 +308,10 @@ Common properties ================= --> <manifestfile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestfile> - <maven.compiler.release>11</maven.compiler.release> - <maven.compiler.target>${maven.compiler.release}</maven.compiler.target> - <!-- JDK version of the main Maven process (used in ASF parent POM) --> - <minimalJavaBuildVersion>[11,12)</minimalJavaBuildVersion> + <!-- target Java 17 --> + <maven.compiler.source>17</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <maven.compiler.release>17</maven.compiler.release> <module.name /> <!-- `project.build.outputTimestamp` is required to be present for reproducible builds.
