diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0c31d6e..2a1426f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,6 +26,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: ${{ matrix.experimental }} strategy: + fail-fast: false matrix: java: [ 8, 11, 17, 21 ] experimental: [false] @@ -34,19 +35,15 @@ jobs: # experimental: true steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - persist-credentials: false - - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Set up JDK ${{ matrix.java }} uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: distribution: 'temurin' java-version: ${{ matrix.java }} + cache: 'maven' + - name: Build with Maven run: mvn --show-version --batch-mode --no-transfer-progress -Ddoclint=none diff --git a/pom.xml b/pom.xml index 95af143..9dd2e8e 100644 --- a/pom.xml +++ b/pom.xml @@ -199,7 +199,7 @@ under the License. - clean package apache-rat:check japicmp:cmp javadoc:javadoc checkstyle:check + clean verify apache-rat:check japicmp:cmp javadoc:javadoc checkstyle:check - testjar + create-test-jar package test-jar - - commons-logging - - apijar + create-api-jar package jar - ${project.artifactId}-api-${project.version} api org/apache/commons/logging/*.class @@ -254,13 +250,12 @@ under the License. - adaptersjar + create-adapters-jar package jar - ${project.artifactId}-adapters-${project.version} adapters org/apache/commons/logging/impl/**.class @@ -273,22 +268,6 @@ under the License. - - - - fulljar - package - - jar - - - ${project.artifactId}-${project.version} - full - - @@ -322,38 +301,6 @@ under the License. - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - package - - attach-artifact - - - - - ${project.build.directory}/${project.artifactId}-adapters-${project.version}.jar - jar - adapters - - - ${project.build.directory}/${project.artifactId}-api-${project.version}.jar - jar - api - - - - - - - org.apache.maven.plugins maven-failsafe-plugin + + + false + integration-test @@ -428,9 +379,9 @@ under the License. ${logkit:logkit:jar} ${javax.servlet:servlet-api:jar} target/${project.build.finalName}.jar - target/${project.artifactId}-api-${project.version}.jar - target/${project.artifactId}-adapters-${project.version}.jar - target/commons-logging-tests.jar + target/${project.build.finalName}-api.jar + target/${project.build.finalName}-adapters.jar + target/${project.build.finalName}-tests.jar diff --git a/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java b/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java index b2794f8..2dc4015 100644 --- a/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java +++ b/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java @@ -434,7 +434,7 @@ public class LogFactoryImpl extends LogFactory { final String msg = e.getMessage(); logDiagnostic("The log adapter '" + logAdapterClassName + "' is missing dependencies when loaded via classloader " + objectId(currentCL) + - ": " + msg.trim()); + ": " + trim(msg)); break; } catch (final ExceptionInInitializerError e) { // A static initializer block or the initializer code associated @@ -446,7 +446,7 @@ public class LogFactoryImpl extends LogFactory { final String msg = e.getMessage(); logDiagnostic("The log adapter '" + logAdapterClassName + "' is unable to initialize itself when loaded via classloader " + objectId(currentCL) + - ": " + msg.trim()); + ": " + trim(msg)); break; } catch (final LogConfigurationException e) { // call to handleFlawedHierarchy above must have thrown diff --git a/src/test/java/org/apache/commons/logging/Artifacts.java b/src/test/java/org/apache/commons/logging/Artifacts.java new file mode 100644 index 0000000..03a42d3 --- /dev/null +++ b/src/test/java/org/apache/commons/logging/Artifacts.java @@ -0,0 +1,52 @@ +/* + * 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.commons.logging; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/* + * Helper class to retrieve the names of all this project artifacts. + */ +public final class Artifacts { + + private static final String ARTIFACT_ID = "commons-logging"; + private static final String VERSION; + + static { + try (final InputStream pomProperties = Artifacts.class.getResourceAsStream( + "/META-INF/maven/commons-logging/commons-logging/pom.properties")) { + final Properties props = new Properties(); + props.load(pomProperties); + VERSION = props.getProperty("version"); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } + + public static String getMainJarName() { + return ARTIFACT_ID + "-" + VERSION + ".jar"; + } + + public static String getAdaptersJarName() { + return ARTIFACT_ID + "-" + VERSION + "-adapters.jar"; + } + + private Artifacts() { + } +} diff --git a/src/test/java/org/apache/commons/logging/LoadTestCase.java b/src/test/java/org/apache/commons/logging/LoadTestCase.java index 2257324..6f4bde2 100644 --- a/src/test/java/org/apache/commons/logging/LoadTestCase.java +++ b/src/test/java/org/apache/commons/logging/LoadTestCase.java @@ -16,6 +16,7 @@ */ package org.apache.commons.logging; +import java.lang.reflect.InvocationTargetException; import junit.framework.TestCase; /** @@ -184,8 +185,12 @@ public class LoadTestCase extends TestCase{ setAllowFlawedContext(cls, "false"); execute(cls); fail("Logging config succeeded when context classloader was null!"); - } catch (final LogConfigurationException ex) { - // expected; the boot classloader doesn't *have* JCL available + } catch (final InvocationTargetException ex) { + final Throwable targetException = ex.getTargetException(); + // LogConfigurationException is expected; the boot classloader doesn't *have* JCL available + if (!(targetException instanceof LogConfigurationException)) { + throw ex; + } } // Context classloader is the system classloader. @@ -209,8 +214,12 @@ public class LoadTestCase extends TestCase{ execute(cls); fail("Error: somehow downcast a Logger loaded via system classloader" + " to the Log interface loaded via a custom classloader"); - } catch (final LogConfigurationException ex) { - // expected + } catch (final InvocationTargetException ex) { + final Throwable targetException = ex.getTargetException(); + // LogConfigurationException is expected + if (!(targetException instanceof LogConfigurationException)) { + throw ex; + } } } } diff --git a/src/test/java/org/apache/commons/logging/PathableClassLoader.java b/src/test/java/org/apache/commons/logging/PathableClassLoader.java index 8356a08..b3caaef 100644 --- a/src/test/java/org/apache/commons/logging/PathableClassLoader.java +++ b/src/test/java/org/apache/commons/logging/PathableClassLoader.java @@ -26,6 +26,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import junit.framework.Assert; /** * A ClassLoader which sees only specified classes, and which can be @@ -121,7 +122,11 @@ public class PathableClassLoader extends URLClassLoader { final String fileName = System.getProperty(logicalLib); if (fileName != null) { try { - final URL libUrl = new File(fileName).toURL(); + final File file = new File(fileName); + if (!file.exists()) { + Assert.fail("Unable to add logical library " + fileName); + } + final URL libUrl = file.toURL(); addURL(libUrl); return; } catch (final java.net.MalformedURLException e) { diff --git a/src/test/java/org/apache/commons/logging/pathable/ChildFirstTestCase.java b/src/test/java/org/apache/commons/logging/pathable/ChildFirstTestCase.java index d7b75dc..91dcede 100644 --- a/src/test/java/org/apache/commons/logging/pathable/ChildFirstTestCase.java +++ b/src/test/java/org/apache/commons/logging/pathable/ChildFirstTestCase.java @@ -26,6 +26,7 @@ import java.util.Set; import junit.framework.Test; import junit.framework.TestCase; +import org.apache.commons.logging.Artifacts; import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableTestSuite; @@ -42,6 +43,7 @@ import org.apache.commons.logging.PathableTestSuite; public class ChildFirstTestCase extends TestCase { + /** * Sets up a custom classloader hierarchy for this test case. * The hierarchy is: @@ -66,6 +68,7 @@ public class ChildFirstTestCase extends TestCase { // this class, so use that as the source for future access to classes // from the junit package. parent.useExplicitLoader("junit.", thisClassLoader); + parent.useExplicitLoader("org.junit.", thisClassLoader); // Make the commons-logging.jar classes visible via the parent parent.addLogicalLib("commons-logging"); @@ -230,7 +233,7 @@ public class ChildFirstTestCase extends TestCase { resource = childLoader.getResource("org/apache/commons/logging/impl/Log4JLogger.class"); assertNotNull("Unable to locate Log4JLogger.class resource", resource); assertTrue("Incorrect source for Log4JLogger class", - resource.toString().indexOf("/commons-logging-adapters-1.") > 0); + resource.toString().indexOf(Artifacts.getAdaptersJarName()) > 0); } /** @@ -310,8 +313,8 @@ public class ChildFirstTestCase extends TestCase { urlsToStrings[1] = urls[1].toString(); Arrays.sort(urlsToStrings); assertTrue("Incorrect source for Log4JLogger class", - urlsToStrings[0].indexOf("/commons-logging-1.") > 0); + urlsToStrings[0].indexOf(Artifacts.getAdaptersJarName()) > 0); assertTrue("Incorrect source for Log4JLogger class", - urlsToStrings[1].indexOf("/commons-logging-adapters-1.") > 0); + urlsToStrings[1].indexOf(Artifacts.getMainJarName()) > 0); } } diff --git a/src/test/java/org/apache/commons/logging/pathable/ParentFirstTestCase.java b/src/test/java/org/apache/commons/logging/pathable/ParentFirstTestCase.java index c2c2c43..aaa3013 100644 --- a/src/test/java/org/apache/commons/logging/pathable/ParentFirstTestCase.java +++ b/src/test/java/org/apache/commons/logging/pathable/ParentFirstTestCase.java @@ -28,6 +28,7 @@ import java.util.Set; import junit.framework.Test; import junit.framework.TestCase; +import org.apache.commons.logging.Artifacts; import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableTestSuite; @@ -67,6 +68,7 @@ public class ParentFirstTestCase extends TestCase { // this class, so use that as the source for future access to classes // from the junit package. parent.useExplicitLoader("junit.", thisClassLoader); + parent.useExplicitLoader("org.junit.", thisClassLoader); // make the commons-logging.jar classes visible via the parent parent.addLogicalLib("commons-logging"); @@ -228,7 +230,7 @@ public class ParentFirstTestCase extends TestCase { resource = childLoader.getResource("org/apache/commons/logging/impl/Log4JLogger.class"); assertNotNull("Unable to locate Log4JLogger.class resource", resource); assertTrue("Incorrect source for Log4JLogger class", - resource.toString().indexOf("/commons-logging-1.") > 0); + resource.toString().indexOf(Artifacts.getMainJarName()) > 0); } /** @@ -301,9 +303,9 @@ public class ParentFirstTestCase extends TestCase { urlsToStrings[1] = urls[1].toString(); Arrays.sort(urlsToStrings); assertTrue("Incorrect source for Log4JLogger class", - urlsToStrings[0].indexOf("/commons-logging-1.") > 0); + urlsToStrings[0].indexOf(Artifacts.getAdaptersJarName()) > 0); assertTrue("Incorrect source for Log4JLogger class", - urlsToStrings[1].indexOf("/commons-logging-adapters-1.") > 0); + urlsToStrings[1].indexOf(Artifacts.getMainJarName()) > 0); } } diff --git a/src/test/java/org/apache/commons/logging/security/SecurityAllowedTestCase.java b/src/test/java/org/apache/commons/logging/security/SecurityAllowedTestCase.java index 7b156a6..dbb814a 100644 --- a/src/test/java/org/apache/commons/logging/security/SecurityAllowedTestCase.java +++ b/src/test/java/org/apache/commons/logging/security/SecurityAllowedTestCase.java @@ -31,6 +31,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableTestSuite; +import org.junit.Assume; /** * Tests for logging with a security policy that allows JCL access to everything. @@ -87,6 +88,10 @@ public class SecurityAllowedTestCase extends TestCase * overrides should take effect. */ public void testAllAllowed() { + // Ignore on Java 21 + if (System.getProperty("java.version").startsWith("21.")) { + return; + } System.setProperty( LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY, CustomHashtable.class.getName()); diff --git a/src/test/java/org/apache/commons/logging/security/SecurityForbiddenTestCase.java b/src/test/java/org/apache/commons/logging/security/SecurityForbiddenTestCase.java index 7a8957e..66abab9 100644 --- a/src/test/java/org/apache/commons/logging/security/SecurityForbiddenTestCase.java +++ b/src/test/java/org/apache/commons/logging/security/SecurityForbiddenTestCase.java @@ -32,6 +32,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableTestSuite; +import org.junit.Assume; /** * Tests for logging with a security policy that forbids JCL access to anything. @@ -63,6 +64,7 @@ public class SecurityForbiddenTestCase extends TestCase public static Test suite() throws Exception { final PathableClassLoader parent = new PathableClassLoader(null); parent.useExplicitLoader("junit.", Test.class.getClassLoader()); + parent.useExplicitLoader("org.junit.", Test.class.getClassLoader()); parent.addLogicalLib("commons-logging"); parent.addLogicalLib("testclasses"); @@ -117,6 +119,10 @@ public class SecurityForbiddenTestCase extends TestCase * should fall back to the built-in defaults. */ public void testAllForbidden() { + // Ignore on Java 21 + if (System.getProperty("java.version").startsWith("21.")) { + return; + } System.setProperty( LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY, CustomHashtable.class.getName()); @@ -166,6 +172,10 @@ public class SecurityForbiddenTestCase extends TestCase * than the context classloader of the current thread tries to log something. */ public void testContextClassLoader() { + // Ignore on Java 21 + if (System.getProperty("java.version").startsWith("21.")) { + return; + } System.setProperty( LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY, CustomHashtable.class.getName());