|
3 | 3 | import java.io.File; |
4 | 4 | import java.net.URI; |
5 | 5 | import java.util.Collection; |
| 6 | +import java.util.Iterator; |
6 | 7 | import java.util.LinkedList; |
7 | 8 | import java.util.List; |
8 | 9 |
|
9 | 10 | import org.eclipse.cdt.core.CCorePlugin; |
10 | 11 | import org.eclipse.cdt.core.cdtvariables.CdtVariableException; |
11 | 12 | import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; |
12 | 13 | import org.eclipse.cdt.core.model.CoreModel; |
| 14 | +import org.eclipse.cdt.core.settings.model.ACPathEntry; |
13 | 15 | import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; |
14 | 16 | import org.eclipse.cdt.core.settings.model.ICFolderDescription; |
15 | 17 | import org.eclipse.cdt.core.settings.model.ICLanguageSetting; |
16 | 18 | import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; |
17 | 19 | import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
18 | 20 | import org.eclipse.cdt.core.settings.model.ICSettingEntry; |
| 21 | +import org.eclipse.cdt.core.settings.model.util.CDataUtil; |
19 | 22 | import org.eclipse.core.resources.IFile; |
20 | 23 | import org.eclipse.core.resources.IPathVariableManager; |
21 | 24 | import org.eclipse.core.resources.IProject; |
| 25 | +import org.eclipse.core.resources.IResource; |
22 | 26 | import org.eclipse.core.resources.IWorkspaceRoot; |
23 | 27 | import org.eclipse.core.resources.ResourcesPlugin; |
| 28 | +import org.eclipse.core.runtime.IPath; |
24 | 29 |
|
| 30 | +import com.google.common.base.Splitter; |
25 | 31 | import com.googlecode.cppcheclipse.core.CppcheclipsePlugin; |
26 | 32 | import com.googlecode.cppcheclipse.core.IToolchainSettings; |
27 | 33 | import com.googlecode.cppcheclipse.core.Symbol; |
@@ -125,26 +131,18 @@ public Collection<Symbol> getSystemSymbols() { |
125 | 131 | * @return the collection of resolved files |
126 | 132 | * @throws CdtVariableException |
127 | 133 | */ |
128 | | - protected Collection<File> resolveIncludePath(File includePath, |
129 | | - IPathVariableManager pathVariableManager) |
| 134 | + protected Collection<File> resolveIncludePath(File includePath) |
130 | 135 | throws CdtVariableException { |
131 | 136 | 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 | + |
137 | 138 | // need to resolve path variables to make an absolute path |
138 | 139 | // convert file path to URI (at this point is an absolute URI) |
139 | 140 | if (includePath.isAbsolute()) { |
140 | 141 | URI includePathUri = includePath.toURI(); |
141 | | - |
142 | | - // try to resolve path variables |
143 | | - includePathUri = pathVariableManager.resolveURI(includePathUri); |
144 | 142 |
|
145 | 143 | // resolve workspace paths, since it may contain linked resources |
146 | 144 | IFile[] files = root.findFilesForLocationURI(includePathUri); |
147 | | - |
| 145 | + |
148 | 146 | // if we could resolve the file |
149 | 147 | if (files.length > 0) { |
150 | 148 | for (IFile file : files) { |
@@ -172,30 +170,38 @@ protected Collection<File> resolveIncludePath(File includePath, |
172 | 170 | */ |
173 | 171 | protected Collection<File> getIncludes(boolean onlyUserDefined) { |
174 | 172 | 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(); |
180 | 175 |
|
181 | 176 | for (ICLanguageSetting languageSetting : languageSettings) { |
182 | 177 | ICLanguageSettingEntry[] includePathSettings = languageSetting |
183 | 178 | .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)) { |
185 | 183 | // only regard user-specified include paths or only |
186 | 184 | // system include paths |
187 | 185 | if ((!includePathSetting.isBuiltIn() && onlyUserDefined) |
188 | 186 | || (includePathSetting.isBuiltIn() && !onlyUserDefined)) { |
189 | 187 | 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(); |
194 | 191 | } 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 | + } |
196 | 202 | } |
197 | 203 | try { |
198 | | - paths.addAll(resolveIncludePath(includePath, pathVariableManager)); |
| 204 | + paths.addAll(resolveIncludePath(includePath)); |
199 | 205 | } catch (CdtVariableException e) { |
200 | 206 | CppcheclipsePlugin.logError("Invalid include path '" |
201 | 207 | + includePathSetting.getValue() + "'", e); |
|
0 commit comments