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
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')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPathMapService.java31
-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
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/PathMapEditorPage.java86
3 files changed, 235 insertions, 68 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPathMapService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPathMapService.java
index 7e9f6f1fc..a59d77cb9 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPathMapService.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPathMapService.java
@@ -10,6 +10,7 @@
package org.eclipse.tcf.te.tcf.core.interfaces;
import org.eclipse.tcf.services.IPathMap;
+import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
import org.eclipse.tcf.te.runtime.services.interfaces.IService;
/**
@@ -30,6 +31,36 @@ public interface IPathMapService extends IService {
public IPathMap.PathMapRule[] getPathMap(Object context);
/**
+ * Adds a new path mapping rule to the configured (object) path mapping for the
+ * given context.
+ * <p>
+ * The method will check the path mappings if a path map rule for the given source
+ * and destination already exist. If this is the case, the method will do nothing
+ * and returns the existing path map rule.
+ * <p>
+ * The method auto applies the new path map to an possibly open shared channel.
+ * <p>
+ * <b>Note:</b> This method must be called from outside the TCF event dispatch thread.
+ *
+ * @param context The context. Must not be <code>null</code>.
+ * @param source The path map rule source attribute value. Must not be <code>null</code>.
+ * @param destination The path map rule destination attribute value. Must not be <code>null</code>.
+ *
+ * @return The path map rule object representing the added path map rule.
+ */
+ public IPathMap.PathMapRule addPathMap(Object context, String source, String destination);
+
+ /**
+ * Apply the configured (object) path mappings to the given context.
+ * <p>
+ * <b>Note:</b> This method must be called from outside the TCF event dispatch thread.
+ *
+ * @param context The context. Must not be <code>null</code>.
+ * @param callback The callback to invoke once the operation completed. Must not be <code>null</code>.
+ */
+ public void applyPathMap(Object context, ICallback callback);
+
+ /**
* Returns the current client ID used to identify path map rules handled
* by the current Eclipse instance.
*
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")
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/PathMapEditorPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/PathMapEditorPage.java
index ecac64ef0..e44294b28 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/PathMapEditorPage.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/editor/PathMapEditorPage.java
@@ -9,29 +9,19 @@
*******************************************************************************/
package org.eclipse.tcf.te.tcf.launch.ui.editor;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.osgi.util.NLS;
-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.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerManager;
import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandler;
import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandlerConstants;
-import org.eclipse.tcf.te.tcf.core.Tcf;
import org.eclipse.tcf.te.tcf.core.interfaces.IPathMapService;
import org.eclipse.tcf.te.tcf.launch.ui.activator.UIPlugin;
import org.eclipse.tcf.te.tcf.launch.ui.editor.tabs.PathMapTab;
@@ -61,67 +51,29 @@ public class PathMapEditorPage extends AbstractTcfLaunchTabContainerEditorPage {
final IPeerModel peerModel = getPeerModel(getEditorInput());
if (peerModel != null && peerModel.getPeer() != null) {
- final IChannel channel = Tcf.getChannelManager().getChannel(peerModel.getPeer());
- if (channel != null && IChannel.STATE_OPEN == channel.getState()) {
- // Channel is open -> Have to update the path maps
- Runnable runnable = new Runnable() {
+ IPathMapService service = ServiceManager.getInstance().getService(peerModel.getPeer(), IPathMapService.class);
+ if (service != null) {
+ service.applyPathMap(peerModel.getPeer(), new Callback() {
@Override
- public void run() {
- final IPeer peer = peerModel.getPeer();
- final IPathMapService service = ServiceManager.getInstance().getService(peer, IPathMapService.class);
- final IPathMap svc = channel.getRemoteService(IPathMap.class);
- if (service != null && svc != null) {
- final PathMapRule[] configuredMap = service.getPathMap(peer);
- 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(service.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) {
- if (error != null) {
- IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
- NLS.bind(Messages.PathMapEditorPage_error_apply, peerModel.getName(), error.getLocalizedMessage()),
- error);
- IStatusHandler[] handlers = StatusHandlerManager.getInstance().getHandler(peerModel);
- if (handlers.length > 0) {
- IPropertiesContainer data = new PropertiesContainer();
- data.setProperty(IStatusHandlerConstants.PROPERTY_TITLE, Messages.PathMapEditorPage_error_title);
- data.setProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, IContextHelpIds.MESSAGE_APPLY_PATHMAP_FAILED);
- data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, this);
-
- handlers[0].handleStatus(status, data, null);
- } else {
- UIPlugin.getDefault().getLog().log(status);
- }
- }
- }
- });
- }
- }
- });
+ protected void internalDone(Object caller, IStatus status) {
+ if (status != null && status.getSeverity() == IStatus.ERROR) {
+ IStatus status2 = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
+ NLS.bind(Messages.PathMapEditorPage_error_apply, peerModel.getName(), status.getMessage()),
+ status.getException());
+ IStatusHandler[] handlers = StatusHandlerManager.getInstance().getHandler(peerModel);
+ if (handlers.length > 0) {
+ IPropertiesContainer data = new PropertiesContainer();
+ data.setProperty(IStatusHandlerConstants.PROPERTY_TITLE, Messages.PathMapEditorPage_error_title);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, IContextHelpIds.MESSAGE_APPLY_PATHMAP_FAILED);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, this);
+ handlers[0].handleStatus(status2, data, null);
+ } else {
+ UIPlugin.getDefault().getLog().log(status2);
}
}
-
}
- };
-
- Protocol.invokeLater(runnable);
+ });
}
}
}

Back to the top