diff options
author | Tobias Schwarz | 2014-04-15 12:51:27 +0000 |
---|---|---|
committer | Tobias Schwarz | 2014-04-15 12:51:27 +0000 |
commit | f6398aaacbd83059a8ba1553b447b9b85ca681e5 (patch) | |
tree | 97fd2349b69a3e328d8c267f90b0e4daf6106bcc | |
parent | 40a80b8b7408d584a9e73c67fe79c07a3abf0c4a (diff) | |
download | org.eclipse.tcf-f6398aaacbd83059a8ba1553b447b9b85ca681e5.tar.gz org.eclipse.tcf-f6398aaacbd83059a8ba1553b447b9b85ca681e5.tar.xz org.eclipse.tcf-f6398aaacbd83059a8ba1553b447b9b85ca681e5.zip |
Target Explorer: extend query service
6 files changed, 140 insertions, 68 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/handler/AbstractDiagnosticsCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/handler/AbstractDiagnosticsCommandHandler.java index 8fd221a63..089f320af 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/handler/AbstractDiagnosticsCommandHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/handler/AbstractDiagnosticsCommandHandler.java @@ -76,9 +76,7 @@ public abstract class AbstractDiagnosticsCommandHandler extends AbstractHandler final IPeerNode node = (IPeerNode)element; IPeerModelQueryService service = node.getModel().getService(IPeerModelQueryService.class); - String remoteServices = service != null ? service.queryRemoteServices(node) : null; - - if (remoteServices != null && remoteServices.contains(IDiagnostics.NAME)) { + if (service != null && service.hasRemoteService(node, IDiagnostics.NAME)) { runDiagnostics(node, shell); } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelQueryService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelQueryService.java index 330925b89..09de473a4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelQueryService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelQueryService.java @@ -17,28 +17,53 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; public interface IPeerModelQueryService extends IPeerModelService { /** - * Query the list of available local services for the given peer node. - * <p> - * <b>Note:</b> The result of the query is cached within the given peer - * node and subsequent calls will return immediately with the cached value. - * <p> + * Returns the list of available local services. * <b>Note:</b> This method must be called outside the TCF dispatch thread. * * @param node The peer node. Must not be <code>null</code>. - * @param done The client callback. Must not be <code>null</code>. + * @return List of local services or null if target is not connected. */ - public String queryLocalServices(IPeerNode node); + public String[] queryLocalServices(IPeerNode node); /** - * Query the list of available remote services for the given peer node. - * <p> - * <b>Note:</b> The result of the query is cached within the given peer - * node and subsequent calls will return immediately with the cached value. - * <p> + * Returns the list of available remote services. * <b>Note:</b> This method must be called outside the TCF dispatch thread. * * @param node The peer node. Must not be <code>null</code>. - * @param done The client callback. Must not be <code>null</code>. + * @return List of remote services or null if target is not connected. */ - public String queryRemoteServices(IPeerNode node); + public String[] queryRemoteServices(IPeerNode node); + + /** + * Returns the list of offline services. + * <b>Note:</b> This method must be called outside the TCF dispatch thread. + * + * @param node The peer node. Must not be <code>null</code>. + * @return List of offline services or empty list. + */ + public String[] queryOfflineServices(IPeerNode node); + + /** + * Check if the given local services are available on the given target. + * @param node The peer node. Must not be <code>null</code>. + * @param service List of services. + * @return <code>true</code> if all services are available. + */ + public boolean hasLocalService(IPeerNode node, String... service); + + /** + * Check if the given remote services are available on the given target. + * @param node The peer node. Must not be <code>null</code>. + * @param service List of services. + * @return <code>true</code> if all services are available. + */ + public boolean hasRemoteService(IPeerNode node, String... service); + + /** + * Check if the given offline services are available on the given target. + * @param node The peer node. Must not be <code>null</code>. + * @param service List of services. + * @return <code>true</code> if all services are available. + */ + public boolean hasOfflineService(IPeerNode node, String... service); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelLookupService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelLookupService.java index 364ec04c7..16c42c621 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelLookupService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelLookupService.java @@ -109,43 +109,11 @@ public class PeerModelLookupService extends AbstractPeerModelService implements List<IPeerNode> nodes = new ArrayList<IPeerNode>(); for (IPeerNode candidate : model.getPeerNodes()) { - String services = queryService.queryLocalServices(candidate); - - boolean matchesExpectations = true; - - // Ignore the local services if no expectations are set - if (expectedLocalServices != null && expectedLocalServices.length > 0) { - if (services != null) { - for (String service : expectedLocalServices) { - if (!services.contains(service)) { - matchesExpectations = false; - break; - } - } - } else { - matchesExpectations = false; - } - } - - if (!matchesExpectations) continue; - - services = queryService.queryRemoteServices(candidate); - - // Ignore the remote services if no expectations are set - if (expectedRemoteServices != null && expectedRemoteServices.length > 0) { - if (services != null) { - for (String service : expectedRemoteServices) { - if (!services.contains(service)) { - matchesExpectations = false; - break; - } - } - } else { - matchesExpectations = false; - } + if (queryService != null && + (expectedLocalServices == null || queryService.hasLocalService(candidate, expectedLocalServices)) && + (expectedRemoteServices == null || queryService.hasRemoteService(candidate, expectedRemoteServices))) { + nodes.add(candidate); } - - if (matchesExpectations) nodes.add(candidate); } return nodes.toArray(new IPeerNode[nodes.size()]); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelQueryService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelQueryService.java index 630a8f2c5..69a48b86e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelQueryService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelQueryService.java @@ -9,6 +9,8 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.locator.services; +import java.util.Arrays; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.runtime.Assert; @@ -36,7 +38,7 @@ public class PeerModelQueryService extends AbstractPeerModelService implements I * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService#queryLocalServices(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode) */ @Override - public String queryLocalServices(final IPeerNode node) { + public String[] queryLocalServices(final IPeerNode node) { Assert.isNotNull(node); final AtomicReference<String> services = new AtomicReference<String>(); @@ -47,14 +49,18 @@ public class PeerModelQueryService extends AbstractPeerModelService implements I } }); - return services.get(); + if (services.get() != null) { + String[] local = services.get().split(",\\s*"); //$NON-NLS-1$ + return local; + } + return null; } /* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService#queryRemoteServices(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode) */ @Override - public String queryRemoteServices(final IPeerNode node) { + public String[] queryRemoteServices(final IPeerNode node) { Assert.isNotNull(node); final AtomicReference<String> services = new AtomicReference<String>(); @@ -65,6 +71,92 @@ public class PeerModelQueryService extends AbstractPeerModelService implements I } }); - return services.get(); + if (services.get() != null) { + String[] remote = services.get().split(",\\s*"); //$NON-NLS-1$ + return remote; + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService#queryOfflineServices(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode) + */ + @Override + public String[] queryOfflineServices(final IPeerNode node) { + Assert.isNotNull(node); + + final AtomicReference<String> services = new AtomicReference<String>(); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + services.set(node.getPeer().getAttributes().get(IPeerNodeProperties.PROP_OFFLINE_SERVICES)); + } + }); + + if (services.get() != null) { + String[] offline = services.get().split(",\\s*"); //$NON-NLS-1$ + return offline; + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService#hasLocalService(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode, java.lang.String[]) + */ + @Override + public boolean hasLocalService(IPeerNode node, String... service) { + String[] localServices = queryLocalServices(node); + if (localServices == null || localServices.length == 0) { + return false; + } + List<String> local = Arrays.asList(localServices); + for (String s : service) { + if (!local.contains(s)) { + return false; + } + } + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService#hasRemoteService(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode, java.lang.String[]) + */ + @Override + public boolean hasRemoteService(IPeerNode node, String... service) { + String[] remoteServices = queryRemoteServices(node); + if (remoteServices == null || remoteServices.length == 0) { + return false; + } + List<String> remote = Arrays.asList(remoteServices); + if (remote == null || remote.isEmpty()) { + return false; + } + for (String s : service) { + if (!remote.contains(s)) { + return false; + } + } + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService#hasOfflineService(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode, java.lang.String[]) + */ + @Override + public boolean hasOfflineService(IPeerNode node, String... service) { + String[] services = queryRemoteServices(node); + if (services == null) { + services = queryOfflineServices(node); + } + if (services == null || services.length == 0) { + return false; + } + List<String> remoteOrOfflineServices = Arrays.asList(services); + for (String s : service) { + if (!remoteOrOfflineServices.contains(s)) { + return false; + } + } + return true; } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/StartDebuggerStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/StartDebuggerStep.java index 337d025ef..a7c9b3629 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/StartDebuggerStep.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/StartDebuggerStep.java @@ -31,7 +31,6 @@ import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; import org.eclipse.tcf.te.tcf.locator.interfaces.IStepAttributes; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService; /** * Start debugger step implementation. @@ -81,8 +80,6 @@ public class StartDebuggerStep extends AbstractPeerNodeStep { @Override public void run() { // Don't attach the debugger if no run control is provided by the target - final IPeerModelQueryService queryService = node.getModel().getService(IPeerModelQueryService.class); - Assert.isNotNull(queryService); String remoteServices = node.getStringProperty(IPeerNodeProperties.PROP_REMOTE_SERVICES); Assert.isNotNull(remoteServices); boolean canAttachDbg = false; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/PeerNodeFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/PeerNodeFactory.java index c9eaa05d5..d0d4d93e8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/PeerNodeFactory.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/PeerNodeFactory.java @@ -14,10 +14,8 @@ import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService; import org.eclipse.tcf.te.tcf.locator.model.ModelManager; import org.eclipse.tcf.te.ui.views.editor.EditorInput; @@ -67,12 +65,6 @@ public class PeerNodeFactory implements IElementFactory { Protocol.invokeAndWait(runnable2); } - - if (node.get() != null) { - IPeerModel model = node.get().getModel(); - IPeerModelQueryService queryService = model.getService(IPeerModelQueryService.class); - queryService.queryRemoteServices(node.get()); - } } return node.get() != null ? new EditorInput(node.get()) : new NullEditorInput(); |