From d5b2a18e14eac50b4af9aa318f9b4513a18cad93 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Tue, 25 Jan 2011 15:42:11 +0000 Subject: [PATCH] Bug 335298 - IncludePaths are canonicalised on creation - Add #getCanonicalPathWindows which only canonicalizes the path on windows. --- .../cdt/internal/core/model/IncludeEntry.java | 4 ++-- .../internal/core/model/IncludeFileEntry.java | 4 ++-- .../internal/core/model/IncludeReference.java | 4 ++-- .../internal/core/model/MacroFileEntry.java | 4 ++-- .../utils/org/eclipse/cdt/utils/PathUtil.java | 20 +++++++++++++++---- .../internal/ui/editor/OpenIncludeAction.java | 6 +++--- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java index b07711016b5..9088cafda72 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -27,7 +27,7 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry { public IncludeEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath includePath, boolean isSystemInclude, IPath[] exclusionPatterns, boolean isExported) { super(IPathEntry.CDT_INCLUDE, basePath, baseRef, resourcePath, exclusionPatterns, isExported); - this.includePath = (includePath == null) ? Path.EMPTY : PathUtil.getCanonicalPath(includePath); + this.includePath = (includePath == null) ? Path.EMPTY : PathUtil.getCanonicalPathWindows(includePath); this.isSystemInclude = isSystemInclude; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeFileEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeFileEntry.java index 8ba8d037f89..ae0ad3748af 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeFileEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeFileEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -27,7 +27,7 @@ public class IncludeFileEntry extends APathEntry implements IIncludeFileEntry { public IncludeFileEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath includeFilePath, IPath[] exclusionPatterns, boolean isExported) { super(IPathEntry.CDT_INCLUDE_FILE, basePath, baseRef, resourcePath, exclusionPatterns, isExported); - this.includeFilePath = (includeFilePath == null) ? Path.EMPTY : PathUtil.getCanonicalPath(includeFilePath); + this.includeFilePath = (includeFilePath == null) ? Path.EMPTY : PathUtil.getCanonicalPathWindows(includeFilePath); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java index 874a8d8599b..9e2f905473c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 QNX Software Systems and others. + * Copyright (c) 2000, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -48,7 +48,7 @@ public class IncludeReference extends Openable implements IIncludeReference { public IncludeReference(ICElement celement, IIncludeEntry entry, IPath path) { super(celement, null, path.toString(), ICElement.C_VCONTAINER); fIncludeEntry = entry; - fPath = PathUtil.getCanonicalPath(path); + fPath = PathUtil.getCanonicalPathWindows(path); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroFileEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroFileEntry.java index 39ad3cd1196..7d4091ed197 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroFileEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroFileEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2011 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -27,7 +27,7 @@ public class MacroFileEntry extends APathEntry implements IMacroFileEntry { public MacroFileEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath macroFilePath, IPath[] exclusionPatterns, boolean isExported) { super(IPathEntry.CDT_MACRO_FILE, basePath, baseRef, resourcePath, exclusionPatterns, isExported); - this.macroFilePath = (macroFilePath == null) ? Path.EMPTY : PathUtil.getCanonicalPath(macroFilePath); + this.macroFilePath = (macroFilePath == null) ? Path.EMPTY : PathUtil.getCanonicalPathWindows(macroFilePath); } /** diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/PathUtil.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/PathUtil.java index cb25d46cfd3..ad25e1106c6 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/PathUtil.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/PathUtil.java @@ -51,14 +51,12 @@ public class PathUtil { } /** - * On Windows discover the {@link java.io.File#getCanonicalPath()} for - * a given absolute path. - * On other platforms, and for relative paths returns the passed in fullPath + * Return the canonical path (or the passed in path, if one couldn't be found). * @param fullPath * @return canonicalized IPath or passed in fullPath. */ public static IPath getCanonicalPath(IPath fullPath) { - if (!WINDOWS || !fullPath.isAbsolute()) + if (!fullPath.isAbsolute()) return fullPath; File file = fullPath.toFile(); @@ -73,6 +71,20 @@ public class PathUtil { return fullPath; } + /** + * On Windows discover the {@link java.io.File#getCanonicalPath()} for + * a given absolute path. + * On other platforms, and for relative paths returns the passed in fullPath + * @param fullPath + * @return canonicalized IPath or passed in fullPath. + * @since 5.3 + */ + public static IPath getCanonicalPathWindows(IPath fullPath) { + if (!WINDOWS) + return fullPath; + return getCanonicalPath(fullPath); + } + public static IPath getWorkspaceRelativePath(IPath fullPath) { IWorkspaceRoot workspaceRoot = getWorkspaceRoot(); if (workspaceRoot != null) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java index f75f053b0e5..de179fa2207 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -201,7 +201,7 @@ public class OpenIncludeAction extends Action { // in case it is an absolute path IPath includeFile= new Path(name); if (includeFile.isAbsolute()) { - includeFile = PathUtil.getCanonicalPath(includeFile); + includeFile = PathUtil.getCanonicalPathWindows(includeFile); if (includeFile.toFile().exists()) { list.add(includeFile); return; @@ -209,7 +209,7 @@ public class OpenIncludeAction extends Action { } HashSet foundSet = new HashSet(); for (String includePath : includePaths) { - IPath path = PathUtil.getCanonicalPath(new Path(includePath).append(includeFile)); + IPath path = PathUtil.getCanonicalPathWindows(new Path(includePath).append(includeFile)); File file = path.toFile(); if (file.exists()) { IPath[] paths = resolveIncludeLink(path);