Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed May 11, 2024
2 parents e29c111 + d67eefa commit f87a5f3
Show file tree
Hide file tree
Showing 38 changed files with 149 additions and 105 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<release version="1.3.2" date="2024-05-11" description="This is a feature and maintenance release. Java 8 or later is required.">
<action dev="ggregory" issue="LOGGING-190" type="fix" due-to="Hannes Wellmann, Gary Gregory, Johan Compagner">Add OSGi metadata to enable Service Loader Mediator #234.</action>
<action dev="ggregory" issue="LOGGING-191" type="fix" due-to="Hannes Wellmann, Gary Gregory, Johan Compagner">Apache commons logging shows 1.4 as latest release instead of 1.3.1.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate org.apache.commons.logging.LogSource.jdk14IsAvailable.</action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">Bump org.apache.commons:commons-parent from 67 to 69 #240.</action>
<action dev="ggregory" type="update" due-to="Dependabot">Bump org.slf4j:slf4j-api from 2.0.12 to 2.0.13 #248.</action>
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/apache/commons/logging/LogFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -1424,12 +1424,11 @@ protected static LogFactory newFactory(final String factoryClass,
protected static LogFactory newFactory(final String factoryClass,
final ClassLoader classLoader,
final ClassLoader contextClassLoader)
throws LogConfigurationException {
throws LogConfigurationException {
// Note that any unchecked exceptions thrown by the createFactory
// method will propagate out of this method; in particular a
// ClassCastException can be thrown.
final Object result = AccessController.doPrivileged(
(PrivilegedAction) () -> createFactory(factoryClass, classLoader));
final Object result = AccessController.doPrivileged((PrivilegedAction<?>) () -> createFactory(factoryClass, classLoader));

if (result instanceof LogConfigurationException) {
final LogConfigurationException ex = (LogConfigurationException) result;
Expand All @@ -1439,8 +1438,7 @@ protected static LogFactory newFactory(final String factoryClass,
throw ex;
}
if (isDiagnosticsEnabled()) {
logDiagnostic("Created object " + objectId(result) + " to manage class loader " +
objectId(contextClassLoader));
logDiagnostic("Created object " + objectId(result) + " to manage class loader " + objectId(contextClassLoader));
}
return (LogFactory) result;
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/apache/commons/logging/LogSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ public class LogSource {
/** Is Log4j available (in the current classpath) */
static protected boolean log4jIsAvailable;

/** Is JDK 1.4 logging available */
static protected boolean jdk14IsAvailable;
/**
* Is JDK 1.4 logging available, always true.
*
* @deprecated Java 8 is the baseline and includes JUL.
*/
@Deprecated
static protected boolean jdk14IsAvailable = true;

/** Constructor for current log class */
static protected Constructor<?> logImplctor;
Expand All @@ -77,9 +82,6 @@ public class LogSource {
// Is Log4J Available?
log4jIsAvailable = isClassForName("org.apache.log4j.Logger");

// Is JDK 1.4 Logging Available?
jdk14IsAvailable = isClassForName("org.apache.commons.logging.impl.Jdk14Logger");

// Set the default Log implementation
String name = null;
try {
Expand All @@ -104,10 +106,8 @@ public class LogSource {
try {
if (log4jIsAvailable) {
setLogImplementation("org.apache.commons.logging.impl.Log4JLogger");
} else if (jdk14IsAvailable) {
setLogImplementation("org.apache.commons.logging.impl.Jdk14Logger");
} else {
setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
setLogImplementation("org.apache.commons.logging.impl.Jdk14Logger");
}
} catch (final Throwable t) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ protected Log newLogger(final String name, final LoggerContext context) {

private final ConcurrentMap<String, Object> attributes = new ConcurrentHashMap<>();

/**
* Constructs a new instance.
*/
public Log4jApiLogFactory() {
// empty
}

@Override
public Object getAttribute(final String name) {
return attributes.get(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public class ServletContextCleaner implements ServletContextListener {

private static final Class<?>[] RELEASE_SIGNATURE = { ClassLoader.class };

/**
* Constructs a new instance.
*/
public ServletContextCleaner() {
// empty
}

/**
* Invoked when a webapp is undeployed, this tells the LogFactory
* class to release any logging information related to the current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ public void warn(final Object message, final Throwable t) {

private final ConcurrentMap<String, Object> attributes = new ConcurrentHashMap<>();

/**
* Constructs a new instance.
*/
public Slf4jLogFactory() {
// empty
}

@Override
public Object getAttribute(final String name) {
return attributes.get(name);
Expand Down Expand Up @@ -303,6 +310,7 @@ public void release() {
try {
factory.getClass().getMethod("stop").invoke(factory);
} catch (final ReflectiveOperationException ignored) {
// empty
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/apache/commons/logging/LogSourceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 static org.junit.jupiter.api.Assertions.assertTrue;

public class LogSourceTest {

@SuppressWarnings("deprecation")
public void testJdk14IsAvailable() throws Exception {
assertTrue(LogSource.jdk14IsAvailable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*/
package org.apache.commons.logging.avalon;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.apache.avalon.framework.logger.NullLogger;
import org.apache.commons.logging.AbstractLogTest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.AvalonLogger;

import junit.framework.Test;
import junit.framework.TestSuite;

/**
*/
public class AvalonLoggerTestCase extends AbstractLogTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import java.net.URL;

import junit.framework.Test;
import junit.framework.TestCase;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;

import junit.framework.Test;
import junit.framework.TestCase;

/**
* Tests that verify that the process of configuring logging on startup
* works correctly by selecting the file with the highest priority.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import java.net.URL;

import junit.framework.Test;
import junit.framework.TestCase;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;

import junit.framework.Test;
import junit.framework.TestCase;

/**
* Tests that verify that the process of configuring logging on startup
* works correctly by selecting the file with the highest priority.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package org.apache.commons.logging.jdk14;

import junit.framework.Test;

import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;

import junit.framework.Test;

/**
* TestCase for Jdk14 logging when the commons-logging-api jar file is in
* the parent classpath and commons-logging.jar is in the child.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package org.apache.commons.logging.jdk14;

import junit.framework.Test;

import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;

import junit.framework.Test;

/**
* TestCase for Jdk14 logging when the commons-logging jar file is in
* the parent classpath.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;

import junit.framework.Test;

import org.apache.commons.logging.DummyException;
import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;

import junit.framework.Test;

/**
* <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with
* custom configuration, so that JDK 1.4 should be selected and an appropriate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import junit.framework.Test;
import junit.framework.TestCase;

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 junit.framework.Test;
import junit.framework.TestCase;

/**
* <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with
* zero configuration, and with Log4J not present (so JDK 1.4 logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.apache.commons.logging.DummyException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import junit.framework.TestCase;

/**
* Abstract set of tests that can be executed with various classpaths set.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package org.apache.commons.logging.log4j.log4j12;

import junit.framework.Test;
import junit.framework.TestCase;

import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.commons.logging.impl.LogFactoryImpl;

import junit.framework.Test;
import junit.framework.TestCase;

/**
* Tests for Log4J logging that emulate a webapp running within
* a container where the commons-logging-api jar file is in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package org.apache.commons.logging.log4j.log4j12;

import junit.framework.Test;
import junit.framework.TestCase;

import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.commons.logging.impl.LogFactoryImpl;

import junit.framework.Test;
import junit.framework.TestCase;

/**
* Tests for Log4J logging when there is only one class loader and everything
* is in it, as would be the situation for a standalone application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package org.apache.commons.logging.log4j.log4j12;

import junit.framework.Test;
import junit.framework.TestCase;

import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.commons.logging.impl.LogFactoryImpl;

import junit.framework.Test;
import junit.framework.TestCase;

/**
* Tests for Log4J logging that emulate a webapp running within
* a container where all the necessary libs are in the child.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package org.apache.commons.logging.log4j.log4j12;

import junit.framework.Test;
import junit.framework.TestCase;

import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.commons.logging.impl.LogFactoryImpl;

import junit.framework.Test;
import junit.framework.TestCase;

/**
* Tests for Log4J logging that emulate a webapp running within
* a container where all the necessary libs are in the parent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.List;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4jApiLogFactory;
Expand All @@ -31,8 +33,6 @@
import org.apache.logging.log4j.message.ObjectMessage;
import org.apache.logging.log4j.message.SimpleMessage;

import junit.framework.TestCase;

public class CallerInformationTestCase extends TestCase {

private static final Object OBJ = new Object();
Expand Down Expand Up @@ -90,9 +90,7 @@ public void testLocationInfo() {
assertEquals("Correct source file.", "CallerInformationTestCase.java", location.getFileName());
assertEquals("Correct method name.", "testLocationInfo", location.getMethodName());
assertEquals("Correct location class.", getClass().getName(), location.getClassName());
assertEquals("Correct location line.",
currentLineNumber + 2 * lev + hasThrowable + 1,
location.getLineNumber());
assertEquals("Correct location line.", currentLineNumber + 2 * lev + hasThrowable + 1, location.getLineNumber());
assertEquals("Correct exception", hasThrowable > 0 ? T : null, event.getThrown());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import junit.framework.Test;

import org.apache.commons.logging.AbstractLogTest;
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.apache.commons.logging.impl.LogKitLogger;

import junit.framework.Test;

/**
* Basic tests for Avalon LogKit logger adapter.
*/
Expand Down

0 comments on commit f87a5f3

Please sign in to comment.