# HG changeset patch # User Ed Swartz # Date 1260817618 21600 # Node ID dabe5b8e3aecb3677f2aabd263461c238456096a # Parent 8e79006903413b6c7bba415d28d0fc99f71c1e08# Parent 7b05fffc0084dd032419d375a9f7ac962744cf76 Merge commit diff -r 7b05fffc0084 -r dabe5b8e3aec builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/TestProjectExportsGatherer.java --- a/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/TestProjectExportsGatherer.java Mon Dec 14 10:28:53 2009 -0600 +++ b/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/TestProjectExportsGatherer.java Mon Dec 14 13:06:58 2009 -0600 @@ -18,6 +18,7 @@ package com.nokia.carbide.cdt.builder.test; import com.nokia.carbide.cdt.internal.api.builder.ProjectExportsGatherer; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.core.runtime.*; import org.osgi.framework.Bundle; @@ -111,8 +112,8 @@ ProjectExportsGatherer gatherer = createGatherer(); IPath src1 = projectDataPath.append("gfx/foo.svg"); IPath src2 = projectDataPath.append("doc/README.txt"); - IPath epoc1 = new Path("c:/private/12345678/foo.svg"); - IPath epoc2 = new Path("c:/sys/readmes/README.txt"); + IPath epoc1 = PathUtils.createPath("c:/private/12345678/foo.svg"); + IPath epoc2 = PathUtils.createPath("c:/sys/readmes/README.txt"); Map filesystemToEpocExportMap = gatherer.getFilesystemToEpocExportMap(); assertEquals(2, filesystemToEpocExportMap.size()); @@ -138,13 +139,13 @@ IPath epoc1a = projectDataPath.append("sis/text/englishfile.txt"); IPath epoc1b = epocRoot.append("text/frenchfile.txt"); - IPath dev1 = new Path("$:/private/10000005/import/InstTest/lang.txt"); + IPath dev1 = PathUtils.createPath("$:/private/10000005/import/InstTest/lang.txt"); IPath epoc2 = epocRoot.append("epoc32/text/file1.txt"); - IPath dev2 = new Path("!:/private/10000005/import/InstTest/file1.txt"); + IPath dev2 = PathUtils.createPath("!:/private/10000005/import/InstTest/file1.txt"); IPath epoc3 = epocRoot.append("epoc32/files/option1.txt"); - IPath dev3 = new Path("!:/private/10000005/import/InstTest/option1.txt"); + IPath dev3 = PathUtils.createPath("!:/private/10000005/import/InstTest/option1.txt"); Map filesystemToEpocExportMap = gatherer.getFilesystemToEpocExportMap(); assertEquals(0, filesystemToEpocExportMap.size()); @@ -178,22 +179,22 @@ //IPath epoc1a = projectDataPath.append("sis/text/englishfile.txt"); //IPath src1b = projectDataPath.append("sis/text/frenchfile.txt"); IPath epoc1b = epocRoot.append("epoc32/text/frenchfile.txt"); - IPath dev1 = new Path("$:/private/10000005/import/InstTest/lang.txt"); + IPath dev1 = PathUtils.createPath("$:/private/10000005/import/InstTest/lang.txt"); IPath src2 = projectDataPath.append("gfx/foo.svg"); - IPath epocTarget2 = new Path("c:/private/12345678/foo.svg"); + IPath epocTarget2 = PathUtils.createPath("c:/private/12345678/foo.svg"); IPath epocHost2 = epocRoot.append("epoc32/data/c/private/12345678/foo.svg"); - IPath dev2 = new Path("!:/private/10000005/foo.svg"); + IPath dev2 = PathUtils.createPath("!:/private/10000005/foo.svg"); IPath src3 = projectDataPath.append("doc/README.txt"); IPath epocHost3 = epocRoot.append("epoc32/release/armv5/udeb/z/sys/readmes/README.txt"); - IPath epoc3 = new Path("z:/sys/readmes/README.txt"); - IPath dev3 = new Path("!:/private/10000005/import/InstTest/README.txt"); + IPath epoc3 = PathUtils.createPath("z:/sys/readmes/README.txt"); + IPath dev3 = PathUtils.createPath("!:/private/10000005/import/InstTest/README.txt"); IPath src4 = projectDataPath.append("inc/Test.h"); - IPath epoc4 = new Path("/epoc32/include/Test.h"); + IPath epoc4 = PathUtils.createPath("/epoc32/include/Test.h"); IPath src5 = projectDataPath.append("inc/Test00.h"); - IPath epoc5 = new Path("/epoc32/include/TestPrefix.h"); + IPath epoc5 = PathUtils.createPath("/epoc32/include/TestPrefix.h"); Map filesystemToEpocExportMap = gatherer.getFilesystemToEpocExportMap(); assertEquals(4, filesystemToEpocExportMap.size()); diff -r 7b05fffc0084 -r dabe5b8e3aec builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/errorParsers/CarbideErrorParserTestHarness.java --- a/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/errorParsers/CarbideErrorParserTestHarness.java Mon Dec 14 10:28:53 2009 -0600 +++ b/builder/com.nokia.carbide.cdt.builder.test/src/com/nokia/carbide/cdt/builder/test/errorParsers/CarbideErrorParserTestHarness.java Mon Dec 14 13:06:58 2009 -0600 @@ -38,6 +38,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; import org.jdom.Attribute; import org.jdom.Comment; import org.jdom.DefaultJDOMFactory; @@ -244,7 +245,8 @@ } } else { if (result.externalPath.equals(expected.externalPath) == false) { - // note: for some reason, on Unix, relative paths become full paths + // note: since we're processing Win32-style paths in our input, these + // get mangled on Unix. Ignore differences in relative vs. absolute if (result.externalPath.makeRelative().equals(expected.externalPath.makeRelative())) { // fine } else { @@ -300,7 +302,8 @@ variableName = variableNameNode.getValue(); Attribute externalPathStringNode = markerInfo.getAttribute(EXTERNAL_PATH_STRING); - externalPath = HostOS.createPathFromString(externalPathStringNode.getValue()); + // need to regress to non-portability here, since CDT doesn't have the Win32 device hack that we do + externalPath = new Path(externalPathStringNode.getValue().replaceAll("\\\\", "/")); ProblemMarkerInfo details = new ProblemMarkerInfo(file, lineNumber, description, severity, variableName, externalPath); xmlFilePromblemMarkerInfoList.add(details); diff -r 7b05fffc0084 -r dabe5b8e3aec builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java --- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java Mon Dec 14 10:28:53 2009 -0600 +++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEngineHelper.java Mon Dec 14 13:06:58 2009 -0600 @@ -63,7 +63,7 @@ absolutePath = new File(absolutePath).getCanonicalPath(); } catch (IOException e) { } - return new Path(absolutePath); + return PathUtils.createPath(absolutePath); } /** @@ -809,7 +809,7 @@ // adapt the exe filename to the variant, if any IPath tempPath = null; if (isVariantBldInf(cpi.getAbsoluteBldInfPath()) || isFeatureVariantMMP(mmpData, cpi.getProject())) { - tempPath = getBinaryVariantTargetName(mmpData, new Path(exePath), cpi.getProject()); + tempPath = getBinaryVariantTargetName(mmpData, PathUtils.createPath(exePath), cpi.getProject()); if (tempPath == null){ return null; } @@ -912,7 +912,7 @@ for (EMMPLanguage language : languages) { String extension = ".R" + language.getCodeString(); //$NON-NLS-1$ resources.put(baseGeneratedPath.toOSString() + extension.toLowerCase(), - HostOS.convertPathToWindows(targetPath)); + PathUtils.convertPathToWindows(targetPath)); } } @@ -992,7 +992,7 @@ IPath targetPath; if (targetPathStr != null) { - targetPath = new Path(targetPathStr).makeAbsolute(); + targetPath = PathUtils.createPath(targetPathStr).makeAbsolute(); } else { // for EKA1 just leave empty. for EKA2 use sys\bin\ if (buildConfig.getSDK().getOSVersion().getMajor() > 8) { @@ -1009,7 +1009,7 @@ for (IMMPAIFInfo aif : aifs) { IPath aifPath = aif.getTarget().makeAbsolute(); resources.put(dataZDir.append(targetPath).append(aifPath.lastSegment()).toOSString(), - HostOS.convertPathToWindows(targetPath.setDevice("C:"))); //$NON-NLS-1$ + PathUtils.convertPathToWindows(targetPath.setDevice("C:"))); //$NON-NLS-1$ } /////////// @@ -1036,7 +1036,7 @@ } IPath mbmDir = mbmPath.removeLastSegments(1).addTrailingSeparator().setDevice("C:"); //$NON-NLS-1$ resources.put(dataZDir.append(mbmPath).toOSString(), - HostOS.convertPathToWindows(mbmDir.toOSString())); + PathUtils.convertPathToWindows(mbmDir.toOSString())); } // get the user resources @@ -1068,7 +1068,7 @@ if (filename == null) { filename = resourceBlock.getSource().removeFileExtension().lastSegment(); } else { - filename = HostOS.createPathFromString(filename).removeFileExtension().toOSString(); + filename = PathUtils.createPath(filename).removeFileExtension().toOSString(); } filename = filename.toLowerCase(); @@ -1129,8 +1129,8 @@ if (targetPath != null && targetPath.segment(0).equalsIgnoreCase("epoc32")) { targetPath = targetPath.removeFirstSegments(3); } - resources.put(HostOS.convertPathToNative(dataZDir + targetPath.toOSString()), - HostOS.convertPathToWindows("C:\\" + targetPath.toOSString())); //$NON-NLS-1$ + resources.put(PathUtils.convertPathToNative(dataZDir + targetPath.toOSString()), + PathUtils.convertPathToWindows("C:\\" + targetPath.toOSString())); //$NON-NLS-1$ } return null; diff -r 7b05fffc0084 -r dabe5b8e3aec builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEnginePathHelper.java --- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEnginePathHelper.java Mon Dec 14 10:28:53 2009 -0600 +++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/builder/EpocEnginePathHelper.java Mon Dec 14 13:06:58 2009 -0600 @@ -33,6 +33,7 @@ import com.nokia.carbide.cpp.epoc.engine.model.IView; import com.nokia.cpp.internal.api.utils.core.Check; import com.nokia.cpp.internal.api.utils.core.FileUtils; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; @@ -133,7 +134,7 @@ * @return workspace-relative non-absolute path, or null if not resolvable to workspace */ public IPath convertFilesystemToWorkspace(IPath fullPath) { - fullPath = FileUtils.findMatchingPathCaseInsensitive(fullPath); + fullPath = PathUtils.findExistingPathIfCaseSensitive(fullPath); IPath wsPath = FileUtils.convertToWorkspacePath(fullPath, true); if (wsPath != null && wsPath.isAbsolute()) wsPath = wsPath.makeRelative(); @@ -220,8 +221,8 @@ } // canonicalize (to remove .. , resolve links, etc) - fullPath = new Path(fullPath.toFile().getCanonicalPath()).setDevice(device); - fullPath = FileUtils.findMatchingPathCaseInsensitive(fullPath); + fullPath = PathUtils.createPath(fullPath.toFile().getCanonicalPath()).setDevice(device); + fullPath = PathUtils.findExistingPathIfCaseSensitive(fullPath); } catch (IOException e) { } diff -r 7b05fffc0084 -r dabe5b8e3aec builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/api/builder/SISBuilderInfo2.java --- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/api/builder/SISBuilderInfo2.java Mon Dec 14 10:28:53 2009 -0600 +++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/api/builder/SISBuilderInfo2.java Mon Dec 14 13:06:58 2009 -0600 @@ -25,7 +25,7 @@ import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo; import com.nokia.carbide.cdt.builder.project.ISISBuilderInfo; import com.nokia.carbide.cpp.sdk.core.ISymbianSDK; -import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import com.nokia.cpp.internal.api.utils.core.TrackedResource; public class SISBuilderInfo2 implements ISISBuilderInfo { @@ -280,7 +280,7 @@ fullPath = fullPath.removeFileExtension(); fullPath = fullPath.addFileExtension(extension); } else { - IPath fileNamePath = HostOS.createPathFromString(fileName); + IPath fileNamePath = PathUtils.createPath(fileName); if (fileNamePath.isAbsolute()) { // SIS already a full path fullPath = fileNamePath; diff -r 7b05fffc0084 -r dabe5b8e3aec builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/EnvironmentVarsInfo2.java --- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/EnvironmentVarsInfo2.java Mon Dec 14 10:28:53 2009 -0600 +++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/EnvironmentVarsInfo2.java Mon Dec 14 13:06:58 2009 -0600 @@ -25,6 +25,7 @@ import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext; import com.nokia.carbide.cpp.sdk.core.ISymbianSDK; import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import com.nokia.cpp.internal.api.utils.core.TrackedResource; import org.eclipse.cdt.core.settings.model.ICStorageElement; @@ -361,7 +362,7 @@ // Fix up the notation in the environment (convert Win32-type variables to Unix-type) if (HostOS.IS_UNIX) { for (int i = 0; i < returnEnvArray.length; i++) { - returnEnvArray[i] = HostOS.convertPathListToUnix(returnEnvArray[i]); + returnEnvArray[i] = PathUtils.convertPathListToUnix(returnEnvArray[i]); } } @@ -387,7 +388,7 @@ // Fix up the notation in the environment (convert Win32-type variables to Unix-type) if (HostOS.IS_UNIX) { for (int i = 0; i < modifiedVars.length; i++) { - modifiedVars[i] = HostOS.convertPathListToUnix(modifiedVars[i]); + modifiedVars[i] = PathUtils.convertPathListToUnix(modifiedVars[i]); } } diff -r 7b05fffc0084 -r dabe5b8e3aec core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/AbstractSDKManager.java --- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/AbstractSDKManager.java Mon Dec 14 10:28:53 2009 -0600 +++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/AbstractSDKManager.java Mon Dec 14 13:06:58 2009 -0600 @@ -60,9 +60,9 @@ import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin; import com.nokia.carbide.cpp.sdk.core.ICarbideInstalledSDKChangeListener.SDKChangeEventType; import com.nokia.cpp.internal.api.utils.core.FileUtils; -import com.nokia.cpp.internal.api.utils.core.HostOS; import com.nokia.cpp.internal.api.utils.core.ListenerList; import com.nokia.cpp.internal.api.utils.core.Logging; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; import com.sun.org.apache.xpath.internal.XPathAPI; @@ -511,7 +511,7 @@ Runtime rt=Runtime.getRuntime(); List rvctToolList = new ArrayList(); - IPath[] pathEntries = HostOS.getPathEntries(null); + IPath[] pathEntries = PathUtils.getPathEntries(null); for(IPath path : pathEntries) { try { diff -r 7b05fffc0084 -r dabe5b8e3aec core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SymbianSDK.java --- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SymbianSDK.java Mon Dec 14 10:28:53 2009 -0600 +++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SymbianSDK.java Mon Dec 14 13:06:58 2009 -0600 @@ -21,7 +21,7 @@ import com.nokia.carbide.cpp.sdk.core.*; import com.nokia.carbide.internal.api.cpp.epoc.engine.preprocessor.BasicIncludeFileLocator; import com.nokia.carbide.internal.api.cpp.epoc.engine.preprocessor.MacroScanner; -import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import com.sun.org.apache.xpath.internal.XPathAPI; import org.eclipse.core.resources.ResourcesPlugin; @@ -1118,7 +1118,7 @@ variantDir = matcher.group(1); variantFile = matcher.group(3); File variantFullPathFile = new File(epocRoot, variantDir + File.separator + variantFile); - IPath variantFilePath = new Path(HostOS.convertPathToUnix(variantFullPathFile.getAbsolutePath())); + IPath variantFilePath = new Path(PathUtils.convertPathToUnix(variantFullPathFile.getAbsolutePath())); return variantFilePath; } } diff -r 7b05fffc0084 -r dabe5b8e3aec core/com.nokia.carbide.cpp.ui/src/com/nokia/carbide/cpp/internal/ui/images/CachingImageLoader.java --- a/core/com.nokia.carbide.cpp.ui/src/com/nokia/carbide/cpp/internal/ui/images/CachingImageLoader.java Mon Dec 14 10:28:53 2009 -0600 +++ b/core/com.nokia.carbide.cpp.ui/src/com/nokia/carbide/cpp/internal/ui/images/CachingImageLoader.java Mon Dec 14 13:06:58 2009 -0600 @@ -18,6 +18,7 @@ package com.nokia.carbide.cpp.internal.ui.images; import com.nokia.carbide.cpp.ui.images.*; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.core.runtime.*; import org.eclipse.swt.graphics.ImageData; @@ -130,7 +131,7 @@ */ private IPath canonicalizePath(IPath path) { try { - return new Path(path.toFile().getCanonicalPath()); + return PathUtils.createPath(path.toFile().getCanonicalPath()); } catch (IOException e) { return path; } diff -r 7b05fffc0084 -r dabe5b8e3aec core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/FileUtils.java --- a/core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/FileUtils.java Mon Dec 14 10:28:53 2009 -0600 +++ b/core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/FileUtils.java Mon Dec 14 13:06:58 2009 -0600 @@ -676,7 +676,7 @@ } } - return new Path(new String(pathChars, offset, pathChars.length - offset)); + return PathUtils.createPath(new String(pathChars, offset, pathChars.length - offset)); } /** @@ -899,68 +899,18 @@ // todo } return res; - } + } /** - * Locate the file on the filesystem which has the same path, but with - * only case sensitivity differences. This is only meaningful for fully - * case sensitive and case-preserving filesystems. + * If the filesystem is case sensitive, locate the file on the filesystem + * on the given path, by ignoring case sensitivity differences. + * This is needed on case-preserving but not case-insensitive filesystems. * @param path * @return path pointing to existing file (possibly with different case in components) or * original path if there is no match */ - public static IPath findMatchingPathCaseInsensitive(IPath path) { - // case is insensitive already - if (HostOS.IS_WIN32) - return path; - - if (path == null || !path.isAbsolute() || path.toFile().exists()) - return path; - - StringBuilder builder = new StringBuilder(); - - if (path.getDevice() != null) { - builder.append(path.getDevice()); - } - - builder.append('/'); - - boolean failedLookup = false; - - for (int seg = 0; seg < path.segmentCount(); seg++) { - final String segment = path.segment(seg); - - final String[] matches = { segment }; - - if (!failedLookup) { - File dir = new File(builder.toString()); - if (!new File(dir, matches[0]).exists()) { - // component has wrong case; find the first one matching case-insensitively - String[] names = dir.list(new FilenameFilter() { - - public boolean accept(File dir, String name) { - if (name.equalsIgnoreCase(segment)) { - matches[0] = name; - return true; - } - return false; - } - }); - - if (names.length == 0) { - // no matches! the rest of the path won't match either - failedLookup = true; - } - } - } - builder.append(matches[0]); - builder.append('/'); - } - - if (!path.hasTrailingSeparator() && builder.length() > 0 && builder.charAt(builder.length() - 1) == '/') { - builder.setLength(builder.length() - 1); - } - return new Path(builder.toString()); - } - + public static IPath findExistingPathIfCaseSensitive(IPath path) { + // PathUtils (shared with EDC) has the stock implementation + return PathUtils.findExistingPathIfCaseSensitive(path); + } } diff -r 7b05fffc0084 -r dabe5b8e3aec core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/HostOS.java --- a/core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/HostOS.java Mon Dec 14 10:28:53 2009 -0600 +++ b/core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/HostOS.java Mon Dec 14 13:06:58 2009 -0600 @@ -22,8 +22,11 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; + /** * Utilities used for portability between hosts. + *

+ * NOTE: please keep this in sync with the org.eclipse.cdt.debug.edc version of this class! */ public class HostOS { /** Is the host Windows? */ @@ -33,98 +36,6 @@ /** Executable file extension */ public static final String EXE_EXT = IS_WIN32 ? ".exe" : ""; - /** The name of the PATH variable in the environment. Capitalized differently per OS. */ - public static String PATH_VARIABLE_NAME = IS_WIN32 ? "Path" : "PATH"; - - /** - * Convert a variable constructed blindly for a Win32 environment into - * Unix-like syntax. This is typically used for PATH or lists - * of paths where ';' is the entry separator and '\' is the - * path component separator. - *

- * NOTE: we assume that the entries in the - * path list are already legal Unix paths, but just with the - * wrong slash. - * @param env - * @return converted string - */ - public static String convertPathListToUnix(String env) { - if (env == null) return null; - env = env.replaceAll(";", ":"); // entry separators - env = env.replaceAll("\\\\", "/"); // path separators - return env; - } - - /** - * Convert a path constructed blindly for a Win32 environment into - * Unix-like syntax.

- * NOTE: we assume that the path is already a legal Unix path, - * but just with the wrong slash. - * @param file - * @return converted string - */ - public static String convertPathToUnix(String file) { - if (file == null) return null; - // handle Windows slashes and canonicalize - file = file.replaceAll("\\\\", "/"); - return file; - } - - - /** - * Convert a path which may be in Windows or Unix format to Windows format. - * NOTE: we assume that the path is already a legal path, - * but just with the wrong slash. - * @param file - * @return converted string - */ - public static String convertPathToWindows(String file) { - if (file == null) return null; - file = file.replaceAll("/", "\\\\"); - return file; - } - - /** - * Convert a path which may be in Windows or Unix format to Windows format. - * NOTE: we assume that the path is already a legal path, - * but just with the wrong slash. - * @param file - * @return converted string - */ - public static String convertPathToWindows(IPath path) { - return convertPathToWindows(path.toPortableString()); - } - - /** - * Convert a path which may be in the opposite slash format to the local slash format. - * NOTE: we assume that the path is already a legal path, - * but just with the wrong slash. - * @param file - * @return converted string - */ - public static String convertPathToNative(String path) { - if (path == null) return null; - if (IS_UNIX) - return path.replaceAll("\\\\", "/"); - else - return path.replaceAll("/", "\\\\"); - } - - /** - * Create an IPath from a string which may be a Win32 path.

- * ("new Path(...)" won't work in Unix when using a Win32 path.) - * @param path - * @return converted string - */ - public static IPath createPathFromString(String path) { - if (path == null) return null; - // handle Windows slashes and canonicalize - path = path.replaceAll("\\\\", "/"); - return new Path(path); - } - - - /** * Ensure that the executable name mentioned is canonical for the machine. * This only affects Windows, currently, ensuring that an ".exe" is attached. @@ -143,27 +54,6 @@ } /** - * Get the PATH entries from the given path environment value or the - * system environment. - * @param pathValue the expected PATH/Path value, or null for the system value - * @return array of IPath, never null - */ - public static IPath[] getPathEntries(String pathValue) { - String pathVar = pathValue != null ? pathValue : System.getenv(PATH_VARIABLE_NAME); - - if (pathVar == null) - pathVar = ""; - - String pathSeparator = System.getProperty("path.separator"); - String[] pathEntries = pathVar.split(pathSeparator); - IPath[] paths = new IPath[pathEntries.length]; - for (int i = 0; i < pathEntries.length; i++) { - paths[i] = new Path(pathEntries[i]); - } - return paths; - } - - /** * Scan the PATH variable and see if the given binary is visible on * the PATH that will be used at runtime (with the default environment and overrides). * @param pathValue the expected Path @@ -173,11 +63,11 @@ public static IPath findProgramOnPath(String program, String pathValue) { // be sure proper path/extension are present - program = canonicalizeExecutableName(program); + program = HostOS.canonicalizeExecutableName(program); IPath path = null; - IPath[] pathEntries = getPathEntries(pathValue); + IPath[] pathEntries = PathUtils.getPathEntries(pathValue); for (IPath pathEntry : pathEntries) { IPath testPath = pathEntry.append(program); if (testPath.toFile().exists()) { diff -r 7b05fffc0084 -r dabe5b8e3aec core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/PathUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.cpp.utils.core/src/com/nokia/cpp/internal/api/utils/core/PathUtils.java Mon Dec 14 13:06:58 2009 -0600 @@ -0,0 +1,272 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.cpp.internal.api.utils.core; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +/** + * These utilities handle some common portability issues when dealing with + * (absolute) paths which may be in a format intended for another operating system. + * It also handles shortcomings in the org.eclipse.core.runtime.Path + * implementation, which is not able to construct a meaningful path from + * a Win32 path outside of Windows. + *

+ * NOTE: please keep this in sync with the org.eclipse.cdt.debug.edc version of this class! + */ +public class PathUtils { + + /** + * Convert a variable constructed blindly for a Win32 environment into + * Unix-like syntax. This is typically used for PATH or lists + * of paths where ';' is the entry separator and '\' is the + * path component separator. + *

+ * NOTE: we assume that the entries in the + * path list are already legal Unix paths, but just with the + * wrong slash. + * @param env + * @return converted string + */ + public static String convertPathListToUnix(String env) { + if (env == null) return null; + env = env.replaceAll(";", ":"); // entry separators + env = env.replaceAll("\\\\", "/"); // path separators + return env; + } + + /** + * Convert a path constructed blindly for a Win32 environment into + * Unix-like syntax.

+ * NOTE: we assume that the path is already a legal Unix path, + * but just with the wrong slash. + * @param file + * @return converted string + */ + public static String convertPathToUnix(String file) { + if (file == null) return null; + // handle Windows slashes and canonicalize + file = file.replaceAll("\\\\", "/"); + return file; + } + + /** + * Convert a path which may be in Windows or Unix format to Windows format. + * NOTE: we assume that the path is already a legal path, + * but just with the wrong slash. + * @param file + * @return converted string + */ + public static String convertPathToWindows(String file) { + if (file == null) return null; + file = file.replaceAll("/", "\\\\"); + return file; + } + + /** + * Convert a path which may be in Windows or Unix format to Windows format. + * NOTE: we assume that the path is already a legal path, + * but just with the wrong slash. + * @param file + * @return converted string + */ + public static String convertPathToWindows(IPath path) { + return convertPathToWindows(path.toPortableString()); + } + + /** + * Convert a path which may be in the opposite slash format to the local slash format. + * NOTE: we assume that the path is already a legal path, + * but just with the wrong slash. + * @param file + * @return converted string + */ + public static String convertPathToNative(String path) { + if (path == null) return null; + if (HostOS.IS_UNIX) + return path.replaceAll("\\\\", "/"); + else + return path.replaceAll("/", "\\\\"); + } + + /** + * Create an IPath from a string which may be a Win32 path.

+ *

+ * ("new Path(...)" won't work in Unix when using a Win32 path: the backslash + * separator and the device notation are completely munged.) + * @param path + * @return converted string + */ + public static IPath createPath(String path) { + if (path == null) return null; + if (path.contains("\\")) { + // handle Windows slashes and canonicalize + path = path.replaceAll("\\\\", "/"); + } + + // also check for device or UNC + int idx = path.indexOf(":"); + if (idx > 0) { + String device = path.substring(0, idx + 1); + path = path.substring(idx + 1); + return new Path(path).setDevice(device); + } + else { + // Cygwin or UNC path + if (path.startsWith("//")) { + String network; + idx = path.indexOf("/", 2); + if (idx > 0) { + network = path.substring(0, idx); + path = path.substring(idx); + } else { + network = path; + path = ""; + } + return new Path(network, path).makeUNC(true); + } + } + + // fallthrough + return new Path(path); + } + + /** + * Get the PATH entries from the given path environment value or the + * system environment. + * @param pathValue the expected PATH/Path value, or null for the system value + * @return array of IPath, never null + */ + public static IPath[] getPathEntries(String pathValue) { + String pathVar = null; + if (pathValue != null) { + pathVar = pathValue; + } else { + if (HostOS.IS_WIN32) { + // canonical name, plus fallback below + pathVar = System.getenv("Path"); //$NON-NLS-1$ + } + if (pathVar == null) { + pathVar = System.getenv("PATH"); //$NON-NLS-1$ + } + } + + if (pathVar == null) + pathVar = ""; + + String pathSeparator = System.getProperty("path.separator"); + String[] pathEntries = pathVar.split(pathSeparator); + IPath[] paths = new IPath[pathEntries.length]; + for (int i = 0; i < pathEntries.length; i++) { + paths[i] = new Path(pathEntries[i]); + } + return paths; + } + + /** + * If the filesystem is case sensitive, locate the file on the filesystem + * on the given path, by ignoring case sensitivity differences. + * This is needed on case-preserving but not case-insensitive filesystems. + * @param path + * @return path pointing to existing file (possibly with different case in components) or + * original path if there is no match + */ + public static IPath findExistingPathIfCaseSensitive(IPath path) { + // case is insensitive already + if (HostOS.IS_WIN32) + return path; + + if (path == null || !path.isAbsolute()) + return path; + + File pathFile = path.toFile(); + if (pathFile.exists()) { + try { + return new Path(pathFile.getCanonicalPath()); + } catch (IOException e) { + // should not happen + return path; + } + } + + + // start with the assumption that the path is mostly correct except for the + // last N segments. + IPath goodPath = Path.ROOT; + if (path.getDevice() != null) + goodPath = goodPath.setDevice(path.getDevice()); + + // if bad drive or no root (?!), just skip + if (!goodPath.toFile().exists()) + return path; + + for (int seg = path.segmentCount(); seg > 0; seg--) { + final IPath prefix = path.uptoSegment(seg - 1); + + if (prefix.toFile().exists()) { + goodPath = prefix; + break; + } + } + + StringBuilder builder = new StringBuilder(); + + builder.append(goodPath.addTrailingSeparator().toOSString()); + + boolean failedLookup = false; + + for (int seg = goodPath.segmentCount(); seg < path.segmentCount(); seg++) { + final String segment = path.segment(seg); + + final String[] matches = { segment }; + + if (!failedLookup) { + File dir = new File(builder.toString()); + if (!new File(dir, matches[0]).exists()) { + // component has wrong case; find the first one matching case-insensitively + String[] names = dir.list(new FilenameFilter() { + + public boolean accept(File dir, String name) { + if (name.equalsIgnoreCase(segment)) { + matches[0] = name; + return true; + } + return false; + } + }); + + if (names.length == 0) { + // no matches! the rest of the path won't match either + failedLookup = true; + } + } + } + builder.append(matches[0]); + builder.append('/'); + } + + if (!path.hasTrailingSeparator() && builder.length() > 0 && builder.charAt(builder.length() - 1) == '/') { + builder.setLength(builder.length() - 1); + } + return new Path(builder.toString()); + } +} diff -r 7b05fffc0084 -r dabe5b8e3aec debuggercdi/com.nokia.cdt.debug.cw.symbian/src/com/nokia/cdt/debug/cw/symbian/SettingsData.java --- a/debuggercdi/com.nokia.cdt.debug.cw.symbian/src/com/nokia/cdt/debug/cw/symbian/SettingsData.java Mon Dec 14 10:28:53 2009 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.cw.symbian/src/com/nokia/cdt/debug/cw/symbian/SettingsData.java Mon Dec 14 13:06:58 2009 -0600 @@ -62,7 +62,7 @@ import com.nokia.carbide.cpp.sdk.core.ISymbianSDK; import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin; import com.nokia.carbide.remoteconnections.interfaces.IConnection; -import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import cwdbg.PreferenceConstants; @@ -383,7 +383,7 @@ // otherwise warn them that we can't set default values. if (buildConfig.getPlatformString().compareTo(ISymbianBuildContext.EMULATOR_PLATFORM) != 0) { configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, mainExeHostPath == null ? "" : mainExeHostPath.toOSString()); - configuration.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, mainExeTargetPath == null ? "" : HostOS.convertPathToWindows(mainExeTargetPath)); + configuration.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, mainExeTargetPath == null ? "" : PathUtils.convertPathToWindows(mainExeTargetPath)); } else { displayWarningDialog(Messages.getString("SettingsData.37")); //$NON-NLS-1$ } @@ -529,9 +529,9 @@ if (hp != null) { IPath tp = EpocEngineHelper.getTargetPathForExecutable(buildConfig, mmp); if (tp == null) { - tp = HostOS.createPathFromString(defaultTargetPath).append(hp.lastSegment()); + tp = PathUtils.createPath(defaultTargetPath).append(hp.lastSegment()); } - prefsData += hp.toOSString() + "," + HostOS.convertPathToWindows(tp) + enabled; //$NON-NLS-1$ + prefsData += hp.toOSString() + "," + PathUtils.convertPathToWindows(tp) + enabled; //$NON-NLS-1$ } HashMap hostTargetRSRCMap = EpocEngineHelper.getHostAndTargetResources(buildConfig, mmp); @@ -1020,7 +1020,7 @@ } public static void setProcessToLaunch(ILaunchConfigurationWorkingCopy configuration, IPath path) { - configuration.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, HostOS.convertPathToWindows(path)); + configuration.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, PathUtils.convertPathToWindows(path)); } } \ No newline at end of file diff -r 7b05fffc0084 -r dabe5b8e3aec debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/FileTransferTab.java --- a/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/FileTransferTab.java Mon Dec 14 10:28:53 2009 -0600 +++ b/debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/ui/FileTransferTab.java Mon Dec 14 13:06:58 2009 -0600 @@ -18,7 +18,7 @@ import com.nokia.cdt.debug.cw.symbian.SettingsData; import com.nokia.cdt.internal.debug.launch.LaunchPlugin; -import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import cwdbg.PreferenceConstants; @@ -91,13 +91,13 @@ StringTokenizer tokenizer = new StringTokenizer(filesString, ","); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { IPath hp = new Path(tokenizer.nextToken()); - IPath tp = HostOS.createPathFromString(tokenizer.nextToken()); + IPath tp = PathUtils.createPath(tokenizer.nextToken()); // ensure there was no filename before if (tp.getFileExtension() == null) { tp = tp.append(hp.lastSegment()); } String enabled = tokenizer.nextToken(); - files.add(new FileToTransfer(hp.toOSString(), HostOS.convertPathToWindows(tp), enabled.compareTo("1") == 0)); //$NON-NLS-1$ + files.add(new FileToTransfer(hp.toOSString(), PathUtils.convertPathToWindows(tp), enabled.compareTo("1") == 0)); //$NON-NLS-1$ } } } else { diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/ParserConfigurationBase.java --- a/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/ParserConfigurationBase.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/ParserConfigurationBase.java Mon Dec 14 13:06:58 2009 -0600 @@ -27,6 +27,7 @@ import com.nokia.carbide.internal.cpp.epoc.engine.parser.IDocumentParser; import com.nokia.carbide.internal.cpp.epoc.engine.parser.ParserFactory; import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -107,7 +108,7 @@ public File findIncludeFile(String file, boolean isUser, File currentDir) { if (HostOS.IS_UNIX) { - file = HostOS.convertPathToUnix(file); + file = PathUtils.convertPathToUnix(file); } if (fs.containsKey(file)) diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/conversion/TestLegacyImageFileConversion.java --- a/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/conversion/TestLegacyImageFileConversion.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/conversion/TestLegacyImageFileConversion.java Mon Dec 14 13:06:58 2009 -0600 @@ -33,6 +33,7 @@ import com.nokia.carbide.internal.api.cpp.epoc.engine.image.IPathResolver; import com.nokia.carbide.internal.api.cpp.epoc.engine.image.LegacyImageFileConverterFactory; import com.nokia.cpp.internal.api.utils.core.FileUtils; +import com.nokia.cpp.internal.api.utils.core.PathUtils; public class TestLegacyImageFileConversion extends BaseTest { @@ -115,7 +116,7 @@ assertEquals(true, src.isColor()); assertEquals(12, src.getDepth()); assertEquals(1, src.getMaskDepth()); - assertEquals(new Path("c:/pix/aif/list_icon.bmp"), src.getPath()); + assertEquals(PathUtils.createPath("c:/pix/aif/list_icon.bmp"), src.getPath()); assertEquals(new Path("list_icon_mask.bmp"), ((IBitmapSource) src).getMaskPath()); src = sources.get(1); diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestBldInfView.java --- a/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestBldInfView.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestBldInfView.java Mon Dec 14 13:06:58 2009 -0600 @@ -25,6 +25,7 @@ import com.nokia.cpp.internal.api.utils.core.FileUtils; import com.nokia.cpp.internal.api.utils.core.HostOS; import com.nokia.cpp.internal.api.utils.core.IMessage; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -425,7 +426,7 @@ exp = exports.get(2); assertEquals(new Path("group/here.exe"), exp.getSourcePath()); - assertEquals(new Path("c:/sys/bin/virus.exe"), exp.getTargetPath()); + assertEquals(PathUtils.createPath("c:/sys/bin/virus.exe"), exp.getTargetPath()); assertFalse(exp.isZipped()); exp = exports.get(3); @@ -460,7 +461,7 @@ exp = view.createExport(); exp.setSourcePath(new Path("group/here.exe")); - exp.setTargetPath(new Path("c:/sys/bin/virus.exe")); + exp.setTargetPath(PathUtils.createPath("c:/sys/bin/virus.exe")); assertFalse(exp.isZipped()); view.getExports().add(exp); diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestImageMakefileView.java --- a/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestImageMakefileView.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestImageMakefileView.java Mon Dec 14 13:06:58 2009 -0600 @@ -27,6 +27,7 @@ import com.nokia.carbide.internal.cpp.epoc.engine.model.StandaloneModelProvider; import com.nokia.cpp.internal.api.utils.core.FileUtils; import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.cdt.make.core.makefile.IDirective; import org.eclipse.cdt.make.core.makefile.gnu.IInclude; @@ -999,8 +1000,8 @@ IPath outBmpPath = stockRootedImgPath.append("foo.bmp").setDevice(null); IPath outSvgPath = stockRootedSvgPath.append("foo.svg"); String refText = "RESOURCE:\n"+ - "\tmifconv hello.mif \\\n\t/c8,1 "+HostOS.convertPathToWindows(outBmpPath) + " " - + "\\\n\t/c32 " + HostOS.convertPathToWindows(outSvgPath) + "\n"; + "\tmifconv hello.mif \\\n\t/c8,1 "+PathUtils.convertPathToWindows(outBmpPath) + " " + + "\\\n\t/c32 " + PathUtils.convertPathToWindows(outSvgPath) + "\n"; commitTest(view, refText); diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMMPView.java --- a/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMMPView.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMMPView.java Mon Dec 14 13:06:58 2009 -0600 @@ -28,6 +28,7 @@ import com.nokia.carbide.internal.cpp.epoc.engine.model.ViewASTBase; import com.nokia.cpp.internal.api.utils.core.HostOS; import com.nokia.cpp.internal.api.utils.core.IMessage; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -1674,10 +1675,7 @@ IMMPBitmap bitmap = view.createMMPBitmap(); bitmap.setTargetFile("target.mbm"); - if (HostOS.IS_WIN32) - bitmap.setTargetPath(new Path("e:\\foo\\bar")); - else - bitmap.setTargetPath(new Path("e:/foo/bar")); + bitmap.setTargetPath(PathUtils.createPath("e:/foo/bar")); bitmap.setHeaderFlags(EGeneratedHeaderFlags.Header); IBitmapSource source = bitmap.createBitmapSource(); @@ -1728,7 +1726,7 @@ IMMPBitmap bitmap = view.getBitmaps().get(0); bitmap.setTargetFile("target.mbm"); - bitmap.setTargetPath(new Path(nativePath)); + bitmap.setTargetPath(PathUtils.createPath(nativePath)); bitmap.setHeaderFlags(EGeneratedHeaderFlags.Header); IBitmapSource source = (IBitmapSource) bitmap.getSources().get(0); diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMMPView3.java --- a/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMMPView3.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMMPView3.java Mon Dec 14 13:06:58 2009 -0600 @@ -28,7 +28,7 @@ import com.nokia.carbide.cpp.sdk.core.ISymbianSDK; import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin; import com.nokia.carbide.cpp.sdk.core.SymbianSDKFactory; -import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.core.runtime.*; import org.osgi.framework.Version; @@ -116,7 +116,7 @@ // if we got here, now try converting back boolean isFixedDirectory = false; String origDefFile = mmpView.getSingleArgumentSettings().get(EMMPStatement.DEFFILE); - if (origDefFile != null && new Path(HostOS.convertPathToUnix(origDefFile)).segmentCount() > 1) + if (origDefFile != null && new Path(PathUtils.convertPathToUnix(origDefFile)).segmentCount() > 1) isFixedDirectory = true; mmpView.setDefFile(realPath, isFixedDirectory); IPath convPath = mmpView.getDefFile(); diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMakefileView.java --- a/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMakefileView.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMakefileView.java Mon Dec 14 13:06:58 2009 -0600 @@ -29,6 +29,7 @@ import com.nokia.carbide.cpp.epoc.engine.tests.BaseTest; import com.nokia.cpp.internal.api.utils.core.HostOS; import com.nokia.cpp.internal.api.utils.core.IMessage; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.cdt.make.core.makefile.ICommand; import org.eclipse.cdt.make.core.makefile.IMacroDefinition; @@ -406,8 +407,8 @@ new String[] { "TARGETDIR", "ZDIR" }); assertEquals(unexpanded, repl); } else { - expanded = HostOS.convertPathToUnix(expanded); - unexpanded = HostOS.convertPathToUnix(unexpanded); + expanded = PathUtils.convertPathToUnix(expanded); + unexpanded = PathUtils.convertPathToUnix(unexpanded); String repl = view.unexpandMacros(expanded, new String[] { "TARGETDIR", "ZDIR" }); assertEquals(unexpanded, repl); diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestModelsAndViews.java --- a/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestModelsAndViews.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestModelsAndViews.java Mon Dec 14 13:06:58 2009 -0600 @@ -31,6 +31,7 @@ import com.nokia.carbide.cpp.epoc.engine.tests.model.dummy.IDummyView; import com.nokia.carbide.internal.api.cpp.epoc.engine.dom.IASTTranslationUnit; import com.nokia.carbide.internal.cpp.epoc.engine.model.ViewASTBase; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -638,8 +639,8 @@ view.convertProjectToModelPath(null)); assertEquals(new Path("/foo/bar/baz.txt"), view.convertProjectToModelPath(new Path("/foo/bar/baz.txt"))); - assertEquals(new Path("x:/foo/bar/baz.txt"), - view.convertProjectToModelPath(new Path("x:/foo/bar/baz.txt"))); + assertEquals(PathUtils.createPath("x:/foo/bar/baz.txt"), + view.convertProjectToModelPath(PathUtils.createPath("x:/foo/bar/baz.txt"))); assertEquals(new Path("path/to/mymodel.mdl"), view.convertModelToProjectPath(new Path("mymodel.mdl"))); @@ -653,8 +654,8 @@ view.convertProjectToModelPath(null)); assertEquals(new Path("/foo/bar/baz.txt"), view.convertProjectToModelPath(new Path("/foo/bar/baz.txt"))); - assertEquals(new Path("x:/foo/bar/baz.txt"), - view.convertProjectToModelPath(new Path("x:/foo/bar/baz.txt"))); + assertEquals(PathUtils.createPath("x:/foo/bar/baz.txt"), + view.convertProjectToModelPath(PathUtils.createPath("x:/foo/bar/baz.txt"))); } } diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestPKGView.java --- a/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestPKGView.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestPKGView.java Mon Dec 14 13:06:58 2009 -0600 @@ -23,8 +23,8 @@ import com.nokia.carbide.cpp.epoc.engine.preprocessor.*; import com.nokia.carbide.internal.api.cpp.epoc.engine.model.pkg.*; import com.nokia.carbide.internal.cpp.epoc.engine.model.pkg.PKGView; -import com.nokia.cpp.internal.api.utils.core.HostOS; import com.nokia.cpp.internal.api.utils.core.Logging; +import com.nokia.cpp.internal.api.utils.core.PathUtils; import org.eclipse.core.runtime.*; import org.eclipse.jface.text.IDocument; @@ -140,24 +140,24 @@ // first install file is language dependent IPKGInstallFile installFile = installFileList.get(0); - assertEquals(HostOS.createPathFromString(LANG_DEST_FILE), installFile.getDestintationFile()); + assertEquals(PathUtils.createPath(LANG_DEST_FILE), installFile.getDestintationFile()); List langs = view.getLanguages(); assertEquals(2, langs.size()); Map sourceFiles = installFile.getSourceFiles(); for (EPKGLanguage lang : langs) { IPath srcFilePath = sourceFiles.get(lang); String srcFile = lang2SrcFileMap.get(lang.getCode()); - assertEquals(HostOS.createPathFromString(srcFile), srcFilePath); + assertEquals(PathUtils.createPath(srcFile), srcFilePath); } // second install file is language independent installFile = installFileList.get(1); - assertEquals(HostOS.createPathFromString(NO_LANG_DEST_FILE), installFile.getDestintationFile()); + assertEquals(PathUtils.createPath(NO_LANG_DEST_FILE), installFile.getDestintationFile()); sourceFiles = installFile.getSourceFiles(); assertEquals(1, sourceFiles.size()); assertTrue(sourceFiles.containsKey(EPKGLanguage.INDEPENDENT)); IPath srcFilePath = sourceFiles.get(EPKGLanguage.INDEPENDENT); - assertEquals(HostOS.createPathFromString(NO_LANG_SRC_FILE), srcFilePath); + assertEquals(PathUtils.createPath(NO_LANG_SRC_FILE), srcFilePath); assertEquals(1, installFile.getOptions().size()); assertEquals(NO_LANG_OPTION, installFile.getOptions().get(0)); @@ -187,7 +187,7 @@ IPath destintationFile = conditionalInstallFile.getDestintationFile(); assertTrue(destintationFile.isEmpty()); assertEquals(1, conditionalInstallFile.getSourceFiles().size()); - assertEquals(HostOS.createPathFromString(CONDITIONAL_SRC_FILE), conditionalInstallFile.getSourceFiles().get(EPKGLanguage.INDEPENDENT)); + assertEquals(PathUtils.createPath(CONDITIONAL_SRC_FILE), conditionalInstallFile.getSourceFiles().get(EPKGLanguage.INDEPENDENT)); assertEquals(2, conditionalInstallFile.getOptions().size()); commitTest(view, modelText); @@ -200,9 +200,9 @@ // fully create and add a language independent install file statement IPKGInstallFile installFile1 = view.createInstallFile(null); - installFile1.getSourceFiles().put(EPKGLanguage.INDEPENDENT, HostOS.createPathFromString(NO_LANG_SRC_FILE)); + installFile1.getSourceFiles().put(EPKGLanguage.INDEPENDENT, PathUtils.createPath(NO_LANG_SRC_FILE)); installFile1.getOptions().add(NO_LANG_OPTION); - installFile1.setDestinationFile(HostOS.createPathFromString(NO_LANG_DEST_FILE)); + installFile1.setDestinationFile(PathUtils.createPath(NO_LANG_DEST_FILE)); view.addInstallFile(installFile1); // create a language dependent install file and modify after add @@ -210,9 +210,9 @@ view.addInstallFile(installFile2); for (String[] lang2SrcFileArray : LANG_TO_SRC_FILES) { installFile2.getSourceFiles().put( - EPKGLanguage.forLangCode(lang2SrcFileArray[0]), HostOS.createPathFromString(lang2SrcFileArray[1])); + EPKGLanguage.forLangCode(lang2SrcFileArray[0]), PathUtils.createPath(lang2SrcFileArray[1])); } - installFile2.setDestinationFile(HostOS.createPathFromString(LANG_DEST_FILE)); + installFile2.setDestinationFile(PathUtils.createPath(LANG_DEST_FILE)); // NOTE: the newlines are lost and shouldn't be //String modifiedModelText = modelText + NO_LANG_INSTALL_FILE_STATEMENT + "\n" + LANG_INSTALL_FILE_STATEMENT; @@ -245,14 +245,14 @@ IPKGInstallFile file = installFiles[0]; assertEquals(2, file.getSourceFiles().size()); - assertEquals(new Path("c:/users/E0192828/back.txt"), file.getSourceFiles().get(EPKGLanguage.EN)); - assertEquals(new Path("c:/users/E0FG/front.txt"), file.getSourceFiles().get(EPKGLanguage.FR)); - assertEquals(new Path("sp ac es.txt"), file.getDestintationFile()); + assertEquals(PathUtils.createPath("c:/users/E0192828/back.txt"), file.getSourceFiles().get(EPKGLanguage.EN)); + assertEquals(PathUtils.createPath("c:/users/E0FG/front.txt"), file.getSourceFiles().get(EPKGLanguage.FR)); + assertEquals(PathUtils.createPath("sp ac es.txt"), file.getDestintationFile()); file = installFiles[1]; assertEquals(1, file.getSourceFiles().size()); - assertEquals(new Path("c:/users/E0192828/back.txt"), file.getSourceFiles().get(EPKGLanguage.INDEPENDENT)); - assertEquals(new Path("sp ac es.txt"), file.getDestintationFile()); + assertEquals(PathUtils.createPath("c:/users/E0192828/back.txt"), file.getSourceFiles().get(EPKGLanguage.INDEPENDENT)); + assertEquals(PathUtils.createPath("sp ac es.txt"), file.getDestintationFile()); commitTest(view, ESCAPABLE_FILES); } diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/api/cpp/epoc/engine/preprocessor/BasicIncludeFileLocator.java --- a/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/api/cpp/epoc/engine/preprocessor/BasicIncludeFileLocator.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/api/cpp/epoc/engine/preprocessor/BasicIncludeFileLocator.java Mon Dec 14 13:06:58 2009 -0600 @@ -27,6 +27,7 @@ import com.nokia.carbide.cpp.epoc.engine.preprocessor.IIncludeFileLocator; import com.nokia.cpp.internal.api.utils.core.HostOS; +import com.nokia.cpp.internal.api.utils.core.PathUtils; public class BasicIncludeFileLocator implements IIncludeFileLocator { private static final File[] NO_DIRS = new File[0]; @@ -45,7 +46,7 @@ public File findIncludeFile(String file, boolean isUser, File currentDir) { if (HostOS.IS_UNIX) { - file = HostOS.convertPathToUnix(file); + file = PathUtils.convertPathToUnix(file); } // see if the file exists as an absolute file diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/ViewBase.java --- a/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/ViewBase.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/ViewBase.java Mon Dec 14 13:06:58 2009 -0600 @@ -563,6 +563,9 @@ /** * Tell if the path is a Win32 path with drive letter or UNC. + * NOTE: this is for backward compatibility only! If this triggers true, + * then likely there is a bug somewhere, where "PathUtils.createPath()" should + * have been used instead of "new Path()". * @param path */ public static boolean isWin32DrivePath(IPath path) { diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/WorkspaceModelProvider.java --- a/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/WorkspaceModelProvider.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/WorkspaceModelProvider.java Mon Dec 14 13:06:58 2009 -0600 @@ -88,7 +88,7 @@ return path; } try { - return FileUtils.findMatchingPathCaseInsensitive(new Path(file.getCanonicalPath())); + return PathUtils.findExistingPathIfCaseSensitive(new Path(file.getCanonicalPath())); } catch (IOException e) { EpocEnginePlugin.log(e); return new Path(file.getAbsolutePath()); diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/bldinf/ExportListConverter.java --- a/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/bldinf/ExportListConverter.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/bldinf/ExportListConverter.java Mon Dec 14 13:06:58 2009 -0600 @@ -91,9 +91,9 @@ if (targetPath != null) { // need the backslashes for an export to a drive, else the build rules are broken // (they use 'copy' in DOS which doesn't like forward slashes) - if (ViewBase.isWin32DrivePath(targetPath)) { - target = HostOS.convertPathToWindows(targetPath.toOSString()); - source = HostOS.convertPathToWindows(sourcePath.toOSString()); + if (targetPath.getDevice() != null) { + target = PathUtils.convertPathToWindows(targetPath.toOSString()); + source = PathUtils.convertPathToWindows(sourcePath.toOSString()); } else target = bldInfView.pathString(targetPath); diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/makefile/MakefileViewBase.java --- a/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/makefile/MakefileViewBase.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/makefile/MakefileViewBase.java Mon Dec 14 13:06:58 2009 -0600 @@ -592,7 +592,7 @@ if (value == null) return null; if (HostOS.IS_UNIX) - value = HostOS.convertPathToUnix(value); + value = PathUtils.convertPathToUnix(value); return value; } }; diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/mmp/MMPView.java --- a/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/mmp/MMPView.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/mmp/MMPView.java Mon Dec 14 13:06:58 2009 -0600 @@ -784,7 +784,7 @@ String dir = singleArgumentSettings.get(EMMPStatement.TARGETPATH); if (dir == null) return null; - IPath path = new Path(FileUtils.createPossiblyRelativePath(dir).append(name).toOSString()); + IPath path = PathUtils.createPath(FileUtils.createPossiblyRelativePath(dir).append(name).toOSString()); if (FileUtils.isPathInParent(path)) { path = getProjectPath().append(path); } diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/mmp/ResourceBlockListConverter.java --- a/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/mmp/ResourceBlockListConverter.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/mmp/ResourceBlockListConverter.java Mon Dec 14 13:06:58 2009 -0600 @@ -109,8 +109,8 @@ resource.setTargetFile(((IASTMMPSingleArgumentStatement) stmt).getArgument().getValue()); } else if (EMMPStatement.TARGETPATH.matches(stmt)) { - resource.setTargetPath(new Path( - HostOS.convertPathToUnix(((IASTMMPSingleArgumentStatement) stmt).getArgument().getValue()))); + resource.setTargetPath(PathUtils.createPath( + ((IASTMMPSingleArgumentStatement) stmt).getArgument().getValue())); } else if (EMMPStatement.HEADER.matches(stmt)) { resource.setHeaderFlags(EGeneratedHeaderFlags.Header); diff -r 7b05fffc0084 -r dabe5b8e3aec project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/pkg/PKGView.java --- a/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/pkg/PKGView.java Mon Dec 14 10:28:53 2009 -0600 +++ b/project/com.nokia.carbide.cpp.epoc.engine/src/com/nokia/carbide/internal/cpp/epoc/engine/model/pkg/PKGView.java Mon Dec 14 13:06:58 2009 -0600 @@ -366,7 +366,7 @@ IASTPKGInstallFileStatement installFileStmt = (IASTPKGInstallFileStatement) node; PKGInstallFile installFile = new PKGInstallFile(installFileStmt, parentNode); IASTLiteralTextNode targetFile = installFileStmt.getTargetFile(); - installFile.setDestinationFile(HostOS.createPathFromString(TextUtils.unquote(targetFile + installFile.setDestinationFile(PathUtils.createPath(TextUtils.unquote(targetFile .getStringValue(), '"'))); IASTListNode optionNodes = installFileStmt .getOptions(); @@ -388,7 +388,7 @@ } else { for (IASTLiteralTextNode sourceNode : sourceNodes) { sourceFiles.put(languages.get(languageIndex++), - HostOS.createPathFromString(TextUtils.unquote(sourceNode + PathUtils.createPath(TextUtils.unquote(sourceNode .getStringValue(), '"'))); } } @@ -397,7 +397,7 @@ // always return // single source // node - sourceFiles.put(EPKGLanguage.INDEPENDENT, HostOS.createPathFromString(TextUtils + sourceFiles.put(EPKGLanguage.INDEPENDENT, PathUtils.createPath(TextUtils .unquote(sourceNodes.get(0).getStringValue(), '"'))); } if (parentNode == null) @@ -460,13 +460,13 @@ for (IASTLiteralTextNode sourceNode : sourceNodes) { // remove the leading '@' sourceFiles.put(languages.get(languageIndex++), - HostOS.createPathFromString(TextUtils.unquote(sourceNode.getStringValue().substring(1), '"'))); + PathUtils.createPath(TextUtils.unquote(sourceNode.getStringValue().substring(1), '"'))); } } } else { // language independent Check.checkContract(sourceNodes.size() == 1); // parser should // always return single source node. remove the leading '@'. - sourceFiles.put(EPKGLanguage.INDEPENDENT, HostOS.createPathFromString(TextUtils + sourceFiles.put(EPKGLanguage.INDEPENDENT, PathUtils.createPath(TextUtils .unquote(sourceNodes.get(0).getStringValue().substring(1), '"'))); }