|
Lines 10-53
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.cdt.make.xlc.core.scannerconfig; |
11 |
package org.eclipse.cdt.make.xlc.core.scannerconfig; |
| 12 |
|
12 |
|
|
|
13 |
import java.util.ArrayList; |
| 13 |
import java.util.Arrays; |
14 |
import java.util.Arrays; |
|
|
15 |
import java.util.Collections; |
| 16 |
import java.util.HashMap; |
| 17 |
import java.util.HashSet; |
| 18 |
import java.util.Iterator; |
| 19 |
import java.util.LinkedHashMap; |
| 20 |
import java.util.LinkedHashSet; |
| 14 |
import java.util.LinkedList; |
21 |
import java.util.LinkedList; |
| 15 |
import java.util.List; |
22 |
import java.util.List; |
| 16 |
import java.util.Map; |
23 |
import java.util.Map; |
|
|
24 |
import java.util.Set; |
| 25 |
import java.util.SortedSet; |
| 26 |
import java.util.TreeSet; |
| 27 |
import java.util.Map.Entry; |
| 17 |
|
28 |
|
|
|
29 |
import org.eclipse.cdt.core.model.CoreModel; |
| 30 |
import org.eclipse.cdt.core.settings.model.CIncludePathEntry; |
| 31 |
import org.eclipse.cdt.core.settings.model.CMacroEntry; |
| 32 |
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; |
| 33 |
import org.eclipse.cdt.core.settings.model.ICLanguageSetting; |
| 34 |
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; |
| 35 |
import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
| 36 |
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; |
| 37 |
import org.eclipse.cdt.core.settings.model.ICSettingEntry; |
| 38 |
import org.eclipse.cdt.make.core.MakeCorePlugin; |
| 39 |
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager; |
| 18 |
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector3; |
40 |
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector3; |
| 19 |
import org.eclipse.cdt.make.internal.core.scannerconfig2.PerFileSICollector; |
41 |
import org.eclipse.cdt.make.core.scannerconfig.InfoContext; |
|
|
42 |
import org.eclipse.cdt.make.core.scannerconfig.PathInfo; |
| 43 |
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes; |
| 44 |
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; |
| 45 |
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredScannerInfoSerializable; |
| 46 |
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo; |
| 47 |
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo2; |
| 48 |
import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredPathInfo; |
| 49 |
import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredPathManager; |
| 50 |
import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore; |
| 51 |
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigUtil; |
| 52 |
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC; |
| 53 |
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CygpathTranslator; |
| 54 |
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; |
| 55 |
import org.eclipse.cdt.make.xlc.core.activator.Activator; |
| 56 |
import org.eclipse.cdt.make.xlc.core.messages.Messages; |
| 57 |
import org.eclipse.cdt.managedbuilder.core.IConfiguration; |
| 58 |
import org.eclipse.cdt.managedbuilder.core.IInputType; |
| 59 |
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; |
| 60 |
import org.eclipse.cdt.managedbuilder.core.ITool; |
| 61 |
import org.eclipse.cdt.managedbuilder.core.IToolChain; |
| 62 |
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; |
| 20 |
import org.eclipse.cdt.managedbuilder.scannerconfig.IManagedScannerInfoCollector; |
63 |
import org.eclipse.cdt.managedbuilder.scannerconfig.IManagedScannerInfoCollector; |
|
|
64 |
import org.eclipse.core.resources.IFile; |
| 65 |
import org.eclipse.core.resources.IProject; |
| 66 |
import org.eclipse.core.resources.IResource; |
| 67 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 68 |
import org.eclipse.core.runtime.CoreException; |
| 21 |
import org.eclipse.core.runtime.IPath; |
69 |
import org.eclipse.core.runtime.IPath; |
|
|
70 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 71 |
import org.eclipse.core.runtime.IStatus; |
| 72 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 73 |
import org.eclipse.core.runtime.Path; |
| 74 |
import org.eclipse.core.runtime.Status; |
| 75 |
import org.eclipse.core.runtime.content.IContentType; |
| 76 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
| 77 |
import org.eclipse.core.runtime.jobs.Job; |
| 78 |
import org.w3c.dom.Document; |
| 79 |
import org.w3c.dom.Element; |
| 80 |
import org.w3c.dom.Node; |
| 81 |
import org.w3c.dom.NodeList; |
| 22 |
|
82 |
|
| 23 |
/** |
83 |
/** |
| 24 |
* @author laggarcia |
84 |
* @author crecoskie |
| 25 |
* |
85 |
* |
| 26 |
*/ |
86 |
*/ |
| 27 |
public class PerFileXLCScannerInfoCollector extends PerFileSICollector |
87 |
public class PerFileXLCScannerInfoCollector implements IScannerInfoCollector3, IManagedScannerInfoCollector { |
| 28 |
implements IScannerInfoCollector3, IManagedScannerInfoCollector { |
|
|
| 29 |
|
88 |
|
| 30 |
/* (non-Javadoc) |
89 |
protected class ScannerConfigUpdateJob extends Job { |
|
|
90 |
|
| 91 |
private InfoContext fContext; |
| 92 |
private IDiscoveredPathInfo fPathInfo; |
| 93 |
private boolean fIsDefaultContext; |
| 94 |
private List<IResource> fChangedResources; |
| 95 |
|
| 96 |
public ScannerConfigUpdateJob(InfoContext context, IDiscoveredPathInfo pathInfo, boolean isDefaultContext, List<IResource> changedResources) { |
| 97 |
super(Messages.getString("PerFileXLCScannerInfoCollector.0")); //$NON-NLS-1$); |
| 98 |
fContext = context; |
| 99 |
fPathInfo = pathInfo; |
| 100 |
fIsDefaultContext = isDefaultContext; |
| 101 |
fChangedResources = changedResources; |
| 102 |
} |
| 103 |
|
| 104 |
@Override |
| 105 |
protected IStatus run(IProgressMonitor monitor) { |
| 106 |
try { |
| 107 |
|
| 108 |
// get the scanner info profile ID |
| 109 |
|
| 110 |
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); |
| 111 |
IConfiguration config = info.getDefaultConfiguration(); |
| 112 |
|
| 113 |
String profileID = config.getToolChain().getScannerConfigDiscoveryProfileId(); |
| 114 |
IDiscoveredPathManager manager = MakeCorePlugin.getDefault().getDiscoveryManager(); |
| 115 |
|
| 116 |
if(manager instanceof DiscoveredPathManager) { |
| 117 |
((DiscoveredPathManager)manager).updateDiscoveredInfo(fContext, fPathInfo, fIsDefaultContext, fChangedResources, profileID); |
| 118 |
} |
| 119 |
|
| 120 |
// reload project description to hopefully get the data to take |
| 121 |
ICProjectDescriptionManager descriptionManager = CoreModel.getDefault().getProjectDescriptionManager(); |
| 122 |
ICProjectDescription cProjectDescription = descriptionManager.getProjectDescription(project, true /* writable */); |
| 123 |
ICConfigurationDescription configDes = cProjectDescription.getActiveConfiguration(); |
| 124 |
|
| 125 |
boolean changedDes = false; |
| 126 |
|
| 127 |
IToolChain toolchain = config.getToolChain(); |
| 128 |
for(ITool tool : toolchain.getTools()) { |
| 129 |
for(IInputType inputType : tool.getInputTypes()) { |
| 130 |
IContentType contentType = inputType.getSourceContentType(); |
| 131 |
if(contentType != null) { |
| 132 |
for(IResource resource : fChangedResources) { |
| 133 |
// get language settings for the resource |
| 134 |
ICLanguageSetting langSetting = configDes.getLanguageSettingForFile(resource.getProjectRelativePath(), false); |
| 135 |
|
| 136 |
if(langSetting == null) { |
| 137 |
continue; |
| 138 |
} |
| 139 |
|
| 140 |
// get content type IDs for the setting |
| 141 |
String[] contentTypeIDs = langSetting.getSourceContentTypeIds(); |
| 142 |
|
| 143 |
// if the setting doesn't handle our content type ID, then go to the next resource |
| 144 |
boolean found = false; |
| 145 |
for(String id : contentTypeIDs) { |
| 146 |
if(id.equals(contentType.getId())) { |
| 147 |
found = true; |
| 148 |
break; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
if(!found) { |
| 153 |
continue; |
| 154 |
} |
| 155 |
|
| 156 |
// update all the scanner config entries on the setting |
| 157 |
changedDes |= updateIncludeSettings(langSetting); |
| 158 |
changedDes |= updateMacroSettings(langSetting); |
| 159 |
|
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
if(changedDes) { |
| 167 |
descriptionManager.setProjectDescription(project, cProjectDescription, true /* force */, monitor); |
| 168 |
} |
| 169 |
|
| 170 |
} catch (CoreException e) { |
| 171 |
Activator.log(e); |
| 172 |
return Activator.createStatus(Messages.getString("PerFileXLCScannerInfoCollector.1")); //$NON-NLS-1$ |
| 173 |
} |
| 174 |
return Status.OK_STATUS; |
| 175 |
} |
| 176 |
|
| 177 |
private boolean updateMacroSettings(ICLanguageSetting langSetting) { |
| 178 |
ICLanguageSettingEntry[] entries = langSetting.getSettingEntries(ICSettingEntry.MACRO); |
| 179 |
List<ICLanguageSettingEntry> newEntries = new LinkedList<ICLanguageSettingEntry>(); |
| 180 |
for(ICLanguageSettingEntry entry : entries) { |
| 181 |
newEntries.add(entry); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
boolean entriesChanged = false; |
| 186 |
|
| 187 |
// look for settings corresponding to each path we discovered |
| 188 |
Map<String, String> discSymbols = fPathInfo.getSymbols(); |
| 189 |
for (String symbol : discSymbols.keySet()) { |
| 190 |
boolean symbolFound = false; |
| 191 |
|
| 192 |
for (ICLanguageSettingEntry entry : entries) { |
| 193 |
if (((CMacroEntry) entry).getName().equals(symbol)) { |
| 194 |
int flags = entry.getFlags(); |
| 195 |
symbolFound = true; // it's already there, so don't set it |
| 196 |
break; |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
// if we didn't find the path, add it |
| 201 |
if(!symbolFound) { |
| 202 |
entriesChanged = true; |
| 203 |
CMacroEntry newEntry = new CMacroEntry(symbol, discSymbols.get(symbol), ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.RESOLVED); |
| 204 |
newEntries.add(newEntry); |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
// if we changed the entries, then set the new ones |
| 209 |
if(entriesChanged) { |
| 210 |
langSetting.setSettingEntries(ICSettingEntry.MACRO, newEntries.toArray(new ICLanguageSettingEntry[0])); |
| 211 |
} |
| 212 |
|
| 213 |
return entriesChanged; |
| 214 |
} |
| 215 |
|
| 216 |
private boolean updateIncludeSettings(ICLanguageSetting langSetting) { |
| 217 |
ICLanguageSettingEntry[] entries = langSetting.getSettingEntries(ICSettingEntry.INCLUDE_PATH); |
| 218 |
List<ICLanguageSettingEntry> newEntries = new LinkedList<ICLanguageSettingEntry>(); |
| 219 |
for(ICLanguageSettingEntry entry : entries) { |
| 220 |
newEntries.add(entry); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
boolean entriesChanged = false; |
| 225 |
|
| 226 |
// look for settings corresponding to each path we discovered |
| 227 |
IPath[] discPaths = fPathInfo.getIncludePaths(); |
| 228 |
for (IPath path : discPaths) { |
| 229 |
boolean pathFound = false; |
| 230 |
|
| 231 |
for (ICLanguageSettingEntry entry : entries) { |
| 232 |
if (((CIncludePathEntry) entry).getLocation().equals(path)) { |
| 233 |
pathFound = true; // it's already there, so don't set it |
| 234 |
break; |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
// if we didn't find the path, add it |
| 239 |
if(!pathFound) { |
| 240 |
entriesChanged = true; |
| 241 |
CIncludePathEntry newEntry = new CIncludePathEntry(path, ICSettingEntry.BUILTIN | ICSettingEntry.READONLY | ICSettingEntry.RESOLVED); |
| 242 |
newEntries.add(newEntry); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
// if we changed the entries, then set the new ones |
| 247 |
if(entriesChanged) { |
| 248 |
langSetting.setSettingEntries(ICSettingEntry.INCLUDE_PATH, newEntries.toArray(new ICLanguageSettingEntry[0])); |
| 249 |
} |
| 250 |
|
| 251 |
return entriesChanged; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
protected class MergedPerFileDiscoveredPathInfo implements IPerFileDiscoveredPathInfo2 { |
| 256 |
private IDiscoveredPathInfo fInfo1; |
| 257 |
private IPerFileDiscoveredPathInfo2 fInfo2; |
| 258 |
|
| 259 |
public MergedPerFileDiscoveredPathInfo(IDiscoveredPathInfo info1, IPerFileDiscoveredPathInfo2 info2) { |
| 260 |
fInfo1 = info1; |
| 261 |
fInfo2 = info2; |
| 262 |
} |
| 263 |
|
| 264 |
private IPerFileDiscoveredPathInfo2 getPerFileInfo1() { |
| 265 |
if(fInfo1 instanceof IPerFileDiscoveredPathInfo2) { |
| 266 |
return (IPerFileDiscoveredPathInfo2) fInfo1; |
| 267 |
} |
| 268 |
|
| 269 |
else { |
| 270 |
return null; |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
public Map getPathInfoMap() { |
| 275 |
synchronized (fLock) { |
| 276 |
IPerFileDiscoveredPathInfo2 info1 = getPerFileInfo1(); |
| 277 |
if (info1 != null) { |
| 278 |
Map map = new HashMap(); |
| 279 |
map.putAll(info1.getPathInfoMap()); |
| 280 |
map.putAll(fInfo2.getPathInfoMap()); |
| 281 |
return map; |
| 282 |
} |
| 283 |
|
| 284 |
else { |
| 285 |
return fInfo2.getPathInfoMap(); |
| 286 |
} |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
/* (non-Javadoc) |
| 291 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo#getIncludeFiles(org.eclipse.core.runtime.IPath) |
| 292 |
*/ |
| 293 |
public IPath[] getIncludeFiles(IPath path) { |
| 294 |
synchronized (fLock) { |
| 295 |
IPerFileDiscoveredPathInfo2 info1 = getPerFileInfo1(); |
| 296 |
if (info1 != null) { |
| 297 |
List<IPath> list = new LinkedList<IPath>(); |
| 298 |
for (IPath path1 : info1.getIncludeFiles(path)) { |
| 299 |
list.add(path1); |
| 300 |
} |
| 301 |
|
| 302 |
for (IPath path1 : fInfo2.getIncludeFiles(path)) { |
| 303 |
list.add(path1); |
| 304 |
} |
| 305 |
return list.toArray(new IPath[0]); |
| 306 |
} |
| 307 |
|
| 308 |
else { |
| 309 |
return fInfo2.getIncludeFiles(path); |
| 310 |
} |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
public IPath[] getIncludePaths(IPath path) { |
| 315 |
synchronized (fLock) { |
| 316 |
|
| 317 |
Set<IPath> pathSet = new HashSet<IPath>(); |
| 318 |
|
| 319 |
// add project level settings if other info is per project |
| 320 |
if (fInfo1 instanceof DiscoveredPathInfo) { |
| 321 |
for (IPath path1 : fInfo1.getIncludePaths()) { |
| 322 |
pathSet.add(path1); |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
else { |
| 327 |
IPerFileDiscoveredPathInfo2 info1 = getPerFileInfo1(); |
| 328 |
if (info1 != null) { |
| 329 |
// add file level settings |
| 330 |
for (IPath path1 : info1.getIncludePaths(path)) { |
| 331 |
pathSet.add(path1); |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
// add file level settings |
| 337 |
for (IPath path2 : fInfo2.getIncludePaths(path)) { |
| 338 |
pathSet.add(path2); |
| 339 |
} |
| 340 |
|
| 341 |
return pathSet.toArray(new IPath[0]); |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
public IPath[] getMacroFiles(IPath path) { |
| 346 |
synchronized (fLock) { |
| 347 |
Set<IPath> pathSet = new HashSet<IPath>(); |
| 348 |
|
| 349 |
IPerFileDiscoveredPathInfo2 info1 = getPerFileInfo1(); |
| 350 |
if (info1 != null) { |
| 351 |
// add file level settings |
| 352 |
for (IPath path1 : info1.getMacroFiles(path)) { |
| 353 |
pathSet.add(path1); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
// add file level settings |
| 358 |
for (IPath path2 : fInfo2.getMacroFiles(path)) { |
| 359 |
pathSet.add(path2); |
| 360 |
} |
| 361 |
|
| 362 |
return pathSet.toArray(new IPath[0]); |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
public IPath[] getQuoteIncludePaths(IPath path) { |
| 367 |
synchronized (fLock) { |
| 368 |
|
| 369 |
Set<IPath> pathSet = new HashSet<IPath>(); |
| 370 |
|
| 371 |
IPerFileDiscoveredPathInfo2 info1 = getPerFileInfo1(); |
| 372 |
if (info1 != null) { |
| 373 |
// add file level settings |
| 374 |
for (IPath path1 : info1.getQuoteIncludePaths(path)) { |
| 375 |
pathSet.add(path1); |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
// add file level settings |
| 380 |
for (IPath path2 : fInfo2.getQuoteIncludePaths(path)) { |
| 381 |
pathSet.add(path2); |
| 382 |
} |
| 383 |
|
| 384 |
return pathSet.toArray(new IPath[0]); |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
public Map getSymbols(IPath path) { |
| 389 |
synchronized (fLock) { |
| 390 |
|
| 391 |
Map<String, String> symbols = new HashMap<String, String>(); |
| 392 |
|
| 393 |
// add project level settings |
| 394 |
Map<String, String> projectSymbols = (Map<String, String>) fInfo1.getSymbols(); |
| 395 |
for (String symbol : projectSymbols.keySet()) { |
| 396 |
symbols.put(symbol, projectSymbols.get(symbol)); |
| 397 |
} |
| 398 |
|
| 399 |
IPerFileDiscoveredPathInfo2 info1 = getPerFileInfo1(); |
| 400 |
if (info1 != null) { |
| 401 |
// add file level settings |
| 402 |
symbols.putAll(info1.getSymbols(path)); |
| 403 |
} |
| 404 |
|
| 405 |
// add file level settings |
| 406 |
symbols.putAll(fInfo2.getSymbols(path)); |
| 407 |
|
| 408 |
return symbols; |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
/* (non-Javadoc) |
| 413 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo#isEmpty(org.eclipse.core.runtime.IPath) |
| 414 |
*/ |
| 415 |
public boolean isEmpty(IPath path) { |
| 416 |
synchronized (fLock) { |
| 417 |
boolean info1empty = false; |
| 418 |
|
| 419 |
IPerFileDiscoveredPathInfo2 info1 = getPerFileInfo1(); |
| 420 |
if (info1 != null) { |
| 421 |
info1empty = info1.isEmpty(path); |
| 422 |
} else { |
| 423 |
info1empty = fInfo1.getIncludePaths().length == 0 && fInfo1.getSymbols().size() == 0; |
| 424 |
} |
| 425 |
|
| 426 |
return fInfo2.isEmpty(path) && info1empty; |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
public IPath[] getIncludePaths() { |
| 431 |
synchronized (fLock) { |
| 432 |
return fInfo1.getIncludePaths(); |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
public IProject getProject() { |
| 437 |
return fInfo1.getProject(); |
| 438 |
} |
| 439 |
|
| 440 |
public IDiscoveredScannerInfoSerializable getSerializable() { |
| 441 |
return fInfo2.getSerializable(); |
| 442 |
} |
| 443 |
|
| 444 |
public Map getSymbols() { |
| 445 |
synchronized (fLock) { |
| 446 |
return fInfo1.getSymbols(); |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
} |
| 451 |
|
| 452 |
/** |
| 453 |
* Per file DPI object |
| 454 |
* |
| 455 |
* @author vhirsl |
| 456 |
*/ |
| 457 |
protected class PerFileDiscoveredPathInfo implements IPerFileDiscoveredPathInfo2 { |
| 458 |
/* (non-Javadoc) |
| 459 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludeFiles(org.eclipse.core.runtime.IPath) |
| 460 |
*/ |
| 461 |
public IPath[] getIncludeFiles(IPath path) { |
| 462 |
synchronized (fLock) { |
| 463 |
|
| 464 |
Set<IPath> pathSet = new LinkedHashSet<IPath>(); |
| 465 |
// get the command |
| 466 |
CCommandDSC cmd = getCommand(path); |
| 467 |
if (cmd != null) { |
| 468 |
pathSet.addAll(cmd.getIncludeFile()); |
| 469 |
} |
| 470 |
// use project scope scanner info |
| 471 |
if (psi == null) { |
| 472 |
generateProjectScannerInfo(); |
| 473 |
} |
| 474 |
|
| 475 |
for(IPath path2 : psi.includeFiles) { |
| 476 |
pathSet.add(path2); |
| 477 |
} |
| 478 |
|
| 479 |
return pathSet.toArray(new IPath[0]); |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
/* (non-Javadoc) |
| 484 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludePaths() |
| 485 |
*/ |
| 486 |
public IPath[] getIncludePaths() { |
| 487 |
final IPath[] includepaths; |
| 488 |
final IPath[] quotepaths; |
| 489 |
synchronized (fLock) { |
| 490 |
// return new IPath[0]; |
| 491 |
includepaths = getAllIncludePaths(INCLUDE_PATH); |
| 492 |
quotepaths = getAllIncludePaths(QUOTE_INCLUDE_PATH); |
| 493 |
} |
| 494 |
if (quotepaths == null || quotepaths.length == 0) { |
| 495 |
return includepaths; |
| 496 |
} |
| 497 |
if (includepaths == null || includepaths.length == 0) { |
| 498 |
return quotepaths; |
| 499 |
} |
| 500 |
ArrayList<IPath> result = new ArrayList<IPath>(includepaths.length + quotepaths.length); |
| 501 |
result.addAll(Arrays.asList(includepaths)); |
| 502 |
result.addAll(Arrays.asList(quotepaths)); |
| 503 |
return result.toArray(new IPath[result.size()]); |
| 504 |
} |
| 505 |
|
| 506 |
/* (non-Javadoc) |
| 507 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludePaths(org.eclipse.core.runtime.IPath) |
| 508 |
*/ |
| 509 |
public IPath[] getIncludePaths(IPath path) { |
| 510 |
synchronized (fLock) { |
| 511 |
Set<IPath> pathSet = new LinkedHashSet<IPath>(); |
| 512 |
// get the command |
| 513 |
CCommandDSC cmd = getCommand(path); |
| 514 |
if (cmd != null) { |
| 515 |
pathSet.addAll(cmd.getIncludes()); |
| 516 |
} |
| 517 |
// use project scope scanner info |
| 518 |
if (psi == null) { |
| 519 |
generateProjectScannerInfo(); |
| 520 |
} |
| 521 |
|
| 522 |
for(IPath path2 : psi.includePaths) { |
| 523 |
pathSet.add(path2); |
| 524 |
} |
| 525 |
|
| 526 |
return pathSet.toArray(new IPath[0]); |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
/* (non-Javadoc) |
| 531 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo#getMacroFiles(org.eclipse.core.runtime.IPath) |
| 532 |
*/ |
| 533 |
public IPath[] getMacroFiles(IPath path) { |
| 534 |
synchronized (fLock) { |
| 535 |
Set<IPath> pathSet = new LinkedHashSet<IPath>(); |
| 536 |
// get the command |
| 537 |
CCommandDSC cmd = getCommand(path); |
| 538 |
if (cmd != null) { |
| 539 |
pathSet.addAll(cmd.getImacrosFile()); |
| 540 |
} |
| 541 |
// use project scope scanner info |
| 542 |
if (psi == null) { |
| 543 |
generateProjectScannerInfo(); |
| 544 |
} |
| 545 |
|
| 546 |
for(IPath path2 : psi.macrosFiles) { |
| 547 |
pathSet.add(path2); |
| 548 |
} |
| 549 |
|
| 550 |
return pathSet.toArray(new IPath[0]); |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
public Map<IResource, PathInfo> getPathInfoMap() { |
| 555 |
synchronized (fLock) { |
| 556 |
//TODO: do we need to cache this? |
| 557 |
return calculatePathInfoMap(); |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
/* (non-Javadoc) |
| 562 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getProject() |
| 563 |
*/ |
| 564 |
public IProject getProject() { |
| 565 |
return project; |
| 566 |
} |
| 567 |
|
| 568 |
/* (non-Javadoc) |
| 569 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo#getQuoteIncludePaths(org.eclipse.core.runtime.IPath) |
| 570 |
*/ |
| 571 |
public IPath[] getQuoteIncludePaths(IPath path) { |
| 572 |
synchronized (fLock) { |
| 573 |
Set<IPath> pathSet = new LinkedHashSet<IPath>(); |
| 574 |
// get the command |
| 575 |
CCommandDSC cmd = getCommand(path); |
| 576 |
if (cmd != null) { |
| 577 |
pathSet.addAll(cmd.getQuoteIncludes()); |
| 578 |
} |
| 579 |
// use project scope scanner info |
| 580 |
if (psi == null) { |
| 581 |
generateProjectScannerInfo(); |
| 582 |
} |
| 583 |
|
| 584 |
for(IPath path2 : psi.quoteIncludePaths) { |
| 585 |
pathSet.add(path2); |
| 586 |
} |
| 587 |
|
| 588 |
return pathSet.toArray(new IPath[0]); |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
/* (non-Javadoc) |
| 593 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo#getSerializable() |
| 594 |
*/ |
| 595 |
public IDiscoveredScannerInfoSerializable getSerializable() { |
| 596 |
synchronized (fLock) { |
| 597 |
return sid; |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
/* (non-Javadoc) |
| 602 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSymbols() |
| 603 |
*/ |
| 604 |
public Map<String, String> getSymbols() { |
| 605 |
// return new HashMap(); |
| 606 |
synchronized (fLock) { |
| 607 |
return getAllSymbols(); |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
/* |
| 612 |
* (non-Javadoc) |
| 613 |
* |
| 614 |
* @seeorg.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager. |
| 615 |
* IDiscoveredPathInfo#getSymbols(org.eclipse.core.runtime.IPath) |
| 616 |
*/ |
| 617 |
public Map<String, String> getSymbols(IPath path) { |
| 618 |
synchronized (fLock) { |
| 619 |
Map<String, String> definedSymbols = new HashMap<String, String>(); |
| 620 |
|
| 621 |
// put project data in first so file level data can override it |
| 622 |
// use project scope scanner info |
| 623 |
if (psi == null) { |
| 624 |
generateProjectScannerInfo(); |
| 625 |
} |
| 626 |
definedSymbols.putAll(psi.definedSymbols); |
| 627 |
|
| 628 |
// get the command |
| 629 |
CCommandDSC cmd = getCommand(path); |
| 630 |
if (cmd != null && cmd.isDiscovered()) { |
| 631 |
List symbols = cmd.getSymbols(); |
| 632 |
for (Iterator i = symbols.iterator(); i.hasNext();) { |
| 633 |
String symbol = (String) i.next(); |
| 634 |
String key = ScannerConfigUtil.getSymbolKey(symbol); |
| 635 |
String value = ScannerConfigUtil.getSymbolValue(symbol); |
| 636 |
definedSymbols.put(key, value); |
| 637 |
} |
| 638 |
|
| 639 |
} |
| 640 |
// use project scope scanner info |
| 641 |
if (psi == null) { |
| 642 |
generateProjectScannerInfo(); |
| 643 |
} |
| 644 |
definedSymbols.putAll(psi.definedSymbols); |
| 645 |
return definedSymbols; |
| 646 |
} |
| 647 |
|
| 648 |
} |
| 649 |
|
| 650 |
/* (non-Javadoc) |
| 651 |
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IPerFileDiscoveredPathInfo#isEmpty(org.eclipse.core.runtime.IPath) |
| 652 |
*/ |
| 653 |
public boolean isEmpty(IPath path) { |
| 654 |
synchronized (fLock) { |
| 655 |
boolean rc = true; |
| 656 |
IResource resource = project.getWorkspace().getRoot().findMember(path); |
| 657 |
if (resource != null) { |
| 658 |
if (resource instanceof IFile) { |
| 659 |
rc = (getCommand((IFile) resource) == null); |
| 660 |
} else if (resource instanceof IProject) { |
| 661 |
synchronized (fLock) { |
| 662 |
rc = (psi == null || psi.isEmpty()); |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
return rc; |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
} |
| 671 |
|
| 672 |
public static class ProjectScannerInfo { |
| 673 |
public Map<String, String> definedSymbols; |
| 674 |
public IPath[] includeFiles; |
| 675 |
public IPath[] includePaths; |
| 676 |
public IPath[] macrosFiles; |
| 677 |
public IPath[] quoteIncludePaths; |
| 678 |
public boolean isEmpty() { |
| 679 |
return (includePaths.length == 0 && |
| 680 |
quoteIncludePaths.length == 0 && |
| 681 |
includeFiles.length == 0 && |
| 682 |
macrosFiles.length == 0 && |
| 683 |
definedSymbols.size() == 0); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
public class ScannerInfoData implements IDiscoveredScannerInfoSerializable { |
| 688 |
public static final String DEFINED_SYMBOL = "definedSymbol"; //$NON-NLS-1$ |
| 689 |
public static final String ID_ATTR = "id"; //$NON-NLS-1$ |
| 690 |
public static final String INCLUDE_PATH = "includePath"; //$NON-NLS-1$ |
| 691 |
|
| 692 |
private static final String NAME = "name"; //$NON-NLS-1$ |
| 693 |
|
| 694 |
public static final String PATH = "path"; //$NON-NLS-1$ |
| 695 |
private static final String PROJECT = "project"; //$NON-NLS-1$ |
| 696 |
public static final String REMOVED = "removed"; //$NON-NLS-1$ |
| 697 |
public static final String SYMBOL = "symbol"; //$NON-NLS-1$ |
| 698 |
public final Map<Integer, CCommandDSC> commandIdCommandMap; // map of all commands |
| 699 |
public final Map<Integer, Set<IFile>> commandIdToFilesMap; // command id and set of files it applies to |
| 700 |
public final Map<IFile, Integer> fileToCommandIdMap; // maps each file to the corresponding command id |
| 701 |
|
| 702 |
public ScannerInfoData() { |
| 703 |
commandIdCommandMap = new LinkedHashMap<Integer, CCommandDSC>(); // [commandId, command] |
| 704 |
fileToCommandIdMap = new HashMap<IFile, Integer>(); // [file, commandId] |
| 705 |
commandIdToFilesMap = new HashMap<Integer, Set<IFile>>(); // [commandId, set of files] |
| 706 |
} |
| 707 |
|
| 708 |
/* (non-Javadoc) |
| 709 |
* @see org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable#deserialize(org.w3c.dom.Element) |
| 710 |
*/ |
| 711 |
public void deserialize(Element collectorElem) { |
| 712 |
synchronized (fLock) { |
| 713 |
|
| 714 |
for (Node child = collectorElem.getFirstChild(); child != null; child = child.getNextSibling()) { |
| 715 |
if(child.getNodeName().equals(PROJECT)) { |
| 716 |
Element projectElement = (Element) child; |
| 717 |
String projectName = projectElement.getAttribute(NAME); |
| 718 |
|
| 719 |
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); |
| 720 |
|
| 721 |
Map<ScannerInfoTypes, List<String>> scannerInfo = new HashMap<ScannerInfoTypes, List<String>>(); |
| 722 |
|
| 723 |
List<String> includes = new LinkedList<String>(); |
| 724 |
List<String> symbols = new LinkedList<String>(); |
| 725 |
|
| 726 |
// iterate over children |
| 727 |
for(Node projectChild = projectElement.getFirstChild(); projectChild != null; projectChild = projectChild.getNextSibling()) { |
| 728 |
if(projectChild.getNodeName().equals(INCLUDE_PATH)) { |
| 729 |
Element childElem = (Element) projectChild; |
| 730 |
String path = childElem.getAttribute(PATH); |
| 731 |
if(path != null) { |
| 732 |
includes.add(path); |
| 733 |
} |
| 734 |
} |
| 735 |
else if(projectChild.getNodeName().equals(DEFINED_SYMBOL)) { |
| 736 |
Element childElem = (Element) projectChild; |
| 737 |
String symbol = childElem.getAttribute(SYMBOL); |
| 738 |
|
| 739 |
if(symbol != null) { |
| 740 |
symbols.add(symbol); |
| 741 |
} |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
// add loaded scanner info to project settings for this collector |
| 746 |
scannerInfo.put(ScannerInfoTypes.INCLUDE_PATHS, includes); |
| 747 |
scannerInfo.put(ScannerInfoTypes.SYMBOL_DEFINITIONS, symbols); |
| 748 |
fProjectSettingsMap.put(project, scannerInfo); |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
else if (child.getNodeName().equals(CC_ELEM)) { |
| 753 |
Element cmdElem = (Element) child; |
| 754 |
boolean cppFileType = cmdElem.getAttribute(FILE_TYPE_ATTR).equals("c++"); //$NON-NLS-1$ |
| 755 |
CCommandDSC command = new CCommandDSC(cppFileType, project); |
| 756 |
command.setCommandId(Integer.parseInt(cmdElem.getAttribute(ID_ATTR))); |
| 757 |
// deserialize command |
| 758 |
command.deserialize(cmdElem); |
| 759 |
// get set of files the command applies to |
| 760 |
NodeList appliesList = cmdElem.getElementsByTagName(APPLIES_TO_ATTR); |
| 761 |
if (appliesList.getLength() > 0) { |
| 762 |
Element appliesElem = (Element) appliesList.item(0); |
| 763 |
NodeList fileList = appliesElem.getElementsByTagName(FILE_ELEM); |
| 764 |
for (int i = 0; i < fileList.getLength(); ++i) { |
| 765 |
Element fileElem = (Element) fileList.item(i); |
| 766 |
String fileName = fileElem.getAttribute(PATH_ATTR); |
| 767 |
IFile file = project.getFile(fileName); |
| 768 |
addCompilerCommand(file, command); |
| 769 |
} |
| 770 |
applyFileDeltas(); |
| 771 |
} |
| 772 |
} |
| 773 |
} |
| 774 |
} |
| 775 |
} |
| 776 |
|
| 777 |
/* (non-Javadoc) |
| 778 |
* @see org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable#getCollectorId() |
| 779 |
*/ |
| 780 |
public String getCollectorId() { |
| 781 |
return COLLECTOR_ID; |
| 782 |
} |
| 783 |
|
| 784 |
/* (non-Javadoc) |
| 785 |
* @see org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore.IDiscoveredScannerInfoSerializable#serialize(org.w3c.dom.Element) |
| 786 |
*/ |
| 787 |
public void serialize(Element collectorElem) { |
| 788 |
try { |
| 789 |
synchronized (fLock) { |
| 790 |
Document doc = collectorElem.getOwnerDocument(); |
| 791 |
|
| 792 |
// serialize project level info |
| 793 |
for (IProject project : fProjectSettingsMap.keySet()) { |
| 794 |
// create a project node |
| 795 |
Element projectElement = doc.createElement(PROJECT); |
| 796 |
projectElement.setAttribute(NAME, project.getName()); |
| 797 |
|
| 798 |
Map<ScannerInfoTypes, List<String>> scannerInfo = (Map<ScannerInfoTypes, List<String>>) fProjectSettingsMap.get(project); |
| 799 |
|
| 800 |
List<String> includes = scannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS); |
| 801 |
for(String include : includes) { |
| 802 |
Element pathElement = doc.createElement(INCLUDE_PATH); |
| 803 |
pathElement.setAttribute(PATH, include); |
| 804 |
//Boolean removed = (Boolean) includes.contains(include); |
| 805 |
//if (removed != null && removed.booleanValue() == true) { |
| 806 |
// pathElement.setAttribute(REMOVED, "true"); //$NON-NLS-1$ |
| 807 |
//} |
| 808 |
pathElement.setAttribute(REMOVED, "false"); //$NON-NLS-1$ |
| 809 |
projectElement.appendChild(pathElement); |
| 810 |
} |
| 811 |
|
| 812 |
// Now do the same for the symbols |
| 813 |
List<String> symbols = scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS); |
| 814 |
|
| 815 |
for(String symbol : symbols) { |
| 816 |
Element symbolElement = doc.createElement(DEFINED_SYMBOL); |
| 817 |
symbolElement.setAttribute(SYMBOL, symbol); |
| 818 |
projectElement.appendChild(symbolElement); |
| 819 |
} |
| 820 |
collectorElem.appendChild(projectElement); |
| 821 |
} |
| 822 |
|
| 823 |
// serialize file level info |
| 824 |
List<Integer> commandIds = new ArrayList<Integer>(commandIdCommandMap.keySet()); |
| 825 |
Collections.sort(commandIds); |
| 826 |
for (Iterator<Integer> i = commandIds.iterator(); i.hasNext(); ) { |
| 827 |
Integer commandId = i.next(); |
| 828 |
CCommandDSC command = commandIdCommandMap.get(commandId); |
| 829 |
|
| 830 |
Element cmdElem = doc.createElement(CC_ELEM); |
| 831 |
collectorElem.appendChild(cmdElem); |
| 832 |
cmdElem.setAttribute(ID_ATTR, commandId.toString()); |
| 833 |
cmdElem.setAttribute(FILE_TYPE_ATTR, command.appliesToCPPFileType() ? "c++" : "c"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 834 |
// write command and scanner info |
| 835 |
command.serialize(cmdElem); |
| 836 |
// write files command applies to |
| 837 |
Element filesElem = doc.createElement(APPLIES_TO_ATTR); |
| 838 |
cmdElem.appendChild(filesElem); |
| 839 |
Set<IFile> files = commandIdToFilesMap.get(commandId); |
| 840 |
if (files != null) { |
| 841 |
for (Iterator<IFile> j = files.iterator(); j.hasNext(); ) { |
| 842 |
Element fileElem = doc.createElement(FILE_ELEM); |
| 843 |
IFile file = j.next(); |
| 844 |
IPath path = file.getProjectRelativePath(); |
| 845 |
fileElem.setAttribute(PATH_ATTR, path.toString()); |
| 846 |
filesElem.appendChild(fileElem); |
| 847 |
} |
| 848 |
} |
| 849 |
} |
| 850 |
} |
| 851 |
|
| 852 |
} |
| 853 |
catch(Throwable e) { |
| 854 |
e.printStackTrace(); |
| 855 |
} |
| 856 |
} |
| 857 |
|
| 858 |
} |
| 859 |
|
| 860 |
protected static final String APPLIES_TO_ATTR = "appliesToFiles"; //$NON-NLS-1$ |
| 861 |
|
| 862 |
protected static final String CC_ELEM = "compilerCommand"; //$NON-NLS-1$ |
| 863 |
|
| 864 |
public static final String COLLECTOR_ID = Activator.PLUGIN_ID + ".PerFileXLCScannerInfoCollector"; //$NON-NLS-1$ |
| 865 |
|
| 866 |
protected static final String FILE_ELEM = "file"; //$NON-NLS-1$ |
| 867 |
|
| 868 |
protected static final String FILE_TYPE_ATTR = "fileType"; //$NON-NLS-1$ |
| 869 |
|
| 870 |
protected static final String ID_ATTR = "id"; //$NON-NLS-1$ |
| 871 |
|
| 872 |
protected static final int INCLUDE_FILE = 3; |
| 873 |
|
| 874 |
protected static final int INCLUDE_PATH = 1; |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
protected static final int MACROS_FILE = 4; |
| 879 |
|
| 880 |
protected static final String PATH_ATTR = "path"; //$NON-NLS-1$ |
| 881 |
|
| 882 |
protected static final int QUOTE_INCLUDE_PATH = 2; |
| 883 |
|
| 884 |
protected static PathInfo createFilePathInfo(CCommandDSC cmd){ |
| 885 |
IPath[] includes = stringListToPathArray(cmd.getIncludes()); |
| 886 |
IPath[] quotedIncludes = stringListToPathArray(cmd.getQuoteIncludes()); |
| 887 |
IPath[] incFiles = stringListToPathArray(cmd.getIncludeFile()); |
| 888 |
IPath[] macroFiles = stringListToPathArray(cmd.getImacrosFile()); |
| 889 |
List symbols = cmd.getSymbols(); |
| 890 |
Map<String, String> definedSymbols = new HashMap<String, String>(symbols.size()); |
| 891 |
for (Iterator i = symbols.iterator(); i.hasNext(); ) { |
| 892 |
String symbol = (String) i.next(); |
| 893 |
String key = ScannerConfigUtil.getSymbolKey(symbol); |
| 894 |
String value = ScannerConfigUtil.getSymbolValue(symbol); |
| 895 |
definedSymbols.put(key, value); |
| 896 |
} |
| 897 |
|
| 898 |
return new PathInfo(includes, quotedIncludes, definedSymbols, incFiles, macroFiles); |
| 899 |
} |
| 900 |
/** |
| 901 |
* @param discovered |
| 902 |
* @param allIncludes |
| 903 |
* @return |
| 904 |
*/ |
| 905 |
protected static IPath[] stringListToPathArray(List<String> discovered) { |
| 906 |
List<Path> allIncludes = new ArrayList<Path>(discovered.size()); |
| 907 |
for (Iterator<String> j = discovered.iterator(); j.hasNext(); ) { |
| 908 |
String include = j.next(); |
| 909 |
if (!allIncludes.contains(include)) { |
| 910 |
allIncludes.add(new Path(include)); |
| 911 |
} |
| 912 |
} |
| 913 |
return allIncludes.toArray(new IPath[allIncludes.size()]); |
| 914 |
} |
| 915 |
protected int commandIdCounter = 0; |
| 916 |
protected InfoContext context; |
| 917 |
|
| 918 |
/** monitor for data access */ |
| 919 |
protected final Object fLock = new Object(); |
| 920 |
|
| 921 |
private Map<IProject, Map<?, ?>> fProjectSettingsMap = new HashMap<IProject, Map<?, ?>>(); |
| 922 |
|
| 923 |
protected final SortedSet<Integer> freeCommandIdPool; // sorted set of free command ids |
| 924 |
protected IProject project; |
| 925 |
protected ProjectScannerInfo psi = null; // sum of all scanner info |
| 926 |
protected final List<Integer> siChangedForCommandIdList; // list of command ids for which scanner info has changed |
| 927 |
// protected List siChangedForFileList; // list of files for which scanner info has changed |
| 928 |
protected final Map<IResource, Integer> siChangedForFileMap; // (file, comandId) map for deltas |
| 929 |
protected ScannerInfoData sid; // scanner info data |
| 930 |
/** |
| 931 |
* |
| 932 |
*/ |
| 933 |
public PerFileXLCScannerInfoCollector() { |
| 934 |
sid = new ScannerInfoData(); |
| 935 |
|
| 936 |
// siChangedForFileList = new ArrayList(); |
| 937 |
siChangedForFileMap = new HashMap<IResource, Integer>(); |
| 938 |
siChangedForCommandIdList = new ArrayList<Integer>(); |
| 939 |
|
| 940 |
freeCommandIdPool = new TreeSet<Integer>(); |
| 941 |
} |
| 942 |
|
| 943 |
/** |
| 944 |
* @param file |
| 945 |
* @param object |
| 946 |
*/ |
| 947 |
protected void addCompilerCommand(IFile file, CCommandDSC cmd) { |
| 948 |
synchronized (fLock) { |
| 949 |
List<CCommandDSC> existingCommands = new ArrayList<CCommandDSC>(sid.commandIdCommandMap.values()); |
| 950 |
int index = existingCommands.indexOf(cmd); |
| 951 |
if (index != -1) { |
| 952 |
cmd = existingCommands.get(index); |
| 953 |
} else { |
| 954 |
int commandId = -1; |
| 955 |
if (!freeCommandIdPool.isEmpty()) { |
| 956 |
Integer freeCommandId = freeCommandIdPool.first(); |
| 957 |
freeCommandIdPool.remove(freeCommandId); |
| 958 |
commandId = freeCommandId.intValue(); |
| 959 |
} else { |
| 960 |
commandId = ++commandIdCounter; |
| 961 |
} |
| 962 |
cmd.setCommandId(commandId); |
| 963 |
sid.commandIdCommandMap.put(cmd.getCommandIdAsInteger(), cmd); |
| 964 |
} |
| 965 |
|
| 966 |
generateFileDelta(file, cmd); |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
/** |
| 971 |
* @param commandId |
| 972 |
* @param scannerInfo |
| 973 |
*/ |
| 974 |
protected void addScannerInfo(Integer commandId, Map scannerInfo) { |
| 975 |
synchronized (fLock) { |
| 976 |
CCommandDSC cmd = sid.commandIdCommandMap.get(commandId); |
| 977 |
if (cmd != null) { |
| 978 |
List<String> siItem = (List<String>) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS); |
| 979 |
cmd.setSymbols(siItem); |
| 980 |
siItem = (List<String>) scannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS); |
| 981 |
siItem = CygpathTranslator.translateIncludePaths(project, siItem); |
| 982 |
siItem = CCommandDSC.makeRelative(project, siItem); |
| 983 |
cmd.setIncludes(siItem); |
| 984 |
siItem = (List<String>) scannerInfo.get(ScannerInfoTypes.QUOTE_INCLUDE_PATHS); |
| 985 |
siItem = CygpathTranslator.translateIncludePaths(project, siItem); |
| 986 |
siItem = CCommandDSC.makeRelative(project, siItem); |
| 987 |
cmd.setQuoteIncludes(siItem); |
| 988 |
|
| 989 |
cmd.setDiscovered(true); |
| 990 |
} |
| 991 |
} |
| 992 |
} |
| 993 |
|
| 994 |
/** |
| 995 |
* @param type |
| 996 |
* @param object |
| 997 |
*/ |
| 998 |
protected void addScannerInfo(ScannerInfoTypes type, List delta) { |
| 999 |
// TODO Auto-generated method stub |
| 1000 |
|
| 1001 |
} |
| 1002 |
/** |
| 1003 |
* @param file |
| 1004 |
* @param cmd |
| 1005 |
*/ |
| 1006 |
protected void applyFileDeltas() { |
| 1007 |
synchronized (fLock) { |
| 1008 |
for (Iterator<IResource> i = siChangedForFileMap.keySet().iterator(); i.hasNext();) { |
| 1009 |
IFile file = (IFile) i.next(); |
| 1010 |
Integer commandId = siChangedForFileMap.get(file); |
| 1011 |
if (commandId != null) { |
| 1012 |
|
| 1013 |
// update sid.commandIdToFilesMap |
| 1014 |
Set<IFile> fileSet = sid.commandIdToFilesMap.get(commandId); |
| 1015 |
if (fileSet == null) { |
| 1016 |
fileSet = new HashSet<IFile>(); |
| 1017 |
sid.commandIdToFilesMap.put(commandId, fileSet); |
| 1018 |
CCommandDSC cmd = sid.commandIdCommandMap.get(commandId); |
| 1019 |
if (cmd != null) { |
| 1020 |
cmd.resolveOptions(project); |
| 1021 |
} |
| 1022 |
} |
| 1023 |
if (fileSet.add(file)) { |
| 1024 |
// update fileToCommandIdsMap |
| 1025 |
boolean change = true; |
| 1026 |
Integer oldCommandId = sid.fileToCommandIdMap.get(file); |
| 1027 |
if (oldCommandId != null) { |
| 1028 |
if (oldCommandId.equals(commandId)) { |
| 1029 |
change = false; |
| 1030 |
} else { |
| 1031 |
Set oldFileSet = sid.commandIdToFilesMap.get(oldCommandId); |
| 1032 |
if (oldFileSet != null) { |
| 1033 |
oldFileSet.remove(file); |
| 1034 |
} |
| 1035 |
} |
| 1036 |
} |
| 1037 |
if (change) { |
| 1038 |
sid.fileToCommandIdMap.put(file, commandId); |
| 1039 |
// TODO generate change event for this resource |
| 1040 |
// IPath path = file.getFullPath(); |
| 1041 |
// if (!siChangedForFileList.contains(path)) { |
| 1042 |
// siChangedForFileList.add(path); |
| 1043 |
// } |
| 1044 |
} |
| 1045 |
} |
| 1046 |
} |
| 1047 |
} |
| 1048 |
generateProjectScannerInfo(); |
| 1049 |
} |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
protected Map<IResource, PathInfo> calculatePathInfoMap() { |
| 1054 |
synchronized (fLock) { |
| 1055 |
Map<IResource, PathInfo> map = new HashMap<IResource, PathInfo>(sid.fileToCommandIdMap.size() + 1); |
| 1056 |
Map.Entry entry; |
| 1057 |
IFile file; |
| 1058 |
CCommandDSC cmd; |
| 1059 |
PathInfo fpi; |
| 1060 |
for (Iterator iter = sid.fileToCommandIdMap.entrySet().iterator(); iter.hasNext();) { |
| 1061 |
entry = (Map.Entry) iter.next(); |
| 1062 |
file = (IFile) entry.getKey(); |
| 1063 |
if (file != null) { |
| 1064 |
cmd = sid.commandIdCommandMap.get(entry.getValue()); |
| 1065 |
if (cmd != null) { |
| 1066 |
fpi = createFilePathInfo(cmd); |
| 1067 |
map.put(file, fpi); |
| 1068 |
} |
| 1069 |
} |
| 1070 |
} |
| 1071 |
|
| 1072 |
if (project != null) { |
| 1073 |
if (psi == null) { |
| 1074 |
generateProjectScannerInfo(); |
| 1075 |
} |
| 1076 |
|
| 1077 |
fpi = new PathInfo(psi.includePaths, psi.quoteIncludePaths, psi.definedSymbols, psi.includeFiles, |
| 1078 |
psi.macrosFiles); |
| 1079 |
map.put(project, fpi); |
| 1080 |
} |
| 1081 |
|
| 1082 |
return map; |
| 1083 |
} |
| 1084 |
} |
| 1085 |
|
| 1086 |
public void contributeToScannerConfig(Object resource, Map scannerInfo) { |
| 1087 |
// check the resource |
| 1088 |
String errorMessage = null; |
| 1089 |
if (resource == null) { |
| 1090 |
errorMessage = "resource is null";//$NON-NLS-1$ |
| 1091 |
} |
| 1092 |
else if (resource instanceof Integer) { |
| 1093 |
synchronized (fLock) { |
| 1094 |
addScannerInfo(((Integer)resource), scannerInfo); |
| 1095 |
} |
| 1096 |
return; |
| 1097 |
} |
| 1098 |
|
| 1099 |
if ((resource instanceof IFile)) { |
| 1100 |
|
| 1101 |
if (((IFile) resource).getProject() == null) { |
| 1102 |
errorMessage = "project is null";//$NON-NLS-1$ |
| 1103 |
} else if (!((IFile) resource).getProject().equals(project)) { |
| 1104 |
errorMessage = "wrong project";//$NON-NLS-1$ |
| 1105 |
} |
| 1106 |
if (errorMessage != null) { |
| 1107 |
TraceUtil.outputError("PerFileSICollector.contributeToScannerConfig : ", errorMessage); //$NON-NLS-1$ |
| 1108 |
return; |
| 1109 |
} |
| 1110 |
|
| 1111 |
IFile file = (IFile) resource; |
| 1112 |
|
| 1113 |
synchronized (fLock) { |
| 1114 |
for (Iterator i = scannerInfo.keySet().iterator(); i.hasNext();) { |
| 1115 |
ScannerInfoTypes type = (ScannerInfoTypes) i.next(); |
| 1116 |
if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) { |
| 1117 |
List commands = (List) scannerInfo.get(type); |
| 1118 |
for (Iterator j = commands.iterator(); j.hasNext();) { |
| 1119 |
addCompilerCommand(file, (CCommandDSC) j.next()); |
| 1120 |
} |
| 1121 |
} else { |
| 1122 |
addScannerInfo(type, (List) scannerInfo.get(type)); |
| 1123 |
} |
| 1124 |
} |
| 1125 |
} |
| 1126 |
} |
| 1127 |
|
| 1128 |
else if(resource instanceof IProject) { |
| 1129 |
// save to project level settings |
| 1130 |
synchronized (fLock) { |
| 1131 |
fProjectSettingsMap.put(((IProject) resource), scannerInfo); |
| 1132 |
} |
| 1133 |
} |
| 1134 |
|
| 1135 |
else { // error |
| 1136 |
TraceUtil.outputError("PerFileSICollector.contributeToScannerConfig : ", "Not a project or file."); //$NON-NLS-1$ //$NON-NLS-2$ |
| 1137 |
return; |
| 1138 |
} |
| 1139 |
} |
| 1140 |
|
| 1141 |
/* (non-Javadoc) |
| 1142 |
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2#createPathInfoObject() |
| 1143 |
*/ |
| 1144 |
public IDiscoveredPathInfo createPathInfoObject() { |
| 1145 |
return new PerFileDiscoveredPathInfo(); |
| 1146 |
} |
| 1147 |
/* (non-Javadoc) |
| 1148 |
* @see org.eclipse.cdt.make.internal.core.scannerconfig2.PerFileSICollector#deleteAll(org.eclipse.core.resources.IResource) |
| 1149 |
*/ |
| 1150 |
public void deleteAll(IResource resource) { |
| 1151 |
synchronized (fLock) { |
| 1152 |
if (resource instanceof IProject) { |
| 1153 |
fProjectSettingsMap.remove(((IProject) resource)); |
| 1154 |
} |
| 1155 |
} |
| 1156 |
} |
| 1157 |
|
| 1158 |
/* (non-Javadoc) |
| 1159 |
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollectorCleaner#deleteAll(org.eclipse.core.resources.IResource) |
| 1160 |
*/ |
| 1161 |
public void deleteAll1(IResource resource) { |
| 1162 |
if (resource.equals(project)) { |
| 1163 |
synchronized (fLock) { |
| 1164 |
// siChangedForFileList = new ArrayList(); |
| 1165 |
siChangedForFileMap.clear(); |
| 1166 |
Set<IFile> changedFiles = sid.fileToCommandIdMap.keySet(); |
| 1167 |
for (Iterator<IFile> i = changedFiles.iterator(); i.hasNext(); ) { |
| 1168 |
IFile file = i.next(); |
| 1169 |
// IPath path = file.getFullPath(); |
| 1170 |
// siChangedForFileList.add(path); |
| 1171 |
siChangedForFileMap.put(file, null); |
| 1172 |
} |
| 1173 |
|
| 1174 |
sid = new ScannerInfoData(); |
| 1175 |
psi = null; |
| 1176 |
|
| 1177 |
commandIdCounter = 0; |
| 1178 |
freeCommandIdPool.clear(); |
| 1179 |
} |
| 1180 |
} |
| 1181 |
} |
| 1182 |
|
| 1183 |
/* |
| 1184 |
* (non-Javadoc) |
| 1185 |
* |
| 1186 |
* @see |
| 1187 |
* org.eclipse.cdt.make.internal.core.scannerconfig2.PerFileSICollector# |
| 1188 |
* deleteAllPaths(org.eclipse.core.resources.IResource) |
| 1189 |
*/ |
| 1190 |
public void deleteAllPaths(IResource resource) { |
| 1191 |
synchronized (fLock) { |
| 1192 |
if (resource instanceof IProject && fProjectSettingsMap != null) { |
| 1193 |
fProjectSettingsMap.remove(((IProject) resource)); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
} |
| 1197 |
|
| 1198 |
/* |
| 1199 |
* (non-Javadoc) |
| 1200 |
* |
| 1201 |
* @see |
| 1202 |
* org.eclipse.cdt.make.internal.core.scannerconfig2.PerFileSICollector# |
| 1203 |
* deleteAllSymbols(org.eclipse.core.resources.IResource) |
| 1204 |
*/ |
| 1205 |
public void deleteAllSymbols(IResource resource) { |
| 1206 |
synchronized (fLock) { |
| 1207 |
if (resource instanceof IProject && fProjectSettingsMap != null) { |
| 1208 |
fProjectSettingsMap.remove(((IProject) resource)); |
| 1209 |
} |
| 1210 |
} |
| 1211 |
} |
| 1212 |
|
| 1213 |
/* |
| 1214 |
* (non-Javadoc) |
| 1215 |
* |
| 1216 |
* @see |
| 1217 |
* org.eclipse.cdt.make.internal.core.scannerconfig2.PerFileSICollector# |
| 1218 |
* deletePath(org.eclipse.core.resources.IResource, java.lang.String) |
| 1219 |
*/ |
| 1220 |
public void deletePath(IResource resource, String path) { |
| 1221 |
synchronized (fLock) { |
| 1222 |
if (resource instanceof IProject && fProjectSettingsMap != null) { |
| 1223 |
fProjectSettingsMap.remove(((IProject) resource)); |
| 1224 |
} |
| 1225 |
} |
| 1226 |
} |
| 1227 |
|
| 1228 |
/* |
| 1229 |
* (non-Javadoc) |
| 1230 |
* |
| 1231 |
* @see |
| 1232 |
* org.eclipse.cdt.make.internal.core.scannerconfig2.PerFileSICollector# |
| 1233 |
* deleteSymbol(org.eclipse.core.resources.IResource, java.lang.String) |
| 1234 |
*/ |
| 1235 |
public void deleteSymbol(IResource resource, String symbol) { |
| 1236 |
synchronized (fLock) { |
| 1237 |
if (resource instanceof IProject && fProjectSettingsMap != null) { |
| 1238 |
fProjectSettingsMap.remove(((IProject) resource)); |
| 1239 |
} |
| 1240 |
} |
| 1241 |
} |
| 1242 |
|
| 1243 |
/** |
| 1244 |
* @param file |
| 1245 |
* @param cmd |
| 1246 |
*/ |
| 1247 |
protected void generateFileDelta(IFile file, CCommandDSC cmd) { |
| 1248 |
synchronized (fLock) { |
| 1249 |
Integer commandId = cmd.getCommandIdAsInteger(); |
| 1250 |
Integer oldCommandId = sid.fileToCommandIdMap.get(file); |
| 1251 |
|
| 1252 |
if (oldCommandId != null && oldCommandId.equals(commandId)) { |
| 1253 |
// already exists; remove form delta |
| 1254 |
siChangedForFileMap.remove(file); |
| 1255 |
} else { |
| 1256 |
// new (file, commandId) pair |
| 1257 |
siChangedForFileMap.put(file, commandId); |
| 1258 |
} |
| 1259 |
} |
| 1260 |
} |
| 1261 |
|
| 1262 |
protected void generateProjectScannerInfo() { |
| 1263 |
synchronized (fLock) { |
| 1264 |
psi = new ProjectScannerInfo(); |
| 1265 |
psi.includePaths = getAllIncludePaths(INCLUDE_PATH); |
| 1266 |
psi.quoteIncludePaths = getAllIncludePaths(QUOTE_INCLUDE_PATH); |
| 1267 |
psi.includeFiles = getAllIncludePaths(INCLUDE_FILE); |
| 1268 |
psi.macrosFiles = getAllIncludePaths(MACROS_FILE); |
| 1269 |
psi.definedSymbols = getAllSymbols(); |
| 1270 |
} |
| 1271 |
} |
| 1272 |
|
| 1273 |
/* (non-Javadoc) |
| 1274 |
* @see org.eclipse.cdt.make.internal.core.scannerconfig2.PerFileSICollector#getAllIncludePaths(int) |
| 1275 |
*/ |
| 1276 |
protected IPath[] getAllIncludePaths(int type) { |
| 1277 |
synchronized (fLock) { |
| 1278 |
IProject project = this.getInfoContext().getProject(); |
| 1279 |
|
| 1280 |
Map projectScannerInfo = fProjectSettingsMap.get(project); |
| 1281 |
List<String> includes = null; |
| 1282 |
|
| 1283 |
if (projectScannerInfo != null) { |
| 1284 |
includes = (List<String>) projectScannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS); |
| 1285 |
} |
| 1286 |
|
| 1287 |
List<IPath> pathList = new LinkedList<IPath>(); |
| 1288 |
|
| 1289 |
if (includes != null) { |
| 1290 |
for (String include : includes) { |
| 1291 |
pathList.add(new Path(include)); |
| 1292 |
} |
| 1293 |
} |
| 1294 |
|
| 1295 |
IPath[] fileIncludes = getAllIncludePaths1(type); |
| 1296 |
|
| 1297 |
for (IPath include : fileIncludes) { |
| 1298 |
pathList.add(include); |
| 1299 |
} |
| 1300 |
|
| 1301 |
return pathList.toArray(new IPath[0]); |
| 1302 |
} |
| 1303 |
} |
| 1304 |
|
| 1305 |
/** |
| 1306 |
* @param type can be one of the following: |
| 1307 |
* <li><code>INCLUDE_PATH</code> |
| 1308 |
* <li><code>QUOTE_INCLUDE_PATH</code> |
| 1309 |
* <li><code>INCLUDE_FILE</code> |
| 1310 |
* <li><code>MACROS_FILE</code> |
| 1311 |
* |
| 1312 |
* @return list of IPath(s). |
| 1313 |
*/ |
| 1314 |
protected IPath[] getAllIncludePaths1(int type) { |
| 1315 |
synchronized (fLock) { |
| 1316 |
List<String> allIncludes = new ArrayList<String>(); |
| 1317 |
for (Iterator<Integer> i = sid.commandIdCommandMap.keySet().iterator(); i.hasNext();) { |
| 1318 |
Integer cmdId = i.next(); |
| 1319 |
CCommandDSC cmd = sid.commandIdCommandMap.get(cmdId); |
| 1320 |
if (cmd.isDiscovered()) { |
| 1321 |
List<String> discovered = null; |
| 1322 |
switch (type) { |
| 1323 |
case INCLUDE_PATH: |
| 1324 |
discovered = cmd.getIncludes(); |
| 1325 |
break; |
| 1326 |
case QUOTE_INCLUDE_PATH: |
| 1327 |
discovered = cmd.getQuoteIncludes(); |
| 1328 |
break; |
| 1329 |
case INCLUDE_FILE: |
| 1330 |
discovered = cmd.getIncludeFile(); |
| 1331 |
break; |
| 1332 |
case MACROS_FILE: |
| 1333 |
discovered = cmd.getImacrosFile(); |
| 1334 |
break; |
| 1335 |
} |
| 1336 |
for (Iterator<String> j = discovered.iterator(); j.hasNext();) { |
| 1337 |
String include = j.next(); |
| 1338 |
// the following line degrades perfomance |
| 1339 |
// see |
| 1340 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=189127 |
| 1341 |
// it is not necessary for renaming projects anyway |
| 1342 |
// include = CCommandDSC.makeRelative(project, new |
| 1343 |
// Path(include)).toPortableString(); |
| 1344 |
if (!allIncludes.contains(include)) { |
| 1345 |
allIncludes.add(include); |
| 1346 |
} |
| 1347 |
} |
| 1348 |
} |
| 1349 |
} |
| 1350 |
return stringListToPathArray(allIncludes); |
| 1351 |
} |
| 1352 |
} |
| 1353 |
|
| 1354 |
/* |
| 1355 |
* (non-Javadoc) |
| 1356 |
* |
| 1357 |
* @see |
| 1358 |
* org.eclipse.cdt.make.internal.core.scannerconfig2.PerFileSICollector# |
| 1359 |
* getAllSymbols() |
| 1360 |
*/ |
| 1361 |
protected Map<String, String> getAllSymbols() { |
| 1362 |
synchronized (fLock) { |
| 1363 |
IProject project = this.getInfoContext().getProject(); |
| 1364 |
|
| 1365 |
Map projectScannerInfo = fProjectSettingsMap.get(project); |
| 1366 |
|
| 1367 |
Map<String, String> symbols = new HashMap<String, String>(); |
| 1368 |
|
| 1369 |
if (projectScannerInfo != null) { |
| 1370 |
List<String> projectSymbols = (List<String>) projectScannerInfo |
| 1371 |
.get(ScannerInfoTypes.SYMBOL_DEFINITIONS); |
| 1372 |
|
| 1373 |
for (String symbol : projectSymbols) { |
| 1374 |
symbols.put(symbol, "1"); //$NON-NLS-1$ |
| 1375 |
} |
| 1376 |
} |
| 1377 |
|
| 1378 |
Map<String, String> fileSymbols = getAllSymbols1(); |
| 1379 |
|
| 1380 |
symbols.putAll(fileSymbols); |
| 1381 |
|
| 1382 |
return symbols; |
| 1383 |
} |
| 1384 |
} |
| 1385 |
|
| 1386 |
/** |
| 1387 |
* @return |
| 1388 |
*/ |
| 1389 |
protected Map<String, String> getAllSymbols1() { |
| 1390 |
synchronized (fLock) { |
| 1391 |
Map<String, String> symbols = new HashMap<String, String>(); |
| 1392 |
for (Iterator<Integer> i = sid.commandIdCommandMap.keySet().iterator(); i.hasNext();) { |
| 1393 |
Integer cmdId = i.next(); |
| 1394 |
CCommandDSC cmd = sid.commandIdCommandMap.get(cmdId); |
| 1395 |
if (cmd.isDiscovered()) { |
| 1396 |
List discovered = cmd.getSymbols(); |
| 1397 |
for (Iterator j = discovered.iterator(); j.hasNext();) { |
| 1398 |
String symbol = (String) j.next(); |
| 1399 |
String key = ScannerConfigUtil.getSymbolKey(symbol); |
| 1400 |
String value = ScannerConfigUtil.getSymbolValue(symbol); |
| 1401 |
symbols.put(key, value); |
| 1402 |
} |
| 1403 |
} |
| 1404 |
} |
| 1405 |
return symbols; |
| 1406 |
} |
| 1407 |
} |
| 1408 |
|
| 1409 |
/* (non-Javadoc) |
| 1410 |
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#getCollectedScannerInfo(java.lang.Object, org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes) |
| 1411 |
*/ |
| 1412 |
public List<CCommandDSC> getCollectedScannerInfo(Object resource, ScannerInfoTypes type) { |
| 1413 |
|
| 1414 |
List<CCommandDSC> rv = new ArrayList<CCommandDSC>(); |
| 1415 |
// check the resource |
| 1416 |
String errorMessage = null; |
| 1417 |
if (resource == null) { |
| 1418 |
errorMessage = "resource is null";//$NON-NLS-1$ |
| 1419 |
} |
| 1420 |
else if (!(resource instanceof IResource)) { |
| 1421 |
errorMessage = "resource is not an IResource";//$NON-NLS-1$ |
| 1422 |
} |
| 1423 |
else if (((IResource) resource).getProject() == null) { |
| 1424 |
errorMessage = "project is null";//$NON-NLS-1$ |
| 1425 |
} |
| 1426 |
else if (((IResource) resource).getProject() != project) { |
| 1427 |
errorMessage = "wrong project";//$NON-NLS-1$ |
| 1428 |
} |
| 1429 |
|
| 1430 |
if (errorMessage != null) { |
| 1431 |
TraceUtil.outputError("PerProjectSICollector.getCollectedScannerInfo : ", errorMessage); //$NON-NLS-1$ |
| 1432 |
return rv; |
| 1433 |
} |
| 1434 |
if (project.equals(((IResource)resource).getProject())) { |
| 1435 |
if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) { |
| 1436 |
synchronized (fLock) { |
| 1437 |
for (Iterator<Integer> i = sid.commandIdCommandMap.keySet().iterator(); i.hasNext(); ) { |
| 1438 |
Integer cmdId = i.next(); |
| 1439 |
Set<IFile> fileSet = sid.commandIdToFilesMap.get(cmdId); |
| 1440 |
if (fileSet != null && !fileSet.isEmpty()) { |
| 1441 |
rv.add(sid.commandIdCommandMap.get(cmdId)); |
| 1442 |
} |
| 1443 |
} |
| 1444 |
} |
| 1445 |
} |
| 1446 |
else if (type.equals(ScannerInfoTypes.UNDISCOVERED_COMPILER_COMMAND)) { |
| 1447 |
// if (!siChangedForFileList.isEmpty()) { |
| 1448 |
synchronized (fLock) { |
| 1449 |
if (scannerInfoChanged()) { |
| 1450 |
if (siChangedForCommandIdList.isEmpty()) { |
| 1451 |
// for (Iterator i = siChangedForFileList.iterator(); i.hasNext(); ) { |
| 1452 |
for (Iterator<IResource> i = siChangedForFileMap.keySet().iterator(); i.hasNext(); ) { |
| 1453 |
// IPath path = (IPath) i.next(); |
| 1454 |
IFile file = (IFile) i.next(); |
| 1455 |
Integer cmdId = siChangedForFileMap.get(file); |
| 1456 |
if (cmdId != null) { |
| 1457 |
if (!siChangedForCommandIdList.contains(cmdId)) { |
| 1458 |
siChangedForCommandIdList.add(cmdId); |
| 1459 |
} |
| 1460 |
} |
| 1461 |
} |
| 1462 |
} |
| 1463 |
Collections.sort(siChangedForCommandIdList); |
| 1464 |
for (Iterator<Integer> i = siChangedForCommandIdList.iterator(); i.hasNext(); ) { |
| 1465 |
Integer cmdId = i.next(); |
| 1466 |
CCommandDSC command = sid.commandIdCommandMap.get(cmdId); |
| 1467 |
rv.add(command); |
| 1468 |
} |
| 1469 |
} |
| 1470 |
} |
| 1471 |
} |
| 1472 |
} |
| 1473 |
return rv; |
| 1474 |
} |
| 1475 |
|
| 1476 |
protected CCommandDSC getCommand(IFile file) { |
| 1477 |
synchronized (fLock) { |
| 1478 |
CCommandDSC cmd = null; |
| 1479 |
if (file != null) { |
| 1480 |
Integer cmdId = sid.fileToCommandIdMap.get(file); |
| 1481 |
if (cmdId != null) { |
| 1482 |
// get the command |
| 1483 |
cmd = sid.commandIdCommandMap.get(cmdId); |
| 1484 |
} |
| 1485 |
} |
| 1486 |
return cmd; |
| 1487 |
} |
| 1488 |
} |
| 1489 |
|
| 1490 |
/** |
| 1491 |
* @param path |
| 1492 |
* @return |
| 1493 |
*/ |
| 1494 |
protected CCommandDSC getCommand(IPath path) { |
| 1495 |
synchronized (fLock) { |
| 1496 |
try { |
| 1497 |
IFile file = project.getWorkspace().getRoot().getFile(path); |
| 1498 |
return getCommand(file); |
| 1499 |
} catch (Exception e) { |
| 1500 |
return null; |
| 1501 |
} |
| 1502 |
} |
| 1503 |
} |
| 1504 |
|
| 1505 |
/* (non-Javadoc) |
| 31 |
* @see org.eclipse.cdt.managedbuilder.scannerconfig.IManagedScannerInfoCollector#getDefinedSymbols() |
1506 |
* @see org.eclipse.cdt.managedbuilder.scannerconfig.IManagedScannerInfoCollector#getDefinedSymbols() |
| 32 |
*/ |
1507 |
*/ |
| 33 |
public Map getDefinedSymbols() { |
1508 |
public Map getDefinedSymbols() { |
| 34 |
return getAllSymbols(); |
1509 |
synchronized (fLock) { |
|
|
1510 |
return getAllSymbols(); |
| 1511 |
} |
| 35 |
} |
1512 |
} |
| 36 |
|
1513 |
|
| 37 |
/* (non-Javadoc) |
1514 |
/* (non-Javadoc) |
| 38 |
* @see org.eclipse.cdt.managedbuilder.scannerconfig.IManagedScannerInfoCollector#getIncludePaths() |
1515 |
* @see org.eclipse.cdt.managedbuilder.scannerconfig.IManagedScannerInfoCollector#getIncludePaths() |
| 39 |
*/ |
1516 |
*/ |
| 40 |
public List getIncludePaths() { |
1517 |
public List getIncludePaths() { |
| 41 |
List<String> pathStrings = new LinkedList<String>(); |
1518 |
synchronized (fLock) { |
| 42 |
|
1519 |
List<String> pathStrings = new LinkedList<String>(); |
| 43 |
List<IPath> paths = Arrays.asList(getAllIncludePaths(INCLUDE_PATH)); |
1520 |
|
| 44 |
paths.addAll(Arrays.asList(getAllIncludePaths(QUOTE_INCLUDE_PATH))); |
1521 |
List<IPath> paths = Arrays.asList(getAllIncludePaths(INCLUDE_PATH)); |
| 45 |
|
1522 |
paths.addAll(Arrays.asList(getAllIncludePaths(QUOTE_INCLUDE_PATH))); |
| 46 |
for(IPath path : paths) { |
1523 |
|
| 47 |
pathStrings.add(path.toString()); |
1524 |
for (IPath path : paths) { |
|
|
1525 |
pathStrings.add(path.toString()); |
| 1526 |
} |
| 1527 |
|
| 1528 |
return pathStrings; |
| 1529 |
} |
| 1530 |
} |
| 1531 |
|
| 1532 |
protected InfoContext getInfoContext() { |
| 1533 |
return context; |
| 1534 |
} |
| 1535 |
|
| 1536 |
protected void removeUnusedCommands() { |
| 1537 |
synchronized (fLock) { |
| 1538 |
for (Iterator i = sid.commandIdToFilesMap.entrySet().iterator(); i.hasNext();) { |
| 1539 |
Entry entry = (Entry) i.next(); |
| 1540 |
Integer cmdId = (Integer) entry.getKey(); |
| 1541 |
Set fileSet = (Set) entry.getValue(); |
| 1542 |
if (fileSet.isEmpty()) { |
| 1543 |
// return cmdId to the free command id pool |
| 1544 |
freeCommandIdPool.add(cmdId); |
| 1545 |
} |
| 1546 |
} |
| 1547 |
for (Iterator<Integer> i = freeCommandIdPool.iterator(); i.hasNext();) { |
| 1548 |
Integer cmdId = i.next(); |
| 1549 |
// the command does not have any files associated; remove |
| 1550 |
sid.commandIdCommandMap.remove(cmdId); |
| 1551 |
sid.commandIdToFilesMap.remove(cmdId); |
| 1552 |
} |
| 1553 |
while (!freeCommandIdPool.isEmpty()) { |
| 1554 |
Integer last = freeCommandIdPool.last(); |
| 1555 |
if (last.intValue() == commandIdCounter) { |
| 1556 |
freeCommandIdPool.remove(last); |
| 1557 |
--commandIdCounter; |
| 1558 |
} else |
| 1559 |
break; |
| 1560 |
} |
| 1561 |
} |
| 1562 |
} |
| 1563 |
|
| 1564 |
protected boolean scannerInfoChanged() { |
| 1565 |
synchronized (fLock) { |
| 1566 |
return (!fProjectSettingsMap.isEmpty()) || !siChangedForFileMap.isEmpty(); |
| 1567 |
} |
| 1568 |
} |
| 1569 |
|
| 1570 |
public void setInfoContext(InfoContext context) { |
| 1571 |
synchronized (fLock) { |
| 1572 |
this.project = context.getProject(); |
| 1573 |
this.context = context; |
| 1574 |
|
| 1575 |
try { |
| 1576 |
// deserialize from SI store |
| 1577 |
DiscoveredScannerInfoStore.getInstance().loadDiscoveredScannerInfoFromState(project, context, sid); |
| 1578 |
} catch (CoreException e) { |
| 1579 |
MakeCorePlugin.log(e); |
| 1580 |
} |
| 48 |
} |
1581 |
} |
| 49 |
|
|
|
| 50 |
return pathStrings; |
| 51 |
} |
1582 |
} |
| 52 |
|
1583 |
|
|
|
1584 |
/* (non-Javadoc) |
| 1585 |
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2#setProject(org.eclipse.core.resources.IProject) |
| 1586 |
*/ |
| 1587 |
public void setProject(IProject project) { |
| 1588 |
synchronized (fLock) { |
| 1589 |
setInfoContext(new InfoContext(project)); |
| 1590 |
} |
| 1591 |
} |
| 1592 |
|
| 1593 |
public void updateScannerConfiguration(IProgressMonitor monitor) throws CoreException { |
| 1594 |
if (monitor == null) { |
| 1595 |
monitor = new NullProgressMonitor(); |
| 1596 |
} |
| 1597 |
monitor.beginTask(Messages.getString("ScannerInfoCollector.Processing"), 100); //$NON-NLS-1$ |
| 1598 |
monitor.subTask(Messages.getString("ScannerInfoCollector.Processing")); //$NON-NLS-1$ |
| 1599 |
ArrayList<IResource> changedResources = new ArrayList<IResource>(); |
| 1600 |
synchronized (fLock) { |
| 1601 |
if (scannerInfoChanged()) { |
| 1602 |
applyFileDeltas(); |
| 1603 |
removeUnusedCommands(); |
| 1604 |
changedResources.addAll(siChangedForFileMap.keySet()); |
| 1605 |
siChangedForFileMap.clear(); |
| 1606 |
} |
| 1607 |
siChangedForCommandIdList.clear(); |
| 1608 |
|
| 1609 |
// add in any projects that got project level info (from the specs provider) |
| 1610 |
changedResources.addAll(fProjectSettingsMap.keySet()); |
| 1611 |
|
| 1612 |
monitor.worked(50); |
| 1613 |
if (!changedResources.isEmpty()) { |
| 1614 |
// update outside monitor scope |
| 1615 |
try { |
| 1616 |
// update scanner configuration |
| 1617 |
monitor.subTask(Messages.getString("ScannerInfoCollector.Updating") + project.getName()); //$NON-NLS-1$ |
| 1618 |
IDiscoveredPathInfo pathInfo = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(project, context); |
| 1619 |
//IDiscoveredPathInfo pathInfo = new PerFileDiscoveredPathInfo(); |
| 1620 |
if (!(pathInfo instanceof IPerFileDiscoveredPathInfo)) { |
| 1621 |
pathInfo = createPathInfoObject(); |
| 1622 |
} |
| 1623 |
else { |
| 1624 |
PerFileDiscoveredPathInfo perFilePathInfo = new PerFileDiscoveredPathInfo(); |
| 1625 |
|
| 1626 |
// merge them |
| 1627 |
if (!(pathInfo instanceof IPerFileDiscoveredPathInfo)) { |
| 1628 |
pathInfo = new MergedPerFileDiscoveredPathInfo(pathInfo, perFilePathInfo); |
| 1629 |
} |
| 1630 |
else { |
| 1631 |
pathInfo = perFilePathInfo; |
| 1632 |
} |
| 1633 |
} |
| 1634 |
|
| 1635 |
ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot(); |
| 1636 |
|
| 1637 |
Job job = new ScannerConfigUpdateJob(context, pathInfo, context.isDefaultContext(), changedResources); |
| 1638 |
job.setRule(ResourcesPlugin.getWorkspace().getRoot()); |
| 1639 |
job.schedule(); |
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
// } finally { |
| 1644 |
// manager.endRule(rule); |
| 1645 |
// } |
| 1646 |
|
| 1647 |
} catch (CoreException e) { |
| 1648 |
MakeCorePlugin.log(e); |
| 1649 |
} |
| 1650 |
|
| 1651 |
catch (Throwable e) { |
| 1652 |
e.printStackTrace(); |
| 1653 |
} |
| 1654 |
} |
| 1655 |
} |
| 1656 |
|
| 1657 |
|
| 1658 |
monitor.worked(50); |
| 1659 |
monitor.done(); |
| 1660 |
} |
| 1661 |
|
| 53 |
} |
1662 |
} |