LOGGING-185: Fix failing tests (#180)
* Fix names of deployed artifacts We remove the obsolete `finalName` property and fix the Maven Failsafe executions. * Fix failing tests * Reenable integration tests * Disable SecurityManager tests on Java 21 * Simplify build workflow * Set `fail-fast` to false * Fix NPEs caused by `String.trim()` * Span a different JVM per test case
This commit is contained in:
15
.github/workflows/maven.yml
vendored
15
.github/workflows/maven.yml
vendored
@@ -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
|
||||
|
||||
71
pom.xml
71
pom.xml
@@ -199,7 +199,7 @@ under the License.
|
||||
<!-- TODO spotbugs:check -->
|
||||
<!-- TODO replace clirr:check with japicmp:cmp -->
|
||||
<!-- The verify goal causes build failures currently, so stop at package for now -->
|
||||
<defaultGoal>clean package apache-rat:check japicmp:cmp javadoc:javadoc checkstyle:check</defaultGoal>
|
||||
<defaultGoal>clean verify apache-rat:check japicmp:cmp javadoc:javadoc checkstyle:check</defaultGoal>
|
||||
<plugins>
|
||||
|
||||
<!--
|
||||
@@ -218,24 +218,20 @@ under the License.
|
||||
- The custom test framework requires the unit test code to be
|
||||
- in a jarfile so it can control its place in the classpath.
|
||||
-->
|
||||
<id>testjar</id>
|
||||
<id>create-test-jar</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<finalName>commons-logging</finalName>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>apijar</id>
|
||||
<id>create-api-jar</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}-api-${project.version}</finalName>
|
||||
<classifier>api</classifier>
|
||||
<includes>
|
||||
<include>org/apache/commons/logging/*.class</include>
|
||||
@@ -254,13 +250,12 @@ under the License.
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>adaptersjar</id>
|
||||
<id>create-adapters-jar</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}-adapters-${project.version}</finalName>
|
||||
<classifier>adapters</classifier>
|
||||
<includes>
|
||||
<include>org/apache/commons/logging/impl/**.class</include>
|
||||
@@ -273,22 +268,6 @@ under the License.
|
||||
</excludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
<!--
|
||||
- Define the full jar last, the deploy/install plugin seems to be broken
|
||||
- and takes the last definition from here.
|
||||
-->
|
||||
<execution>
|
||||
<id>fulljar</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<classifier>full</classifier>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<archive combine.children="append">
|
||||
@@ -322,38 +301,6 @@ under the License.
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!--
|
||||
- Attach the adapters and api jars to the normal artifact. This way
|
||||
- they will be deployed when the normal artifact is deployed.
|
||||
-->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-artifacts</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>attach-artifact</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifacts>
|
||||
<artifact>
|
||||
<file>${project.build.directory}/${project.artifactId}-adapters-${project.version}.jar</file>
|
||||
<type>jar</type>
|
||||
<classifier>adapters</classifier>
|
||||
</artifact>
|
||||
<artifact>
|
||||
<file>${project.build.directory}/${project.artifactId}-api-${project.version}.jar</file>
|
||||
<type>jar</type>
|
||||
<classifier>api</classifier>
|
||||
</artifact>
|
||||
</artifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<!--
|
||||
- Many of JCL's tests use tricky techniques to place the generated
|
||||
@@ -398,6 +345,10 @@ under the License.
|
||||
-->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<!-- Span a different JVM per test -->
|
||||
<configuration>
|
||||
<reuseForks>false</reuseForks>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration-test</id>
|
||||
@@ -428,9 +379,9 @@ under the License.
|
||||
<logkit>${logkit:logkit:jar}</logkit>
|
||||
<servlet-api>${javax.servlet:servlet-api:jar}</servlet-api>
|
||||
<commons-logging>target/${project.build.finalName}.jar</commons-logging>
|
||||
<commons-logging-api>target/${project.artifactId}-api-${project.version}.jar</commons-logging-api>
|
||||
<commons-logging-adapters>target/${project.artifactId}-adapters-${project.version}.jar</commons-logging-adapters>
|
||||
<testclasses>target/commons-logging-tests.jar</testclasses>
|
||||
<commons-logging-api>target/${project.build.finalName}-api.jar</commons-logging-api>
|
||||
<commons-logging-adapters>target/${project.build.finalName}-adapters.jar</commons-logging-adapters>
|
||||
<testclasses>target/${project.build.finalName}-tests.jar</testclasses>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
@@ -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
|
||||
|
||||
52
src/test/java/org/apache/commons/logging/Artifacts.java
Normal file
52
src/test/java/org/apache/commons/logging/Artifacts.java
Normal file
@@ -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() {
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user