Skip to content

Commit 8508075

Browse files
committed
Fixes issue #56. Resolve project directories outside the workspace correctly. Rely on CDT Utils for path resolution, remove test class as it is too complicated to come up with the righ CDT environment
1 parent b7eb123 commit 8508075

File tree

2 files changed

+29
-235
lines changed

2 files changed

+29
-235
lines changed

com.googlecode.cppcheclipse.ui.tests/src/com/googlecode/cppcheclipse/ui/ToolchainSettingsTest.java

Lines changed: 0 additions & 212 deletions
This file was deleted.

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/ToolchainSettings.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,31 @@
33
import java.io.File;
44
import java.net.URI;
55
import java.util.Collection;
6+
import java.util.Iterator;
67
import java.util.LinkedList;
78
import java.util.List;
89

910
import org.eclipse.cdt.core.CCorePlugin;
1011
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
1112
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
1213
import org.eclipse.cdt.core.model.CoreModel;
14+
import org.eclipse.cdt.core.settings.model.ACPathEntry;
1315
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
1416
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
1517
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
1618
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
1719
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
1820
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
21+
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
1922
import org.eclipse.core.resources.IFile;
2023
import org.eclipse.core.resources.IPathVariableManager;
2124
import org.eclipse.core.resources.IProject;
25+
import org.eclipse.core.resources.IResource;
2226
import org.eclipse.core.resources.IWorkspaceRoot;
2327
import org.eclipse.core.resources.ResourcesPlugin;
28+
import org.eclipse.core.runtime.IPath;
2429

30+
import com.google.common.base.Splitter;
2531
import com.googlecode.cppcheclipse.core.CppcheclipsePlugin;
2632
import com.googlecode.cppcheclipse.core.IToolchainSettings;
2733
import com.googlecode.cppcheclipse.core.Symbol;
@@ -125,26 +131,18 @@ public Collection<Symbol> getSystemSymbols() {
125131
* @return the collection of resolved files
126132
* @throws CdtVariableException
127133
*/
128-
protected Collection<File> resolveIncludePath(File includePath,
129-
IPathVariableManager pathVariableManager)
134+
protected Collection<File> resolveIncludePath(File includePath)
130135
throws CdtVariableException {
131136
Collection<File> result = new LinkedList<File>();
132-
133-
// try to resolve CDT variables
134-
includePath = new File(variableManager.resolveValue(includePath.toString(), null,
135-
null, activeConfiguration));
136-
137+
137138
// need to resolve path variables to make an absolute path
138139
// convert file path to URI (at this point is an absolute URI)
139140
if (includePath.isAbsolute()) {
140141
URI includePathUri = includePath.toURI();
141-
142-
// try to resolve path variables
143-
includePathUri = pathVariableManager.resolveURI(includePathUri);
144142

145143
// resolve workspace paths, since it may contain linked resources
146144
IFile[] files = root.findFilesForLocationURI(includePathUri);
147-
145+
148146
// if we could resolve the file
149147
if (files.length > 0) {
150148
for (IFile file : files) {
@@ -172,30 +170,38 @@ protected Collection<File> resolveIncludePath(File includePath,
172170
*/
173171
protected Collection<File> getIncludes(boolean onlyUserDefined) {
174172
Collection<File> paths = new LinkedList<File>();
175-
URI workspaceUri = project.getWorkspace().getRoot().getLocationURI();
176-
177-
// evaluate path variables
178-
IPathVariableManager pathVariableManager = project.getWorkspace()
179-
.getPathVariableManager();
173+
IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
174+
URI workspaceUri = workspaceRoot.getLocationURI();
180175

181176
for (ICLanguageSetting languageSetting : languageSettings) {
182177
ICLanguageSettingEntry[] includePathSettings = languageSetting
183178
.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
184-
for (ICLanguageSettingEntry includePathSetting : includePathSettings) {
179+
180+
// resolve entries first (with CD)
181+
for (ICLanguageSettingEntry includePathSetting : CDataUtil
182+
.resolveEntries(includePathSettings, activeConfiguration)) {
185183
// only regard user-specified include paths or only
186184
// system include paths
187185
if ((!includePathSetting.isBuiltIn() && onlyUserDefined)
188186
|| (includePathSetting.isBuiltIn() && !onlyUserDefined)) {
189187
File includePath;
190-
191-
// make path absolute
192-
if ((includePathSetting.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) == ICSettingEntry.VALUE_WORKSPACE_PATH) {
193-
includePath = new File(new File(workspaceUri.getPath()), includePathSetting.getValue());
188+
if (includePathSetting instanceof ACPathEntry) {
189+
ACPathEntry includePathEntry = (ACPathEntry) includePathSetting;
190+
includePath = includePathEntry.getLocation().toFile();
194191
} else {
195-
includePath = new File(includePathSetting.getValue());
192+
193+
// make path absolute
194+
if ((includePathSetting.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) == ICSettingEntry.VALUE_WORKSPACE_PATH) {
195+
includePath = new File(new File(
196+
workspaceUri.getPath()),
197+
includePathSetting.getValue());
198+
} else {
199+
includePath = new File(
200+
includePathSetting.getValue());
201+
}
196202
}
197203
try {
198-
paths.addAll(resolveIncludePath(includePath, pathVariableManager));
204+
paths.addAll(resolveIncludePath(includePath));
199205
} catch (CdtVariableException e) {
200206
CppcheclipsePlugin.logError("Invalid include path '"
201207
+ includePathSetting.getValue() + "'", e);

0 commit comments

Comments
 (0)