Skip to content

Commit

Permalink
Fix issue where JDT-LS's logback configuration was being ignored
Browse files Browse the repository at this point in the history
- JavaLanguageServerPlugin.start() -> StandardPreferenceManager() ->
  StandardPreferenceManager.initializeMavenPreferences() triggered M2E
  before JavaLanguageServerPlugin.start() could set
  "logback.configurationFile"

Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Apr 29, 2022
1 parent a05b37a commit 03aa9ab
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,25 @@ public void start(BundleContext bundleContext) throws Exception {
JavaLanguageServerPlugin.pluginInstance = this;
setPreferenceNodeId();

// Override logback preferences *before* M2E plugin is activated below
if (isDebug && System.getProperty(LOGBACK_CONFIG_FILE_PROPERTY) == null) {
File stateDir = getStateLocation().toFile();
File configFile = new File(stateDir, LOGBACK_DEFAULT_FILENAME);
if (!configFile.isFile()) {
try (InputStream is = bundleContext.getBundle().getEntry(LOGBACK_DEFAULT_FILENAME).openStream(); FileOutputStream fos = new FileOutputStream(configFile)) {
for (byte[] buffer = new byte[1024 * 4];;) {
int n = is.read(buffer);
if (n < 0) {
break;
}
fos.write(buffer, 0, n);
}
}
}
// ContextInitializer.CONFIG_FILE_PROPERTY
System.setProperty(LOGBACK_CONFIG_FILE_PROPERTY, configFile.getAbsolutePath());
}

if (JDTEnvironmentUtils.isSyntaxServer()) {
disableServices();
preferenceManager = new PreferenceManager();
Expand All @@ -201,24 +220,6 @@ public void start(BundleContext bundleContext) throws Exception {
if (System.getProperty(AssistOptions.PROPERTY_SubstringMatch) == null) {
System.setProperty(AssistOptions.PROPERTY_SubstringMatch, "false");
}

if (isDebug && System.getProperty(LOGBACK_CONFIG_FILE_PROPERTY) == null) {
File stateDir = getStateLocation().toFile();
File configFile = new File(stateDir, LOGBACK_DEFAULT_FILENAME);
if (!configFile.isFile()) {
try (InputStream is = bundleContext.getBundle().getEntry(LOGBACK_DEFAULT_FILENAME).openStream(); FileOutputStream fos = new FileOutputStream(configFile)) {
for (byte[] buffer = new byte[1024 * 4];;) {
int n = is.read(buffer);
if (n < 0) {
break;
}
fos.write(buffer, 0, n);
}
}
}
// ContextInitializer.CONFIG_FILE_PROPERTY
System.setProperty(LOGBACK_CONFIG_FILE_PROPERTY, configFile.getAbsolutePath());
}
}

private void disableServices() {
Expand Down

0 comments on commit 03aa9ab

Please sign in to comment.