Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvladt2011-02-17 20:03:43 +0000
committervladt2011-02-17 20:03:43 +0000
commit52d3db5c53c2d3fe6a34886bb0139ef3b2da1032 (patch)
tree2de4c521a258fb0637704bbfca281754502bce6c
parentea432ab47e2dddc985a348cdfe6dc654e046d102 (diff)
downloadm2e-core-52d3db5c53c2d3fe6a34886bb0139ef3b2da1032.tar.gz
m2e-core-52d3db5c53c2d3fe6a34886bb0139ef3b2da1032.tar.xz
m2e-core-52d3db5c53c2d3fe6a34886bb0139ef3b2da1032.zip
335872: Start the m2e logback bundle by default and configure logback only after the eclipse instance location is initialized
-rw-r--r--org.eclipse.m2e.core/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java17
-rw-r--r--org.eclipse.m2e.logback.configuration/META-INF/p2.inf1
-rw-r--r--org.eclipse.m2e.logback.configuration/build.properties3
-rw-r--r--org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java81
5 files changed, 58 insertions, 47 deletions
diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
index 0eca3f36..10a56c81 100644
--- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
@@ -20,8 +20,7 @@ Require-Bundle:
com.ibm.icu;bundle-version="4.0.1",
org.slf4j.api;bundle-version="1.5.11",
com.ning.async-http-client;bundle-version="1.4.1",
- org.jboss.netty;bundle-version="3.2.3",
- org.eclipse.m2e.logback.configuration;bundle-version="0.13.0";resolution:=optional
+ org.jboss.netty;bundle-version="3.2.3"
Eclipse-LazyStart: true
Bundle-ClassPath: .
Bundle-RequiredExecutionEnvironment: J2SE-1.5,
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
index 2e139e57..67bc4e5a 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
@@ -13,7 +13,6 @@ package org.eclipse.m2e.core;
import java.io.File;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
@@ -84,7 +83,7 @@ import org.eclipse.m2e.core.repository.IRepositoryRegistry;
public class MavenPlugin extends Plugin {
private static final String M2E_LOGBACK_BUNDLE_ID = "org.eclipse.m2e.logback.configuration";
- private final Logger log;
+ private final Logger log = LoggerFactory.getLogger(MavenPlugin.class);
// preferences
private static final String PREFS_ARCHETYPES = "archetypesInfo.xml"; //$NON-NLS-1$
@@ -135,20 +134,6 @@ public class MavenPlugin extends Plugin {
System.err.println("### executing constructor " + IMavenConstants.PLUGIN_ID); //$NON-NLS-1$
new Throwable().printStackTrace();
}
-
- Bundle m2eLogbackBundle = Platform.getBundle(M2E_LOGBACK_BUNDLE_ID);
- if(m2eLogbackBundle != null) {
- if(m2eLogbackBundle.getState() != Bundle.ACTIVE) {
- try {
- m2eLogbackBundle.start(Bundle.START_TRANSIENT);
- } catch(Exception e) {
- // Since the logging bundle was not initialized, we can't use slf4j to log this error
- e.printStackTrace();
- }
- }
- }
-
- log = LoggerFactory.getLogger(MavenPlugin.class);
}
public IMaven getMaven() {
diff --git a/org.eclipse.m2e.logback.configuration/META-INF/p2.inf b/org.eclipse.m2e.logback.configuration/META-INF/p2.inf
new file mode 100644
index 00000000..fe8e606a
--- /dev/null
+++ b/org.eclipse.m2e.logback.configuration/META-INF/p2.inf
@@ -0,0 +1 @@
+instructions.configure = markStarted(started: true); \ No newline at end of file
diff --git a/org.eclipse.m2e.logback.configuration/build.properties b/org.eclipse.m2e.logback.configuration/build.properties
index e5f876ad..11399196 100644
--- a/org.eclipse.m2e.logback.configuration/build.properties
+++ b/org.eclipse.m2e.logback.configuration/build.properties
@@ -3,4 +3,5 @@ output.. = target/classes/
bin.includes = META-INF/,\
.,\
defaultLogbackConfiguration/,\
- OSGI-INF/l10n/bundle.properties
+ OSGI-INF/l10n/bundle.properties,\
+ OSGI-INF/
diff --git a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java
index 5de2236a..375e7c2d 100644
--- a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java
+++ b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java
@@ -15,6 +15,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
+import java.util.Timer;
+import java.util.TimerTask;
import org.osgi.framework.BundleContext;
import org.slf4j.ILoggerFactory;
@@ -31,7 +33,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.service.datalocation.Location;
+
public class LogPlugin extends Plugin {
private static final String PLUGIN_ID = "org.eclipse.m2e.logback.configuration"; //$NON-NLS-1$
@@ -39,43 +41,64 @@ public class LogPlugin extends Plugin {
// This has to match the log directory in defaultLogbackConfiguration/logback.xml
public static final String PROPERTY_LOG_DIRECTORY = "org.eclipse.m2e.log.dir"; //$NON-NLS-1$
+ private BundleContext bundleContext;
+
+ private boolean isConfigured;
+
+ private Timer timer = new Timer("logback configurator timer");
+
+ private TimerTask timerTask = new TimerTask() {
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ if(Platform.getInstanceLocation().isSet()) {
+ timer.cancel();
+ configureLogback();
+ }
+ }
+ };
+
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
+ bundleContext = context;
- configureLogger(context);
-
- LogHelper.logJavaProperties(LoggerFactory.getLogger(LogPlugin.class));
+ if(System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY) != null) {
+ // The standard logback config file property is set - don't force our configuration
+ systemOut(ContextInitializer.CONFIG_FILE_PROPERTY + "=" //$NON-NLS-1$
+ + System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY));
+ } else {
+ if(!Platform.getInstanceLocation().isSet()) {
+ systemOut("The " + PLUGIN_ID + " bundle was activated before the platform instance location was initialized."); //$NON-NLS-1$ //$NON-NLS-2$
+ timer.schedule(timerTask, 0 /*delay*/, 50 /*period*/);
+ } else {
+ configureLogback();
+ }
+ }
}
private static void systemOut(String message) {
- System.out.println(PLUGIN_ID + ": " + message);
+ System.out.println(PLUGIN_ID + ": " + message); //$NON-NLS-1$
}
private static void systemErr(String message) {
- System.err.println(PLUGIN_ID + ": " + message);
+ System.err.println(PLUGIN_ID + ": " + message); //$NON-NLS-1$
}
- private void configureLogger(BundleContext context) {
- if(System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY) != null) {
- systemOut(ContextInitializer.CONFIG_FILE_PROPERTY + "="
- + System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY));
+ private synchronized void configureLogback() {
+ if(isConfigured) {
+ systemOut("Logback was configured already"); //$NON-NLS-1$
return;
}
- Location instanceLocation = Platform.getInstanceLocation();
- if(!instanceLocation.isSet()) {
- new Exception("The " + PLUGIN_ID + " bundle was activated before the platform instance location was initialized.");
- return;
- }
- File stateDir = getStateLocation().toFile();
-
- File configFile = new File(stateDir, "logback." + context.getBundle().getVersion().toString() + ".xml");
- systemOut("Logback config file: " + configFile.getAbsolutePath());
try {
+ File stateDir = getStateLocation().toFile();
+
+ File configFile = new File(stateDir, "logback." + bundleContext.getBundle().getVersion().toString() + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ systemOut("Logback config file: " + configFile.getAbsolutePath()); //$NON-NLS-1$
+
if(!configFile.isFile()) {
// Copy the default config file to the actual config file
- InputStream is = context.getBundle().getEntry("defaultLogbackConfiguration/logback.xml").openStream();
+ InputStream is = bundleContext.getBundle().getEntry("defaultLogbackConfiguration/logback.xml").openStream(); //$NON-NLS-1$
try {
configFile.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(configFile);
@@ -95,13 +118,15 @@ public class LogPlugin extends Plugin {
}
}
- if(System.getProperty(PROPERTY_LOG_DIRECTORY, "").length() <= 0) {
+ if(System.getProperty(PROPERTY_LOG_DIRECTORY, "").length() <= 0) { //$NON-NLS-1$
System.setProperty(PROPERTY_LOG_DIRECTORY, stateDir.getAbsolutePath());
}
loadConfiguration(configFile.toURL());
+
+ isConfigured = true;
} catch(Exception e) {
e.printStackTrace();
- getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, "Exception while setting up logging:" + e.getMessage(), e));
+ getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, "Exception while setting up logging:" + e.getMessage(), e)); //$NON-NLS-1$
return;
}
}
@@ -111,9 +136,7 @@ public class LogPlugin extends Plugin {
int i = 0;
while(loggerFactory instanceof SubstituteLoggerFactory && i < 100) {
// slf4j is initialization phase
- if(loggerFactory != null) {
- systemOut("SLF4J logger factory class: " + loggerFactory.getClass().getName());
- }
+ systemOut("SLF4J logger factory class: " + loggerFactory.getClass().getName()); //$NON-NLS-1$
try {
Thread.sleep(50);
} catch(InterruptedException e) {
@@ -125,15 +148,15 @@ public class LogPlugin extends Plugin {
if(!(loggerFactory instanceof LoggerContext)) {
if(loggerFactory == null) {
// Is it possible?
- systemErr("SLF4J logger factory is null");
+ systemErr("SLF4J logger factory is null"); //$NON-NLS-1$
return;
}
- systemErr("SLF4J logger factory is not an instance of LoggerContext: "
+ systemErr("SLF4J logger factory is not an instance of LoggerContext: " //$NON-NLS-1$
+ loggerFactory.getClass().getName());
return;
}
- systemOut("Initializing logback");
+ systemOut("Initializing logback"); //$NON-NLS-1$
LoggerContext lc = (LoggerContext) loggerFactory;
lc.reset();
@@ -142,5 +165,7 @@ public class LogPlugin extends Plugin {
configurator.doConfigure(configFile);
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
+
+ LogHelper.logJavaProperties(LoggerFactory.getLogger(LogPlugin.class));
}
}

Back to the top