diff options
author | Uwe Stieber | 2012-11-23 11:59:29 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-11-23 12:00:11 +0000 |
commit | 2c43a1b5e56a84729b0f47e032c05313bb454a43 (patch) | |
tree | cb01e35d5be04285dcc76672c296f5f3c650c728 | |
parent | 7aeb78abbc0eac3c2a64183220e6f01312206537 (diff) | |
download | org.eclipse.tcf-2c43a1b5e56a84729b0f47e032c05313bb454a43.tar.gz org.eclipse.tcf-2c43a1b5e56a84729b0f47e032c05313bb454a43.tar.xz org.eclipse.tcf-2c43a1b5e56a84729b0f47e032c05313bb454a43.zip |
Target Explorer: Added property tester to test if a debugger has been launched already for a given context
6 files changed, 213 insertions, 31 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF index aa98599a8..07f12c8c7 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF @@ -38,6 +38,7 @@ Export-Package: org.eclipse.tcf.te.launch.core.activator;x-internal:=true, org.eclipse.tcf.te.launch.core.persistence.launchcontext, org.eclipse.tcf.te.launch.core.persistence.projects, org.eclipse.tcf.te.launch.core.preferences, + org.eclipse.tcf.te.launch.core.properties, org.eclipse.tcf.te.launch.core.selection, org.eclipse.tcf.te.launch.core.selection.interfaces, org.eclipse.tcf.te.launch.core.steps, diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml index 756dde536..97452e1eb 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml @@ -39,6 +39,13 @@ properties="isValidLaunchConfigType" type="java.lang.Object"> </propertyTester> + <propertyTester + class="org.eclipse.tcf.te.launch.core.properties.PropertyTester" + id="org.eclipse.tcf.te.launch.core.properties.PropertyTester" + namespace="org.eclipse.tcf.te.launch.core" + properties="isLaunched" + type="java.lang.Object"> + </propertyTester> </extension> <!-- Launch Step contributions --> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/properties/PropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/properties/PropertyTester.java new file mode 100644 index 000000000..28e7ca609 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/properties/PropertyTester.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.launch.core.properties; + +import org.eclipse.tcf.te.runtime.services.ServiceManager; +import org.eclipse.tcf.te.runtime.services.interfaces.IDebugService; + + +/** + * Launch framework property tester implementation. + */ +public class PropertyTester extends org.eclipse.core.expressions.PropertyTester { + + /* (non-Javadoc) + * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object) + */ + @Override + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + + // "isLaunched": Checks if the debugger has been attached for the given context + if ("isLaunched".equals(property) && expectedValue instanceof Boolean) { //$NON-NLS-1$ + IDebugService dbgService = ServiceManager.getInstance().getService(receiver, IDebugService.class, false); + if (dbgService != null) { + return ((Boolean)expectedValue).booleanValue() == dbgService.isLaunched(receiver); + } + } + + return false; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/IDebugService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/IDebugService.java index b5fc8e4d7..7a1aa975b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/IDebugService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/IDebugService.java @@ -1,31 +1,39 @@ -/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.runtime.services.interfaces;
-
-import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
-import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-
-/**
- * Debug service.
- * <p>
- * Allow to start and control the debugger for a set of given debug contexts.
- */
-public interface IDebugService extends IService {
-
- /**
- * Launches a debug session for the given context and attaches to it. The attach
- * can be parameterized via the data properties.
- *
- * @param context The debug context. Must not be <code>null</code>.
- * @param data The data properties to parameterize the attach. Must not be <code>null</code>.
- * @param callback The callback to invoke once the operation completed. Must not be <code>null</code>.
- */
- public void attach(Object context, IPropertiesContainer data, ICallback callback);
-}
+/******************************************************************************* + * Copyright (c) 2011 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.runtime.services.interfaces; + +import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; +import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; + +/** + * Debug service. + * <p> + * Allow to start and control the debugger for a set of given debug contexts. + */ +public interface IDebugService extends IService { + + /** + * Launches a debug session for the given context and attaches to it. The attach + * can be parameterized via the data properties. + * + * @param context The debug context. Must not be <code>null</code>. + * @param data The data properties to parameterize the attach. Must not be <code>null</code>. + * @param callback The callback to invoke once the operation completed. Must not be <code>null</code>. + */ + public void attach(Object context, IPropertiesContainer data, ICallback callback); + + /** + * Returns if or if not the debugger has been launched for the given context. + * + * @param context The debug context. Must not be <code>null</code>. + * @return <code>True</code> if the debugger has been launched for the context, <code>false</code> otherwise. + */ + public boolean isLaunched(Object context); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/internal/services/DebugService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/internal/services/DebugService.java index faae61e9c..3a34d5811 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/internal/services/DebugService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/internal/services/DebugService.java @@ -10,12 +10,15 @@ package org.eclipse.tcf.te.tcf.launch.ui.internal.services; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.ILaunchesListener; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.launch.core.lm.LaunchManager; @@ -38,6 +41,19 @@ import org.eclipse.tcf.te.tcf.launch.core.interfaces.ILaunchTypes; * Debug service implementations for TCF contexts. */ public class DebugService extends AbstractService implements IDebugService { + // Reference to the launches listener + private final ILaunchesListener listener; + + /** + * Constructor + */ + public DebugService() { + super(); + + // Create and register the launches listener instance + listener = new DebugServicesLaunchesListener(); + DebugPlugin.getDefault().getLaunchManager().addLaunchListener(listener); + } /* (non-Javadoc) * @see org.eclipse.tcf.te.runtime.services.interfaces.IDebugService#attach(java.lang.Object, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) @@ -114,4 +130,35 @@ public class DebugService extends AbstractService implements IDebugService { callback.done(this, Status.OK_STATUS); } } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.services.interfaces.IDebugService#isLaunched(java.lang.Object) + */ + @Override + public boolean isLaunched(Object context) { + Assert.isNotNull(context); + + boolean isLaunched = false; + + if (context instanceof IModelNode) { + ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); + for (ILaunch launch : launches) { + try { + if (launch.getLaunchConfiguration().getType().getIdentifier().equals(ILaunchTypes.ATTACH) && !launch.isTerminated()) { + IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(launch.getLaunchConfiguration()); + if (contexts != null && contexts.length == 1 && contexts[0].equals(context)) { + isLaunched = true; + break; + } + } + } catch (CoreException e) { + if (Platform.inDebugMode()) e.printStackTrace(); + } + } + } + + System.out.println("DebugService.isLaunched: " + isLaunched); //$NON-NLS-1$ + + return isLaunched; + } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/internal/services/DebugServicesLaunchesListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/internal/services/DebugServicesLaunchesListener.java new file mode 100644 index 000000000..c82b15a51 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/internal/services/DebugServicesLaunchesListener.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.launch.ui.internal.services; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchesListener2; +import org.eclipse.tcf.te.launch.core.persistence.launchcontext.LaunchContextsPersistenceDelegate; +import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode; +import org.eclipse.tcf.te.tcf.launch.core.interfaces.ILaunchTypes; + +/** + * Debug service launches listener implementation + */ +public class DebugServicesLaunchesListener implements ILaunchesListener2 { + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchesListener#launchesRemoved(org.eclipse.debug.core.ILaunch[]) + */ + @Override + public void launchesRemoved(ILaunch[] launches) { + firePropertyChange(launches); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchesListener#launchesAdded(org.eclipse.debug.core.ILaunch[]) + */ + @Override + public void launchesAdded(ILaunch[] launches) { + firePropertyChange(launches); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchesListener#launchesChanged(org.eclipse.debug.core.ILaunch[]) + */ + @Override + public void launchesChanged(ILaunch[] launches) { +// firePropertyChange(launches); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchesListener2#launchesTerminated(org.eclipse.debug.core.ILaunch[]) + */ + @Override + public void launchesTerminated(ILaunch[] launches) { + firePropertyChange(launches); + } + + /** + * Fires a property change event for the watched context if one of the given + * launches matches. + * + * @param launches The launches. Must not be <code>null</code>. + * @param unregister <code>True</code> to unregister the listener if a matching launch is found, <code>false</code> otherwise. + */ + protected void firePropertyChange(ILaunch[] launches) { + Assert.isNotNull(launches); + + for (ILaunch launch : launches) { + try { + if (launch.getLaunchConfiguration().getType().getIdentifier().equals(ILaunchTypes.ATTACH)) { + IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(launch.getLaunchConfiguration()); + if (contexts != null && contexts.length == 1 && contexts[0] != null) { + contexts[0].fireChangeEvent("dbgLaunchedState", null, null); //$NON-NLS-1$ + } + } + } catch (CoreException e) { + if (Platform.inDebugMode()) e.printStackTrace(); + } + } + } + +} |