[344289] Fix FindBug warnings in WAR Products
Work in progress
diff --git a/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/FrameworkCorePlugin.java b/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/FrameworkCorePlugin.java
index 80a9b18..9f0ddd5 100644
--- a/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/FrameworkCorePlugin.java
+++ b/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/FrameworkCorePlugin.java
@@ -19,11 +19,15 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.osgi.service.debug.DebugOptions;
import org.eclipse.pde.core.project.IBundleProjectDescription;
import org.eclipse.pde.core.project.IBundleProjectService;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
public class FrameworkCorePlugin extends AbstractUIPlugin {
@@ -31,17 +35,43 @@
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.libra.framework.core"; //$NON-NLS-1$
- // The shared instance
- private static FrameworkCorePlugin plugin;
-
/**
* The constructor
*/
public FrameworkCorePlugin() {
super();
- plugin = this;
}
+ /**
+ * Tracing enabled?
+ * @return whether debug is enabled on the Platform (-debug) AND the {@value #PLUGIN_ID}/debug option
+ * is set to "true".
+ */
+ public static boolean isTraceEnabled() {
+ /* This implementation is a mix of
+ * https://wiki.eclipse.org/FAQ_How_do_I_use_the_platform_debug_tracing_facility
+ * and the previous (defacto deprecated) implementation in org.eclipse.core.runtime.Plugin
+ */
+ if (! Platform.inDebugMode()) return false;
+
+ Bundle bdl = FrameworkUtil.getBundle(FrameworkCorePlugin.class);
+ if (bdl == null){
+ throw new RuntimeException("Could not resolve my own OSGi bundle, something seriously wrong with the Framework!"); //$NON-NLS-1$
+ }
+ String key = bdl.getSymbolicName() + "/debug"; //$NON-NLS-1$
+
+ ServiceReference<DebugOptions> ref = bdl.getBundleContext().getServiceReference(DebugOptions.class);
+ DebugOptions service = ref == null ? null : bdl.getBundleContext().getService(ref);
+
+ // if platform debugging is enabled, check to see if this plugin is enabled for debugging
+ if (service != null){
+ if (! service.isDebugEnabled()) return false;
+ return service.getBooleanOption(key, false);
+ }
+
+ return "true".equalsIgnoreCase(Platform.getDebugOption(key));
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
@@ -49,7 +79,6 @@
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
- plugin = this;
}
/*
@@ -58,21 +87,9 @@
*/
@Override
public void stop(BundleContext context) throws Exception {
- plugin = null;
super.stop(context);
}
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static FrameworkCorePlugin getDefault() {
- return plugin;
- }
-
-
-
public static String getPreference(String id) {
return Platform.getPreferencesService().getString(PLUGIN_ID, id, "", null);
}
@@ -81,7 +98,6 @@
(new DefaultScope()).getNode(PLUGIN_ID).put(id, value);
}
-
public static IBundleProjectService getBundleProjectService() {
PDECore instance = PDECore.getDefault();
if (instance == null)
@@ -97,6 +113,5 @@
return null;
}
}
-
-
+
}
diff --git a/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/Trace.java b/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/Trace.java
index a6a003d..90277f0 100644
--- a/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/Trace.java
+++ b/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/Trace.java
@@ -32,8 +32,6 @@
"CONFIG ", "WARNING ", "SEVERE ", "FINER ", "FINEST "};
private static final String spacer = " ";
- private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm.ss.SSS");
-
static int pluginLength = -1;
/**
@@ -61,9 +59,6 @@
* @param t a throwable
*/
public static void trace(byte level, String s, Throwable t) {
- if (!FrameworkCorePlugin.getDefault().isDebugging())
- return;
-
trace(FrameworkCorePlugin.PLUGIN_ID, level, s, t);
}
@@ -78,9 +73,11 @@
if (pluginId == null || s == null)
return;
- if (!FrameworkCorePlugin.getDefault().isDebugging())
+ if (! isTraceEnabled())
return;
-
+
+ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm.ss.SSS");
+
StringBuffer sb = new StringBuffer(pluginId);
if (pluginId.length() > pluginLength)
pluginLength = pluginId.length();
@@ -105,6 +102,6 @@
* @return true if tracing is enabled
*/
public static boolean isTraceEnabled() {
- return FrameworkCorePlugin.getDefault().isDebugging();
+ return FrameworkCorePlugin.isTraceEnabled();
}
}
diff --git a/plugins/org.eclipse.libra.framework.editor.ui/src/org/eclipse/libra/framework/editor/ui/internal/EditorUIPlugin.java b/plugins/org.eclipse.libra.framework.editor.ui/src/org/eclipse/libra/framework/editor/ui/internal/EditorUIPlugin.java
index e3e4870..3566862 100644
--- a/plugins/org.eclipse.libra.framework.editor.ui/src/org/eclipse/libra/framework/editor/ui/internal/EditorUIPlugin.java
+++ b/plugins/org.eclipse.libra.framework.editor.ui/src/org/eclipse/libra/framework/editor/ui/internal/EditorUIPlugin.java
@@ -11,9 +11,13 @@
package org.eclipse.libra.framework.editor.ui.internal;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
/**
* @author Kaloyan Raev
@@ -22,20 +26,10 @@
public static final String PLUGIN_ID = "org.eclipse.libra.framework.editor";
- private static EditorUIPlugin plugin = null;
-
public EditorUIPlugin() {
super();
- plugin = this;
}
- public static EditorUIPlugin getDefault() {
- if (plugin == null) {
- plugin = new EditorUIPlugin();
- }
- return plugin;
- }
-
/**
* Constructs new IStatus object from the given String message.
*
@@ -60,7 +54,9 @@
* @param status status to log
*/
public static void log(IStatus status) {
- getDefault().getLog().log(status);
+ Bundle bdl = FrameworkUtil.getBundle(EditorUIPlugin.class);
+ ILog log = bdl==null ? null : Platform.getLog(bdl);
+ if (log!=null) log.log(status);
}
/**
diff --git a/plugins/org.eclipse.libra.framework.equinox.ui/src/org/eclipse/libra/framework/equinox/ui/EquinoxUIPlugin.java b/plugins/org.eclipse.libra.framework.equinox.ui/src/org/eclipse/libra/framework/equinox/ui/EquinoxUIPlugin.java
index 5a3468a..43e273f 100644
--- a/plugins/org.eclipse.libra.framework.equinox.ui/src/org/eclipse/libra/framework/equinox/ui/EquinoxUIPlugin.java
+++ b/plugins/org.eclipse.libra.framework.equinox.ui/src/org/eclipse/libra/framework/equinox/ui/EquinoxUIPlugin.java
@@ -11,26 +11,20 @@
*******************************************************************************/
+import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
public class EquinoxUIPlugin extends AbstractUIPlugin {
- protected static EquinoxUIPlugin singleton;
public static final String PLUGIN_ID = "org.eclipse.libra.framework.equinox.ui";
public EquinoxUIPlugin() {
super();
- singleton = this;
- }
-
- /**
- * Returns the singleton instance of this plugin.
- * @return org.eclipse.jst.server.tomcat.internal.TomcatUIPlugin
- */
- public static EquinoxUIPlugin getInstance() {
- return singleton;
}
/**
@@ -39,7 +33,9 @@
* @param status org.eclipse.core.runtime.IStatus
*/
public static void log(IStatus status) {
- getInstance().getLog().log(status);
+ Bundle bdl = FrameworkUtil.getBundle(EquinoxUIPlugin.class);
+ ILog log = bdl==null ? null : Platform.getLog(bdl);
+ if (log!=null) log.log(status);
}
/**
diff --git a/plugins/org.eclipse.libra.framework.equinox/src/org/eclipse/libra/framework/equinox/EquinoxPlugin.java b/plugins/org.eclipse.libra.framework.equinox/src/org/eclipse/libra/framework/equinox/EquinoxPlugin.java
index 564f1f9..73abb3f 100644
--- a/plugins/org.eclipse.libra.framework.equinox/src/org/eclipse/libra/framework/equinox/EquinoxPlugin.java
+++ b/plugins/org.eclipse.libra.framework.equinox/src/org/eclipse/libra/framework/equinox/EquinoxPlugin.java
@@ -21,15 +21,11 @@
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.libra.framework.equinox"; //$NON-NLS-1$
- // The shared instance
- private static EquinoxPlugin plugin;
-
/**
* The constructor
*/
public EquinoxPlugin() {
super();
- plugin = this;
}
/*
@@ -39,7 +35,6 @@
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
- plugin = this;
}
/*
@@ -48,21 +43,9 @@
*/
@Override
public void stop(BundleContext context) throws Exception {
- plugin = null;
super.stop(context);
}
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static EquinoxPlugin getDefault() {
- return plugin;
- }
-
-
-
public static String getPreference(String id) {
return Platform.getPreferencesService().getString(PLUGIN_ID, id, "", null);
}
@@ -81,5 +64,4 @@
return new EquinoxHandler();
}
-
}
diff --git a/plugins/org.eclipse.libra.framework.felix.ui/src/org/eclipse/libra/framework/felix/ui/FelixUIPlugin.java b/plugins/org.eclipse.libra.framework.felix.ui/src/org/eclipse/libra/framework/felix/ui/FelixUIPlugin.java
index 22cdc1e..f23e622 100644
--- a/plugins/org.eclipse.libra.framework.felix.ui/src/org/eclipse/libra/framework/felix/ui/FelixUIPlugin.java
+++ b/plugins/org.eclipse.libra.framework.felix.ui/src/org/eclipse/libra/framework/felix/ui/FelixUIPlugin.java
@@ -11,26 +11,20 @@
*******************************************************************************/
+import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
public class FelixUIPlugin extends AbstractUIPlugin {
- protected static FelixUIPlugin singleton;
public static final String PLUGIN_ID = "org.eclipse.libra.framework.felix.ui";
public FelixUIPlugin() {
super();
- singleton = this;
- }
-
- /**
- * Returns the singleton instance of this plugin.
- * @return org.eclipse.jst.server.tomcat.internal.TomcatUIPlugin
- */
- public static FelixUIPlugin getInstance() {
- return singleton;
}
/**
@@ -39,7 +33,9 @@
* @param status org.eclipse.core.runtime.IStatus
*/
public static void log(IStatus status) {
- getInstance().getLog().log(status);
+ Bundle bdl = FrameworkUtil.getBundle(FelixUIPlugin.class);
+ ILog log = bdl==null ? null : Platform.getLog(bdl);
+ if (log!=null) log.log(status);
}
/**
diff --git a/plugins/org.eclipse.libra.framework.felix/src/org/eclipse/libra/framework/felix/FelixPlugin.java b/plugins/org.eclipse.libra.framework.felix/src/org/eclipse/libra/framework/felix/FelixPlugin.java
index 336ba40..c616905 100644
--- a/plugins/org.eclipse.libra.framework.felix/src/org/eclipse/libra/framework/felix/FelixPlugin.java
+++ b/plugins/org.eclipse.libra.framework.felix/src/org/eclipse/libra/framework/felix/FelixPlugin.java
@@ -21,15 +21,11 @@
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.libra.framework.felix"; //$NON-NLS-1$
- // The shared instance
- private static FelixPlugin plugin;
-
/**
* The constructor
*/
public FelixPlugin() {
super();
- plugin = this;
}
/*
@@ -39,7 +35,6 @@
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
- plugin = this;
}
/*
@@ -48,21 +43,9 @@
*/
@Override
public void stop(BundleContext context) throws Exception {
- plugin = null;
super.stop(context);
}
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static FelixPlugin getDefault() {
- return plugin;
- }
-
-
-
public static String getPreference(String id) {
return Platform.getPreferencesService().getString(PLUGIN_ID, id, "", null);
}
@@ -81,5 +64,4 @@
return new Felix2Handler();
}
-
}
diff --git a/plugins/org.eclipse.libra.framework.jonas.ui/src/org/eclipse/libra/framework/jonas/ui/JonasUIPlugin.java b/plugins/org.eclipse.libra.framework.jonas.ui/src/org/eclipse/libra/framework/jonas/ui/JonasUIPlugin.java
index bab184c..d088eea 100644
--- a/plugins/org.eclipse.libra.framework.jonas.ui/src/org/eclipse/libra/framework/jonas/ui/JonasUIPlugin.java
+++ b/plugins/org.eclipse.libra.framework.jonas.ui/src/org/eclipse/libra/framework/jonas/ui/JonasUIPlugin.java
@@ -11,26 +11,20 @@
*******************************************************************************/
+import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
public class JonasUIPlugin extends AbstractUIPlugin {
- protected static JonasUIPlugin singleton;
public static final String PLUGIN_ID = "org.eclipse.libra.framework.jonas.ui";
public JonasUIPlugin() {
super();
- singleton = this;
- }
-
- /**
- * Returns the singleton instance of this plugin.
- * @return org.eclipse.jst.server.tomcat.internal.TomcatUIPlugin
- */
- public static JonasUIPlugin getInstance() {
- return singleton;
}
/**
@@ -39,7 +33,9 @@
* @param status org.eclipse.core.runtime.IStatus
*/
public static void log(IStatus status) {
- getInstance().getLog().log(status);
+ Bundle bdl = FrameworkUtil.getBundle(JonasUIPlugin.class);
+ ILog log = bdl==null ? null : Platform.getLog(bdl);
+ if (log!=null) log.log(status);
}
/**
diff --git a/plugins/org.eclipse.libra.framework.jonas/src/org/eclipse/libra/framework/jonas/JonasPlugin.java b/plugins/org.eclipse.libra.framework.jonas/src/org/eclipse/libra/framework/jonas/JonasPlugin.java
index 04da65a..16b2d8a 100644
--- a/plugins/org.eclipse.libra.framework.jonas/src/org/eclipse/libra/framework/jonas/JonasPlugin.java
+++ b/plugins/org.eclipse.libra.framework.jonas/src/org/eclipse/libra/framework/jonas/JonasPlugin.java
@@ -21,15 +21,11 @@
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.libra.framework.jonas"; //$NON-NLS-1$
- // The shared instance
- private static JonasPlugin plugin;
-
/**
* The constructor
*/
public JonasPlugin() {
super();
- plugin = this;
}
/*
@@ -39,7 +35,6 @@
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
- plugin = this;
}
/*
@@ -48,21 +43,9 @@
*/
@Override
public void stop(BundleContext context) throws Exception {
- plugin = null;
super.stop(context);
}
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static JonasPlugin getDefault() {
- return plugin;
- }
-
-
-
public static String getPreference(String id) {
return Platform.getPreferencesService().getString(PLUGIN_ID, id, "", null);
}
@@ -81,5 +64,4 @@
return new JonasHandler();
}
-
}
diff --git a/plugins/org.eclipse.libra.framework.knopflerfish.ui/src/org/eclipse/libra/framework/knopflerfish/ui/KnopflerfishUIPlugin.java b/plugins/org.eclipse.libra.framework.knopflerfish.ui/src/org/eclipse/libra/framework/knopflerfish/ui/KnopflerfishUIPlugin.java
index 56b184a..bfeee36 100644
--- a/plugins/org.eclipse.libra.framework.knopflerfish.ui/src/org/eclipse/libra/framework/knopflerfish/ui/KnopflerfishUIPlugin.java
+++ b/plugins/org.eclipse.libra.framework.knopflerfish.ui/src/org/eclipse/libra/framework/knopflerfish/ui/KnopflerfishUIPlugin.java
@@ -11,26 +11,20 @@
*******************************************************************************/
+import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
public class KnopflerfishUIPlugin extends AbstractUIPlugin {
- protected static KnopflerfishUIPlugin singleton;
public static final String PLUGIN_ID = "org.eclipse.libra.framework.knopflerfish.ui";
-
-
-
public KnopflerfishUIPlugin() {
super();
- singleton = this;
- }
-
-
- public static KnopflerfishUIPlugin getInstance() {
- return singleton;
}
/**
@@ -39,7 +33,9 @@
* @param status org.eclipse.core.runtime.IStatus
*/
public static void log(IStatus status) {
- getInstance().getLog().log(status);
+ Bundle bdl = FrameworkUtil.getBundle(KnopflerfishUIPlugin.class);
+ ILog log = bdl==null ? null : Platform.getLog(bdl);
+ if (log!=null) log.log(status);
}
/**
diff --git a/plugins/org.eclipse.libra.framework.knopflerfish/src/org/eclipse/libra/framework/knopflerfish/KnopflerfishPlugin.java b/plugins/org.eclipse.libra.framework.knopflerfish/src/org/eclipse/libra/framework/knopflerfish/KnopflerfishPlugin.java
index 70383df..17cdc05 100644
--- a/plugins/org.eclipse.libra.framework.knopflerfish/src/org/eclipse/libra/framework/knopflerfish/KnopflerfishPlugin.java
+++ b/plugins/org.eclipse.libra.framework.knopflerfish/src/org/eclipse/libra/framework/knopflerfish/KnopflerfishPlugin.java
@@ -21,15 +21,11 @@
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.libra.framework.knopflerfish"; //$NON-NLS-1$
- // The shared instance
- private static KnopflerfishPlugin plugin;
-
/**
* The constructor
*/
public KnopflerfishPlugin() {
super();
- plugin = this;
}
/*
@@ -39,7 +35,6 @@
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
- plugin = this;
}
/*
@@ -48,21 +43,9 @@
*/
@Override
public void stop(BundleContext context) throws Exception {
- plugin = null;
super.stop(context);
}
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static KnopflerfishPlugin getDefault() {
- return plugin;
- }
-
-
-
public static String getPreference(String id) {
return Platform.getPreferencesService().getString(PLUGIN_ID, id, "", null);
}
@@ -81,5 +64,4 @@
return new Knopflerfish31Handler();
}
-
}
diff --git a/plugins/org.eclipse.libra.framework.ui/src/org/eclipse/libra/framework/ui/FrameworkUIPlugin.java b/plugins/org.eclipse.libra.framework.ui/src/org/eclipse/libra/framework/ui/FrameworkUIPlugin.java
index 51c712e..add6158 100644
--- a/plugins/org.eclipse.libra.framework.ui/src/org/eclipse/libra/framework/ui/FrameworkUIPlugin.java
+++ b/plugins/org.eclipse.libra.framework.ui/src/org/eclipse/libra/framework/ui/FrameworkUIPlugin.java
@@ -56,13 +56,10 @@
public static final String IMG_PORT = "port";
public static final String IMG_PROJECT_MISSING = "projectMissing";
-
public static final String PREF_JDK_INSTALL_DIR = "jdkinstall";
-
public FrameworkUIPlugin() {
super();
- singleton = this;
}
protected ImageRegistry createImageRegistry() {