Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 293598 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/cdt/make/xlc/core/scannerconfig/XlCSpecsConsoleParser.java (-5 / +17 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 17-27 Link Here
17
import java.util.regex.Matcher;
17
import java.util.regex.Matcher;
18
import java.util.regex.Pattern;
18
import java.util.regex.Pattern;
19
19
20
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2;
20
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
21
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
21
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
22
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
22
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
23
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
23
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
24
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
25
import org.eclipse.cdt.make.xlc.core.activator.Activator;
24
import org.eclipse.core.resources.IProject;
26
import org.eclipse.core.resources.IProject;
27
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.cdt.core.IMarkerGenerator;
29
import org.eclipse.cdt.core.IMarkerGenerator;
27
30
Lines 48-56 Link Here
48
51
49
	private IScannerInfoCollector fCollector = null;
52
	private IScannerInfoCollector fCollector = null;
50
53
51
	private List symbols = new ArrayList();
54
	private List<String> symbols = new ArrayList<String>();
52
55
53
	private List includes = new ArrayList();
56
	private List<String> includes = new ArrayList<String>();
54
57
55
	/*
58
	/*
56
	 * (non-Javadoc)
59
	 * (non-Javadoc)
Lines 126-139 Link Here
126
	 * @since 1.0
129
	 * @since 1.0
127
	 */
130
	 */
128
	public void shutdown() {
131
	public void shutdown() {
129
		Map scannerInfo = new HashMap();
132
		Map<ScannerInfoTypes, List<String>> scannerInfo = new HashMap<ScannerInfoTypes, List<String>>();
130
		scannerInfo.put(ScannerInfoTypes.INCLUDE_PATHS, includes);
133
		scannerInfo.put(ScannerInfoTypes.INCLUDE_PATHS, includes);
131
		scannerInfo.put(ScannerInfoTypes.SYMBOL_DEFINITIONS, symbols);
134
		scannerInfo.put(ScannerInfoTypes.SYMBOL_DEFINITIONS, symbols);
132
		fCollector.contributeToScannerConfig(fProject, scannerInfo);
135
		fCollector.contributeToScannerConfig(fProject, scannerInfo);
136
		if(fCollector != null && fCollector instanceof IScannerInfoCollector2) {
137
			IScannerInfoCollector2 collector = (IScannerInfoCollector2) fCollector;
138
			try {
139
				collector.updateScannerConfiguration(null);
140
			} catch (CoreException e) {
141
				// TODO Auto-generated catch block
142
				Activator.log(e);
143
			}
144
		}
133
		TraceUtil
145
		TraceUtil
134
				.outputTrace(
146
				.outputTrace(
135
						"Scanner info from \'specs\' file", //$NON-NLS-1$
147
						"Scanner info from \'specs\' file", //$NON-NLS-1$
136
						"Include paths", includes, new ArrayList(), "Defined symbols", symbols); //$NON-NLS-1$ //$NON-NLS-2$
148
						"Include paths", includes, new ArrayList<Object>(), "Defined symbols", symbols); //$NON-NLS-1$ //$NON-NLS-2$
137
	}
149
	}
138
150
139
}
151
}
(-)src/org/eclipse/cdt/make/xlc/core/scannerconfig/XLCPerProjectBuildOutputParser.java (-11 / +17 lines)
Lines 10-32 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.io.File;
14
import java.io.IOException;
15
import java.util.ArrayList;
13
import java.util.ArrayList;
16
import java.util.HashMap;
14
import java.util.HashMap;
17
import java.util.List;
15
import java.util.List;
18
import java.util.Map;
16
import java.util.Map;
19
17
20
import org.eclipse.cdt.core.IMarkerGenerator;
18
import org.eclipse.cdt.core.IMarkerGenerator;
19
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2;
21
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
20
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
22
import org.eclipse.cdt.make.internal.core.MakeMessages;
21
import org.eclipse.cdt.make.internal.core.MakeMessages;
23
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParserUtility;
24
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
22
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
23
import org.eclipse.cdt.make.xlc.core.activator.Activator;
25
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IFile;
26
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.resources.IProject;
27
import org.eclipse.core.resources.IWorkspaceRoot;
26
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.Path;
30
27
31
/**
28
/**
32
 * @author crecoskie
29
 * @author crecoskie
Lines 50-58 Link Here
50
        }
47
        }
51
48
52
        // Recognized gcc or g++ compiler invocation
49
        // Recognized gcc or g++ compiler invocation
53
        List includes = new ArrayList();
50
        List<String> includes = new ArrayList<String>();
54
        List symbols = new ArrayList();
51
        List<String> symbols = new ArrayList<String>();
55
        List targetSpecificOptions = new ArrayList();
52
        List<String> targetSpecificOptions = new ArrayList<String>();
56
53
57
        String fileName = null;
54
        String fileName = null;
58
        for (int j= compilerInvocationIdx+1; j < tokens.length; j++) {
55
        for (int j= compilerInvocationIdx+1; j < tokens.length; j++) {
Lines 125-131 Link Here
125
122
126
        IProject project = getProject();   
123
        IProject project = getProject();   
127
        IFile file = null;
124
        IFile file = null;
128
        List translatedIncludes = includes;
125
        List<String> translatedIncludes = includes;
129
        if (includes.size() > 0) {
126
        if (includes.size() > 0) {
130
        	if (fileName != null) {
127
        	if (fileName != null) {
131
        		if (getUtility() != null) {
128
        		if (getUtility() != null) {
Lines 155-165 Link Here
155
        }
152
        }
156
        // Contribute discovered includes and symbols to the ScannerInfoCollector
153
        // Contribute discovered includes and symbols to the ScannerInfoCollector
157
        if (translatedIncludes.size() > 0 || symbols.size() > 0) {
154
        if (translatedIncludes.size() > 0 || symbols.size() > 0) {
158
        	Map scannerInfo = new HashMap();
155
        	Map<ScannerInfoTypes, List<String>> scannerInfo = new HashMap<ScannerInfoTypes, List<String>>();
159
        	scannerInfo.put(ScannerInfoTypes.INCLUDE_PATHS, translatedIncludes);
156
        	scannerInfo.put(ScannerInfoTypes.INCLUDE_PATHS, translatedIncludes);
160
        	scannerInfo.put(ScannerInfoTypes.SYMBOL_DEFINITIONS, symbols);
157
        	scannerInfo.put(ScannerInfoTypes.SYMBOL_DEFINITIONS, symbols);
161
        	scannerInfo.put(ScannerInfoTypes.TARGET_SPECIFIC_OPTION, targetSpecificOptions);
158
        	scannerInfo.put(ScannerInfoTypes.TARGET_SPECIFIC_OPTION, targetSpecificOptions);
162
        	getCollector().contributeToScannerConfig(project, scannerInfo);
159
        	getCollector().contributeToScannerConfig(project, scannerInfo);
160
        	if(fCollector != null && fCollector instanceof IScannerInfoCollector2) {
161
    			IScannerInfoCollector2 collector = (IScannerInfoCollector2) fCollector;
162
    			try {
163
    				collector.updateScannerConfiguration(null);
164
    			} catch (CoreException e) {
165
    				// TODO Auto-generated catch block
166
    				Activator.log(e);
167
    			}
168
    		}
163
169
164
        	TraceUtil.outputTrace("Discovered scanner info for file \'" + fileName + '\'',	//$NON-NLS-1$
170
        	TraceUtil.outputTrace("Discovered scanner info for file \'" + fileName + '\'',	//$NON-NLS-1$
165
        			"Include paths", includes, translatedIncludes, "Defined symbols", symbols);	//$NON-NLS-1$ //$NON-NLS-2$
171
        			"Include paths", includes, translatedIncludes, "Defined symbols", symbols);	//$NON-NLS-1$ //$NON-NLS-2$
(-)src/org/eclipse/cdt/make/xlc/core/scannerconfig/PerFileXLCScannerInfoCollector.java (-17 / +1626 lines)
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
}
(-)src/org/eclipse/cdt/make/xlc/core/scannerconfig/XLCPerFileBuildOutputParser.java (-73 / +92 lines)
Lines 15-27 Link Here
15
import java.util.List;
15
import java.util.List;
16
import java.util.Map;
16
import java.util.Map;
17
17
18
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2;
18
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
19
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
19
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
20
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
20
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
21
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
22
import org.eclipse.cdt.make.xlc.core.activator.Activator;
21
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.resources.IWorkspaceRoot;
24
import org.eclipse.core.resources.ResourcesPlugin;
25
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IPath;
26
26
27
/**
27
/**
Lines 35-117 Link Here
35
	 */
35
	 */
36
	@Override
36
	@Override
37
	protected boolean processCommand(String[] tokens) {
37
	protected boolean processCommand(String[] tokens) {
38
	    // GCC C/C++ compiler invocation 
38
		try {
39
        int compilerInvocationIndex= findCompilerInvocation(tokens);
39
			
40
        if (compilerInvocationIndex < 0) {
40
		// GCC C/C++ compiler invocation
41
            return false;
41
		int compilerInvocationIndex = findCompilerInvocation(tokens);
42
        }
42
		if (compilerInvocationIndex < 0) {
43
43
			return false;
44
        // find a file name
44
		}
45
        int extensionsIndex = -1;
46
        boolean found = false;
47
        String filePath = null;
48
        for (int i = compilerInvocationIndex+1; i < tokens.length; i++) {
49
        	String token= tokens[i];
50
            int k = token.lastIndexOf('.');
51
            if (k != -1 && (token.length() - k < 5)) {
52
                String fileExtension = token.substring(k);
53
                extensionsIndex = getFileExtensionsList().indexOf(fileExtension);
54
                if (extensionsIndex != -1) {
55
                    filePath = token;
56
                    found = true;
57
                    break;
58
                }
59
            }
60
        }
61
        if (!found) {
62
            TraceUtil.outputTrace("Error identifying file name :1", tokens, TraceUtil.EOL); //$NON-NLS-1$
63
            return false;
64
        }
65
        // sanity check
66
        if (filePath.indexOf(getFileExtensions()[extensionsIndex]) == -1) {
67
            TraceUtil.outputTrace("Error identifying file name :2", tokens, TraceUtil.EOL); //$NON-NLS-1$
68
            return false;
69
        }
70
        if (fUtility != null) {
71
            IPath pFilePath = fUtility.getAbsolutePath(filePath);
72
            String shortFileName = pFilePath.removeFileExtension().lastSegment();
73
45
74
            // generalize occurrences of the file name
46
		// find a file name
75
            for (int i = compilerInvocationIndex+1; i < tokens.length; i++) {
47
		int extensionsIndex = -1;
48
		boolean found = false;
49
		String filePath = null;
50
		for (int i = compilerInvocationIndex + 1; i < tokens.length; i++) {
51
			String token = tokens[i];
52
			int k = token.lastIndexOf('.');
53
			if (k != -1 && (token.length() - k < 5)) {
54
				String fileExtension = token.substring(k);
55
				extensionsIndex = getFileExtensionsList().indexOf(fileExtension);
56
				if (extensionsIndex != -1) {
57
					filePath = token;
58
					found = true;
59
					break;
60
				}
61
			}
62
		}
63
		if (!found) {
64
			TraceUtil.outputTrace("Error identifying file name :1", tokens, TraceUtil.EOL); //$NON-NLS-1$
65
			return false;
66
		}
67
		// sanity check
68
		if (filePath.indexOf(getFileExtensions()[extensionsIndex]) == -1) {
69
			TraceUtil.outputTrace("Error identifying file name :2", tokens, TraceUtil.EOL); //$NON-NLS-1$
70
			return false;
71
		}
72
		if (getUtility() != null) {
73
			IPath pFilePath = fUtility.getAbsolutePath(filePath);
74
			String shortFileName = pFilePath.removeFileExtension().lastSegment();
75
76
			// generalize occurrences of the file name
77
			for (int i = compilerInvocationIndex + 1; i < tokens.length; i++) {
76
				String token = tokens[i];
78
				String token = tokens[i];
77
				if (token.equals("-include")) { //$NON-NLS-1$
79
				if (token.equals("-include")) { //$NON-NLS-1$
78
					++i;
80
					++i;
79
				}
81
				} else if (token.equals("-imacros")) { //$NON-NLS-1$
80
				else if (token.equals("-imacros")) { //$NON-NLS-1$
81
					++i;
82
					++i;
82
				}
83
				} else if (token.equals(filePath)) {
83
				else if (token.equals(filePath)) {
84
					tokens[i] = "LONG_NAME"; //$NON-NLS-1$
84
					tokens[i]= "LONG_NAME"; //$NON-NLS-1$
85
				} else if (token.startsWith(shortFileName)) {
85
				}
86
					tokens[i] = token.replaceFirst(shortFileName, "SHORT_NAME"); //$NON-NLS-1$
86
				else if (token.startsWith(shortFileName)) {
87
					tokens[i]= token.replaceFirst(shortFileName, "SHORT_NAME"); //$NON-NLS-1$
88
				}
87
				}
89
			}
88
			}
90
            
89
91
            IFile file= null;
90
			IFile file = null;
92
            IPath baseDirectory= fUtility.getBaseDirectory();
91
			IPath baseDirectory = fUtility.getBaseDirectory();
93
            if (baseDirectory.isPrefixOf(pFilePath)) {
92
			if (baseDirectory.isPrefixOf(pFilePath)) {
94
				IPath relPath = pFilePath.removeFirstSegments(baseDirectory.segmentCount());
93
				IPath relPath = pFilePath.removeFirstSegments(baseDirectory.segmentCount());
95
				//Note: We add the scanner-config even if the resource doesn't actually
94
				// Note: We add the scanner-config even if the resource doesn't
96
				//exist below this project (which may happen when reading existing
95
				// actually
97
				//build logs, because resources can be created as part of the build
96
				// exist below this project (which may happen when reading
98
				//and may not exist at the time of analyzing the config but re-built
97
				// existing
99
				//later on.
98
				// build logs, because resources can be created as part of the
100
				//if (getProject().exists(relPath)) {
99
				// build
101
	            file = getProject().getFile(relPath);
100
				// and may not exist at the time of analyzing the config but
102
            } else {
101
				// re-built
103
            	file = getUtility().findFileInWorkspace(pFilePath);
102
				// later on.
104
            }
103
				// if (getProject().exists(relPath)) {
105
            if (file != null) {
104
				file = getProject().getFile(relPath);
106
                CCommandDSC cmd = getUtility().getNewCCommandDSC(tokens, compilerInvocationIndex, extensionsIndex > 0);
105
			} else {
107
	            List cmdList = new ArrayList();
106
				file = getUtility().findFileInWorkspace(pFilePath);
108
	            cmdList.add(cmd);
107
			}
109
	            Map sc = new HashMap(1);
108
			if (file != null) {
110
	            sc.put(ScannerInfoTypes.COMPILER_COMMAND, cmdList);
109
				CCommandDSC cmd = getUtility().getNewCCommandDSC(tokens, compilerInvocationIndex, extensionsIndex > 0);
111
	            getCollector().contributeToScannerConfig(file, sc);
110
				List<CCommandDSC> cmdList = new ArrayList<CCommandDSC>();
112
            } else
111
				cmdList.add(cmd);
113
            	TraceUtil.outputError("Build command for file outside project: "+pFilePath.toString(), tokens); //$NON-NLS-1$
112
				Map<ScannerInfoTypes, List<CCommandDSC>> sc = new HashMap<ScannerInfoTypes, List<CCommandDSC>>(1);
114
        }
113
				sc.put(ScannerInfoTypes.COMPILER_COMMAND, cmdList);
115
        return true;	}
114
				getCollector().contributeToScannerConfig(file, sc);
115
				if (fCollector != null && fCollector instanceof IScannerInfoCollector2) {
116
					IScannerInfoCollector2 collector = (IScannerInfoCollector2) fCollector;
117
					try {
118
						collector.updateScannerConfiguration(null);
119
					} catch (CoreException e) {
120
						// TODO Auto-generated catch block
121
						Activator.log(e);
122
					}
123
				}
124
			} else
125
				TraceUtil.outputError("Build command for file outside project: " + pFilePath.toString(), tokens); //$NON-NLS-1$
126
		}
127
 		return true;
128
		
129
		}
130
		catch(Throwable e) {
131
			e.printStackTrace();
132
			return false;
133
		}
134
	}
116
135
117
}
136
}
(-)src/org/eclipse/cdt/make/xlc/core/scannerconfig/AbstractXLCBuildOutputParser.java (-17 / +20 lines)
Lines 11-43 Link Here
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.ArrayList;
14
import java.util.HashMap;
15
import java.util.LinkedList;
14
import java.util.LinkedList;
16
import java.util.List;
15
import java.util.List;
17
import java.util.Map;
18
16
19
import org.eclipse.cdt.core.CCorePlugin;
17
import org.eclipse.cdt.core.CCorePlugin;
20
import org.eclipse.cdt.core.IMarkerGenerator;
18
import org.eclipse.cdt.core.IMarkerGenerator;
21
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
19
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
20
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2;
22
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
21
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
23
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
24
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParserUtility;
25
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
26
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
22
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
27
import org.eclipse.cdt.make.internal.core.scannerconfig2.SCProfileInstance;
23
import org.eclipse.cdt.make.internal.core.scannerconfig2.SCProfileInstance;
28
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager;
24
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager;
29
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile.BuildOutputProvider;
25
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfile.BuildOutputProvider;
30
import org.eclipse.core.resources.IFile;
26
import org.eclipse.cdt.make.xlc.core.activator.Activator;
31
import org.eclipse.core.resources.IProject;
27
import org.eclipse.core.resources.IProject;
32
import org.eclipse.core.resources.IWorkspaceRoot;
28
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.resources.ResourcesPlugin;
34
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.IPath;
35
import org.eclipse.core.runtime.Platform;
30
import org.eclipse.core.runtime.Platform;
36
import org.eclipse.core.runtime.content.IContentType;
31
import org.eclipse.core.runtime.content.IContentType;
37
import org.eclipse.core.runtime.content.IContentTypeManager;
32
import org.eclipse.core.runtime.content.IContentTypeManager;
38
33
39
import sun.misc.FpUtils;
40
41
/**
34
/**
42
 * @author crecoskie
35
 * @author crecoskie
43
 * 
36
 * 
Lines 59-65 Link Here
59
	protected boolean fBMultiline = false;
52
	protected boolean fBMultiline = false;
60
	protected String fSMultiline = ""; //$NON-NLS-1$
53
	protected String fSMultiline = ""; //$NON-NLS-1$
61
54
62
	protected String[] fCompilerCommands = { "xlc", "xlC" };
55
	protected String[] fCompilerCommands = { "xlc", "xlC" }; //$NON-NLS-1$ //$NON-NLS-2$
63
56
64
	/**
57
	/**
65
	 * @return Returns the fProject.
58
	 * @return Returns the fProject.
Lines 163-169 Link Here
163
		return processSingleLine(line.trim());
156
		return processSingleLine(line.trim());
164
	}
157
	}
165
158
166
	protected XLCBuildOutputParserUtility getUtility() {
159
	protected synchronized XLCBuildOutputParserUtility getUtility() {
167
		if (fUtility == null)
160
		if (fUtility == null)
168
			fUtility = new XLCBuildOutputParserUtility(fProject, fWorkingDir, fMarkerGenerator);
161
			fUtility = new XLCBuildOutputParserUtility(fProject, fWorkingDir, fMarkerGenerator);
169
162
Lines 195-200 Link Here
195
		if (getUtility() != null) {
188
		if (getUtility() != null) {
196
			getUtility().reportProblems();
189
			getUtility().reportProblems();
197
		}
190
		}
191
		
192
		if(fCollector != null && fCollector instanceof IScannerInfoCollector2) {
193
			IScannerInfoCollector2 collector = (IScannerInfoCollector2) fCollector;
194
			try {
195
				collector.updateScannerConfiguration(null);
196
			} catch (CoreException e) {
197
				// TODO Auto-generated catch block
198
				Activator.log(e);
199
			}
200
		}
198
	}
201
	}
199
202
200
	/**
203
	/**
Lines 369-375 Link Here
369
372
370
	abstract protected boolean processCommand(String[] tokens);
373
	abstract protected boolean processCommand(String[] tokens);
371
374
372
	protected List<String> getFileExtensionsList() {
375
	protected  List<String> getFileExtensionsList() {
373
		IContentTypeManager manager = Platform.getContentTypeManager();
376
		IContentTypeManager manager = Platform.getContentTypeManager();
374
		List<String> extensions = new LinkedList<String>();
377
		List<String> extensions = new LinkedList<String>();
375
		IContentType cSource = manager.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE);
378
		IContentType cSource = manager.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE);
Lines 379-389 Link Here
379
		String[] cppExtensions = cppSource.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
382
		String[] cppExtensions = cppSource.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
380
383
381
		for (int k = 0; k < cExtensions.length; k++) {
384
		for (int k = 0; k < cExtensions.length; k++) {
382
			extensions.add("." + cExtensions[k]);
385
			extensions.add("." + cExtensions[k]); //$NON-NLS-1$
383
		}
386
		}
384
387
385
		for (int k = 0; k < cppExtensions.length; k++) {
388
		for (int k = 0; k < cppExtensions.length; k++) {
386
			extensions.add("." + cppExtensions[k]);
389
			extensions.add("." + cppExtensions[k]); //$NON-NLS-1$
387
		}
390
		}
388
391
389
		return extensions;
392
		return extensions;
Lines 399-409 Link Here
399
		String[] cppExtensions = cppSource.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
402
		String[] cppExtensions = cppSource.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
400
403
401
		for (int k = 0; k < cExtensions.length; k++) {
404
		for (int k = 0; k < cExtensions.length; k++) {
402
			extensions.add("." + cExtensions[k]);
405
			extensions.add("." + cExtensions[k]); //$NON-NLS-1$
403
		}
406
		}
404
407
405
		for (int k = 0; k < cppExtensions.length; k++) {
408
		for (int k = 0; k < cppExtensions.length; k++) {
406
			extensions.add("." + cppExtensions[k]);
409
			extensions.add("." + cppExtensions[k]); //$NON-NLS-1$
407
		}
410
		}
408
411
409
		return extensions.toArray(new String[0]);
412
		return extensions.toArray(new String[0]);
(-)META-INF/MANIFEST.MF (-1 / +4 lines)
Lines 10-13 Link Here
10
 org.eclipse.core.resources,
10
 org.eclipse.core.resources,
11
 org.eclipse.core.runtime,
11
 org.eclipse.core.runtime,
12
 org.eclipse.cdt.managedbuilder.core
12
 org.eclipse.cdt.managedbuilder.core
13
Export-Package: org.eclipse.cdt.make.xlc.core.scannerconfig
13
Export-Package: org.eclipse.cdt.make.xlc.core.activator,
14
 org.eclipse.cdt.make.xlc.core.scannerconfig
15
Bundle-ActivationPolicy: lazy
16
Bundle-Activator: org.eclipse.cdt.make.xlc.core.activator.Activator
(-).settings/org.eclipse.jdt.core.prefs (-1 / +59 lines)
Lines 1-5 Link Here
1
#Tue Sep 29 13:43:38 EDT 2009
1
#Mon Nov 23 16:55:49 EST 2009
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
4
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
5
org.eclipse.jdt.core.compiler.problem.deprecation=warning
6
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
7
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
8
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
9
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
10
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
11
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
12
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
13
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
14
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
15
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
16
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
17
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
18
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
19
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
20
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
21
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
22
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
23
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
24
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
25
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
26
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
27
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error
28
org.eclipse.jdt.core.compiler.problem.nullReference=warning
29
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
30
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
31
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
32
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
33
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
34
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
35
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
36
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
37
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
38
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
39
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
40
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
41
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
42
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
43
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
44
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
45
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
46
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
47
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
48
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
49
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
50
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
51
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
52
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
53
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
54
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
55
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
56
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
57
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
58
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
59
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
60
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
3
org.eclipse.jdt.core.formatter.comment.clear_blank_lines=false
61
org.eclipse.jdt.core.formatter.comment.clear_blank_lines=false
4
org.eclipse.jdt.core.formatter.comment.format_comments=true
62
org.eclipse.jdt.core.formatter.comment.format_comments=true
5
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
63
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
(-)src/org/eclipse/cdt/make/xlc/core/messages/Messages.properties (+4 lines)
Added Link Here
1
PerFileXLCScannerInfoCollector.0=Updating discovered includes and macros
2
PerFileXLCScannerInfoCollector.1=Error updating discovered info.
3
ScannerInfoCollector.Processing=Processing discovered scanner configuration ... 
4
ScannerInfoCollector.Updating=Updating Scanner Configuration for project 
(-)src/org/eclipse/cdt/make/xlc/core/activator/Activator.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.make.xlc.core.activator;
12
13
import org.eclipse.cdt.core.model.CModelException;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Plugin;
16
import org.eclipse.core.runtime.Status;
17
18
/**
19
 * @author crecoskie
20
 *
21
 */
22
public class Activator extends Plugin {
23
24
	public static final String PLUGIN_ID = "org.eclipse.cdt.make.xlc.core"; //$NON-NLS-1$
25
	private static Activator fInstance;
26
27
	/**
28
	 * 
29
	 */
30
	public Activator() {
31
		super();
32
		if(fInstance == null) {
33
			fInstance = this;
34
		}
35
	}
36
	
37
	public static void log(String e) {
38
		log(createStatus(e));
39
	}
40
	
41
	public static void log(Throwable e) {
42
		log("Error", e); //$NON-NLS-1$
43
	}
44
	
45
	public static void log(String message, Throwable e) {
46
		Throwable nestedException;
47
		if (e instanceof CModelException 
48
				&& (nestedException = ((CModelException)e).getException()) != null) {
49
			e = nestedException;
50
		}
51
		log(createStatus(message, e));
52
	}
53
54
	public static IStatus createStatus(String msg) {
55
		return createStatus(msg, null);
56
	}
57
58
	public static IStatus createStatus(String msg, Throwable e) {
59
		return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, msg, e);
60
	}
61
	
62
	public static void log(IStatus status) {
63
		getDefault().getLog().log(status);
64
	}
65
66
	private static Plugin getDefault() {
67
		return fInstance;
68
	}
69
70
}
(-)src/org/eclipse/cdt/make/xlc/core/messages/Messages.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.make.xlc.core.messages;
13
14
import java.util.MissingResourceException;
15
import java.util.ResourceBundle;
16
17
public class Messages {
18
	private static final String BUNDLE_NAME = "org.eclipse.cdt.make.xlc.core.messages.Messages"; //$NON-NLS-1$
19
20
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
21
22
	private Messages() {
23
	}
24
25
	public static String getString(String key) {
26
		try {
27
			return RESOURCE_BUNDLE.getString(key);
28
		} catch (MissingResourceException e) {
29
			return '!' + key + '!';
30
		}
31
	}
32
}
(-)src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathManager.java (-6 / +41 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 QNX Software Systems and others.
2
 * Copyright (c) 2004, 2009 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     QNX Software Systems - initial API and implementation
9
 *     QNX Software Systems - initial API and implementation
10
 *     IBM Corporation
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.cdt.make.internal.core.scannerconfig;
12
package org.eclipse.cdt.make.internal.core.scannerconfig;
12
13
Lines 247-257 Link Here
247
				fireUpdate(INFO_CHANGED, info);
248
				fireUpdate(INFO_CHANGED, info);
248
                
249
                
249
				if(updateContainer){
250
				if(updateContainer){
250
//				ICProject cProject = CoreModel.getDefault().create(info.getProject());
251
251
//				if (cProject != null) {
252
//					CoreModel.setPathEntryContainer(new ICProject[]{cProject},
253
//							new DiscoveredPathContainer(info.getProject()), null);
254
//				}
255
	                IScannerConfigBuilderInfo2 buildInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(project);
252
	                IScannerConfigBuilderInfo2 buildInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(project);
256
	                String profileId = buildInfo.getSelectedProfileId();
253
	                String profileId = buildInfo.getSelectedProfileId();
257
	                ScannerConfigScope profileScope = ScannerConfigProfileManager.getInstance().
254
	                ScannerConfigScope profileScope = ScannerConfigProfileManager.getInstance().
Lines 265-270 Link Here
265
			}
262
			}
266
		}
263
		}
267
	}
264
	}
265
    
266
    /**
267
     * Allows one to update the discovered information for a particular scanner discovery profile ID.
268
     * TODO:  This should be made API in IDiscoveredPathManager, or in an interface derived there from.
269
     * 
270
     * @param context
271
     * @param info
272
     * @param updateContainer
273
     * @param changedResources
274
     * @param profileId
275
     * @throws CoreException
276
     */
277
    public void updateDiscoveredInfo(InfoContext context, IDiscoveredPathInfo info, boolean updateContainer, List<IResource> changedResources, String profileId) throws CoreException {
278
    	DiscoveredInfoHolder holder = getHolder(info.getProject(), true);
279
    	IDiscoveredPathInfo oldInfo = holder.getInfo(context); 
280
		if (oldInfo != null) {
281
            IDiscoveredScannerInfoSerializable serializable = info.getSerializable();
282
			if (serializable != null) {
283
				holder.setInfo(context, info);
284
                IProject project = info.getProject();
285
				DiscoveredScannerInfoStore.getInstance().saveDiscoveredScannerInfoToState(project, context, serializable);
286
				fireUpdate(INFO_CHANGED, info);
287
                
288
				if(updateContainer){
289
290
	                IScannerConfigBuilderInfo2 buildInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(project);
291
	                
292
	                ScannerConfigScope profileScope = ScannerConfigProfileManager.getInstance().
293
	                        getSCProfileConfiguration(profileId).getProfileScope();
294
	                changeDiscoveredContainer(project, profileScope, changedResources);
295
				}
296
			}
297
			else {
298
		        throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1,
299
		                MakeMessages.getString("DiscoveredPathManager.Info_Not_Serializable"), null)); //$NON-NLS-1$
300
			}
301
		}
302
	}
268
303
269
    /* (non-Javadoc)
304
    /* (non-Javadoc)
270
     * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager#changeDiscoveredContainer(org.eclipse.core.resources.IProject, java.lang.String)
305
     * @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager#changeDiscoveredContainer(org.eclipse.core.resources.IProject, java.lang.String)

Return to bug 293598