mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 226453: NPE in CygpathTranslator if no Cygwin installed
This commit is contained in:
parent
68db07fc5d
commit
02686bc022
1 changed files with 18 additions and 17 deletions
|
@ -84,12 +84,12 @@ public class CygpathTranslator {
|
||||||
* @param sumIncludes
|
* @param sumIncludes
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static List translateIncludePaths(IProject project, List sumIncludes) {
|
public static List<String> translateIncludePaths(IProject project, List<String> sumIncludes) {
|
||||||
// first check if cygpath translation is needed at all
|
// first check if cygpath translation is needed at all
|
||||||
boolean translationNeeded = false;
|
boolean translationNeeded = false;
|
||||||
if (Platform.getOS().equals(Platform.OS_WIN32)) {
|
if (Platform.getOS().equals(Platform.OS_WIN32)) {
|
||||||
for (Iterator i = sumIncludes.iterator(); i.hasNext(); ) {
|
for (Iterator<String> i = sumIncludes.iterator(); i.hasNext(); ) {
|
||||||
String include = (String) i.next();
|
String include = i.next();
|
||||||
if (include.startsWith("/")) { //$NON-NLS-1$
|
if (include.startsWith("/")) { //$NON-NLS-1$
|
||||||
translationNeeded = true;
|
translationNeeded = true;
|
||||||
break;
|
break;
|
||||||
|
@ -102,9 +102,9 @@ public class CygpathTranslator {
|
||||||
|
|
||||||
CygpathTranslator cygpath = new CygpathTranslator(project);
|
CygpathTranslator cygpath = new CygpathTranslator(project);
|
||||||
|
|
||||||
List translatedIncludePaths = new ArrayList();
|
List<String> translatedIncludePaths = new ArrayList<String>();
|
||||||
for (Iterator i = sumIncludes.iterator(); i.hasNext(); ) {
|
for (Iterator<String> i = sumIncludes.iterator(); i.hasNext(); ) {
|
||||||
String includePath = (String) i.next();
|
String includePath = i.next();
|
||||||
IPath realPath = new Path(includePath);
|
IPath realPath = new Path(includePath);
|
||||||
// only allow native pathes if they have a device prefix
|
// only allow native pathes if they have a device prefix
|
||||||
// to avoid matches on the current drive, e.g. /usr/bin = C:\\usr\\bin
|
// to avoid matches on the current drive, e.g. /usr/bin = C:\\usr\\bin
|
||||||
|
@ -123,26 +123,25 @@ public class CygpathTranslator {
|
||||||
} else if (realPath.segmentCount() >= 2) {
|
} else if (realPath.segmentCount() >= 2) {
|
||||||
// try default conversions
|
// try default conversions
|
||||||
// /cygdrive/x/ --> X:\
|
// /cygdrive/x/ --> X:\
|
||||||
// /usr/ --> C:\Cygwin\\usr\\
|
|
||||||
if ("cygdrive".equals(realPath.segment(0))) { //$NON-NLS-1$
|
if ("cygdrive".equals(realPath.segment(0))) { //$NON-NLS-1$
|
||||||
String drive= realPath.segment(1);
|
String drive= realPath.segment(1);
|
||||||
if (drive.length() == 1) {
|
if (drive.length() == 1) {
|
||||||
translatedPath= realPath.removeFirstSegments(2).setDevice(drive.toUpperCase() + ':').toOSString();
|
translatedPath= realPath.removeFirstSegments(2).setDevice(drive.toUpperCase() + ':').toOSString();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
translatedPath= DEFAULT_CYGWIN_ROOT + realPath.toOSString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!translatedPath.equals(includePath)) {
|
if (!translatedPath.equals(includePath)) {
|
||||||
// Check if the translated path exists
|
// Check if the translated path exists
|
||||||
IPath transPath = new Path(translatedPath);
|
if (new File(translatedPath).exists()) {
|
||||||
if (transPath.toFile().exists()) {
|
translatedIncludePaths.add(translatedPath);
|
||||||
translatedIncludePaths.add(transPath.toPortableString());
|
|
||||||
}
|
}
|
||||||
else {
|
else if (cygpath.isAvailable) {
|
||||||
// TODO VMIR for now add even if it does not exist
|
// TODO VMIR for now add even if it does not exist
|
||||||
translatedIncludePaths.add(translatedPath);
|
translatedIncludePaths.add(translatedPath);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
translatedIncludePaths.add(includePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO VMIR for now add even if it does not exist
|
// TODO VMIR for now add even if it does not exist
|
||||||
|
@ -150,7 +149,9 @@ public class CygpathTranslator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cygpath.cygPath != null) {
|
||||||
cygpath.cygPath.dispose();
|
cygpath.cygPath.dispose();
|
||||||
|
}
|
||||||
return translatedIncludePaths;
|
return translatedIncludePaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue