mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 05:15:43 +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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,7 +55,12 @@ public abstract class EFSExtensionProvider {
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,7 +97,7 @@ public abstract class EFSExtensionProvider {
|
||||||
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('/');
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
// On Windows "C:/folder/" -> "/C:/folder/"
|
} else {
|
||||||
if (path.isAbsolute() && uriString.charAt(0) != IPath.SEPARATOR) {
|
uri = EFSExtensionManager.getDefault().append(workingDirectoryURI, path.toString());
|
||||||
uriString = IPath.SEPARATOR + uriString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EFSExtensionManager.getDefault().createNewURIFromPath(baseURI, uriString);
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue