Skip to content

Commit e59b6d6

Browse files
committed
ongoing work on jigsaw modularization
1 parent 0e25744 commit e59b6d6

21 files changed

+69
-303
lines changed

logback-classic/pom.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@
108108
</dependency>
109109
<dependency>
110110
<groupId>org.codehaus.groovy</groupId>
111-
<artifactId>groovy</artifactId>
111+
<artifactId>groovy-all</artifactId>
112112
<scope>compile</scope>
113-
<!--<optional>true</optional>-->
113+
<optional>true</optional>
114114
</dependency>
115+
<!-- <dependency>
116+
<groupId>org.codehaus.groovy</groupId>
117+
<artifactId>groovy-test</artifactId>
118+
<scope>test</scope>
119+
</dependency>
120+
-->
115121
<dependency>
116122
<groupId>ch.qos.logback</groupId>
117123
<artifactId>logback-core</artifactId>
@@ -235,6 +241,7 @@
235241
</dependencies>
236242

237243
<executions>
244+
<!--
238245
<execution>
239246
<id>ant-osgi-test</id>
240247
<phase>package</phase>
@@ -250,7 +257,7 @@
250257
<goal>run</goal>
251258
</goals>
252259
</execution>
253-
260+
-->
254261
<execution>
255262
<id>ant-integration-test</id>
256263
<phase>package</phase>

logback-classic/src/main/java/ch/qos/logback/classic/provider/LogbackServiceProvider.java renamed to logback-classic/src/main/java/ch/qos/logback/classic/spi/LogbackServiceProvider.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ch.qos.logback.classic.provider;
1+
package ch.qos.logback.classic.spi;
22

33
import org.slf4j.ILoggerFactory;
44
import org.slf4j.IMarkerFactory;
@@ -27,29 +27,35 @@ public class LogbackServiceProvider implements SLF4JServiceProvider {
2727
// to avoid constant folding by the compiler, this field must *not* be final
2828
public static String REQUESTED_API_VERSION = "1.8.99"; // !final
2929

30-
private LoggerContext loggerFactory;
30+
private LoggerContext defaultLoggerContext;
3131
private IMarkerFactory markerFactory;
3232
private MDCAdapter mdcAdapter;
33-
33+
private final ContextSelectorStaticBinder contextSelectorBinder = ContextSelectorStaticBinder.getSingleton();
34+
private static Object KEY = new Object();
35+
private boolean initialized = false;
36+
3437
@Override
3538
public void initialize() {
36-
loggerFactory = new LoggerContext();
37-
initializeLoggerContext(loggerFactory);
39+
defaultLoggerContext = new LoggerContext();
40+
defaultLoggerContext.setName(CoreConstants.DEFAULT_CONTEXT_NAME);
41+
initializeLoggerContext();
3842
markerFactory = new BasicMarkerFactory();
3943
mdcAdapter = new LogbackMDCAdapter();
4044
}
4145

42-
private void initializeLoggerContext(LoggerContext loggerFactory) {
46+
private void initializeLoggerContext() {
4347
try {
4448
try {
45-
new ContextInitializer(loggerFactory).autoConfig();
49+
new ContextInitializer(defaultLoggerContext).autoConfig();
4650
} catch (JoranException je) {
4751
Util.report("Failed to auto configure default logger context", je);
4852
}
4953
// logback-292
50-
if (!StatusUtil.contextHasStatusListener(loggerFactory)) {
51-
StatusPrinter.printInCaseOfErrorsOrWarnings(loggerFactory);
54+
if (!StatusUtil.contextHasStatusListener(defaultLoggerContext)) {
55+
StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
5256
}
57+
contextSelectorBinder.init(defaultLoggerContext, KEY);
58+
initialized = true;
5359
} catch (Exception t) { // see LOGBACK-1159
5460
Util.report("Failed to instantiate [" + LoggerContext.class.getName() + "]", t);
5561
}
@@ -58,7 +64,14 @@ private void initializeLoggerContext(LoggerContext loggerFactory) {
5864
@Override
5965

6066
public ILoggerFactory getLoggerFactory() {
61-
return loggerFactory;
67+
if (!initialized) {
68+
return defaultLoggerContext;
69+
}
70+
71+
if (contextSelectorBinder.getContextSelector() == null) {
72+
throw new IllegalStateException("contextSelector cannot be null. See also " + NULL_CS_URL);
73+
}
74+
return contextSelectorBinder.getContextSelector().getLoggerContext();
6275
}
6376

6477
@Override

logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.security.CodeSource;
1818
import java.util.HashMap;
1919

20-
import sun.reflect.Reflection;
20+
//import sun.reflect.Reflection;
2121

2222
// import java.security.AccessControlException; import java.security.AccessController;import java.security.PrivilegedAction;
2323
/**
@@ -42,8 +42,8 @@ public class PackagingDataCalculator {
4242
// sun.reflect.Reflection class. However, this class will *not compile*
4343
// on JDKs lacking sun.reflect.Reflection.
4444
try {
45-
Reflection.getCallerClass(2);
46-
GET_CALLER_CLASS_METHOD_AVAILABLE = true;
45+
//Reflection.getCallerClass(2);
46+
//GET_CALLER_CLASS_METHOD_AVAILABLE = true;
4747
} catch (NoClassDefFoundError e) {
4848
} catch (NoSuchMethodError e) {
4949
} catch (UnsupportedOperationException e) {
@@ -70,9 +70,9 @@ void populateFrames(StackTraceElementProxy[] stepArray) {
7070
// in the initial part of this method we populate package information for
7171
// common stack frames
7272
final Throwable t = new Throwable("local stack reference");
73-
final StackTraceElement[] localteSTEArray = t.getStackTrace();
74-
final int commonFrames = STEUtil.findNumberOfCommonFrames(localteSTEArray, stepArray);
75-
final int localFirstCommon = localteSTEArray.length - commonFrames;
73+
final StackTraceElement[] localSTEArray = t.getStackTrace();
74+
final int commonFrames = STEUtil.findNumberOfCommonFrames(localSTEArray, stepArray);
75+
final int localFirstCommon = localSTEArray.length - commonFrames;
7676
final int stepFirstCommon = stepArray.length - commonFrames;
7777

7878
ClassLoader lastExactClassLoader = null;
@@ -82,7 +82,7 @@ void populateFrames(StackTraceElementProxy[] stepArray) {
8282
for (int i = 0; i < commonFrames; i++) {
8383
Class callerClass = null;
8484
if (GET_CALLER_CLASS_METHOD_AVAILABLE) {
85-
callerClass = Reflection.getCallerClass(localFirstCommon + i - missfireCount + 1);
85+
//callerClass = Reflection.getCallerClass(localFirstCommon + i - missfireCount + 1);
8686
}
8787
StackTraceElementProxy step = stepArray[stepFirstCommon + i];
8888
String stepClassname = step.ste.getClassName();

logback-classic/src/main/java/module-info.java renamed to logback-classic/src/main/java/module-info.Xjava

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
requires static java.management;
66

77

8+
89
requires ch.qos.logback.core;
10+
requires static groovy;
911

10-
provides org.slf4j.spi.SLF4JServiceProvider with ch.qos.logback.classic.provider.LogbackServiceProvider;
12+
provides org.slf4j.spi.SLF4JServiceProvider with ch.qos.logback.classic.spi.LogbackServiceProvider;
1113

1214
}

logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java

Lines changed: 0 additions & 114 deletions
This file was deleted.

logback-classic/src/main/java/org/slf4j/impl/StaticMDCBinder.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

logback-classic/src/main/java/org/slf4j/impl/StaticMarkerBinder.java

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ch.qos.logback.classic.spi.LogbackServiceProvider

logback-classic/src/test/groovy/ch/qos/logback/classic/gaffer/GafferConfiguratorTest.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class GafferConfiguratorTest {
172172

173173
@Test
174174
void appenderRefShouldWork() {
175+
context.putProperty("p", "HELLO");
175176
File file = new File(ClassicTestConstants.GAFFER_INPUT_PREFIX + "asyncAppender.groovy")
176177
configurator.run file.text
177178

@@ -183,6 +184,7 @@ class GafferConfiguratorTest {
183184

184185
@Test
185186
void appenderRefWithNonAppenderAttachable() {
187+
context.putProperty("p", "HELLO");
186188
String message = shouldFail(IllegalArgumentException) {
187189
File file = new File(ClassicTestConstants.GAFFER_INPUT_PREFIX + "appenderRefWithNonAppenderAttachable.groovy")
188190
configurator.run file.text

0 commit comments

Comments
 (0)