Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2013-09-04 12:00:16 +0000
committerUwe Stieber2013-09-04 12:03:05 +0000
commitf5b3650761b1817389a672b1a50addb1b0627d7a (patch)
tree6d367de7cfcca6e5e1fc43bb3d6034a5be79c140 /target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src
parent19c9cc800fd14c7d5f84324a798255c4618f99c7 (diff)
downloadorg.eclipse.tcf-f5b3650761b1817389a672b1a50addb1b0627d7a.tar.gz
org.eclipse.tcf-f5b3650761b1817389a672b1a50addb1b0627d7a.tar.xz
org.eclipse.tcf-f5b3650761b1817389a672b1a50addb1b0627d7a.zip
Target Explorer: Extend the path map service to provide possibilities to add path maps and apply path maps
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/services/PathMapService.java186
1 files changed, 185 insertions, 1 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/services/PathMapService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/services/PathMapService.java
index df407872e..6abd028ec 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/services/PathMapService.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/services/PathMapService.java
@@ -11,19 +11,35 @@ package org.eclipse.tcf.te.tcf.launch.core.internal.services;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate;
+import org.eclipse.tcf.protocol.IChannel;
+import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.protocol.IToken;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.services.IPathMap;
import org.eclipse.tcf.services.IPathMap.PathMapRule;
+import org.eclipse.tcf.te.runtime.callback.Callback;
+import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
import org.eclipse.tcf.te.runtime.services.AbstractService;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.utils.StatusHelper;
+import org.eclipse.tcf.te.tcf.core.Tcf;
import org.eclipse.tcf.te.tcf.core.interfaces.IPathMapGeneratorService;
import org.eclipse.tcf.te.tcf.core.interfaces.IPathMapService;
+import org.eclipse.tcf.te.tcf.launch.core.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProvider;
/**
* Path map service implementation.
@@ -49,7 +65,6 @@ public class PathMapService extends AbstractService implements IPathMapService {
if (config != null) {
try {
-
String path_map_cfg = config.getAttribute(org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.ATTR_PATH_MAP, ""); //$NON-NLS-1$
rulesList.addAll(org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.parsePathMapAttribute(path_map_cfg));
@@ -77,6 +92,175 @@ public class PathMapService extends AbstractService implements IPathMapService {
}
/* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.core.interfaces.IPathMapService#addPathMap(java.lang.Object, java.lang.String, java.lang.String)
+ */
+ @Override
+ public PathMapRule addPathMap(Object context, String source, String destination) {
+ Assert.isTrue(!Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+ Assert.isNotNull(context);
+ Assert.isNotNull(source);
+ Assert.isNotNull(destination);
+
+ PathMapRule rule = null;
+ List<PathMapRule> rulesList = new ArrayList<PathMapRule>();
+
+ // Get the launch configuration for that peer model
+ ILaunchConfigurationWorkingCopy config = (ILaunchConfigurationWorkingCopy) Platform.getAdapterManager().getAdapter(context, ILaunchConfigurationWorkingCopy.class);
+ if (config == null) {
+ config = (ILaunchConfigurationWorkingCopy) Platform.getAdapterManager().loadAdapter(context, "org.eclipse.debug.core.ILaunchConfigurationWorkingCopy"); //$NON-NLS-1$
+ }
+
+ if (config != null) {
+ try {
+ String path_map_cfg = config.getAttribute(org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.ATTR_PATH_MAP, ""); //$NON-NLS-1$
+ String path_map_cfgV1 = config.getAttribute(org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.ATTR_PATH_MAP + "V1", ""); //$NON-NLS-1$ //$NON-NLS-2$
+
+ rulesList.addAll(org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.parsePathMapAttribute(path_map_cfgV1));
+
+ int i = -1;
+ for (PathMapRule candidate : org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.parsePathMapAttribute(path_map_cfg)) {
+ if (rulesList.contains(candidate)) {
+ i = rulesList.indexOf(candidate);
+ } else {
+ rulesList.add(++i, candidate);
+ }
+ }
+ } catch (CoreException e) { /* ignored on purpose */ }
+
+ // Find an existing path map rule for the given source and destination
+ for (PathMapRule candidate : rulesList) {
+ if (source.equals(candidate.getSource()) && destination.equals(candidate.getDestination())) {
+ rule = candidate;
+ break;
+ }
+ }
+
+ // If not matching path map rule exist, create a new one
+ if (rule == null) {
+ Map<String, Object> props = new LinkedHashMap<String, Object>();
+ rule = new org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.PathMapRule(props);
+ rulesList.add(rule);
+
+ // Update the launch configuration
+ for (PathMapRule candidate : rulesList) {
+ candidate.getProperties().remove(IPathMap.PROP_ID);
+ }
+
+ StringBuilder bf = new StringBuilder();
+ StringBuilder bf1 = new StringBuilder();
+
+ for (PathMapRule candidate : rulesList) {
+ if (!(candidate instanceof org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.PathMapRule)) continue;
+
+ boolean enabled = true;
+ if (candidate.getProperties().containsKey("Enabled")) { //$NON-NLS-1$
+ enabled = Boolean.parseBoolean(candidate.getProperties().get("Enabled").toString()); //$NON-NLS-1$
+ }
+ if (enabled) {
+ candidate.getProperties().remove("Enabled"); //$NON-NLS-1$
+ bf.append(candidate.toString());
+ }
+ bf1.append(candidate.toString());
+ }
+
+ if (bf.length() == 0) {
+ config.removeAttribute(TCFLaunchDelegate.ATTR_PATH_MAP);
+ } else {
+ config.setAttribute(TCFLaunchDelegate.ATTR_PATH_MAP, bf.toString());
+ }
+
+ if (bf1.length() == 0) {
+ config.removeAttribute(org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.ATTR_PATH_MAP + "V1"); //$NON-NLS-1$
+ } else {
+ config.setAttribute(org.eclipse.tcf.internal.debug.launch.TCFLaunchDelegate.ATTR_PATH_MAP + "V1", bf1.toString()); //$NON-NLS-1$
+ }
+
+ // Apply the path map
+ applyPathMap(context, new Callback() {
+ @Override
+ protected void internalDone(Object caller, IStatus status) {
+ if (status != null && Platform.inDebugMode()) {
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+ });
+ }
+ }
+
+ return rule;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.core.interfaces.IPathMapService#applyPathMap(java.lang.Object, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback)
+ */
+ @Override
+ public void applyPathMap(final Object context, final ICallback callback) {
+ Assert.isTrue(!Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+ Assert.isNotNull(context);
+ Assert.isNotNull(callback);
+
+ IPeer peer = context instanceof IPeer ? (IPeer)context : null;
+ if (peer == null && context instanceof IPeerModel) peer = ((IPeerModel)context).getPeer();
+ if (peer == null && context instanceof IPeerModelProvider && ((IPeerModelProvider)context).getPeerModel() != null) peer = ((IPeerModelProvider)context).getPeerModel().getPeer();
+
+ if (peer != null) {
+ final IChannel channel = Tcf.getChannelManager().getChannel(peer);
+ if (channel != null && IChannel.STATE_OPEN == channel.getState()) {
+ // Channel is open -> Have to update the path maps
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ final IPathMap svc = channel.getRemoteService(IPathMap.class);
+ if (svc != null) {
+ final PathMapRule[] configuredMap = getPathMap(context);
+ if (configuredMap != null && configuredMap.length > 0) {
+ // Get the old path maps first. Keep path map rules not coming from us
+ svc.get(new IPathMap.DoneGet() {
+ @Override
+ public void doneGet(IToken token, Exception error, PathMapRule[] map) {
+ // Merge the maps to a new list
+ List<PathMapRule> rules = new ArrayList<PathMapRule>();
+
+ if (map != null && map.length > 0) {
+ for (PathMapRule rule : map) {
+ if (rule.getID() == null || !rule.getID().startsWith(getClientID())) {
+ rules.add(rule);
+ }
+ }
+ }
+
+ rules.addAll(Arrays.asList(configuredMap));
+ if (!rules.isEmpty()) {
+ svc.set(rules.toArray(new PathMapRule[rules.size()]), new IPathMap.DoneSet() {
+ @Override
+ public void doneSet(IToken token, Exception error) {
+ callback.done(PathMapService.this, StatusHelper.getStatus(error));
+ }
+ });
+ } else {
+ callback.done(PathMapService.this, Status.OK_STATUS);
+ }
+ }
+ });
+ } else {
+ callback.done(PathMapService.this, Status.OK_STATUS);
+ }
+ } else {
+ callback.done(PathMapService.this, Status.OK_STATUS);
+ }
+ }
+ };
+
+ Protocol.invokeLater(runnable);
+ } else {
+ callback.done(PathMapService.this, Status.OK_STATUS);
+ }
+ } else {
+ callback.done(PathMapService.this, Status.OK_STATUS);
+ }
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.tcf.te.tcf.core.interfaces.IPathMapService#getClientID()
*/
@SuppressWarnings("restriction")

Back to the top