author | timkelly |
Thu, 06 Aug 2009 12:01:58 -0500 | |
changeset 52 | 42077b7eab6e |
parent 51 | 49c226a8748e |
permissions | -rw-r--r-- |
37 | 1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 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 |
* Markus Schorn (Wind River Systems) |
|
11 |
* Andrew Ferguson (Symbian) |
|
12 |
* Anton Leherbauer (Wind River Systems) |
|
13 |
* oyvind.harboe@zylin.com - http://bugs.eclipse.org/250638 |
|
14 |
*******************************************************************************/ |
|
15 |
package org.eclipse.cdt.core; |
|
16 |
||
17 |
import java.io.IOException; |
|
18 |
import java.util.ArrayList; |
|
19 |
import java.util.Collection; |
|
20 |
import java.util.HashMap; |
|
21 |
import java.util.HashSet; |
|
22 |
import java.util.List; |
|
23 |
import java.util.Map; |
|
24 |
import java.util.MissingResourceException; |
|
25 |
import java.util.ResourceBundle; |
|
26 |
||
27 |
import com.ibm.icu.text.MessageFormat; |
|
28 |
||
29 |
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager; |
|
30 |
import org.eclipse.cdt.core.cdtvariables.IUserVarSupplier; |
|
51
49c226a8748e
CDT 6.0 from cdt_6_0 branch (eclipse.org cvs repository). This overwrites previous CDT 6.0 merges.
timkelly
parents:
44
diff
changeset
|
31 |
import org.eclipse.cdt.core.dom.CDOM; |
37 | 32 |
import org.eclipse.cdt.core.dom.IPDOMManager; |
33 |
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; |
|
34 |
import org.eclipse.cdt.core.index.IIndexManager; |
|
35 |
import org.eclipse.cdt.core.model.CModelException; |
|
36 |
import org.eclipse.cdt.core.model.CoreModel; |
|
37 |
import org.eclipse.cdt.core.model.ITranslationUnit; |
|
38 |
import org.eclipse.cdt.core.model.IWorkingCopy; |
|
39 |
import org.eclipse.cdt.core.parser.IScannerInfoProvider; |
|
40 |
import org.eclipse.cdt.core.resources.IConsole; |
|
41 |
import org.eclipse.cdt.core.resources.IPathEntryVariableManager; |
|
42 |
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; |
|
43 |
import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
|
44 |
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; |
|
45 |
import org.eclipse.cdt.core.settings.model.WriteAccessException; |
|
46 |
import org.eclipse.cdt.core.settings.model.util.CDataUtil; |
|
47 |
import org.eclipse.cdt.internal.core.CContentTypes; |
|
48 |
import org.eclipse.cdt.internal.core.CDTLogWriter; |
|
49 |
import org.eclipse.cdt.internal.core.CdtVarPathEntryVariableManager; |
|
50 |
import org.eclipse.cdt.internal.core.PositionTrackerManager; |
|
51 |
import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager; |
|
52 |
import org.eclipse.cdt.internal.core.cdtvariables.UserVarSupplier; |
|
53 |
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager; |
|
54 |
import org.eclipse.cdt.internal.core.model.BufferManager; |
|
55 |
import org.eclipse.cdt.internal.core.model.CModelManager; |
|
56 |
import org.eclipse.cdt.internal.core.model.IBufferFactory; |
|
57 |
import org.eclipse.cdt.internal.core.model.Util; |
|
58 |
import org.eclipse.cdt.internal.core.model.WorkingCopy; |
|
59 |
import org.eclipse.cdt.internal.core.pdom.PDOMManager; |
|
60 |
import org.eclipse.cdt.internal.core.resources.ResourceLookup; |
|
61 |
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; |
|
62 |
import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory; |
|
63 |
import org.eclipse.core.resources.IProject; |
|
64 |
import org.eclipse.core.resources.IProjectDescription; |
|
65 |
import org.eclipse.core.resources.IResource; |
|
66 |
import org.eclipse.core.resources.IWorkspace; |
|
67 |
import org.eclipse.core.resources.IWorkspaceRunnable; |
|
68 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
69 |
import org.eclipse.core.runtime.CoreException; |
|
70 |
import org.eclipse.core.runtime.IConfigurationElement; |
|
71 |
import org.eclipse.core.runtime.IExtension; |
|
72 |
import org.eclipse.core.runtime.IExtensionPoint; |
|
73 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
74 |
import org.eclipse.core.runtime.IStatus; |
|
75 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
76 |
import org.eclipse.core.runtime.OperationCanceledException; |
|
77 |
import org.eclipse.core.runtime.Platform; |
|
78 |
import org.eclipse.core.runtime.Plugin; |
|
79 |
import org.eclipse.core.runtime.Preferences; |
|
80 |
import org.eclipse.core.runtime.Status; |
|
81 |
import org.eclipse.core.runtime.SubProgressMonitor; |
|
82 |
import org.eclipse.core.runtime.content.IContentType; |
|
83 |
import org.eclipse.core.runtime.jobs.Job; |
|
84 |
import org.osgi.framework.BundleContext; |
|
85 |
||
86 |
/** |
|
87 |
* CCorePlugin is the life-cycle owner of the core plug-in, and starting point for access to many core APIs. |
|
88 |
* |
|
89 |
* @noextend This class is not intended to be subclassed by clients. |
|
90 |
* @noinstantiate This class is not intended to be instantiated by clients. |
|
91 |
*/ |
|
92 |
public class CCorePlugin extends Plugin { |
|
93 |
||
94 |
public static final int STATUS_CDTPROJECT_EXISTS = 1; |
|
95 |
public static final int STATUS_CDTPROJECT_MISMATCH = 2; |
|
96 |
public static final int CDT_PROJECT_NATURE_ID_MISMATCH = 3; |
|
97 |
/** |
|
51
49c226a8748e
CDT 6.0 from cdt_6_0 branch (eclipse.org cvs repository). This overwrites previous CDT 6.0 merges.
timkelly
parents:
44
diff
changeset
|
98 |
* Will be public and final in the next CDT version. |
49c226a8748e
CDT 6.0 from cdt_6_0 branch (eclipse.org cvs repository). This overwrites previous CDT 6.0 merges.
timkelly
parents:
44
diff
changeset
|
99 |
* @noreference |
37 | 100 |
*/ |
51
49c226a8748e
CDT 6.0 from cdt_6_0 branch (eclipse.org cvs repository). This overwrites previous CDT 6.0 merges.
timkelly
parents:
44
diff
changeset
|
101 |
public static int STATUS_PDOM_TOO_LARGE = 4; |
37 | 102 |
public static final String PLUGIN_ID = "org.eclipse.cdt.core"; //$NON-NLS-1$ |
103 |
||
104 |
public static final String BUILDER_MODEL_ID = PLUGIN_ID + ".CBuildModel"; //$NON-NLS-1$ |
|
105 |
public static final String BINARY_PARSER_SIMPLE_ID = "BinaryParser"; //$NON-NLS-1$ |
|
106 |
public final static String BINARY_PARSER_UNIQ_ID = PLUGIN_ID + "." + BINARY_PARSER_SIMPLE_ID; //$NON-NLS-1$ |
|
107 |
public final static String PREF_BINARY_PARSER = "binaryparser"; //$NON-NLS-1$ |
|
108 |
public final static String DEFAULT_BINARY_PARSER_SIMPLE_ID = "ELF"; //$NON-NLS-1$ |
|
109 |
public final static String DEFAULT_BINARY_PARSER_UNIQ_ID = PLUGIN_ID + "." + DEFAULT_BINARY_PARSER_SIMPLE_ID; //$NON-NLS-1$ |
|
110 |
public final static String PREF_USE_STRUCTURAL_PARSE_MODE = "useStructualParseMode"; //$NON-NLS-1$ |
|
111 |
||
112 |
public static final String INDEX_SIMPLE_ID = "CIndex"; //$NON-NLS-1$ |
|
113 |
public static final String INDEX_UNIQ_ID = PLUGIN_ID + "." + INDEX_SIMPLE_ID; //$NON-NLS-1$ |
|
114 |
||
115 |
public static final String INDEXER_SIMPLE_ID = "CIndexer"; //$NON-NLS-1$ |
|
116 |
public static final String INDEXER_UNIQ_ID = PLUGIN_ID + "." + INDEXER_SIMPLE_ID; //$NON-NLS-1$ |
|
117 |
public static final String PREF_INDEXER = "indexer"; //$NON-NLS-1$ |
|
118 |
public static final String DEFAULT_INDEXER = IPDOMManager.ID_FAST_INDEXER; |
|
119 |
||
120 |
public final static String ERROR_PARSER_SIMPLE_ID = "ErrorParser"; //$NON-NLS-1$ |
|
121 |
public final static String ERROR_PARSER_UNIQ_ID = PLUGIN_ID + "." + ERROR_PARSER_SIMPLE_ID; //$NON-NLS-1$ |
|
122 |
||
123 |
// default store for pathentry |
|
124 |
public final static String DEFAULT_PATHENTRY_STORE_ID = PLUGIN_ID + ".cdtPathEntryStore"; //$NON-NLS-1$ |
|
125 |
||
126 |
// Build Model Interface Discovery |
|
127 |
public final static String BUILD_SCANNER_INFO_SIMPLE_ID = "ScannerInfoProvider"; //$NON-NLS-1$ |
|
128 |
public final static String BUILD_SCANNER_INFO_UNIQ_ID = PLUGIN_ID + "." + BUILD_SCANNER_INFO_SIMPLE_ID; //$NON-NLS-1$ |
|
129 |
||
130 |
public static final String DEFAULT_PROVIDER_ID = CCorePlugin.PLUGIN_ID + ".defaultConfigDataProvider"; //$NON-NLS-1$ |
|
131 |
||
132 |
/** |
|
133 |
* Name of the extension point for contributing a source code formatter |
|
134 |
*/ |
|
135 |
public static final String FORMATTER_EXTPOINT_ID = "CodeFormatter" ; //$NON-NLS-1$ |
|
136 |
||
137 |
/** |
|
138 |
* Possible configurable option ID. |
|
139 |
* @see #getDefaultOptions |
|
140 |
*/ |
|
141 |
public static final String CORE_ENCODING = PLUGIN_ID + ".encoding"; //$NON-NLS-1$ |
|
142 |
||
143 |
/** |
|
144 |
* IContentType id for C Source Unit |
|
145 |
*/ |
|
146 |
public final static String CONTENT_TYPE_CSOURCE = "org.eclipse.cdt.core.cSource"; //$NON-NLS-1$ |
|
147 |
/** |
|
148 |
* IContentType id for C Header Unit |
|
149 |
*/ |
|
150 |
public final static String CONTENT_TYPE_CHEADER = "org.eclipse.cdt.core.cHeader"; //$NON-NLS-1$ |
|
151 |
/** |
|
152 |
* IContentType id for C++ Source Unit |
|
153 |
*/ |
|
154 |
public final static String CONTENT_TYPE_CXXSOURCE = "org.eclipse.cdt.core.cxxSource"; //$NON-NLS-1$ |
|
155 |
/** |
|
156 |
* IContentType id for C++ Header Unit |
|
157 |
*/ |
|
158 |
public final static String CONTENT_TYPE_CXXHEADER = "org.eclipse.cdt.core.cxxHeader"; //$NON-NLS-1$ |
|
159 |
/** |
|
160 |
* IContentType id for ASM Unit |
|
161 |
*/ |
|
162 |
public final static String CONTENT_TYPE_ASMSOURCE = "org.eclipse.cdt.core.asmSource"; //$NON-NLS-1$ |
|
163 |
/** |
|
164 |
* IContentType id for Binary Files |
|
165 |
*/ |
|
166 |
public final static String CONTENT_TYPE_BINARYFILE = "org.eclipse.cdt.core.binaryFile"; //$NON-NLS-1$ |
|
167 |
||
168 |
/** |
|
169 |
* Possible configurable option value. |
|
170 |
* @see #getDefaultOptions() |
|
171 |
*/ |
|
172 |
public static final String INSERT = "insert"; //$NON-NLS-1$ |
|
173 |
/** |
|
174 |
* Possible configurable option value. |
|
175 |
* @see #getDefaultOptions() |
|
176 |
*/ |
|
177 |
public static final String DO_NOT_INSERT = "do not insert"; //$NON-NLS-1$ |
|
178 |
/** |
|
179 |
* Possible configurable option value. |
|
180 |
* @see #getDefaultOptions() |
|
181 |
*/ |
|
182 |
public static final String TAB = "tab"; //$NON-NLS-1$ |
|
183 |
/** |
|
184 |
* Possible configurable option value. |
|
185 |
* @see #getDefaultOptions() |
|
186 |
*/ |
|
187 |
public static final String SPACE = "space"; //$NON-NLS-1$ |
|
188 |
||
189 |
private static CCorePlugin fgCPlugin; |
|
190 |
private static ResourceBundle fgResourceBundle; |
|
191 |
||
192 |
||
193 |
/** |
|
194 |
* @noreference This field is not intended to be referenced by clients. |
|
195 |
*/ |
|
196 |
public CDTLogWriter cdtLog = null; |
|
197 |
||
198 |
private CProjectDescriptionManager fNewCProjectDescriptionManager; |
|
199 |
||
200 |
private CoreModel fCoreModel; |
|
201 |
||
202 |
private PDOMManager pdomManager; |
|
203 |
||
204 |
private CdtVarPathEntryVariableManager fPathEntryVariableManager; |
|
205 |
||
206 |
// -------- static methods -------- |
|
207 |
||
208 |
static { |
|
209 |
try { |
|
210 |
fgResourceBundle = ResourceBundle.getBundle("org.eclipse.cdt.internal.core.CCorePluginResources"); //$NON-NLS-1$ |
|
211 |
} catch (MissingResourceException x) { |
|
212 |
fgResourceBundle = null; |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* Returns the shared working copies currently registered for the default buffer factory. |
|
218 |
* @since 5.1 |
|
219 |
*/ |
|
220 |
public static IWorkingCopy[] getSharedWorkingCopies() { |
|
221 |
return getSharedWorkingCopies(null); |
|
222 |
} |
|
223 |
||
224 |
public static String getResourceString(String key) { |
|
225 |
try { |
|
226 |
return fgResourceBundle.getString(key); |
|
227 |
} catch (MissingResourceException e) { |
|
228 |
return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$ |
|
229 |
} catch (NullPointerException e) { |
|
230 |
return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$ |
|
231 |
} |
|
232 |
} |
|
233 |
||
234 |
public static IWorkspace getWorkspace() { |
|
235 |
return ResourcesPlugin.getWorkspace(); |
|
236 |
} |
|
237 |
||
238 |
public static String getFormattedString(String key, String arg) { |
|
239 |
return MessageFormat.format(getResourceString(key), new Object[] { arg }); |
|
240 |
} |
|
241 |
||
242 |
@SuppressWarnings("cast") // java.text.MessageFormat would require the cast |
|
243 |
public static String getFormattedString(String key, String[] args) { |
|
244 |
return MessageFormat.format(getResourceString(key), (Object[])args); |
|
245 |
} |
|
246 |
||
247 |
public static ResourceBundle getResourceBundle() { |
|
248 |
return fgResourceBundle; |
|
249 |
} |
|
250 |
||
251 |
public static IPositionTrackerManager getPositionTrackerManager() { |
|
252 |
return PositionTrackerManager.getInstance(); |
|
253 |
} |
|
254 |
||
255 |
public static CCorePlugin getDefault() { |
|
256 |
return fgCPlugin; |
|
257 |
} |
|
258 |
||
259 |
||
260 |
/** |
|
261 |
* @see Plugin#shutdown |
|
262 |
*/ |
|
263 |
@Override |
|
264 |
public void stop(BundleContext context) throws Exception { |
|
265 |
try { |
|
266 |
pdomManager.shutdown(); |
|
267 |
||
268 |
PositionTrackerManager.getInstance().uninstall(); |
|
269 |
||
270 |
// if (fDescriptorManager != null) { |
|
271 |
// fDescriptorManager.shutdown(); |
|
272 |
// } |
|
273 |
||
274 |
if (fCoreModel != null) { |
|
275 |
fCoreModel.shutdown(); |
|
276 |
} |
|
277 |
||
278 |
if (cdtLog != null) { |
|
279 |
cdtLog.shutdown(); |
|
280 |
} |
|
281 |
||
282 |
if (fPathEntryVariableManager != null) { |
|
283 |
fPathEntryVariableManager.shutdown(); |
|
284 |
} |
|
285 |
||
286 |
fNewCProjectDescriptionManager.shutdown(); |
|
287 |
ResourceLookup.shutdown(); |
|
288 |
||
289 |
savePluginPreferences(); |
|
290 |
} finally { |
|
291 |
super.stop(context); |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
/** |
|
296 |
* @see Plugin#startup |
|
297 |
*/ |
|
298 |
@Override |
|
299 |
public void start(BundleContext context) throws Exception { |
|
300 |
super.start(context); |
|
301 |
||
302 |
// do harmless stuff first. |
|
303 |
cdtLog = new CDTLogWriter(CCorePlugin.getDefault().getStateLocation().append(".log").toFile()); //$NON-NLS-1$ |
|
304 |
configurePluginDebugOptions(); |
|
305 |
PositionTrackerManager.getInstance().install(); |
|
306 |
ResourceLookup.startup(); |
|
307 |
||
308 |
// new project model needs to register the resource listener first. |
|
309 |
fNewCProjectDescriptionManager= CProjectDescriptionManager.getInstance(); |
|
310 |
final Job post1= fNewCProjectDescriptionManager.startup(); |
|
311 |
||
312 |
fPathEntryVariableManager = new CdtVarPathEntryVariableManager(); |
|
313 |
fPathEntryVariableManager.startup(); |
|
314 |
||
315 |
fCoreModel = CoreModel.getDefault(); |
|
316 |
fCoreModel.startup(); |
|
317 |
||
318 |
pdomManager = new PDOMManager(); |
|
319 |
final Job post2= pdomManager.startup(); |
|
320 |
||
321 |
// bug 186755, when started after the platform has been started the job manager |
|
322 |
// is no longer suspended. So we have to start a job at the very end to make |
|
323 |
// sure we don't trigger a concurrent plug-in activation from within the job. |
|
324 |
post1.schedule(); |
|
325 |
post2.schedule(); |
|
326 |
} |
|
327 |
||
328 |
/** |
|
329 |
* TODO: Add all options here |
|
330 |
* Returns a table of all known configurable options with their default values. |
|
331 |
* These options allow to configure the behavior of the underlying components. |
|
332 |
* The client may safely use the result as a template that they can modify and |
|
333 |
* then pass to <code>setOptions</code>. |
|
334 |
* |
|
335 |
* Helper constants have been defined on CCorePlugin for each of the option ID and |
|
336 |
* their possible constant values. |
|
337 |
* |
|
338 |
* Note: more options might be added in further releases. |
|
339 |
* <pre> |
|
340 |
* RECOGNIZED OPTIONS: |
|
341 |
* |
|
342 |
* CORE / Specify Default Source Encoding Format |
|
343 |
* Get the encoding format for translated sources. This setting is read-only, it is equivalent |
|
344 |
* to 'ResourcesPlugin.getEncoding()'. |
|
345 |
* - option id: "org.eclipse.cdt.core.encoding" |
|
346 |
* - possible values: { any of the supported encoding names}. |
|
347 |
* - default: <platform default> |
|
348 |
* </pre> |
|
349 |
* |
|
350 |
* @return a mutable map containing the default settings of all known options |
|
351 |
* (key type: <code>String</code>; value type: <code>String</code>) |
|
352 |
* @see #setOptions |
|
353 |
*/ |
|
354 |
||
355 |
public static HashMap<String, String> getDefaultOptions() |
|
356 |
{ |
|
357 |
HashMap<String, String> defaultOptions = new HashMap<String, String>(10); |
|
358 |
||
359 |
// see #initializeDefaultPluginPreferences() for changing default settings |
|
360 |
Preferences preferences = getDefault().getPluginPreferences(); |
|
361 |
HashSet<String> optionNames = CModelManager.OptionNames; |
|
362 |
||
363 |
// get preferences set to their default |
|
364 |
for (String propertyName : preferences.defaultPropertyNames()){ |
|
365 |
if (optionNames.contains(propertyName)) |
|
366 |
defaultOptions.put(propertyName, preferences.getDefaultString(propertyName)); |
|
367 |
} |
|
368 |
// get preferences not set to their default |
|
369 |
for (String propertyName : preferences.propertyNames()) { |
|
370 |
if (optionNames.contains(propertyName)) |
|
371 |
defaultOptions.put(propertyName, preferences.getDefaultString(propertyName)); |
|
372 |
} |
|
373 |
// get encoding through resource plugin |
|
374 |
defaultOptions.put(CORE_ENCODING, ResourcesPlugin.getEncoding()); |
|
375 |
||
376 |
return defaultOptions; |
|
377 |
} |
|
378 |
||
379 |
||
380 |
/** |
|
381 |
* Helper method for returning one option value only. Equivalent to <code>(String)CCorePlugin.getOptions().get(optionName)</code> |
|
382 |
* Note that it may answer <code>null</code> if this option does not exist. |
|
383 |
* <p> |
|
384 |
* For a complete description of the configurable options, see <code>getDefaultOptions</code>. |
|
385 |
* </p> |
|
386 |
* |
|
387 |
* @param optionName the name of an option |
|
388 |
* @return the String value of a given option |
|
389 |
* @see CCorePlugin#getDefaultOptions |
|
390 |
*/ |
|
391 |
public static String getOption(String optionName) { |
|
392 |
||
393 |
if (CORE_ENCODING.equals(optionName)){ |
|
394 |
return ResourcesPlugin.getEncoding(); |
|
395 |
} |
|
396 |
if (CModelManager.OptionNames.contains(optionName)){ |
|
397 |
Preferences preferences = getDefault().getPluginPreferences(); |
|
398 |
return preferences.getString(optionName).trim(); |
|
399 |
} |
|
400 |
return null; |
|
401 |
} |
|
402 |
||
403 |
/** |
|
404 |
* Returns the table of the current options. Initially, all options have their default values, |
|
405 |
* and this method returns a table that includes all known options. |
|
406 |
* <p> |
|
407 |
* For a complete description of the configurable options, see <code>getDefaultOptions</code>. |
|
408 |
* </p> |
|
409 |
* |
|
410 |
* @return table of current settings of all options |
|
411 |
* (key type: <code>String</code>; value type: <code>String</code>) |
|
412 |
* @see CCorePlugin#getDefaultOptions |
|
413 |
*/ |
|
414 |
public static HashMap<String, String> getOptions() { |
|
415 |
||
416 |
HashMap<String, String> options = new HashMap<String, String>(10); |
|
417 |
||
418 |
// see #initializeDefaultPluginPreferences() for changing default settings |
|
419 |
Plugin plugin = getDefault(); |
|
420 |
if (plugin != null) { |
|
421 |
Preferences preferences = plugin.getPluginPreferences(); |
|
422 |
HashSet<String> optionNames = CModelManager.OptionNames; |
|
423 |
||
424 |
// get preferences set to their default |
|
425 |
for (String propertyName : preferences.defaultPropertyNames()){ |
|
426 |
if (optionNames.contains(propertyName)){ |
|
427 |
options.put(propertyName, preferences.getDefaultString(propertyName)); |
|
428 |
} |
|
429 |
} |
|
430 |
// get preferences not set to their default |
|
431 |
for (String propertyName : preferences.propertyNames()){ |
|
432 |
if (optionNames.contains(propertyName)){ |
|
433 |
options.put(propertyName, preferences.getString(propertyName).trim()); |
|
434 |
} |
|
435 |
} |
|
436 |
// get encoding through resource plugin |
|
437 |
options.put(CORE_ENCODING, ResourcesPlugin.getEncoding()); |
|
438 |
} |
|
439 |
return options; |
|
440 |
} |
|
441 |
||
442 |
/** |
|
443 |
* Sets the current table of options. All and only the options explicitly included in the given table |
|
444 |
* are remembered; all previous option settings are forgotten, including ones not explicitly |
|
445 |
* mentioned. |
|
446 |
* <p> |
|
447 |
* For a complete description of the configurable options, see <code>getDefaultOptions</code>. |
|
448 |
* </p> |
|
449 |
* |
|
450 |
* @param newOptions the new options (key type: <code>String</code>; value type: <code>String</code>), |
|
451 |
* or <code>null</code> to reset all options to their default values |
|
452 |
* @see CCorePlugin#getDefaultOptions |
|
453 |
*/ |
|
454 |
public static void setOptions(HashMap<String, String> newOptions) { |
|
455 |
||
456 |
// see #initializeDefaultPluginPreferences() for changing default settings |
|
457 |
Preferences preferences = getDefault().getPluginPreferences(); |
|
458 |
||
459 |
if (newOptions == null){ |
|
460 |
newOptions = getDefaultOptions(); |
|
461 |
} |
|
462 |
for (String key : newOptions.keySet()){ |
|
463 |
if (!CModelManager.OptionNames.contains(key)) continue; // unrecognized option |
|
464 |
if (key.equals(CORE_ENCODING)) continue; // skipped, contributed by resource prefs |
|
465 |
String value = newOptions.get(key); |
|
466 |
preferences.setValue(key, value); |
|
467 |
} |
|
468 |
||
469 |
// persist options |
|
470 |
getDefault().savePluginPreferences(); |
|
471 |
} |
|
472 |
||
473 |
||
474 |
public IConsole getConsole(String id) { |
|
475 |
try { |
|
476 |
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, "CBuildConsole"); //$NON-NLS-1$ |
|
477 |
if (extension != null) { |
|
478 |
IExtension[] extensions = extension.getExtensions(); |
|
479 |
for (IExtension extension2 : extensions) { |
|
480 |
IConfigurationElement[] configElements = extension2.getConfigurationElements(); |
|
481 |
for (IConfigurationElement configElement : configElements) { |
|
482 |
String consoleID = configElement.getAttribute("id"); //$NON-NLS-1$ |
|
483 |
if ((id == null && consoleID == null) || (id != null && id.equals(consoleID))) { |
|
484 |
return (IConsole) configElement.createExecutableExtension("class"); //$NON-NLS-1$ |
|
485 |
} |
|
486 |
} |
|
487 |
} |
|
488 |
} |
|
489 |
} catch (CoreException e) { |
|
490 |
log(e); |
|
491 |
} |
|
492 |
return new IConsole() { // return a null console |
|
493 |
private ConsoleOutputStream nullStream = new ConsoleOutputStream() { |
|
494 |
@Override |
|
495 |
public void write(byte[] b) throws IOException { |
|
496 |
} |
|
497 |
@Override |
|
498 |
public void write(byte[] b, int off, int len) throws IOException { |
|
499 |
} |
|
500 |
@Override |
|
501 |
public void write(int c) throws IOException { |
|
502 |
} |
|
503 |
}; |
|
504 |
||
505 |
public void start(IProject project) { |
|
506 |
} |
|
507 |
// this can be a null console.... |
|
508 |
public ConsoleOutputStream getOutputStream() { |
|
509 |
return nullStream; |
|
510 |
} |
|
511 |
public ConsoleOutputStream getInfoStream() { |
|
512 |
return nullStream; |
|
513 |
} |
|
514 |
public ConsoleOutputStream getErrorStream() { |
|
515 |
return nullStream; |
|
516 |
} |
|
517 |
}; |
|
518 |
} |
|
519 |
||
520 |
public IConsole getConsole() { |
|
521 |
String consoleID = System.getProperty("org.eclipse.cdt.core.console"); //$NON-NLS-1$ |
|
522 |
return getConsole(consoleID); |
|
523 |
} |
|
524 |
||
525 |
public ICExtensionReference[] getBinaryParserExtensions(IProject project) throws CoreException { |
|
526 |
ICExtensionReference ext[] = new ICExtensionReference[0]; |
|
527 |
if (project != null) { |
|
528 |
try { |
|
529 |
ICDescriptor cdesc = getCProjectDescription(project, false); |
|
530 |
if (cdesc==null) |
|
531 |
return ext; |
|
532 |
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true); |
|
533 |
if (cextensions != null && cextensions.length > 0) |
|
534 |
ext = cextensions; |
|
535 |
} catch (CoreException e) { |
|
536 |
log(e); |
|
537 |
} |
|
538 |
} |
|
539 |
return ext; |
|
540 |
} |
|
541 |
||
542 |
/** |
|
543 |
* @deprecated - use getBinaryParserExtensions(IProject project) |
|
544 |
*/ |
|
545 |
@Deprecated |
|
546 |
public IBinaryParser[] getBinaryParser(IProject project) throws CoreException { |
|
547 |
IBinaryParser parsers[] = null; |
|
548 |
if (project != null) { |
|
549 |
try { |
|
550 |
ICDescriptor cdesc = getCProjectDescription(project, false); |
|
551 |
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true); |
|
552 |
if (cextensions.length > 0) { |
|
553 |
ArrayList<IBinaryParser> list = new ArrayList<IBinaryParser>(cextensions.length); |
|
554 |
for (ICExtensionReference ref : cextensions) { |
|
555 |
IBinaryParser parser = null; |
|
556 |
try { |
|
557 |
parser = (IBinaryParser)ref.createExtension(); |
|
558 |
} catch (ClassCastException e) { |
|
559 |
log(e); // wrong binary parser definition ? |
|
560 |
} |
|
561 |
if (parser != null) { |
|
562 |
list.add(parser); |
|
563 |
} |
|
564 |
} |
|
565 |
parsers = new IBinaryParser[list.size()]; |
|
566 |
list.toArray(parsers); |
|
567 |
} |
|
568 |
} catch (CoreException e) { |
|
569 |
// ignore since we fall back to a default.... |
|
570 |
} |
|
571 |
} |
|
572 |
if (parsers == null) { |
|
573 |
IBinaryParser parser = getDefaultBinaryParser(); |
|
574 |
if (parser != null) { |
|
575 |
parsers = new IBinaryParser[] {parser}; |
|
576 |
} |
|
577 |
} |
|
578 |
return parsers; |
|
579 |
} |
|
580 |
||
581 |
public IBinaryParser getDefaultBinaryParser() throws CoreException { |
|
582 |
IBinaryParser parser = null; |
|
583 |
String id = getPluginPreferences().getDefaultString(PREF_BINARY_PARSER); |
|
584 |
if (id == null || id.length() == 0) { |
|
585 |
id = DEFAULT_BINARY_PARSER_UNIQ_ID; |
|
586 |
} |
|
587 |
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, BINARY_PARSER_SIMPLE_ID); |
|
588 |
IExtension extension = extensionPoint.getExtension(id); |
|
589 |
if (extension != null) { |
|
590 |
IConfigurationElement element[] = extension.getConfigurationElements(); |
|
591 |
for (IConfigurationElement element2 : element) { |
|
592 |
if (element2.getName().equalsIgnoreCase("cextension")) { //$NON-NLS-1$ |
|
593 |
parser = (IBinaryParser) element2.createExecutableExtension("run"); //$NON-NLS-1$ |
|
594 |
break; |
|
595 |
} |
|
596 |
} |
|
597 |
} else { |
|
598 |
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, CCorePlugin.getResourceString("CCorePlugin.exception.noBinaryFormat"), null); //$NON-NLS-1$ |
|
599 |
throw new CoreException(s); |
|
600 |
} |
|
601 |
return parser; |
|
602 |
} |
|
603 |
||
604 |
public CoreModel getCoreModel() { |
|
605 |
return fCoreModel; |
|
606 |
} |
|
607 |
||
608 |
public static IIndexManager getIndexManager() { |
|
609 |
return getDefault().pdomManager; |
|
610 |
} |
|
611 |
||
612 |
public IPathEntryVariableManager getPathEntryVariableManager() { |
|
613 |
return fPathEntryVariableManager; |
|
614 |
} |
|
615 |
||
616 |
/** |
|
617 |
* @deprecated use {@link #getProjectDescription(IProject, boolean)} instead |
|
618 |
*/ |
|
619 |
@Deprecated |
|
620 |
public ICDescriptor getCProjectDescription(IProject project) throws CoreException { |
|
621 |
return fNewCProjectDescriptionManager.getDescriptorManager().getDescriptor(project); |
|
622 |
} |
|
623 |
||
624 |
/** |
|
625 |
* Please use {@link #getProjectDescription(IProject, boolean)} to fetch the |
|
626 |
* ICProjectDescription for the project. And use {@link ICProjectDescription#getConfigurations()} |
|
627 |
* to get an array of ICConfigurationDescriptions, which have similar API to ICDescriptor, |
|
628 |
* allowing you to store settings and configure extensions at the Configuration level |
|
629 |
* rather than at the project level. |
|
630 |
* |
|
631 |
* @param project |
|
632 |
* @param create |
|
633 |
* @return ICDescriptor or <b>null</b> if <b>create</b> is <b>false</b> and no .cdtproject file exists on disk. |
|
634 |
* @throws CoreException |
|
635 |
* @deprecated |
|
636 |
*/ |
|
637 |
@Deprecated |
|
638 |
public ICDescriptor getCProjectDescription(IProject project, boolean create) throws CoreException { |
|
639 |
return fNewCProjectDescriptionManager.getDescriptorManager().getDescriptor(project, create); |
|
640 |
} |
|
641 |
||
642 |
public void mapCProjectOwner(IProject project, String id, boolean override) throws CoreException { |
|
643 |
try { |
|
644 |
if (!override) { |
|
645 |
fNewCProjectDescriptionManager.getDescriptorManager().configure(project, id); |
|
646 |
} else { |
|
647 |
fNewCProjectDescriptionManager.getDescriptorManager().convert(project, id); |
|
648 |
} |
|
649 |
} catch (Exception e) { |
|
650 |
throw ExceptionFactory.createCoreException(e); |
|
651 |
} |
|
652 |
} |
|
653 |
||
654 |
/** |
|
655 |
* @deprecated Settings should be set per ICConfigurationDescription rather than |
|
656 |
* global to the project. Please use {@link #getProjectDescription(IProject, boolean)} |
|
657 |
* to fetch the ICProjectDescription for the project. And use |
|
658 |
* {@link ICProjectDescription#getConfigurations()} to get an array of |
|
659 |
* ICConfigurationDescriptions, which have similar API to ICDescriptor, |
|
660 |
* allowing you to store settings and configure extensions at the Configuration level |
|
661 |
* rather than at the project level. |
|
662 |
*/ |
|
663 |
@Deprecated |
|
664 |
public ICDescriptorManager getCDescriptorManager() { |
|
665 |
return fNewCProjectDescriptionManager.getDescriptorManager(); |
|
666 |
} |
|
667 |
||
668 |
/** |
|
669 |
* Creates a C project resource given the project handle and description. |
|
670 |
* |
|
671 |
* @param description the project description to create a project resource for |
|
672 |
* @param projectHandle the project handle to create a project resource for |
|
673 |
* @param monitor the progress monitor to show visual progress with |
|
674 |
* @param projectID required for mapping the project to an owner |
|
675 |
* |
|
676 |
* @exception CoreException if the operation fails |
|
677 |
* @exception OperationCanceledException if the operation is canceled |
|
678 |
*/ |
|
679 |
public IProject createCProject( |
|
680 |
final IProjectDescription description, |
|
681 |
final IProject projectHandle, |
|
682 |
IProgressMonitor monitor, |
|
683 |
final String projectID) |
|
684 |
throws CoreException, OperationCanceledException { |
|
685 |
||
686 |
getWorkspace().run(new IWorkspaceRunnable() { |
|
687 |
public void run(IProgressMonitor monitor) throws CoreException { |
|
688 |
try { |
|
689 |
if (monitor == null) { |
|
690 |
monitor = new NullProgressMonitor(); |
|
691 |
} |
|
692 |
monitor.beginTask("Creating C Project...", 3); //$NON-NLS-1$ |
|
693 |
if (!projectHandle.exists()) { |
|
694 |
projectHandle.create(description, new SubProgressMonitor(monitor, 1)); |
|
695 |
} |
|
696 |
||
697 |
if (monitor.isCanceled()) { |
|
698 |
throw new OperationCanceledException(); |
|
699 |
} |
|
700 |
||
701 |
// Open first. |
|
702 |
projectHandle.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1)); |
|
703 |
||
704 |
mapCProjectOwner(projectHandle, projectID, false); |
|
705 |
||
706 |
// Add C Nature ... does not add duplicates |
|
707 |
CProjectNature.addCNature(projectHandle, new SubProgressMonitor(monitor, 1)); |
|
708 |
} finally { |
|
709 |
monitor.done(); |
|
710 |
} |
|
711 |
} |
|
712 |
}, getWorkspace().getRoot(), 0, monitor); |
|
713 |
return projectHandle; |
|
714 |
} |
|
715 |
||
716 |
public IProject createCDTProject( |
|
717 |
final IProjectDescription description, |
|
718 |
final IProject projectHandle, |
|
719 |
IProgressMonitor monitor) throws CoreException, OperationCanceledException{ |
|
720 |
return createCDTProject(description, projectHandle, null, monitor); |
|
721 |
} |
|
722 |
||
723 |
public IProject createCDTProject( |
|
724 |
final IProjectDescription description, |
|
725 |
final IProject projectHandle, |
|
726 |
final String bsId, |
|
727 |
IProgressMonitor monitor) |
|
728 |
throws CoreException, OperationCanceledException { |
|
729 |
||
730 |
getWorkspace().run(new IWorkspaceRunnable() { |
|
731 |
public void run(IProgressMonitor monitor) throws CoreException { |
|
732 |
try { |
|
733 |
if (monitor == null) { |
|
734 |
monitor = new NullProgressMonitor(); |
|
735 |
} |
|
736 |
monitor.beginTask("Creating C Project...", 3); //$NON-NLS-1$ |
|
737 |
if (!projectHandle.exists()) { |
|
738 |
projectHandle.create(description, new SubProgressMonitor(monitor, 1)); |
|
739 |
} |
|
740 |
||
741 |
if (monitor.isCanceled()) { |
|
742 |
throw new OperationCanceledException(); |
|
743 |
} |
|
744 |
||
745 |
// Open first. |
|
746 |
projectHandle.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1)); |
|
747 |
||
748 |
// mapCProjectOwner(projectHandle, projectID, false); |
|
749 |
||
750 |
// Add C Nature ... does not add duplicates |
|
751 |
CProjectNature.addCNature(projectHandle, new SubProgressMonitor(monitor, 1)); |
|
752 |
||
753 |
if(bsId != null){ |
|
754 |
ICProjectDescription projDes = createProjectDescription(projectHandle, true); |
|
755 |
ICConfigurationDescription cfgs[] = projDes.getConfigurations(); |
|
756 |
ICConfigurationDescription cfg = null; |
|
757 |
for (ICConfigurationDescription cfg2 : cfgs) { |
|
758 |
if(bsId.equals(cfg2.getBuildSystemId())){ |
|
759 |
cfg = cfg2; |
|
760 |
break; |
|
761 |
} |
|
762 |
} |
|
763 |
||
764 |
if(cfg == null){ |
|
765 |
ICConfigurationDescription prefCfg = getPreferenceConfiguration(bsId); |
|
766 |
if(prefCfg != null){ |
|
767 |
cfg = projDes.createConfiguration(CDataUtil.genId(prefCfg.getId()), prefCfg.getName(), prefCfg); |
|
768 |
} |
|
769 |
} |
|
770 |
||
771 |
if(cfg != null){ |
|
772 |
setProjectDescription(projectHandle, projDes); |
|
773 |
} |
|
774 |
} |
|
775 |
} finally { |
|
776 |
monitor.done(); |
|
777 |
} |
|
778 |
} |
|
779 |
}, getWorkspace().getRoot(), 0, monitor); |
|
780 |
return projectHandle; |
|
781 |
} |
|
782 |
||
783 |
/** |
|
784 |
* Method convertProjectFromCtoCC converts |
|
785 |
* a C Project to a C++ Project |
|
786 |
* The newProject MUST, not be null, already have a C Nature |
|
787 |
* && must NOT already have a C++ Nature |
|
788 |
* |
|
789 |
* @param projectHandle |
|
790 |
* @param monitor |
|
791 |
* @throws CoreException |
|
792 |
*/ |
|
793 |
||
794 |
public void convertProjectFromCtoCC(IProject projectHandle, IProgressMonitor monitor) throws CoreException { |
|
795 |
if ((projectHandle != null) |
|
796 |
&& projectHandle.hasNature(CProjectNature.C_NATURE_ID) |
|
797 |
&& !projectHandle.hasNature(CCProjectNature.CC_NATURE_ID)) { |
|
798 |
// Add C++ Nature ... does not add duplicates |
|
799 |
CCProjectNature.addCCNature(projectHandle, monitor); |
|
800 |
} |
|
801 |
} |
|
802 |
||
803 |
/** |
|
804 |
* Method to convert a project to a C nature |
|
805 |
* All checks should have been done externally |
|
806 |
* (as in the Conversion Wizards). |
|
807 |
* This method blindly does the conversion. |
|
808 |
*/ |
|
809 |
public void convertProjectToC(IProject projectHandle, IProgressMonitor monitor, String projectID) |
|
810 |
throws CoreException { |
|
811 |
if ((projectHandle == null) || (monitor == null) || (projectID == null)) { |
|
812 |
return; |
|
813 |
} |
|
814 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
|
815 |
IProjectDescription description = workspace.newProjectDescription(projectHandle.getName()); |
|
816 |
description.setLocation(projectHandle.getFullPath()); |
|
817 |
createCProject(description, projectHandle, monitor, projectID); |
|
818 |
} |
|
819 |
||
820 |
public void convertProjectToNewC(IProject projectHandle, String bsId, IProgressMonitor monitor) |
|
821 |
throws CoreException { |
|
822 |
if ((projectHandle == null) || (monitor == null) || (bsId == null)) { |
|
823 |
throw new NullPointerException(); |
|
824 |
} |
|
825 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
|
826 |
IProjectDescription description = workspace.newProjectDescription(projectHandle.getName()); |
|
827 |
description.setLocation(projectHandle.getFullPath()); |
|
828 |
createCDTProject(description, projectHandle, bsId, monitor); |
|
829 |
} |
|
830 |
||
831 |
/** |
|
832 |
* Method to convert a project to a C++ nature |
|
833 |
*/ |
|
834 |
public void convertProjectToCC(IProject projectHandle, IProgressMonitor monitor, String projectID) |
|
835 |
throws CoreException { |
|
836 |
if ((projectHandle == null) || (monitor == null) || (projectID == null)) { |
|
837 |
return; |
|
838 |
} |
|
839 |
createCProject(projectHandle.getDescription(), projectHandle, monitor, projectID); |
|
840 |
// now add C++ nature |
|
841 |
convertProjectFromCtoCC(projectHandle, monitor); |
|
842 |
} |
|
843 |
||
844 |
public void convertProjectToNewCC(IProject projectHandle, String bsId, IProgressMonitor monitor) |
|
845 |
throws CoreException { |
|
846 |
if ((projectHandle == null) || (monitor == null) || (bsId == null)) { |
|
847 |
throw new NullPointerException(); |
|
848 |
} |
|
849 |
createCDTProject(projectHandle.getDescription(), projectHandle, bsId, monitor); |
|
850 |
// now add C++ nature |
|
851 |
convertProjectFromCtoCC(projectHandle, monitor); |
|
852 |
} |
|
853 |
||
854 |
/** |
|
855 |
* Get the IProcessList contributed interface for the platform. |
|
856 |
* @return IProcessList |
|
857 |
*/ |
|
858 |
public IProcessList getProcessList() throws CoreException { |
|
859 |
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, "ProcessList"); //$NON-NLS-1$ |
|
860 |
if (extension != null) { |
|
861 |
IExtension[] extensions = extension.getExtensions(); |
|
862 |
IConfigurationElement defaultContributor = null; |
|
863 |
for (IExtension extension2 : extensions) { |
|
864 |
IConfigurationElement[] configElements = extension2.getConfigurationElements(); |
|
865 |
for (IConfigurationElement configElement : configElements) { |
|
866 |
if (configElement.getName().equals("processList")) { //$NON-NLS-1$ |
|
867 |
String platform = configElement.getAttribute("platform"); //$NON-NLS-1$ |
|
868 |
if (platform == null ) { // first contributor found with not platform will be default. |
|
869 |
if (defaultContributor == null) { |
|
870 |
defaultContributor = configElement; |
|
871 |
} |
|
872 |
} else if (platform.equals(Platform.getOS())) { |
|
873 |
// found explicit contributor for this platform. |
|
874 |
return (IProcessList) configElement.createExecutableExtension("class"); //$NON-NLS-1$ |
|
875 |
} |
|
876 |
} |
|
877 |
} |
|
878 |
} |
|
879 |
if ( defaultContributor != null) { |
|
880 |
return (IProcessList) defaultContributor.createExecutableExtension("class"); //$NON-NLS-1$ |
|
881 |
} |
|
882 |
} |
|
883 |
return null; |
|
884 |
||
885 |
} |
|
886 |
||
887 |
/** |
|
888 |
* Array of error parsers ids. |
|
889 |
*/ |
|
890 |
public String[] getAllErrorParsersIDs() { |
|
891 |
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ERROR_PARSER_SIMPLE_ID); |
|
892 |
String[] empty = new String[0]; |
|
893 |
if (extension != null) { |
|
894 |
IExtension[] extensions = extension.getExtensions(); |
|
895 |
ArrayList<String> list = new ArrayList<String>(extensions.length); |
|
896 |
for (IExtension e : extensions) |
|
897 |
list.add(e.getUniqueIdentifier()); |
|
898 |
return list.toArray(empty); |
|
899 |
} |
|
900 |
return empty; |
|
901 |
} |
|
902 |
||
903 |
public IErrorParser[] getErrorParser(String id) { |
|
904 |
IErrorParser[] empty = new IErrorParser[0]; |
|
905 |
try { |
|
906 |
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ERROR_PARSER_SIMPLE_ID); |
|
907 |
if (extension != null) { |
|
908 |
IExtension[] extensions = extension.getExtensions(); |
|
909 |
List<IErrorParser> list = new ArrayList<IErrorParser>(extensions.length); |
|
910 |
for (IExtension e : extensions) { |
|
911 |
String parserID = e.getUniqueIdentifier(); |
|
912 |
if ((id == null && parserID != null) || (id != null && id.equals(parserID))) { |
|
913 |
for (IConfigurationElement ce : e.getConfigurationElements()) |
|
914 |
list.add((IErrorParser)ce.createExecutableExtension("class")); //$NON-NLS-1$ |
|
915 |
} |
|
916 |
} |
|
917 |
return list.toArray(empty); |
|
918 |
} |
|
919 |
} catch (CoreException e) { |
|
920 |
log(e); |
|
921 |
} |
|
922 |
return empty; |
|
923 |
} |
|
924 |
||
925 |
public IScannerInfoProvider getScannerInfoProvider(IProject project) { |
|
926 |
return fNewCProjectDescriptionManager.getScannerInfoProviderProxy(project); |
|
927 |
} |
|
928 |
||
929 |
/** |
|
930 |
* Helper function, returning the content type for a filename |
|
931 |
* Same as: <pre> |
|
932 |
* getContentType(null, filename) |
|
933 |
* </pre> |
|
934 |
* @param filename |
|
935 |
* @return the content type found, or <code>null</code> |
|
936 |
*/ |
|
937 |
public static IContentType getContentType(String filename) { |
|
938 |
return CContentTypes.getContentType(null, filename); |
|
939 |
} |
|
940 |
||
941 |
/** |
|
942 |
* Returns the content type for a filename. The method respects |
|
943 |
* project specific content type definitions. The lookup prefers case- |
|
944 |
* sensitive matches over the others. |
|
945 |
* @param project a project with possible project specific settings. Can be <code>null</code> |
|
946 |
* @param filename a filename to compute the content type for |
|
947 |
* @return the content type found or <code>null</code> |
|
948 |
*/ |
|
949 |
public static IContentType getContentType(IProject project, String filename) { |
|
950 |
return CContentTypes.getContentType(project, filename); |
|
951 |
} |
|
952 |
||
953 |
/** |
|
954 |
* Tests whether the given project uses its project specific content types. |
|
955 |
*/ |
|
956 |
public static boolean usesProjectSpecificContentTypes(IProject project) { |
|
957 |
return CContentTypes.usesProjectSpecificContentTypes(project); |
|
958 |
} |
|
959 |
||
960 |
/** |
|
961 |
* Enables or disables the project specific content types. |
|
962 |
*/ |
|
963 |
public static void setUseProjectSpecificContentTypes(IProject project, boolean val) { |
|
964 |
CContentTypes.setUseProjectSpecificContentTypes(project, val); |
|
965 |
} |
|
966 |
||
967 |
||
968 |
||
969 |
private static final String MODEL = CCorePlugin.PLUGIN_ID + "/debug/model" ; //$NON-NLS-1$ |
|
970 |
private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$ |
|
971 |
private static final String PARSER_EXCEPTIONS = CCorePlugin.PLUGIN_ID + "/debug/parser/exceptions" ; //$NON-NLS-1$ |
|
972 |
private static final String SCANNER = CCorePlugin.PLUGIN_ID + "/debug/scanner"; //$NON-NLS-1$ |
|
973 |
private static final String DELTA = CCorePlugin.PLUGIN_ID + "/debug/deltaprocessor" ; //$NON-NLS-1$ |
|
974 |
//private static final String CONTENTASSIST = CCorePlugin.PLUGIN_ID + "/debug/contentassist" ; //$NON-NLS-1$ |
|
975 |
||
976 |
/** |
|
977 |
* Configure the plug-in with respect to option settings defined in ".options" file |
|
978 |
*/ |
|
979 |
public void configurePluginDebugOptions() { |
|
980 |
||
981 |
if(CCorePlugin.getDefault().isDebugging()) { |
|
982 |
String option = Platform.getDebugOption(PARSER); |
|
983 |
if(option != null) Util.VERBOSE_PARSER = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ |
|
984 |
||
985 |
option = Platform.getDebugOption(PARSER_EXCEPTIONS); |
|
986 |
if( option != null ) Util.PARSER_EXCEPTIONS = option.equalsIgnoreCase("true"); //$NON-NLS-1$ |
|
987 |
||
988 |
option = Platform.getDebugOption(SCANNER); |
|
989 |
if( option != null ) Util.VERBOSE_SCANNER = option.equalsIgnoreCase("true"); //$NON-NLS-1$ |
|
990 |
||
991 |
option = Platform.getDebugOption(MODEL); |
|
992 |
if(option != null) Util.VERBOSE_MODEL = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ |
|
993 |
||
994 |
option = Platform.getDebugOption(DELTA); |
|
995 |
if(option != null) Util.VERBOSE_DELTA= option.equalsIgnoreCase("true") ; //$NON-NLS-1$ |
|
996 |
||
997 |
} |
|
998 |
} |
|
999 |
||
1000 |
// Preference to turn on/off the use of structural parse mode to build the CModel |
|
1001 |
public void setStructuralParseMode(boolean useNewParser) { |
|
1002 |
getPluginPreferences().setValue(PREF_USE_STRUCTURAL_PARSE_MODE, useNewParser); |
|
1003 |
savePluginPreferences(); |
|
1004 |
} |
|
1005 |
||
1006 |
public boolean useStructuralParseMode() { |
|
1007 |
return getPluginPreferences().getBoolean(PREF_USE_STRUCTURAL_PARSE_MODE); |
|
1008 |
} |
|
1009 |
||
51
49c226a8748e
CDT 6.0 from cdt_6_0 branch (eclipse.org cvs repository). This overwrites previous CDT 6.0 merges.
timkelly
parents:
44
diff
changeset
|
1010 |
public CDOM getDOM() { |
49c226a8748e
CDT 6.0 from cdt_6_0 branch (eclipse.org cvs repository). This overwrites previous CDT 6.0 merges.
timkelly
parents:
44
diff
changeset
|
1011 |
return CDOM.getInstance(); |
37 | 1012 |
} |
1013 |
||
1014 |
public ICdtVariableManager getCdtVariableManager(){ |
|
1015 |
return CdtVariableManager.getDefault(); |
|
1016 |
} |
|
1017 |
||
1018 |
public IEnvironmentVariableManager getBuildEnvironmentManager(){ |
|
1019 |
return EnvironmentVariableManager.getDefault(); |
|
1020 |
} |
|
1021 |
||
1022 |
public ICConfigurationDescription getPreferenceConfiguration(String buildSystemId) throws CoreException{ |
|
1023 |
return fNewCProjectDescriptionManager.getPreferenceConfiguration(buildSystemId); |
|
1024 |
} |
|
1025 |
||
1026 |
public ICConfigurationDescription getPreferenceConfiguration(String buildSystemId, boolean write) throws CoreException{ |
|
1027 |
return fNewCProjectDescriptionManager.getPreferenceConfiguration(buildSystemId, write); |
|
1028 |
} |
|
1029 |
||
1030 |
public void setPreferenceConfiguration(String buildSystemId, ICConfigurationDescription des) throws CoreException { |
|
1031 |
fNewCProjectDescriptionManager.setPreferenceConfiguration(buildSystemId, des); |
|
1032 |
} |
|
1033 |
||
1034 |
/** |
|
1035 |
* this method is a full equivalent to <code>createProjectDescription(IProject, boolean, false)</code>. |
|
1036 |
* |
|
1037 |
* @see #createProjectDescription(IProject, boolean, boolean) |
|
1038 |
*/ |
|
1039 |
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException{ |
|
1040 |
return fNewCProjectDescriptionManager.createProjectDescription(project, loadIfExists); |
|
1041 |
} |
|
1042 |
||
1043 |
/** |
|
1044 |
* the method creates and returns a writable project description |
|
1045 |
* |
|
1046 |
* @param project project for which the project description is requested |
|
1047 |
* @param loadIfExists if true the method first tries to load and return the project description |
|
1048 |
* from the settings file (.cproject) |
|
1049 |
* if false, the stored settings are ignored and the new (empty) project description is created |
|
1050 |
* @param creating if true the created project description will be contain the true "isCdtProjectCreating" state. |
|
1051 |
* NOTE: in case the project already contains the project description AND its "isCdtProjectCreating" is false |
|
1052 |
* the resulting description will be created with the false "isCdtProjectCreating" state |
|
1053 |
* |
|
1054 |
* NOTE: changes made to the returned project description will not be applied until the {@link #setProjectDescription(IProject, ICProjectDescription)} is called |
|
1055 |
* @return {@link ICProjectDescription} |
|
1056 |
* @throws CoreException |
|
1057 |
*/ |
|
1058 |
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists, boolean creating) throws CoreException{ |
|
1059 |
return fNewCProjectDescriptionManager.createProjectDescription(project, loadIfExists, creating); |
|
1060 |
} |
|
1061 |
||
1062 |
/** |
|
1063 |
* returns the project description associated with this project or null if the project does not contain the |
|
1064 |
* CDT data associated with it. |
|
1065 |
* |
|
1066 |
* this is a convenience method fully equivalent to getProjectDescription(project, true) |
|
1067 |
* see {@link #getProjectDescription(IProject, boolean)} for more detail |
|
1068 |
* @param project |
|
1069 |
* @return a writable copy of the ICProjectDescription or null if the project does not contain the |
|
1070 |
* CDT data associated with it. |
|
1071 |
* Note: changes to the project description will not be reflected/used by the core |
|
1072 |
* until the {@link #setProjectDescription(IProject, ICProjectDescription)} is called |
|
1073 |
* |
|
1074 |
* @see #getProjectDescription(IProject, boolean) |
|
1075 |
*/ |
|
1076 |
public ICProjectDescription getProjectDescription(IProject project){ |
|
1077 |
return fNewCProjectDescriptionManager.getProjectDescription(project); |
|
1078 |
} |
|
1079 |
||
1080 |
/** |
|
1081 |
* this method is called to save/apply the project description |
|
1082 |
* the method should be called to apply changes made to the project description |
|
1083 |
* returned by the {@link #getProjectDescription(IProject, boolean)} or {@link #createProjectDescription(IProject, boolean)} |
|
1084 |
* |
|
1085 |
* @param project |
|
1086 |
* @param des |
|
1087 |
* @throws CoreException |
|
1088 |
* |
|
1089 |
* @see #getProjectDescription(IProject, boolean) |
|
1090 |
* @see #createProjectDescription(IProject, boolean) |
|
1091 |
*/ |
|
1092 |
public void setProjectDescription(IProject project, ICProjectDescription des) throws CoreException { |
|
1093 |
fNewCProjectDescriptionManager.setProjectDescription(project, des); |
|
1094 |
} |
|
1095 |
||
1096 |
public void setProjectDescription(IProject project, ICProjectDescription des, boolean force, IProgressMonitor monitor) throws CoreException { |
|
1097 |
fNewCProjectDescriptionManager.setProjectDescription(project, des, force, monitor); |
|
1098 |
} |
|
1099 |
||
1100 |
/** |
|
1101 |
* returns the project description associated with this project or null if the project does not contain the |
|
1102 |
* CDT data associated with it. |
|
1103 |
* |
|
1104 |
* @param project project for which the description is requested |
|
1105 |
* @param write if true, the writable description copy is returned. |
|
1106 |
* If false the cached read-only description is returned. |
|
1107 |
* |
|
1108 |
* CDT core maintains the cached project description settings. If only read access is needed to description, |
|
1109 |
* then the read-only project description should be obtained. |
|
1110 |
* This description always operates with cached data and thus it is better to use it for performance reasons |
|
1111 |
* All set* calls to the read-only description result in the {@link WriteAccessException} |
|
1112 |
* |
|
1113 |
* When the writable description is requested, the description copy is created. |
|
1114 |
* Changes to this description will not be reflected/used by the core and Build System untill the |
|
1115 |
* {@link #setProjectDescription(IProject, ICProjectDescription)} is called |
|
1116 |
* |
|
1117 |
* Each getProjectDescription(project, true) returns a new copy of the project description |
|
1118 |
* |
|
1119 |
* The writable description uses the cached data untill the first set call |
|
1120 |
* after that the description communicates directly to the Build System |
|
1121 |
* i.e. the implementer of the org.eclipse.cdt.core.CConfigurationDataProvider extension |
|
1122 |
* This ensures the Core<->Build System settings integrity |
|
1123 |
* |
|
1124 |
* @return {@link ICProjectDescription} or null if the project does not contain the |
|
1125 |
* CDT data associated with it. |
|
1126 |
*/ |
|
1127 |
public ICProjectDescription getProjectDescription(IProject project, boolean write){ |
|
1128 |
return fNewCProjectDescriptionManager.getProjectDescription(project, write); |
|
1129 |
} |
|
1130 |
||
1131 |
/** |
|
1132 |
* forces the cached data of the specified projects to be re-calculated. |
|
1133 |
* if the <code>projects</code> argument is <code>null</code> al projects |
|
1134 |
* within the workspace are updated |
|
1135 |
* |
|
1136 |
* @param projects |
|
1137 |
* @param monitor |
|
1138 |
* @throws CoreException |
|
1139 |
*/ |
|
1140 |
public void updateProjectDescriptions(IProject projects[], IProgressMonitor monitor) throws CoreException{ |
|
1141 |
fNewCProjectDescriptionManager.updateProjectDescriptions(projects, monitor); |
|
1142 |
} |
|
1143 |
||
1144 |
/** |
|
1145 |
* Answers whether the given project is a new-style project, i.e. CConfigurationDataProvider-driven |
|
1146 |
*/ |
|
1147 |
public boolean isNewStyleProject(IProject project){ |
|
1148 |
return fNewCProjectDescriptionManager.isNewStyleProject(project); |
|
1149 |
} |
|
1150 |
||
1151 |
/** |
|
1152 |
* Answers whether the given project is a new-style project, i.e. CConfigurationDataProvider-driven |
|
1153 |
*/ |
|
1154 |
public boolean isNewStyleProject(ICProjectDescription des){ |
|
1155 |
return fNewCProjectDescriptionManager.isNewStyleProject(des); |
|
1156 |
} |
|
1157 |
||
1158 |
public ICProjectDescriptionManager getProjectDescriptionManager(){ |
|
1159 |
return fNewCProjectDescriptionManager; |
|
1160 |
} |
|
1161 |
||
1162 |
/** |
|
1163 |
* @return editable User-variable's supplier |
|
1164 |
*/ |
|
1165 |
public static IUserVarSupplier getUserVarSupplier() { |
|
1166 |
return UserVarSupplier.getInstance(); |
|
1167 |
} |
|
44
b0f794238767
Merge CDT bug 181020 (from CDT patch, not from patch from Carbide Bug 9031)
timkelly
parents:
43
diff
changeset
|
1168 |
|
37 | 1169 |
// NON-API |
1170 |
||
1171 |
/** |
|
1172 |
* @noreference This constructor is not intended to be referenced by clients. |
|
1173 |
*/ |
|
1174 |
public CCorePlugin() { |
|
1175 |
super(); |
|
1176 |
fgCPlugin = this; |
|
1177 |
} |
|
1178 |
||
1179 |
/** |
|
1180 |
* Answers the shared working copies currently registered for this buffer factory. |
|
1181 |
* Working copies can be shared by several clients using the same buffer factory,see |
|
1182 |
* <code>IWorkingCopy.getSharedWorkingCopy</code>. |
|
1183 |
* |
|
1184 |
* @param factory the given buffer factory |
|
1185 |
* @return the list of shared working copies for a given buffer factory |
|
1186 |
* @see IWorkingCopy |
|
1187 |
* @noreference This method is not intended to be referenced by clients. |
|
1188 |
*/ |
|
1189 |
public static IWorkingCopy[] getSharedWorkingCopies(IBufferFactory factory) { |
|
1190 |
// if factory is null, default factory must be used |
|
1191 |
if (factory == null) |
|
1192 |
factory = BufferManager.getDefaultBufferManager().getDefaultBufferFactory(); |
|
1193 |
Map<IBufferFactory, Map<ITranslationUnit, WorkingCopy>> sharedWorkingCopies = CModelManager |
|
1194 |
.getDefault().sharedWorkingCopies; |
|
1195 |
||
1196 |
Map<ITranslationUnit, WorkingCopy> perFactoryWorkingCopies = sharedWorkingCopies.get(factory); |
|
1197 |
if (perFactoryWorkingCopies == null) |
|
1198 |
return CModelManager.NoWorkingCopy; |
|
1199 |
Collection<WorkingCopy> copies = perFactoryWorkingCopies.values(); |
|
1200 |
IWorkingCopy[] result = new IWorkingCopy[copies.size()]; |
|
1201 |
copies.toArray(result); |
|
1202 |
return result; |
|
1203 |
} |
|
1204 |
||
1205 |
/** |
|
1206 |
* @noreference This method is not intended to be referenced by clients. |
|
1207 |
*/ |
|
1208 |
public static void log(String e) { |
|
1209 |
log(createStatus(e)); |
|
1210 |
} |
|
1211 |
||
1212 |
/** |
|
1213 |
* @noreference This method is not intended to be referenced by clients. |
|
1214 |
*/ |
|
1215 |
public static void log(Throwable e) { |
|
1216 |
String msg= e.getMessage(); |
|
1217 |
if (msg == null) { |
|
1218 |
log("Error", e); //$NON-NLS-1$ |
|
1219 |
} else { |
|
1220 |
log("Error: " + msg, e); //$NON-NLS-1$ |
|
1221 |
} |
|
1222 |
} |
|
1223 |
||
1224 |
/** |
|
1225 |
* @noreference This method is not intended to be referenced by clients. |
|
1226 |
*/ |
|
1227 |
public static void log(String message, Throwable e) { |
|
1228 |
Throwable nestedException; |
|
1229 |
if (e instanceof CModelException |
|
1230 |
&& (nestedException = ((CModelException)e).getException()) != null) { |
|
1231 |
e = nestedException; |
|
1232 |
} |
|
1233 |
log(createStatus(message, e)); |
|
1234 |
} |
|
1235 |
||
1236 |
/** |
|
1237 |
* @noreference This method is not intended to be referenced by clients. |
|
1238 |
*/ |
|
1239 |
public static IStatus createStatus(String msg) { |
|
1240 |
return createStatus(msg, null); |
|
1241 |
} |
|
1242 |
||
1243 |
/** |
|
1244 |
* @noreference This method is not intended to be referenced by clients. |
|
1245 |
*/ |
|
1246 |
public static IStatus createStatus(String msg, Throwable e) { |
|
1247 |
return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, msg, e); |
|
1248 |
} |
|
1249 |
||
1250 |
/** |
|
1251 |
* @noreference This method is not intended to be referenced by clients. |
|
1252 |
*/ |
|
1253 |
public static void log(IStatus status) { |
|
1254 |
getDefault().getLog().log(status); |
|
1255 |
} |
|
1256 |
||
1257 |
/** |
|
1258 |
* @deprecated use getIndexManager(). |
|
1259 |
* @noreference This method is not intended to be referenced by clients. |
|
1260 |
*/ |
|
1261 |
@Deprecated |
|
1262 |
public static IPDOMManager getPDOMManager() { |
|
1263 |
return getDefault().pdomManager; |
|
1264 |
} |
|
52
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1265 |
|
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1266 |
/** |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1267 |
* Returns preference controlling whether source roots are shown at the top of projects |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1268 |
* or embedded within the resource tree of projects when they are not top level folders. |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1269 |
* |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1270 |
* @return boolean preference value |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1271 |
*/ |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1272 |
public static boolean showSourceRootsAtTopOfProject() { |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1273 |
return getDefault().getPluginPreferences().getBoolean( CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT); |
42077b7eab6e
Second merge to proper cdt_6_0 branch for CDT bugs 181020, 279844, & Carbide bugs 6152 & 9031.
timkelly
parents:
51
diff
changeset
|
1274 |
} |
37 | 1275 |
} |