1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 03:15:33 +02:00

Bug 335298 - IncludePaths are canonicalised on creation

- Add #getCanonicalPathWindows which only canonicalizes the path on windows.
This commit is contained in:
James Blackburn 2011-01-25 15:42:11 +00:00
parent d20b5fe5b2
commit d5b2a18e14
6 changed files with 27 additions and 15 deletions

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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, public IncludeEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath includePath, boolean isSystemInclude,
IPath[] exclusionPatterns, boolean isExported) { IPath[] exclusionPatterns, boolean isExported) {
super(IPathEntry.CDT_INCLUDE, basePath, baseRef, resourcePath, exclusionPatterns, 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; this.isSystemInclude = isSystemInclude;
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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, public IncludeFileEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath includeFilePath,
IPath[] exclusionPatterns, boolean isExported) { IPath[] exclusionPatterns, boolean isExported) {
super(IPathEntry.CDT_INCLUDE_FILE, basePath, baseRef, resourcePath, exclusionPatterns, 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);
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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) { public IncludeReference(ICElement celement, IIncludeEntry entry, IPath path) {
super(celement, null, path.toString(), ICElement.C_VCONTAINER); super(celement, null, path.toString(), ICElement.C_VCONTAINER);
fIncludeEntry = entry; fIncludeEntry = entry;
fPath = PathUtil.getCanonicalPath(path); fPath = PathUtil.getCanonicalPathWindows(path);
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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, public MacroFileEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath macroFilePath,
IPath[] exclusionPatterns, boolean isExported) { IPath[] exclusionPatterns, boolean isExported) {
super(IPathEntry.CDT_MACRO_FILE, basePath, baseRef, resourcePath, exclusionPatterns, 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);
} }
/** /**

View file

@ -51,14 +51,12 @@ public class PathUtil {
} }
/** /**
* On Windows discover the {@link java.io.File#getCanonicalPath()} for * Return the canonical path (or the passed in path, if one couldn't be found).
* a given absolute path.
* On other platforms, and for relative paths returns the passed in fullPath
* @param fullPath * @param fullPath
* @return canonicalized IPath or passed in fullPath. * @return canonicalized IPath or passed in fullPath.
*/ */
public static IPath getCanonicalPath(IPath fullPath) { public static IPath getCanonicalPath(IPath fullPath) {
if (!WINDOWS || !fullPath.isAbsolute()) if (!fullPath.isAbsolute())
return fullPath; return fullPath;
File file = fullPath.toFile(); File file = fullPath.toFile();
@ -73,6 +71,20 @@ public class PathUtil {
return fullPath; 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) { public static IPath getWorkspaceRelativePath(IPath fullPath) {
IWorkspaceRoot workspaceRoot = getWorkspaceRoot(); IWorkspaceRoot workspaceRoot = getWorkspaceRoot();
if (workspaceRoot != null) { if (workspaceRoot != null) {

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -201,7 +201,7 @@ public class OpenIncludeAction extends Action {
// in case it is an absolute path // in case it is an absolute path
IPath includeFile= new Path(name); IPath includeFile= new Path(name);
if (includeFile.isAbsolute()) { if (includeFile.isAbsolute()) {
includeFile = PathUtil.getCanonicalPath(includeFile); includeFile = PathUtil.getCanonicalPathWindows(includeFile);
if (includeFile.toFile().exists()) { if (includeFile.toFile().exists()) {
list.add(includeFile); list.add(includeFile);
return; return;
@ -209,7 +209,7 @@ public class OpenIncludeAction extends Action {
} }
HashSet<IPath> foundSet = new HashSet<IPath>(); HashSet<IPath> foundSet = new HashSet<IPath>();
for (String includePath : includePaths) { 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(); File file = path.toFile();
if (file.exists()) { if (file.exists()) {
IPath[] paths = resolveIncludeLink(path); IPath[] paths = resolveIncludeLink(path);