mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
bug 388755: Fix EFSExtensionProvider to return conventional path on Windows as C:/path (without extra leading slash)
Change-Id: I82507744f069d774579f0bdd301e210df8157305
This commit is contained in:
parent
2a008d29cf
commit
c8075218df
3 changed files with 44 additions and 60 deletions
|
@ -235,7 +235,7 @@ public class EFSExtensionTests extends TestCase {
|
||||||
|
|
||||||
String path = EFSExtensionManager.getDefault().getMappedPath(originalURI);
|
String path = EFSExtensionManager.getDefault().getMappedPath(originalURI);
|
||||||
|
|
||||||
assertEquals(path, "/c:/foo");
|
assertEquals(path, "c:/foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetPathFromURI() {
|
public void testGetPathFromURI() {
|
||||||
|
@ -248,7 +248,7 @@ public class EFSExtensionTests extends TestCase {
|
||||||
|
|
||||||
String path = EFSExtensionManager.getDefault().getMappedPath(originalURI);
|
String path = EFSExtensionManager.getDefault().getMappedPath(originalURI);
|
||||||
|
|
||||||
assertEquals(path, "/c:/foo");
|
assertEquals(path, "c:/foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExtension() {
|
public void testExtension() {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.URIUtil;
|
import org.eclipse.core.runtime.URIUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,25 +23,25 @@ import org.eclipse.core.runtime.URIUtil;
|
||||||
* operate on virtual EFS filesystems (where IFileStores are just links to other IFileStores), or that operate
|
* operate on virtual EFS filesystems (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
|
* on the physical file backed by an IFileStore, without having to know the implementation details of a given
|
||||||
* EFS filesystem.
|
* EFS filesystem.
|
||||||
*
|
*
|
||||||
* Provides a default implementation that assumes that URIs for the given filesystem map directly to resources
|
* 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
|
* 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.
|
* absolute path to the file in the physical filesystem.
|
||||||
*
|
*
|
||||||
* Clients wishing to support a filesystem with different behaviour should extend this class and override its
|
* Clients wishing to support a filesystem with different behaviour should extend this class and override its
|
||||||
* methods where appropriate.
|
* methods where appropriate.
|
||||||
*
|
*
|
||||||
* Clients should not typically call methods on this class or its descendants directly. Instead, they should
|
* 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
|
* 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 filesystem.
|
||||||
*
|
*
|
||||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as part of a work in progress. There
|
* <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
|
* 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.
|
* consulting with the CDT team.
|
||||||
*
|
*
|
||||||
* @author crecoskie
|
* @author crecoskie
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class EFSExtensionProvider {
|
public abstract class EFSExtensionProvider {
|
||||||
|
|
||||||
|
@ -48,20 +49,25 @@ public abstract class EFSExtensionProvider {
|
||||||
* If the EFS store represented by locationURI is backed by a physical file, gets the path corresponding
|
* If the EFS store represented by locationURI is backed by a physical file, gets the path corresponding
|
||||||
* to the underlying file as the operating system on hosting machine would see it. In the future, it would
|
* to the underlying file as the operating system on hosting machine would see it. In the future, it would
|
||||||
* be better if EFS had an API for this.
|
* be better if EFS had an API for this.
|
||||||
*
|
*
|
||||||
* @param locationURI
|
* @param locationURI
|
||||||
* @return String representing the path, or <code>null</code> if there is an error or if there is no such
|
* @return String representing the path, or <code>null</code> if there is an error or if there is no such
|
||||||
* physical file.
|
* physical file.
|
||||||
*/
|
*/
|
||||||
public String getPathFromURI(URI locationURI) {
|
public String getPathFromURI(URI locationURI) {
|
||||||
return locationURI.getPath();
|
String path = locationURI.getPath();
|
||||||
|
// URI path on Windows is represented as "/C:/path"
|
||||||
|
if (path != null && Platform.getOS().equals(Platform.WS_WIN32) && 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
|
* 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,
|
* URIs in other filesystems, returns the URI that this URI links to. If the filesystem is not virtual,
|
||||||
* then this method acts as an identity mapping.
|
* then this method acts as an identity mapping.
|
||||||
*
|
*
|
||||||
* @param locationURI
|
* @param locationURI
|
||||||
* @return A URI corresponding to the linked store, or <code>null</code> on error.
|
* @return A URI corresponding to the linked store, or <code>null</code> on error.
|
||||||
*/
|
*/
|
||||||
|
@ -73,25 +79,25 @@ public abstract class EFSExtensionProvider {
|
||||||
* Creates a new URI which clones the contents of the original URI, but with the path replaced by the
|
* Creates a new URI which clones the contents of the original URI, but with the path replaced by the
|
||||||
* given absolute path, such that calling getPathFromURI() on the returned URI will return the given path. Returns
|
* given absolute path, such that calling getPathFromURI() on the returned URI will return the given path. Returns
|
||||||
* null on error.
|
* null on error.
|
||||||
*
|
*
|
||||||
* The default implementation places the path in the path field of the URI, ensuring that there is a leading slash.
|
* 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
|
* 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
|
* local operating system's file separator is a backslash, thus ensuring proper behaviour for URIs corresponding
|
||||||
* to the local filesystem.
|
* to the local filesystem.
|
||||||
*
|
*
|
||||||
* @param locationOnSameFilesystem
|
* @param locationOnSameFilesystem
|
||||||
* @param path An absolute path.
|
* @param path An absolute path.
|
||||||
* @return URI
|
* @return URI
|
||||||
*/
|
*/
|
||||||
public URI createNewURIFromPath(URI locationOnSameFilesystem, String path) {
|
public URI createNewURIFromPath(URI locationOnSameFilesystem, String path) {
|
||||||
URI uri = locationOnSameFilesystem;
|
URI uri = locationOnSameFilesystem;
|
||||||
|
|
||||||
Path p = new Path(path);
|
Path p = new Path(path);
|
||||||
String pathString = p.toString(); // to convert any backslashes to slashes if we are on Windows
|
String pathString = p.toString(); // to convert any backslashes to slashes if we are on Windows
|
||||||
final int length = pathString.length();
|
final int length = pathString.length();
|
||||||
StringBuffer pathBuf = new StringBuffer(length + 1);
|
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) != '/')) {
|
if (length > 0 && (pathString.charAt(0) != '/')) {
|
||||||
pathBuf.append('/');
|
pathBuf.append('/');
|
||||||
}
|
}
|
||||||
|
@ -99,9 +105,9 @@ public abstract class EFSExtensionProvider {
|
||||||
if (pathString.startsWith("//")) //$NON-NLS-1$
|
if (pathString.startsWith("//")) //$NON-NLS-1$
|
||||||
pathBuf.append('/').append('/');
|
pathBuf.append('/').append('/');
|
||||||
pathBuf.append(pathString);
|
pathBuf.append(pathString);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//Bug 326957 - EFSExtensionProvider does not handle URI's correctly
|
//Bug 326957 - EFSExtensionProvider does not handle URI's correctly
|
||||||
return new URI(uri.getScheme(), uri.getAuthority(), pathBuf.toString(), // replaced!
|
return new URI(uri.getScheme(), uri.getAuthority(), pathBuf.toString(), // replaced!
|
||||||
uri.getQuery(), uri.getFragment());
|
uri.getQuery(), uri.getFragment());
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
|
@ -115,11 +121,11 @@ public abstract class EFSExtensionProvider {
|
||||||
* another path (say, on the local machine), this method returns the path that the store maps to. I.e., it
|
* 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
|
* 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.
|
* 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 filesystem maps one filesytem 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
|
* field of its URIs (which the default implementation assumes), but this is not guaranteed to be so for
|
||||||
* all filesystem implementations.
|
* all filesystem implementations.
|
||||||
*
|
*
|
||||||
* @return String representing the path, or <code>null</code> on error.
|
* @return String representing the path, or <code>null</code> on error.
|
||||||
*/
|
*/
|
||||||
public String getMappedPath(URI locationURI) {
|
public String getMappedPath(URI locationURI) {
|
||||||
|
@ -129,7 +135,7 @@ public abstract class EFSExtensionProvider {
|
||||||
/**
|
/**
|
||||||
* Returns true if the given URI is part of a virtual filesystem and thus points to another underlying
|
* 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.
|
* URI. Returns false otherwise. By default, filesystems are assumed to be non-virtual.
|
||||||
*
|
*
|
||||||
* @param locationURI
|
* @param locationURI
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
@ -139,12 +145,12 @@ public abstract class EFSExtensionProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new URI with the same components as the baseURI, except that calling
|
* Creates a new URI with the same components as the baseURI, except that calling
|
||||||
* getPathFromURI() on the new URI will return a path that has the extension appended to
|
* getPathFromURI() on the new URI will return a path that has the extension appended to
|
||||||
* the path returned by baseURI.getPathFromURI()
|
* the path returned by baseURI.getPathFromURI()
|
||||||
*
|
*
|
||||||
* The default implementation assumes that the path component of the URI is used
|
* The default implementation assumes that the path component of the URI is used
|
||||||
* to store the path.
|
* to store the path.
|
||||||
*
|
*
|
||||||
* @param baseURI
|
* @param baseURI
|
||||||
* @param extension
|
* @param extension
|
||||||
* @return the new URI, or <code>null</code> on error.
|
* @return the new URI, or <code>null</code> on error.
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class ErrorParserManager extends OutputStream implements IConsoleParser,
|
||||||
* @since 5.4
|
* @since 5.4
|
||||||
*/
|
*/
|
||||||
public static final String BUILD_CONTEXT = "build"; //$NON-NLS-1$
|
public static final String BUILD_CONTEXT = "build"; //$NON-NLS-1$
|
||||||
|
|
||||||
private int nOpens;
|
private int nOpens;
|
||||||
private int lineCounter=0;
|
private int lineCounter=0;
|
||||||
|
|
||||||
|
@ -221,16 +221,7 @@ public class ErrorParserManager extends OutputStream implements IConsoleParser,
|
||||||
*/
|
*/
|
||||||
public void pushDirectory(IPath dir) {
|
public void pushDirectory(IPath dir) {
|
||||||
if (dir != null) {
|
if (dir != null) {
|
||||||
URI uri;
|
URI uri = toURI(dir);
|
||||||
URI workingDirectoryURI = getWorkingDirectoryURI();
|
|
||||||
if (!dir.isAbsolute()) {
|
|
||||||
uri = URIUtil.append(workingDirectoryURI, dir.toString());
|
|
||||||
} else {
|
|
||||||
uri = toURI(dir);
|
|
||||||
if (uri == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pushDirectoryURI(uri);
|
pushDirectoryURI(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -485,18 +476,9 @@ outer:
|
||||||
* @return - file in the workspace or {@code null} if such a file doesn't exist
|
* @return - file in the workspace or {@code null} if such a file doesn't exist
|
||||||
*/
|
*/
|
||||||
protected IFile findFileInWorkspace(IPath path) {
|
protected IFile findFileInWorkspace(IPath path) {
|
||||||
URI uri;
|
URI uri = toURI(path);
|
||||||
if (!path.isAbsolute()) {
|
IFile file = findFileInWorkspace(uri);
|
||||||
URI workingDirectoryURI = getWorkingDirectoryURI();
|
return file;
|
||||||
uri = EFSExtensionManager.getDefault().append(workingDirectoryURI, path.toString());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uri = toURI(path);
|
|
||||||
if (uri == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return findFileInWorkspace(uri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -728,10 +710,7 @@ outer:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a location {@link IPath} to an {@link URI}. Contrary to
|
* Converts a location {@link IPath} to an {@link URI}.
|
||||||
* {@link URIUtil#toURI(IPath)} this method does not assume that the path belongs
|
|
||||||
* to local file system.
|
|
||||||
*
|
|
||||||
* The returned URI uses the scheme and authority of the current working directory
|
* The returned URI uses the scheme and authority of the current working directory
|
||||||
* as returned by {@link #getWorkingDirectoryURI()}
|
* as returned by {@link #getWorkingDirectoryURI()}
|
||||||
*
|
*
|
||||||
|
@ -740,16 +719,15 @@ outer:
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
private URI toURI(IPath path) {
|
private URI toURI(IPath path) {
|
||||||
// try {
|
URI uri = null;
|
||||||
URI baseURI = getWorkingDirectoryURI();
|
URI workingDirectoryURI = getWorkingDirectoryURI();
|
||||||
String uriString = path.toString();
|
if (path.isAbsolute()) {
|
||||||
|
uri = EFSExtensionManager.getDefault().createNewURIFromPath(workingDirectoryURI, path.toString());
|
||||||
|
} else {
|
||||||
|
uri = EFSExtensionManager.getDefault().append(workingDirectoryURI, path.toString());
|
||||||
|
}
|
||||||
|
|
||||||
// On Windows "C:/folder/" -> "/C:/folder/"
|
return uri;
|
||||||
if (path.isAbsolute() && uriString.charAt(0) != IPath.SEPARATOR) {
|
|
||||||
uriString = IPath.SEPARATOR + uriString;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EFSExtensionManager.getDefault().createNewURIFromPath(baseURI, uriString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -828,7 +806,7 @@ outer:
|
||||||
public static String[] getErrorParserAvailableIdsInContext(String context) {
|
public static String[] getErrorParserAvailableIdsInContext(String context) {
|
||||||
return ErrorParserExtensionManager.getErrorParserAvailableIdsInContext(context);
|
return ErrorParserExtensionManager.getErrorParserAvailableIdsInContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return IDs of error parsers contributed through error parser extension point.
|
* @return IDs of error parsers contributed through error parser extension point.
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
|
|
Loading…
Add table
Reference in a new issue