1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 13:05:22 +02:00

[195285] more changes for mount path mapper

This commit is contained in:
David McKnight 2007-12-13 16:10:13 +00:00
parent 42324f2e58
commit 1305fc2295
6 changed files with 85 additions and 32 deletions

View file

@ -22,18 +22,22 @@ import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
* This interface is used to provide a common way of mapping mounted resources to the temp files project. * This interface is used to provide a common way of mapping mounted resources to the temp files project.
* Since local (or remote) mounts can change or be removed (i.e. disconnected) this provides a way for a vendor to * Since local (or remote) mounts can change or be removed (i.e. disconnected) this provides a way for a vendor to
* remap a particular resource if the vendor software is able to determine the new mount location. * remap a particular resource if the vendor software is able to determine the new mount location.
*
* There are a number of use cases where a customized workspace mapping would be desirable:
* <ul>
* <li>Two connections to the same host using different user IDs for each connection. In that case, it may make
* sense to store the temp files differently for each connection (for example, qualified by user ID).
* <li>If port-forwarding is used then a port could be used to qualify the temp file path.
* <li>If the remote path contains invalid characters for the local file system, then the temp file mapping could
* be made such that invalid characters ( e.g. :<>?* on Windows) translate to a sequence of valid characters on the client.
* </ul>
*
*
* Implementors of this interface should register their mappers via the mountPathMappers extension point. * Implementors of this interface should register their mappers via the mountPathMappers extension point.
*/ */
public interface ISystemMountPathMapper public interface ISystemMountPathMapper
{ {
/**
* Indicates whether this mapper handles remapping of the specified resource
* @param hostname the remote host
* @param remotePath the remote path as seen by the file subsystem
* @return whether this mapper handles remapping of the specified remote resource
*/
public boolean handlesMappingFor(String hostname, String remotePath);
/** /**
* Returns the qualified workspace path for a replica of this mounted file. Since the * Returns the qualified workspace path for a replica of this mounted file. Since the
@ -72,4 +76,29 @@ public interface ISystemMountPathMapper
* @return the local system path that represents the mounted file * @return the local system path that represents the mounted file
*/ */
public String getMountedMappingFor(String hostname, String remotePath); public String getMountedMappingFor(String hostname, String remotePath);
/**
* Indicates whether this mapper handles remapping of the specified resource. If more than one mount
* path mapper returns true for this, then the getPriority() method will be used to determine precedence.
* @param hostname the remote host
* @param remotePath the remote path as seen by the file subsystem
* @param subsystem the remote file subsystem
* @return whether this mapper handles remapping of the specified remote resource
*/
public boolean handlesMappingFor(String hostname, String remotePath, IRemoteFileSubSystem subsystem);
/**
*
* Returns the priority of this mount path mapper. This is used to determine which mount
* path mapper to use when more than one are applicable. The lower the return value, the
* higher priority.
*
* @param hostname the host name for the file system
* @param remotePath the path on the remote file system
* @param subsystem the subsystem used to retrieve files
*
* @return the priority, where the lower in value, the higher the priority.
*/
int getPriority(String hostname, String remotePath, IRemoteFileSubSystem subsystem);
} }

View file

@ -947,7 +947,7 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
//DKM && subsystem.getHost().getSystemType().isLocal() //DKM && subsystem.getHost().getSystemType().isLocal()
) )
{ {
String result = SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath); String result = SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath, subsystem);
if (!result.equals(hostname)) if (!result.equals(hostname))
{ {
_isRemoteFileMounted = true; _isRemoteFileMounted = true;

View file

@ -151,7 +151,7 @@ public class SystemUniversalTempFileListener extends SystemTempFileListener
{ {
String mappedHostPath = properties.getResolvedMountedRemoteFilePath(); String mappedHostPath = properties.getResolvedMountedRemoteFilePath();
String mappedHostName = properties.getResolvedMountedRemoteFileHost(); String mappedHostName = properties.getResolvedMountedRemoteFileHost();
String systemRemotePath = SystemRemoteEditManager.getInstance().getMountPathFor(mappedHostName, mappedHostPath); String systemRemotePath = SystemRemoteEditManager.getInstance().getMountPathFor(mappedHostName, mappedHostPath, (IRemoteFileSubSystem)subsystem);
if (systemRemotePath == null) if (systemRemotePath == null)
{ {

View file

@ -316,6 +316,13 @@ public class UniversalFileTransferUtility
} }
} }
/**
* Used for local files - special case!
* @param tempFile
* @param remoteFile
* @param hostname
* @param userId
*/
protected static void setIFileProperties(IFile tempFile, File remoteFile, String hostname, String userId) protected static void setIFileProperties(IFile tempFile, File remoteFile, String hostname, String userId)
{ {
// set it's properties for use later // set it's properties for use later
@ -326,10 +333,14 @@ public class UniversalFileTransferUtility
properties.setDirty(false); properties.setDirty(false);
String remotePath = remoteFile.getAbsolutePath(); String remotePath = remoteFile.getAbsolutePath();
// String subSystemId = registry.getAbsoluteNameForSubSystem(subSystem);
// properties.setRemoteFileSubSystem(subSystemId);
properties.setRemoteFilePath(remotePath); properties.setRemoteFilePath(remotePath);
try
{
properties.setEncoding(tempFile.getCharset());
}
catch (CoreException e){
}
// get the modified timestamp from the File, not the IFile // get the modified timestamp from the File, not the IFile
// for some reason, the modified timestamp from the IFile does not always return // for some reason, the modified timestamp from the IFile does not always return
@ -337,11 +348,11 @@ public class UniversalFileTransferUtility
// cached value and that might be the cause of the problem. // cached value and that might be the cause of the problem.
properties.setDownloadFileTimeStamp(tempFile.getLocation().toFile().lastModified()); properties.setDownloadFileTimeStamp(tempFile.getLocation().toFile().lastModified());
boolean isMounted = isRemoteFileMounted(hostname, remotePath); boolean isMounted = isRemoteFileMounted(hostname, remotePath, null); // no subsystem
properties.setRemoteFileMounted(isMounted); properties.setRemoteFileMounted(isMounted);
if (isMounted) if (isMounted)
{ {
String actualRemoteHost = getActualHostFor(hostname, remotePath); String actualRemoteHost = getActualHostFor(hostname, remotePath, null); // no subsystem
String actualRemotePath = getWorkspaceRemotePath(hostname, remotePath, null); // no subsystem String actualRemotePath = getWorkspaceRemotePath(hostname, remotePath, null); // no subsystem
properties.setResolvedMountedRemoteFileHost(actualRemoteHost); properties.setResolvedMountedRemoteFileHost(actualRemoteHost);
properties.setResolvedMountedRemoteFilePath(actualRemotePath); properties.setResolvedMountedRemoteFilePath(actualRemotePath);
@ -2271,20 +2282,20 @@ public class UniversalFileTransferUtility
} }
public static String getActualHostFor(ISubSystem subsystem, String remotePath) public static String getActualHostFor(IRemoteFileSubSystem subsystem, String remotePath)
{ {
String hostname = subsystem.getHost().getHostName(); String hostname = subsystem.getHost().getHostName();
if (subsystem.getHost().getSystemType().isLocal()) if (subsystem.getHost().getSystemType().isLocal())
{ {
String result = SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath); String result = SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath, subsystem);
return result; return result;
} }
return hostname; return hostname;
} }
public static String getActualHostFor(String hostname, String remotePath) public static String getActualHostFor(String hostname, String remotePath, IRemoteFileSubSystem subsystem)
{ {
return SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath); return SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath, subsystem);
} }
private static void refreshResourceInWorkspace(IResource parent) private static void refreshResourceInWorkspace(IResource parent)
@ -2310,7 +2321,7 @@ public class UniversalFileTransferUtility
String hostname = subsystem.getHost().getHostName(); String hostname = subsystem.getHost().getHostName();
if (subsystem.getHost().getSystemType().isLocal()) if (subsystem.getHost().getSystemType().isLocal())
{ {
String result = SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath); String result = SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath, (IRemoteFileSubSystem)subsystem);
if (!result.equals(hostname)) if (!result.equals(hostname))
{ {
return true; return true;
@ -2319,9 +2330,9 @@ public class UniversalFileTransferUtility
return false; return false;
} }
protected static boolean isRemoteFileMounted(String hostname, String remotePath) protected static boolean isRemoteFileMounted(String hostname, String remotePath, IRemoteFileSubSystem subsystem)
{ {
String result = SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath); String result = SystemRemoteEditManager.getInstance().getActualHostFor(hostname, remotePath, subsystem);
if (!result.equals(hostname)) { if (!result.equals(hostname)) {
return true; return true;

View file

@ -24,7 +24,7 @@ import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
public class DefaultMountPathMapper implements ISystemMountPathMapper public class DefaultMountPathMapper implements ISystemMountPathMapper
{ {
public boolean handlesMappingFor(String hostname, String remotePath) public boolean handlesMappingFor(String hostname, String remotePath, IRemoteFileSubSystem subsystem)
{ {
return false; return false;
} }
@ -46,4 +46,9 @@ public class DefaultMountPathMapper implements ISystemMountPathMapper
{ {
return remotePath; return remotePath;
} }
public int getPriority(String hostname, String remotePath,
IRemoteFileSubSystem subsystem) {
return Integer.MAX_VALUE;
}
} }

View file

@ -96,11 +96,12 @@ public class SystemRemoteEditManager
* the resource is mounted then a mount path mapper has the opportunity to return the actual host. * the resource is mounted then a mount path mapper has the opportunity to return the actual host.
* @param hostname the system on which a resource is obtained (may contain the file via a mount) * @param hostname the system on which a resource is obtained (may contain the file via a mount)
* @param remotePath the path on the host where the resource is obtained * @param remotePath the path on the host where the resource is obtained
* @param subsystem the subsystem
* @return the actual host where the resource exists * @return the actual host where the resource exists
*/ */
public String getActualHostFor(String hostname, String remotePath) public String getActualHostFor(String hostname, String remotePath, IRemoteFileSubSystem subsystem)
{ {
ISystemMountPathMapper mapper = getMountPathMapperFor(hostname, remotePath); ISystemMountPathMapper mapper = getMountPathMapperFor(hostname, remotePath, subsystem);
if (mapper != null) if (mapper != null)
{ {
return mapper.getActualHostFor(hostname, remotePath); return mapper.getActualHostFor(hostname, remotePath);
@ -115,12 +116,12 @@ public class SystemRemoteEditManager
* Return the path to use on the system (i.e. Windows) for saving from the workspace to remote * Return the path to use on the system (i.e. Windows) for saving from the workspace to remote
* @param hostname the remote host * @param hostname the remote host
* @param remotePath the file path on the remote host * @param remotePath the file path on the remote host
* @param subsystem the subsystem
* @return the system path * @return the system path
*/ */
public String getMountPathFor(String hostname, String remotePath) public String getMountPathFor(String hostname, String remotePath, IRemoteFileSubSystem subsystem)
{ {
ISystemMountPathMapper mapper = getMountPathMapperFor(hostname, remotePath); ISystemMountPathMapper mapper = getMountPathMapperFor(hostname, remotePath, subsystem);
if (mapper != null) if (mapper != null)
{ {
return mapper.getMountedMappingFor(hostname, remotePath); return mapper.getMountedMappingFor(hostname, remotePath);
@ -141,7 +142,7 @@ public class SystemRemoteEditManager
*/ */
public String getWorkspacePathFor(String hostname, String remotePath, IRemoteFileSubSystem subsystem) public String getWorkspacePathFor(String hostname, String remotePath, IRemoteFileSubSystem subsystem)
{ {
ISystemMountPathMapper mapper = getMountPathMapperFor(hostname, remotePath); ISystemMountPathMapper mapper = getMountPathMapperFor(hostname, remotePath, subsystem);
if (mapper != null) if (mapper != null)
{ {
return mapper.getWorkspaceMappingFor(hostname, remotePath, subsystem); return mapper.getWorkspaceMappingFor(hostname, remotePath, subsystem);
@ -156,22 +157,29 @@ public class SystemRemoteEditManager
* Return the appropriate registered mapper for a host & path * Return the appropriate registered mapper for a host & path
* @param hostname * @param hostname
* @param remotePath * @param remotePath
* @param subsystem
* @return appropriate mapper * @return appropriate mapper
*/ */
public ISystemMountPathMapper getMountPathMapperFor(String hostname, String remotePath) public ISystemMountPathMapper getMountPathMapperFor(String hostname, String remotePath, IRemoteFileSubSystem subsystem)
{ {
ISystemMountPathMapper result = null;
for (int i = 0; i < _mountPathMappers.size(); i++) for (int i = 0; i < _mountPathMappers.size(); i++)
{ {
ISystemMountPathMapper mapper = (ISystemMountPathMapper) _mountPathMappers.get(i); ISystemMountPathMapper mapper = (ISystemMountPathMapper) _mountPathMappers.get(i);
if (mapper != null) if (mapper != null)
{ {
if (mapper.handlesMappingFor(hostname, remotePath)) if (mapper.handlesMappingFor(hostname, remotePath, subsystem))
{ {
return mapper; if (result == null) {
result = mapper;
}
else if (mapper.getPriority(hostname, remotePath, subsystem) < result.getPriority(hostname, remotePath, subsystem)){
result = mapper;
}
} }
} }
} }
return null; return result;
} }
protected void registerMountPathMappers() protected void registerMountPathMappers()