Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2013-09-13 12:37:25 +0000
committerUwe Stieber2013-09-13 12:37:25 +0000
commitf73e359e26de640a5ecf1b7dedb47d42de83f84a (patch)
tree4c4d2402e0841bd4a793f094b1bc113258d65895 /target_explorer
parent5fda781d84d1d01f5006815795739241d8d2bee8 (diff)
downloadorg.eclipse.tcf-f73e359e26de640a5ecf1b7dedb47d42de83f84a.tar.gz
org.eclipse.tcf-f73e359e26de640a5ecf1b7dedb47d42de83f84a.tar.xz
org.eclipse.tcf-f73e359e26de640a5ecf1b7dedb47d42de83f84a.zip
Target Explorer: Added path map resolver service interface and implementation
Diffstat (limited to 'target_explorer')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.xml9
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPathMapResolverService.java94
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/services/PathMapResolverService.java133
4 files changed, 237 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF
index f38dc6107..90e4e9c17 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF
@@ -27,6 +27,7 @@ Export-Package: org.eclipse.tcf.te.tcf.core,
org.eclipse.tcf.te.tcf.core.interfaces.steps,
org.eclipse.tcf.te.tcf.core.interfaces.tracing,
org.eclipse.tcf.te.tcf.core.internal;x-internal:=true,
+ org.eclipse.tcf.te.tcf.core.internal.services,
org.eclipse.tcf.te.tcf.core.internal.utils;x-internal:=true,
org.eclipse.tcf.te.tcf.core.iterators,
org.eclipse.tcf.te.tcf.core.jobs,
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.xml
index a86dfa5b7..5adce2509 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.xml
@@ -10,6 +10,15 @@
<class name="org.eclipse.tcf.te.tcf.core.internal.Startup"/>
</extension>
+<!-- Service contributions -->
+ <extension point="org.eclipse.tcf.te.runtime.services.services">
+ <service
+ id="org.eclipse.tcf.te.tcf.core.services.pathmapresolver"
+ class="org.eclipse.tcf.te.tcf.core.internal.services.PathMapResolverService">
+ <serviceType class="org.eclipse.tcf.te.tcf.core.interfaces.IPathMapResolverService"/>
+ </service>
+ </extension>
+
<!-- Launch Step contributions -->
<extension point="org.eclipse.tcf.te.runtime.stepper.steps">
<step
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPathMapResolverService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPathMapResolverService.java
new file mode 100644
index 000000000..595da4063
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPathMapResolverService.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.core.interfaces;
+
+import org.eclipse.tcf.services.IPathMap;
+import org.eclipse.tcf.te.runtime.services.interfaces.IService;
+
+/**
+ * Path map resolver service.
+ * <p>
+ * Allows to map a host path to a target path and a target path
+ * to a host path.
+ */
+public interface IPathMapResolverService extends IService {
+
+ /**
+ * Resolves the given file name by checking if the given path map rule is a match.
+ * <p>
+ * The path map rule matches, if the path map rule source attribute is
+ * equal to the given file name or if the path map rule source attribute
+ * is a prefix of the given file name.
+ * <p>
+ * If the path map rule is a match, the corresponding fraction of the
+ * given file name is replaced with the path map rule destination attribute.
+ * <p>
+ * If the path map rule is not a match, <code>null</code> is returned.
+ *
+ * @param rule The path map rule. Must not be <code>null</code>.
+ * @param fnm The file name. Must not be <code>null</code>.
+ * @return The mapped path or <code>null</code>.
+ */
+ public String map(IPathMap.PathMapRule rule, String fnm);
+
+ /**
+ * Resolves the given file name by checking if the given path map rule is a match.
+ * <p>
+ * The path map rule matches, if the path map rule destination attribute is
+ * equal to the given file name or if the path map rule destination attribute
+ * is a prefix of the given file name.
+ * <p>
+ * If the path map rule is a match, the corresponding fraction of the
+ * given file name is replaced with the path map rule source attribute.
+ * <p>
+ * If the path map rule is not a match, <code>null</code> is returned.
+ *
+ * @param rule The path map rule. Must not be <code>null</code>.
+ * @param fnm The file name. Must not be <code>null</code>.
+ * @return The mapped path or <code>null</code<.
+ */
+ public String mapReverse(IPathMap.PathMapRule rule, String fnm);
+
+ /**
+ * Find a matching target path for the given host path.
+ * <p>
+ * Walks the configured (object) path map for the given context and search
+ * for matching path map rules by trying to reverse map the given host path
+ * with each path map rule.
+ * <p>
+ * If a path map rule matches, the search is stopped and the mapped target
+ * path is returned.
+ * <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 hostPath The host path. Must not be <code>null</code>
+ * @return The mapped target path or the given host path.
+ */
+ public String findTargetPath(Object context, String hostPath);
+
+ /**
+ * Find a matching host path for the given target path.
+ * <p>
+ * Walks the configured (object) path map for the given context and search
+ * for matching path map rules by trying to map the given target path with
+ * each path map rule.
+ * <p>
+ * If a path map rule matches, the host path is validated by checking if a file system
+ * element exist and the element can be accessed for reading.
+ * <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 targetPath The target path. Must not be <code>null</code>
+ * @return The mapped host path or the given target path.
+ */
+ public String findHostPath(Object context, String targetPath);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/services/PathMapResolverService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/services/PathMapResolverService.java
new file mode 100644
index 000000000..f2f6f5bbd
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/services/PathMapResolverService.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.core.internal.services;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.services.IPathMap;
+import org.eclipse.tcf.te.runtime.services.AbstractService;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil;
+import org.eclipse.tcf.te.tcf.core.interfaces.IPathMapResolverService;
+import org.eclipse.tcf.te.tcf.core.interfaces.IPathMapService;
+
+/**
+ * Path map resolver service implementation.
+ */
+public class PathMapResolverService extends AbstractService implements IPathMapResolverService {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.core.interfaces.IPathMapResolverService#map(org.eclipse.tcf.services.IPathMap.PathMapRule, java.lang.String)
+ */
+ @Override
+ public String map(IPathMap.PathMapRule rule, String fnm) {
+ Assert.isNotNull(rule);
+ Assert.isNotNull(fnm);
+
+ String src = rule.getSource();
+ if (src == null) return null;
+ if (!(new Path(src).isPrefixOf(new Path(fnm)))) return null;
+ String host = rule.getHost();
+ if (host != null && host.length() > 0) {
+ if (!IPAddressUtil.getInstance().isLocalHost(host)) return null;
+ }
+ String dst = rule.getDestination();
+ if (dst == null || dst.length() == 0) return null;
+ int l = src.length();
+ if (dst.endsWith("/") && l < fnm.length() && fnm.charAt(l) == '/') l++; //$NON-NLS-1$
+ return new Path(dst + fnm.substring(l)).toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.core.interfaces.IPathMapResolverService#mapReverse(org.eclipse.tcf.services.IPathMap.PathMapRule, java.lang.String)
+ */
+ @Override
+ public String mapReverse(IPathMap.PathMapRule rule, String fnm) {
+ Assert.isNotNull(rule);
+ Assert.isNotNull(fnm);
+
+ String dst = rule.getDestination();
+ if (dst == null) return null;
+ if (!(new Path(dst).isPrefixOf(new Path(fnm)))) return null;
+ String host = rule.getHost();
+ if (host != null && host.length() > 0) {
+ if (!IPAddressUtil.getInstance().isLocalHost(host)) return null;
+ }
+ String src = rule.getSource();
+ if (src == null || src.length() == 0) return null;
+ int l = dst.length();
+ if (src.endsWith("/") && l < fnm.length() && fnm.charAt(l) == '/') l++; //$NON-NLS-1$
+ return new Path(src + fnm.substring(l)).toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.core.interfaces.IPathMapResolverService#findTargetPath(java.lang.Object, java.lang.String)
+ */
+ @Override
+ public String findTargetPath(Object context, String hostPath) {
+ Assert.isTrue(!Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+ Assert.isNotNull(context);
+ Assert.isNotNull(hostPath);
+
+ IPathMapService svc = ServiceManager.getInstance().getService(context, IPathMapService.class);
+ if (svc != null) {
+ IPathMap.PathMapRule[] rules = svc.getPathMap(context);
+ if (rules != null && rules.length > 0) {
+ for (IPathMap.PathMapRule rule : rules) {
+ String query = rule.getContextQuery();
+ if (query != null && query.length() > 0 && !query.equals("*")) continue; //$NON-NLS-1$
+ String targetPath = mapReverse(rule, hostPath);
+ if (targetPath != null) {
+ return targetPath;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.core.interfaces.IPathMapResolverService#findHostPath(java.lang.Object, java.lang.String)
+ */
+ @Override
+ public String findHostPath(Object context, String targetPath) {
+ Assert.isTrue(!Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+ Assert.isNotNull(context);
+ Assert.isNotNull(targetPath);
+
+ IPathMapService svc = ServiceManager.getInstance().getService(context, IPathMapService.class);
+ if (svc != null) {
+ IPathMap.PathMapRule[] rules = svc.getPathMap(context);
+ if (rules != null && rules.length > 0) {
+ for (IPathMap.PathMapRule rule : rules) {
+ String query = rule.getContextQuery();
+ if (query != null && query.length() > 0 && !query.equals("*")) continue; //$NON-NLS-1$
+ String hostPath = mapReverse(rule, targetPath);
+ if (hostPath != null) {
+ if (hostPath.startsWith("/cygdrive/")) { //$NON-NLS-1$
+ hostPath = hostPath.substring(10, 11) + ":" + hostPath.substring(11); //$NON-NLS-1$
+ }
+ File f = new File(hostPath);
+ if (f.exists() && f.canRead()) {
+ return hostPath;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+}

Back to the top