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);
|
||||
|
||||
assertEquals(path, "/c:/foo");
|
||||
assertEquals(path, "c:/foo");
|
||||
}
|
||||
|
||||
public void testGetPathFromURI() {
|
||||
|
@ -248,7 +248,7 @@ public class EFSExtensionTests extends TestCase {
|
|||
|
||||
String path = EFSExtensionManager.getDefault().getMappedPath(originalURI);
|
||||
|
||||
assertEquals(path, "/c:/foo");
|
||||
assertEquals(path, "c:/foo");
|
||||
}
|
||||
|
||||
public void testExtension() {
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.URIUtil;
|
||||
|
||||
/**
|
||||
|
@ -54,7 +55,12 @@ public abstract class EFSExtensionProvider {
|
|||
* physical file.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,7 +97,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('/');
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
// On Windows "C:/folder/" -> "/C:/folder/"
|
||||
if (path.isAbsolute() && uriString.charAt(0) != IPath.SEPARATOR) {
|
||||
uriString = IPath.SEPARATOR + uriString;
|
||||
URI uri = null;
|
||||
URI workingDirectoryURI = getWorkingDirectoryURI();
|
||||
if (path.isAbsolute()) {
|
||||
uri = EFSExtensionManager.getDefault().createNewURIFromPath(workingDirectoryURI, path.toString());
|
||||
} else {
|
||||
uri = EFSExtensionManager.getDefault().append(workingDirectoryURI, path.toString());
|
||||
}
|
||||
|
||||
return EFSExtensionManager.getDefault().createNewURIFromPath(baseURI, uriString);
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue