summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTroy Bishop2012-12-04 17:35:21 (EST)
committerCurtis Windatt2012-12-04 17:35:21 (EST)
commit8d46594bf85c01f5e7f84c9f4485c4659cbf2fc5 (patch)
treed2ddaaff9be7b5c0a63c4ba79a7d13035eeb6cfe
parentf019f984b90e5b5b1564b0c938ff6ba6366150e2 (diff)
downloadeclipse.pde.ui-8d46594bf85c01f5e7f84c9f4485c4659cbf2fc5.zip
eclipse.pde.ui-8d46594bf85c01f5e7f84c9f4485c4659cbf2fc5.tar.gz
eclipse.pde.ui-8d46594bf85c01f5e7f84c9f4485c4659cbf2fc5.tar.bz2
Bug 395632 - Tracing UI bundle declarative service causes the workspacev20121204-223521I20121204-2230
prompt to not display
-rw-r--r--ui/org.eclipse.ui.trace/src/org/eclipse/ui/trace/internal/TracingStartupMonitor.java50
-rw-r--r--ui/org.eclipse.ui.trace/src/org/eclipse/ui/trace/internal/TracingUIActivator.java52
2 files changed, 84 insertions, 18 deletions
diff --git a/ui/org.eclipse.ui.trace/src/org/eclipse/ui/trace/internal/TracingStartupMonitor.java b/ui/org.eclipse.ui.trace/src/org/eclipse/ui/trace/internal/TracingStartupMonitor.java
new file mode 100644
index 0000000..ebb4530
--- /dev/null
+++ b/ui/org.eclipse.ui.trace/src/org/eclipse/ui/trace/internal/TracingStartupMonitor.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ui.trace.internal;
+
+import org.eclipse.osgi.service.runnable.StartupMonitor;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * A {@link StartupMonitor} implementation for initializing the tracing preferences after the application has started.
+ */
+public class TracingStartupMonitor implements StartupMonitor {
+
+ private ServiceRegistration<StartupMonitor> registration;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osgi.service.runnable.StartupMonitor#update()
+ */
+ public void update() {
+
+ // empty implementation
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osgi.service.runnable.StartupMonitor#applicationRunning()
+ */
+ public void applicationRunning() {
+
+ // bug 395632: The application is running now so it's safe to initialize the preferences
+ TracingUIActivator.getDefault().initPreferences();
+ // Unregister this service as its purpose is complete
+ registration.unregister();
+
+ }
+
+ /**
+ * Set the service registration on this monitor so it can unregister itself after {@link #applicationRunning()}
+ * @param registration the service registration returned when registering a {@link StartupMonitor} service or <code>null</code>
+ */
+ public void setRegistration(ServiceRegistration<StartupMonitor> registration) {
+ this.registration = registration;
+ }
+} \ No newline at end of file
diff --git a/ui/org.eclipse.ui.trace/src/org/eclipse/ui/trace/internal/TracingUIActivator.java b/ui/org.eclipse.ui.trace/src/org/eclipse/ui/trace/internal/TracingUIActivator.java
index 28f75bd..4892050 100644
--- a/ui/org.eclipse.ui.trace/src/org/eclipse/ui/trace/internal/TracingUIActivator.java
+++ b/ui/org.eclipse.ui.trace/src/org/eclipse/ui/trace/internal/TracingUIActivator.java
@@ -11,14 +11,13 @@
package org.eclipse.ui.trace.internal;
import java.io.File;
-import java.util.Hashtable;
-import java.util.Map;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.service.debug.DebugOptions;
+import java.util.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.osgi.service.runnable.StartupMonitor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.trace.internal.utils.*;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
/**
* The activator class controls the plug-in life cycle
@@ -54,20 +53,20 @@ public class TracingUIActivator extends AbstractUIPlugin {
// Set option so we know debug mode is set, not preferences
DebugOptionsHandler.setLaunchInDebugMode(true);
- } else if (PreferenceHandler.isTracingEnabled()) {
- // User has previously enabled tracing options
- DebugOptionsHandler.setDebugEnabled(true);
- DebugOptionsHandler.getDebugOptions().setFile(new File(PreferenceHandler.getFilePath()));
- System.setProperty(TracingConstants.PROP_TRACE_SIZE_MAX, String.valueOf(PreferenceHandler.getMaxFileSize()));
- System.setProperty(TracingConstants.PROP_TRACE_FILE_MAX, String.valueOf(PreferenceHandler.getMaxFileCount()));
-
- Map<String, String> prefs = PreferenceHandler.getPreferenceProperties();
- DebugOptionsHandler.getDebugOptions().setOptions(prefs);
+ } else {
+ // bug 395632: see if the instance location is defined. if not then defer accessing
+ // the preferences until it is defined by being notified via the org.eclipse.osgi.service.runnable.StartupMonitor
+ // service
+ if (!Platform.getInstanceLocation().isSet()) {
+ // register a startup monitor to notify us when the application is running
+ final TracingStartupMonitor startupMonitor = new TracingStartupMonitor();
+ final Dictionary<String, ?> properties = new Hashtable<String, Object>(1);
+ ServiceRegistration<StartupMonitor> registration = context.registerService(StartupMonitor.class, startupMonitor, properties);
+ startupMonitor.setRegistration(registration);
+ } else {
+ this.initPreferences();
+ }
}
-
- final Hashtable<String, String> props = new Hashtable<String, String>(4);
- props.put(DebugOptions.LISTENER_SYMBOLICNAME, TracingConstants.BUNDLE_ID);
-
}
@Override
@@ -91,6 +90,23 @@ public class TracingUIActivator extends AbstractUIPlugin {
}
}
+ /**
+ * Initialize the tracing preferences if tracing is enabled.
+ */
+ protected final void initPreferences() {
+
+ if (PreferenceHandler.isTracingEnabled()) {
+ // User has previously enabled tracing options
+ DebugOptionsHandler.setDebugEnabled(true);
+ DebugOptionsHandler.getDebugOptions().setFile(new File(PreferenceHandler.getFilePath()));
+ System.setProperty(TracingConstants.PROP_TRACE_SIZE_MAX, String.valueOf(PreferenceHandler.getMaxFileSize()));
+ System.setProperty(TracingConstants.PROP_TRACE_FILE_MAX, String.valueOf(PreferenceHandler.getMaxFileCount()));
+
+ Map<String, String> prefs = PreferenceHandler.getPreferenceProperties();
+ DebugOptionsHandler.getDebugOptions().setOptions(prefs);
+ }
+ }
+
/** The shared instance */
private static TracingUIActivator plugin = null;