Skip to content

Commit

Permalink
migrate to Java 11
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Dec 18, 2023
1 parent c573117 commit 8f86910
Show file tree
Hide file tree
Showing 34 changed files with 238 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ public void test() throws Exception {
Logger logger = LoggerFactory.getLogger(this.getClass());
String msg = "hello world " + diff;
logger.info(msg);
assertEquals(1, sps.stringList.size());
assertEquals(2, sps.stringList.size());
String s0 = (String) sps.stringList.get(0);
assertTrue(s0.contains(msg));
assertTrue(s0.startsWith("SLF4J(I): Connected with provider of type [org.slf4j.simple.SimpleServiceProvider"));
String s1 = (String) sps.stringList.get(1);
assertTrue(s1.contains(msg));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void test() throws Exception {
assertMsgContains(list, 1, "Found provider");
assertMsgContains(list, 2, "Found provider");
assertMsgContains(list, 3, "See https://www.slf4j.org/codes.html#multiple_bindings for an explanation.");
assertMsgContains(list, 4, "Actual provider is of type [");
assertMsgContains(list, 4, "SLF4J(I): Connected with provider of type [org.slf4j.simple.SimpleServiceProvider");
}

void assertMsgContains(List<String> strList, int index, String msg) {
Expand Down
56 changes: 56 additions & 0 deletions jcl-over-slf4j-blackbox/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>2.1.0-alpha0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>jcl-over-slf4j-blackbox</artifactId>
<packaging>jar</packaging>
<name>jcl-over-slf4j blackbox testing</name>
<description>jcl-over-slf4j blackbox testing</description>
<url>http://www.slf4j.org</url>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>

</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>
</dependencies>

</project>
7 changes: 7 additions & 0 deletions jcl-over-slf4j-blackbox/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module org.apache.commons.logging.blackbox {
requires org.slf4j;
requires org.slf4j.jul;
requires org.apache.commons.logging;
requires java.logging;
requires junit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package org.apache.commons.logging.test;
package org.apache.commons.logging.blackbox;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -36,6 +36,7 @@
import org.apache.commons.logging.impl.SLF4JLog;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.jul.JDK14LoggerFactory;
import org.slf4j.spi.LocationAwareLogger;
Expand Down
2 changes: 1 addition & 1 deletion jcl-over-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<artifactId>jcl-over-slf4j</artifactId>
<packaging>jar</packaging>
<name>JCL 1.2 implemented over SLF4J</name>
<description>JCL 1.2 implemented over SLF4J</description>
<description>Jakarta/Apache commons logging 1.2 implemented over SLF4J</description>
<url>http://www.slf4j.org</url>

<licenses>
Expand Down
1 change: 1 addition & 0 deletions jcl-over-slf4j/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module org.apache.commons.logging {
requires org.slf4j;
exports org.apache.commons.logging;
exports org.apache.commons.logging.impl to org.apache.commons.logging.blackbox;
}
56 changes: 56 additions & 0 deletions log4j-over-slf4j-blackbox/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>2.1.0-alpha0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>log4j-over-slf4j-blackbox</artifactId>
<packaging>jar</packaging>
<name>log4j-over-slf4j blackbox testing</name>
<description>log4j-over-slf4j blackbox testing</description>
<url>http://www.slf4j.org</url>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>

</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package org.dummy;
package org.apache.log4j.blackbox;

import static org.junit.Assert.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package org.dummy;
package org.apache.log4j.blackbox;

import static org.junit.Assert.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package org.dummy;
package org.apache.log4j.blackbox;

import java.util.ArrayList;
import java.util.List;
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<modules>
<module>parent</module>
<module>slf4j-api</module>
<module>slf4j-testing</module>
<module>slf4j-simple</module>
<module>slf4j-nop</module>
<module>slf4j-jdk14</module>
Expand All @@ -41,7 +42,9 @@
<module>slf4j-reload4j</module>
<module>slf4j-ext</module>
<module>jcl-over-slf4j</module>
<module>jcl-over-slf4j-blackbox</module>
<module>log4j-over-slf4j</module>
<module>log4j-over-slf4j-blackbox</module>
<module>jul-to-slf4j</module>
<module>osgi-over-slf4j</module>
<module>integration</module>
Expand Down
9 changes: 6 additions & 3 deletions slf4j-api/src/main/java/org/slf4j/LoggerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public final class LoggerFactory {
static final String UNSUCCESSFUL_INIT_URL = CODES_PREFIX + "#unsuccessfulInit";
static final String UNSUCCESSFUL_INIT_MSG = "org.slf4j.LoggerFactory in failed state. Original exception was thrown EARLIER. See also "
+ UNSUCCESSFUL_INIT_URL;

static final String CONNECTED_WITH_MSG = "Connected with provider of type [";

/**
* System property for explicitly setting the provider class. If set and the provider could be instantiated,
* then the service loading mechanism will be bypassed.
Expand Down Expand Up @@ -403,9 +406,9 @@ private static void reportMultipleBindingAmbiguity(List<SLF4JServiceProvider> pr
}

private static void reportActualBinding(List<SLF4JServiceProvider> providerList) {
// binderPathSet can be null under Android
if (!providerList.isEmpty() && isAmbiguousProviderList(providerList)) {
Reporter.info("Actual provider is of type [" + providerList.get(0) + "]");
if (!providerList.isEmpty()) {
SLF4JServiceProvider provider = providerList.get(0);
Reporter.info(CONNECTED_WITH_MSG + provider.getClass().getName() + "]");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.LoggerFactory;

/**
* The present test is fragile in the sense that it sets up SimpleLogger
Expand Down Expand Up @@ -105,14 +106,17 @@ public void throwTest() throws IOException {
systemLogger.log(Level.INFO, "we have a problem", new Exception());

List<String> results = SPS.stringList;
//INFO throwTest - a problem
//java.lang.Exception
// SLF4J(I): Actual provider is of type [org.slf4j.simple.SimpleServiceProvider@67c27493]
// INFO throwTest - a problem
// java.lang.Exception
// at org.slf4j.jdk.platform.logging/org.slf4j.jdk.platform.logging.SLF4JPlatformLoggingTest.throwTest(SLF4JPlatformLoggingTest.java:92)

assertEquals("INFO throwTest - we have a problem", results.get(0));
assertEquals(Exception.class.getName(), results.get(1));
assertTrue(results.get(2).contains("at "));
assertTrue(results.get(2).contains(this.getClass().getName()));

String firstLine = results.get(0);
assertTrue(firstLine.startsWith("SLF4J(I): Connected with provider of type [org.slf4j.simple.SimpleServiceProvider"));
assertEquals("INFO throwTest - we have a problem", results.get(1));
assertEquals(Exception.class.getName(), results.get(2));
assertTrue(results.get(3).contains("at "));
assertTrue(results.get(3).contains(this.getClass().getName()));
}


Expand Down
4 changes: 2 additions & 2 deletions slf4j-jdk14/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<type>test-jar</type>
<artifactId>slf4j-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>
4 changes: 4 additions & 0 deletions slf4j-jdk14/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
requires org.slf4j;
requires java.logging;
provides org.slf4j.spi.SLF4JServiceProvider with org.slf4j.jul.JULServiceProvider;
opens org.slf4j.jul to org.slf4j;

// selective export
exports org.slf4j.jul to org.apache.commons.logging.blackbox;
}

2 changes: 2 additions & 0 deletions slf4j-jdk14/src/test/java/org/slf4j/issue/CallerInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.slf4j.event.SubstituteLoggingEvent;
import org.slf4j.helpers.SubstituteLogger;
import org.slf4j.helpers.SubstituteServiceProvider;
import org.slf4j.jul.JDK14LoggerAdapter;
import org.slf4j.jul.ListHandler;

public class CallerInfoTest {
Expand Down Expand Up @@ -103,6 +104,7 @@ public void testIntraInitializationCallerInfoWithSubstituteLogger() throws Inter

substituteLogger.debug("jello");
Logger logger = LoggerFactory.getLogger(loggerName);
assertTrue(logger instanceof JDK14LoggerAdapter);
substituteLogger.setDelegate(logger);

final LinkedBlockingQueue<SubstituteLoggingEvent> queue = substituteServiceProvider.getSubstituteLoggerFactory().getEventQueue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import org.junit.After;
import org.junit.Before;
import org.slf4j.testHarness.MultithreadedInitializationTest;
import org.slf4j.testing.MultithreadedInitializationTest;

public class JDK14MultithreadedInitializationTest extends MultithreadedInitializationTest {

Expand Down
7 changes: 7 additions & 0 deletions slf4j-nop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void multiThreadedInitialization() throws InterruptedException, BrokenBar
logger.info("hello");
EVENT_COUNT.getAndIncrement();

assertEquals(0, sps.stringList.size());
// SLF4J(I): Actual provider is of type [org.slf4j.nop.NOPServiceProvider@21b3698b]
assertEquals(1, sps.stringList.size());
}

private static LoggerAccessingThread[] harness() throws InterruptedException, BrokenBarrierException {
Expand Down
4 changes: 2 additions & 2 deletions slf4j-reload4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<type>test-jar</type>
<artifactId>slf4j-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

</dependencies>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.slf4j.reload4j;

import org.junit.Test;
import org.slf4j.helpers.MDCAdapterTestBase;
import org.slf4j.testing.MDCAdapterTestBase;
import org.slf4j.spi.MDCAdapter;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.junit.Before;
import org.slf4j.reload4j.testHarness.RecursiveAppender;

public class Reload4jMultithreadedInitializationTest extends org.slf4j.testHarness.MultithreadedInitializationTest {
public class Reload4jMultithreadedInitializationTest extends org.slf4j.testing.MultithreadedInitializationTest {
static int NUM_LINES_BY_RECURSIVE_APPENDER = 3;

// value of LogManager.DEFAULT_CONFIGURATION_KEY;
Expand Down
8 changes: 8 additions & 0 deletions slf4j-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>

0 comments on commit 8f86910

Please sign in to comment.