1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-10 10:35:23 +02:00

bug 388755: Fix EFSExtensionProvider to return conventional path on Windows as C:/path (without extra leading slash) - combined patch from master

This commit is contained in:
Andrew Gvozdev 2013-01-05 07:45:43 -05:00
parent 5138ee947f
commit 7a1956c019
3 changed files with 75 additions and 79 deletions

View file

@ -20,6 +20,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.utils.EFSExtensionManager;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
/**
* Tests the EFSExtensionManager and EFSExtensionProvider classes, as well as the EFSExtensionProvider extension point.
@ -235,7 +236,11 @@ public class EFSExtensionTests extends TestCase {
String path = EFSExtensionManager.getDefault().getMappedPath(originalURI);
assertEquals(path, "/c:/foo");
if (Platform.getOS().equals(Platform.WS_WIN32)) {
assertEquals(path, "c:/foo");
} else {
assertEquals(path, "/c:/foo");
}
}
public void testGetPathFromURI() {
@ -248,7 +253,11 @@ public class EFSExtensionTests extends TestCase {
String path = EFSExtensionManager.getDefault().getMappedPath(originalURI);
assertEquals(path, "/c:/foo");
if (Platform.getOS().equals(Platform.WS_WIN32)) {
assertEquals(path, "c:/foo");
} else {
assertEquals(path, "/c:/foo");
}
}
public void testExtension() {

View file

@ -10,33 +10,34 @@
*******************************************************************************/
package org.eclipse.cdt.core;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.URIUtil;
/**
* Abstract class providing the basis for supplementary support classes that can extract meaningful
* information from and provide useful operations on EFS filesystems. This allows for operations that can
* operate on virtual EFS filesystems (where IFileStores are just links to other IFileStores), or that operate
* information from and provide useful operations on EFS file-systems. This allows for operations that can
* operate on virtual EFS file-systems (where IFileStores are just links to other IFileStores), or that operate
* on the physical file backed by an IFileStore, without having to know the implementation details of a given
* EFS filesystem.
* EFS file-system.
*
* Provides a default implementation that assumes that URIs for the given filesystem map directly to resources
* in the physical filesystem, and that the path component of the URI is a direct representation of the
* absolute path to the file in the physical filesystem.
* Provides a default implementation that assumes that URIs for the given file-system map directly to resources
* in the physical file-system, and that the path component of the URI is a direct representation of the
* absolute path to the file in the physical file-system.
*
* Clients wishing to support a filesystem with different behaviour should extend this class and override its
* Clients wishing to support a file-system with different behavior should extend this class and override its
* methods where appropriate.
*
* Clients should not typically call methods on this class or its descendants directly. Instead, they should
* call the appropriate method in FileSystemUtilityManager so that said manager can properly route calls to
* the proper utility, depending on the filesystem.
* the proper utility, depending on the file-system.
*
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as part of a work in progress. There
* is no guarantee that this API will work or that it will remain the same. Please do not use this API without
* <strong>EXPERIMENTAL</strong>. This class or interface has been added to CDT 7.0 as part of a work in progress.
* There is no guarantee that this API will work or that it will remain the same. Please do not use this API without
* consulting with the CDT team.
*
* @author crecoskie
@ -55,12 +56,20 @@ public abstract class EFSExtensionProvider {
* physical file.
*/
public String getPathFromURI(URI locationURI) {
return new File(locationURI).getAbsolutePath();
String path = locationURI.getPath();
String schema = locationURI.getScheme();
if (schema != null && schema.equals(EFS.SCHEME_FILE) && Platform.getOS().equals(Platform.WS_WIN32)) {
// URI path on Windows is represented as "/C:/path"
if (path != null && path.matches("/[A-Za-z]:.*")) { //$NON-NLS-1$
path = path.substring(1);
}
}
return path;
}
/**
* In the case of a virtual filesystem, where URIs in the given filesystem are just soft links in EFS to
* URIs in other filesystems, returns the URI that this URI links to. If the filesystem is not virtual,
* In the case of a virtual file-system, where URIs in the given file-system are just soft links in EFS to
* URIs in other file-systems, returns the URI that this URI links to. If the file-system is not virtual,
* then this method acts as an identity mapping.
*
* @param locationURI
@ -78,7 +87,7 @@ public abstract class EFSExtensionProvider {
* The default implementation places the path in the path field of the URI, ensuring that there is a leading slash.
* It also determines whether or not to convert backslashes in the provided path based on whether or not the
* local operating system's file separator is a backslash, thus ensuring proper behaviour for URIs corresponding
* to the local filesystem.
* to the local file-system.
*
* @param locationOnSameFilesystem
* @param path An absolute path.
@ -92,7 +101,7 @@ public abstract class EFSExtensionProvider {
final int length = pathString.length();
StringBuffer pathBuf = new StringBuffer(length + 1);
// force the path to be absolute
// force the path to be absolute including Windows where URI path is represented as "/C:/path"
if (length > 0 && (pathString.charAt(0) != '/')) {
pathBuf.append('/');
}
@ -112,14 +121,14 @@ public abstract class EFSExtensionProvider {
}
/**
* For filesystems that map the path to a physical file in one filesystem (say on a remote machine) to
* For file-systems that map the path to a physical file in one file-system (say on a remote machine) to
* another path (say, on the local machine), this method returns the path that the store maps to. I.e., it
* returns the path that the path returned by getPathFromURI(URI locationURI) maps to. If there is no such
* mapping, then an identity mapping of the paths is assumed.
*
* Typically if a filesystem maps one filesytem to another, it will place the mapped path in the path
* Typically if a file-system maps one file-system to another, it will place the mapped path in the path
* field of its URIs (which the default implementation assumes), but this is not guaranteed to be so for
* all filesystem implementations.
* all file-system implementations.
*
* @return String representing the path, or <code>null</code> on error.
*/
@ -128,8 +137,8 @@ public abstract class EFSExtensionProvider {
}
/**
* Returns true if the given URI is part of a virtual filesystem and thus points to another underlying
* URI. Returns false otherwise. By default, filesystems are assumed to be non-virtual.
* Returns true if the given URI is part of a virtual file-system and thus points to another underlying
* URI. Returns false otherwise. By default, file-systems are assumed to be non-virtual.
*
* @param locationURI
* @return boolean

View file

@ -221,16 +221,7 @@ public class ErrorParserManager extends OutputStream implements IConsoleParser,
*/
public void pushDirectory(IPath dir) {
if (dir != null) {
URI uri;
URI workingDirectoryURI = getWorkingDirectoryURI();
if (!dir.isAbsolute()) {
uri = URIUtil.append(workingDirectoryURI, dir.toString());
} else {
uri = toURI(dir);
if (uri == null) {
return;
}
}
URI uri = toURI(dir);
pushDirectoryURI(uri);
}
}
@ -485,18 +476,9 @@ outer:
* @return - file in the workspace or {@code null} if such a file doesn't exist
*/
protected IFile findFileInWorkspace(IPath path) {
URI uri;
if (!path.isAbsolute()) {
URI workingDirectoryURI = getWorkingDirectoryURI();
uri = EFSExtensionManager.getDefault().append(workingDirectoryURI, path.toString());
}
else {
uri = toURI(path);
if (uri == null) {
return null;
}
}
return findFileInWorkspace(uri);
URI uri = toURI(path);
IFile file = findFileInWorkspace(uri);
return file;
}
/**
@ -728,10 +710,7 @@ outer:
}
/**
* Converts a location {@link IPath} to an {@link URI}. Contrary to
* {@link URIUtil#toURI(IPath)} this method does not assume that the path belongs
* to local file system.
*
* Converts a location {@link IPath} to an {@link URI}.
* The returned URI uses the scheme and authority of the current working directory
* as returned by {@link #getWorkingDirectoryURI()}
*
@ -740,16 +719,15 @@ outer:
* @since 5.1
*/
private URI toURI(IPath path) {
// try {
URI baseURI = getWorkingDirectoryURI();
String uriString = path.toString();
URI uri = null;
URI workingDirectoryURI = getWorkingDirectoryURI();
if (path.isAbsolute()) {
uri = EFSExtensionManager.getDefault().createNewURIFromPath(workingDirectoryURI, path.toString());
} else {
uri = EFSExtensionManager.getDefault().append(workingDirectoryURI, path.toString());
}
// On Windows "C:/folder/" -> "/C:/folder/"
if (path.isAbsolute() && uriString.charAt(0) != IPath.SEPARATOR) {
uriString = IPath.SEPARATOR + uriString;
}
return EFSExtensionManager.getDefault().createNewURIFromPath(baseURI, uriString);
return uri;
}
/**