Skip to content

Commit 3aef4e9

Browse files
committed
Fix missing dependencies when installing
* removed dependency to apache commons logging * removed feature plugin dependency to slf4j logback binding. Newer eclipse distributions have this by default, so it is not needed. If it is missing, it needs to be installed manually from orbit. * removed slf4j-api from plugin classpath Fixes #115
1 parent e40f4f9 commit 3aef4e9

File tree

9 files changed

+103
-45
lines changed

9 files changed

+103
-45
lines changed

ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Eclipse Update Site:
1414
### Fixed Issues
1515

1616
* [#114](https://github.com/pmd/pmd-eclipse-plugin/issues/114): NPE in PriorityDescriptorCache
17+
* [#115](https://github.com/pmd/pmd-eclipse-plugin/issues/115): Missing dependencies when installing
1718

1819
### API Changes
1920

net.sourceforge.pmd.eclipse.plugin.test/META-INF/MANIFEST.MF

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Require-Bundle: org.eclipse.ui,
1313
org.eclipse.jdt.core,
1414
org.eclipse.jdt.launching,
1515
org.junit,
16-
org.apache.log4j,
1716
org.apache.commons.io
1817
Import-Package: ch.qos.logback.classic,
1918
org.slf4j

net.sourceforge.pmd.eclipse.plugin/META-INF/MANIFEST.MF

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Bundle-Name: %plugin.name
44
Bundle-SymbolicName: net.sourceforge.pmd.eclipse.plugin;singleton:=true
55
Bundle-Version: 4.10.1.qualifier
66
Bundle-Activator: net.sourceforge.pmd.eclipse.plugin.PMDPlugin
7-
Require-Bundle: org.apache.commons.logging;bundle-version="1.0.4",
8-
org.eclipse.core.resources,
7+
Require-Bundle: org.eclipse.core.resources,
98
org.eclipse.core.runtime,
109
org.eclipse.jdt.core,
1110
org.eclipse.jface.text,
@@ -19,8 +18,7 @@ Require-Bundle: org.apache.commons.logging;bundle-version="1.0.4",
1918
org.eclipse.wst.xml.core,
2019
org.eclipse.ui.workbench.texteditor,
2120
ch.qos.logback.classic,
22-
ch.qos.logback.core,
23-
org.slf4j.jul
21+
ch.qos.logback.core
2422
Bundle-ActivationPolicy: lazy
2523
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
2624
Bundle-Vendor: %plugin.provider
@@ -75,7 +73,6 @@ Bundle-ClassPath: target/lib/antlr-runtime.jar,
7573
target/lib/scalameta_2.13.jar,
7674
target/lib/scalap.jar,
7775
target/lib/scalapb-runtime_2.13.jar,
78-
target/lib/slf4j-api.jar,
7976
target/lib/sourcecode_2.13.jar,
8077
target/lib/stringtemplate.jar,
8178
target/lib/trees_2.13.jar,

net.sourceforge.pmd.eclipse.plugin/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bin.includes = .,\
1616
welcome.xml,\
1717
doc/,\
1818
target/lib/,\
19-
target/schema/,\
19+
target/schema/
2020
src.includes = icons/,\
2121
META-INF/,\
2222
plugin.xml,\
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.eclipse.logging.internal;
6+
7+
import java.text.MessageFormat;
8+
import java.util.logging.Handler;
9+
import java.util.logging.Level;
10+
import java.util.logging.LogRecord;
11+
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
15+
/**
16+
* This logger is needed in order to channel PMD's own logs through eclipse/logback.
17+
*/
18+
public class JulLoggingHandler extends Handler {
19+
20+
public static void install() {
21+
java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(LogbackConfiguration.ROOT_LOG_ID);
22+
for (Handler handler : julLogger.getHandlers()) {
23+
if (handler instanceof JulLoggingHandler) {
24+
return; // already installed
25+
}
26+
}
27+
julLogger.addHandler(new JulLoggingHandler());
28+
julLogger.setUseParentHandlers(false);
29+
}
30+
31+
public static void uninstall() {
32+
JulLoggingHandler julLoggingHandler = null;
33+
java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(LogbackConfiguration.ROOT_LOG_ID);
34+
for (Handler handler : julLogger.getHandlers()) {
35+
if (handler instanceof JulLoggingHandler) {
36+
julLoggingHandler = (JulLoggingHandler) handler;
37+
break;
38+
}
39+
}
40+
julLogger.removeHandler(julLoggingHandler);
41+
julLogger.setUseParentHandlers(true);
42+
}
43+
44+
@Override
45+
public void publish(LogRecord record) {
46+
if (record == null) {
47+
return;
48+
}
49+
50+
String loggerName = record.getLoggerName();
51+
if (loggerName == null) {
52+
loggerName = LogbackConfiguration.ROOT_LOG_ID;
53+
}
54+
String message = record.getMessage();
55+
if (message == null) {
56+
message = "";
57+
}
58+
Object[] parameters = record.getParameters();
59+
if (parameters != null) {
60+
message = MessageFormat.format(message, parameters);
61+
}
62+
Throwable thrown = record.getThrown();
63+
int loglevel = record.getLevel().intValue();
64+
65+
Logger slf4j = LoggerFactory.getLogger(loggerName);
66+
67+
if (loglevel <= Level.FINE.intValue()) {
68+
slf4j.debug(message, thrown);
69+
} else if (loglevel <= Level.INFO.intValue()) {
70+
slf4j.info(message, thrown);
71+
} else if (loglevel <= Level.WARNING.intValue()) {
72+
slf4j.warn(message, thrown);
73+
} else {
74+
slf4j.error(message, thrown);
75+
}
76+
}
77+
78+
@Override
79+
public void close() throws SecurityException {
80+
// empty
81+
}
82+
83+
@Override
84+
public void flush() {
85+
// empty
86+
}
87+
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/logging/internal/LogbackConfiguration.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.eclipse.core.runtime.Status;
1010
import org.slf4j.ILoggerFactory;
1111
import org.slf4j.LoggerFactory;
12-
import org.slf4j.bridge.SLF4JBridgeHandler;
1312

1413
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1514

@@ -55,9 +54,7 @@ public void configureLogback() {
5554
l.addAppender(logbackEclipseAppender);
5655
l.setAdditive(false);
5756

58-
if (!SLF4JBridgeHandler.isInstalled()) {
59-
SLF4JBridgeHandler.install();
60-
}
57+
JulLoggingHandler.install();
6158
}
6259

6360
public void unconfigureLogback() {
@@ -69,7 +66,7 @@ public void unconfigureLogback() {
6966
Logger l = logbackContext.getLogger(ROOT_LOG_ID);
7067
l.detachAndStopAllAppenders();
7168

72-
SLF4JBridgeHandler.uninstall();
69+
JulLoggingHandler.uninstall();
7370
}
7471

7572
private void configureLogs(String logFileName, String logLevel) {

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/GeneralPreferencesPage.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
package net.sourceforge.pmd.eclipse.ui.preferences;
66

77
import java.text.MessageFormat;
8+
import java.util.Arrays;
89
import java.util.Date;
910
import java.util.List;
1011
import java.util.Set;
1112

12-
import org.apache.log4j.Level;
1313
import org.eclipse.core.resources.IFile;
1414
import org.eclipse.core.resources.ResourcesPlugin;
1515
import org.eclipse.core.runtime.preferences.InstanceScope;
@@ -553,7 +553,7 @@ public void widgetDefaultSelected(SelectionEvent event) {
553553
}
554554
});
555555

556-
logLevelScale.setSelection(intLogLevel(this.preferences.getLogLevel()));
556+
logLevelScale.setSelection(intLogLevel(this.preferences.getLogLevelName()));
557557
updateLogLevelValueLabel();
558558

559559
return loggingGroup;
@@ -801,7 +801,7 @@ protected void performDefaults() {
801801
setText(logFileNameText, IPreferences.LOG_FILENAME_DEFAULT);
802802

803803
if (logLevelScale != null) {
804-
logLevelScale.setSelection(intLogLevel(IPreferences.LOG_LEVEL));
804+
logLevelScale.setSelection(intLogLevel(IPreferences.LOG_LEVEL_DEFAULT));
805805
updateLogLevelValueLabel();
806806
}
807807
}
@@ -934,7 +934,7 @@ public boolean performOk() {
934934
}
935935

936936
if (logLevelScale != null) {
937-
preferences.setLogLevel(Level.toLevel(LOG_LEVELS[logLevelScale.getSelection()]));
937+
preferences.setLogLevel(LOG_LEVELS[logLevelScale.getSelection()]);
938938
}
939939

940940
preferences.sync();
@@ -947,27 +947,12 @@ public boolean performOk() {
947947
/**
948948
* Return the selection index corresponding to the log level
949949
*/
950-
private int intLogLevel(Level level) {
951-
int result = 0;
952-
953-
if (level.equals(Level.OFF)) {
950+
private int intLogLevel(String level) {
951+
int result = Arrays.asList(LOG_LEVELS).indexOf(level);
952+
if (result < 0 || result > 6) {
954953
result = 0;
955-
} else if (level.equals(Level.FATAL)) {
956-
result = 1;
957-
} else if (level.equals(Level.ERROR)) {
958-
result = 2;
959-
} else if (level.equals(Level.WARN)) {
960-
result = 3;
961-
} else if (level.equals(Level.INFO)) {
962-
result = 4;
963-
} else if (level.equals(Level.DEBUG)) {
964-
result = 5;
965-
} else if (level.equals(Level.ALL)) {
966-
result = 6;
967954
}
968-
969955
return result;
970-
971956
}
972957

973958
/**

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/ViolationOverviewContentProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12-
import org.apache.commons.logging.Log;
13-
import org.apache.commons.logging.LogFactory;
1412
import org.eclipse.core.resources.IResourceChangeEvent;
1513
import org.eclipse.core.resources.IResourceChangeListener;
1614
import org.eclipse.core.resources.IWorkspaceRoot;
1715
import org.eclipse.jface.viewers.IStructuredContentProvider;
1816
import org.eclipse.jface.viewers.ITreeContentProvider;
1917
import org.eclipse.jface.viewers.TreeViewer;
2018
import org.eclipse.jface.viewers.Viewer;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
2121

2222
import net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord;
2323
import net.sourceforge.pmd.eclipse.ui.model.FileRecord;
@@ -38,7 +38,7 @@
3838
public class ViolationOverviewContentProvider
3939
implements ITreeContentProvider, IStructuredContentProvider, IResourceChangeListener {
4040

41-
private static final Log LOG = LogFactory.getLog(ViolationOverviewContentProvider.class);
41+
private static final Logger LOG = LoggerFactory.getLogger(ViolationOverviewContentProvider.class);
4242
protected boolean filterPackages;
4343

4444
private final ViolationOverview violationView;

net.sourceforge.pmd.eclipse/feature.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,4 @@
3838
install-size="0"
3939
version="4.10.1.qualifier"/>
4040

41-
<plugin
42-
id="ch.qos.logback.slf4j"
43-
download-size="0"
44-
install-size="0"
45-
version="0.0.0"
46-
fragment="true"
47-
unpack="false"/>
48-
4941
</feature>

0 commit comments

Comments
 (0)