Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2e57720201eca09ef9835fad6b813986dedb0923 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/*******************************************************************************
 * Copyright (c) 2007, 2010 Intel Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.dataprovider;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigInfoFactory2;
import org.eclipse.cdt.core.model.ILanguageDescriptor;
import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.core.settings.model.IModificationContext;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationDataProvider;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
import org.eclipse.cdt.managedbuilder.core.IInputType;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.internal.core.Builder;
import org.eclipse.cdt.managedbuilder.internal.core.BuilderFactory;
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.ISettingsChangeListener;
import org.eclipse.cdt.managedbuilder.internal.core.InputType;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.internal.core.NotificationManager;
import org.eclipse.cdt.managedbuilder.internal.core.SettingsChangeEvent;
import org.eclipse.cdt.managedbuilder.internal.core.Tool;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.content.IContentType;

/**
 * The main hook ManagedBuild uses to connect to cdt.core's project model.
 * Provides & Persists Build configuration data in the project model storage.
 */
public class ConfigurationDataProvider extends CConfigurationDataProvider implements ISettingsChangeListener {
	private static final String BUILD_SYSTEM_DATA_MODULE_NAME = "cdtBuildSystem";	//$NON-NLS-1$
	private static final String VERSION_ATTRIBUTE = "version";	//$NON-NLS-1$
	private static final String PREF_CFG_ID = "org.eclipse.cdt.build.core.prefbase.cfg";	//$NON-NLS-1$
	public static final String PREF_TC_ID = "org.eclipse.cdt.build.core.prefbase.toolchain";	//$NON-NLS-1$
	private static final String PREF_TOOL_ID = "org.eclipse.cdt.build.core.settings.holder";	//$NON-NLS-1$
	private static final QualifiedName CFG_PERSISTED_PROPERTY = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "configPersisted");	//$NON-NLS-1$
	private static final QualifiedName NATURES_USED_ON_CACHE_PROPERTY = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "naturesUsedOnCache");	//$NON-NLS-1$
	private static final QualifiedName BUILD_INFO_PROPERTY = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "buildInfo");	//$NON-NLS-1$

	private static boolean registered;

	public ConfigurationDataProvider(){
		if(!registered){
			registered = true;
			NotificationManager.getInstance().subscribe(this);
		}
	}

	private static class DesApplyRunnable implements IWorkspaceRunnable {
		IBuilder fBuilder;
		IProject fProject;

		DesApplyRunnable(IProject project, IBuilder builder){
			fProject = project;
			fBuilder = builder;
		}

		@Override
		public void run(IProgressMonitor monitor) throws CoreException {
			try {
				IProjectDescription eDes = fProject.getDescription();
				if(BuilderFactory.applyBuilder(eDes, fBuilder) == BuilderFactory.CMD_CHANGED) {
						fProject.setDescription(eDes, monitor);
				}
			} catch (Exception e){
				ManagedBuilderCorePlugin.log(e);
			}
		}

	}
	static BuildConfigurationData writeConfiguration(ICConfigurationDescription cfgDescription,
			BuildConfigurationData base) throws CoreException {
		BuildConfigurationData appliedCfg = base;
		ICStorageElement rootElement = cfgDescription.getStorage(BUILD_SYSTEM_DATA_MODULE_NAME, true);
		rootElement.clear();
		rootElement.setAttribute(VERSION_ATTRIBUTE, ManagedBuildManager.getVersion().toString());
		ICStorageElement cfgElemen = rootElement.createChild(IConfiguration.CONFIGURATION_ELEMENT_NAME);
		Configuration cfg = (Configuration)appliedCfg.getConfiguration();
		Builder b = (Builder)cfg.getEditableBuilder();
		// Need to ensure that build macro supplier can get the description for this configuration during the write...
		cfg.setConfigurationDescription(cfgDescription);
		if(b != null && b.isManagedBuildOn() && b.getBuildPathAttribute(false) == null){
			String bPath = b.getDefaultBuildPath();
			b.setBuildPathAttribute(bPath);
		}
//		cfg.setConfigurationDescription(des);
//		ManagedBuildManager.performValueHandlerEvent(cfg, IManagedOptionValueHandler.EVENT_APPLY);
		cfg.serialize(cfgElemen);

		return appliedCfg;
	}

	protected CConfigurationData applyPreferences(
			ICConfigurationDescription cfgDescription, CConfigurationData base) throws CoreException{

		BuildConfigurationData appliedCfg = writeConfiguration(cfgDescription, (BuildConfigurationData)base);

		IConfiguration cfg = ((BuildConfigurationData)base).getConfiguration();
		try {
			CfgScannerConfigInfoFactory2.savePreference(cfg);
		} catch (CoreException e){
			ManagedBuilderCorePlugin.log(e);
		}

		return appliedCfg;
	}

	@Override
	public CConfigurationData applyConfiguration(
			ICConfigurationDescription cfgDescription,
			ICConfigurationDescription baseCfgDescription,
			CConfigurationData base,
			IModificationContext context,
			IProgressMonitor monitor)
			throws CoreException {
		if(cfgDescription.isPreferenceConfiguration())
			return applyPreferences(cfgDescription, base);

		BuildConfigurationData baseCfgData = (BuildConfigurationData)base;
		IConfiguration baseCfg = baseCfgData.getConfiguration();
		BuildConfigurationData appliedCfg;
		if(context.isBaseDataCached() && !baseCfg.isDirty()){
			appliedCfg = baseCfgData;
			context.setConfigurationSettingsFlags(IModificationContext.CFG_DATA_STORAGE_UNMODIFIED | IModificationContext.CFG_DATA_SETTINGS_UNMODIFIED);
		} else {
			appliedCfg = writeConfiguration(cfgDescription, baseCfgData);

			IManagedBuildInfo info = getBuildInfo(cfgDescription);
			ManagedProject mProj = (ManagedProject)info.getManagedProject();
			mProj.applyConfiguration((Configuration)appliedCfg.getConfiguration());
			writeManagedProjectInfo(cfgDescription.getProjectDescription(), mProj);
			try {
				CfgScannerConfigInfoFactory2.save(appliedCfg, cfgDescription.getProjectDescription(), baseCfgDescription.getProjectDescription(), !isPersistedCfg(cfgDescription));
			} catch (CoreException e){
				ManagedBuilderCorePlugin.log(e);
			}
			info.setValid(true);
			// Update the ManagedBuildInfo in the ManagedBuildManager map. Doing this creates a barrier for subsequent
			// ManagedBuildManager#getBuildInfo(...) see Bug 305146 for more
			ManagedBuildManager.setLoaddedBuildInfo(cfgDescription.getProjectDescription().getProject(), info);

			setPersistedFlag(cfgDescription);
			cacheNaturesIdsUsedOnCache(cfgDescription);

			if(cfgDescription.isActive()){
				IConfiguration cfg = appliedCfg.getConfiguration();
				IBuilder builder = cfg.getEditableBuilder();
				IProject project = context.getProject();
				IProjectDescription eDes = context.getEclipseProjectDescription();
				switch(BuilderFactory.applyBuilder(eDes, builder)){
				case BuilderFactory.CMD_UNDEFINED:
					IWorkspaceRunnable applyR = new DesApplyRunnable(project, builder);
					context.addWorkspaceRunnable(applyR);
					break;
				case BuilderFactory.CMD_CHANGED:
					context.setEclipseProjectDescription(eDes);
					break;
				}
			}
		}
		return appliedCfg;
	}

	private void setPersistedFlag(ICConfigurationDescription cfgDescription){
		cfgDescription.setSessionProperty(CFG_PERSISTED_PROPERTY, Boolean.TRUE);
	}

	private static void writeManagedProjectInfo(ICProjectDescription des,
			ManagedProject mProj) throws CoreException {
		ICStorageElement rootElement = des.getStorage(BUILD_SYSTEM_DATA_MODULE_NAME, true);
		rootElement.clear();
		rootElement.setAttribute(VERSION_ATTRIBUTE, ManagedBuildManager.getVersion().toString());
		ICStorageElement mProjElem = rootElement.createChild(IManagedProject.MANAGED_PROJECT_ELEMENT_NAME);
		mProj.serializeProjectInfo(mProjElem);
	}


	protected CConfigurationData createPreferences(
			ICConfigurationDescription cfgDescription, CConfigurationData base)
			throws CoreException {
		Configuration cfg = (Configuration)((BuildConfigurationData)base).getConfiguration();
		Configuration newCfg = new Configuration((ManagedProject)cfg.getManagedProject(), cfg, cfgDescription.getId(), true, true, true);
		newCfg.setConfigurationDescription(cfgDescription);
		newCfg.setName(cfgDescription.getName());
//		if(!newCfg.getId().equals(cfg.getId())){
//			newCfg.exportArtifactInfo();
//		}

		return newCfg.getConfigurationData();
	}


	@Override
	public CConfigurationData createConfiguration(
			ICConfigurationDescription cfgDescription,
			ICConfigurationDescription baseCfgDescription,
			CConfigurationData base, boolean clone,
			IProgressMonitor monitor)
			throws CoreException {
		if(cfgDescription.isPreferenceConfiguration())
			return createPreferences(cfgDescription, base);

		Configuration cfg = (Configuration)((BuildConfigurationData)base).getConfiguration();
		Configuration newCfg = copyCfg(cfg, cfgDescription);

		if(!newCfg.getId().equals(cfg.getId()) && newCfg.canExportedArtifactInfo()){
			// Bug 335001: Remove existing exported settings as they point at this configuration
			for (ICExternalSetting extSetting : newCfg.getConfigurationDescription().getExternalSettings())
				newCfg.getConfigurationDescription().removeExternalSetting(extSetting);
			// Now export the new settings
			newCfg.exportArtifactInfo();
		}

		setPersistedFlag(cfgDescription);

		return newCfg.getConfigurationData();
	}

	public static Configuration copyCfg(Configuration cfg, ICConfigurationDescription cfgDescription){
		IManagedBuildInfo info = getBuildInfo(cfgDescription);
		ManagedProject mProj = (ManagedProject)info.getManagedProject();

		Configuration newCfg = new Configuration(mProj, cfg, cfgDescription.getId(), true, true, false);
		newCfg.setConfigurationDescription(cfgDescription);
		newCfg.setName(cfgDescription.getName());

		cfgDescription.setConfigurationData(ManagedBuildManager.CFG_DATA_PROVIDER_ID, newCfg.getConfigurationData());

		ManagedBuildManager.performValueHandlerEvent(newCfg, IManagedOptionValueHandler.EVENT_OPEN);

//		if(!newCfg.getId().equals(cfg.getId())){
//			newCfg.exportArtifactInfo();
//		}

		return newCfg;
	}

	private static IManagedBuildInfo getBuildInfo(ICConfigurationDescription cfgDescription){
		ICProjectDescription projDes = cfgDescription.getProjectDescription();
		IProject project = projDes.getProject();
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project, false);
		if(info == null)
			info = ManagedBuildManager.createBuildInfo(project);

		setLoaddedBuildInfo(projDes, info);

		getManagedProject(cfgDescription, info);

		return info;
	}

	private static void setLoaddedBuildInfo(ICProjectDescription des, IManagedBuildInfo info){
		des.setSessionProperty(BUILD_INFO_PROPERTY, info);
	}

	public static ManagedBuildInfo getLoaddedBuildInfo(ICProjectDescription des){
		return (ManagedBuildInfo)des.getSessionProperty(BUILD_INFO_PROPERTY);
	}

	private static IManagedProject getManagedProject(ICConfigurationDescription cfgDescription, IManagedBuildInfo info){
		IManagedProject mProj = info.getManagedProject();
		if(mProj == null){
			mProj = createManagedProject(info, cfgDescription.getProjectDescription());
		}
		return mProj;
	}

	private static IManagedProject createManagedProject(IManagedBuildInfo info, ICProjectDescription des){
		IManagedProject mProj = null;
		try {
			ICStorageElement rootElem = des.getStorage(BUILD_SYSTEM_DATA_MODULE_NAME, false);
			if(rootElem != null){
				String version = rootElem.getAttribute(VERSION_ATTRIBUTE);
				ICStorageElement children[] = rootElem.getChildren();
				for(int i = 0; i < children.length; i++){
					if(IManagedProject.MANAGED_PROJECT_ELEMENT_NAME.equals(children[i].getName())){
						mProj = new ManagedProject((ManagedBuildInfo)info, children[i], false, version);
						break;
					}
				}
			}
		} catch (CoreException e) {
			mProj = null;
		}

		if(mProj == null){
			mProj = new ManagedProject(des);
			info.setManagedProject(mProj);
		}

		return mProj;
	}

	public static String[] getNaturesIdsUsedOnCache(IConfiguration cfg){
		ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(cfg);
		if(cfgDescription != null)
			return getNaturesIdsUsedOnCache(cfgDescription);
		return null;
	}

	public static String[] getNaturesIdsUsedOnCache(ICConfigurationDescription cfgDescription){
		String[] strs = (String[])cfgDescription.getSessionProperty(NATURES_USED_ON_CACHE_PROPERTY);
		return strs != null && strs.length != 0 ? (String[])strs.clone() : strs;
	}

	public static void cacheNaturesIdsUsedOnCache(ICConfigurationDescription cfgDescription){
		IProject project = cfgDescription.getProjectDescription().getProject();
		try {
			IProjectDescription eDes = project.getDescription();
			String[] natures = eDes.getNatureIds();
			setNaturesIdsUsedOnCache(cfgDescription, natures);
		} catch (CoreException e) {
			ManagedBuilderCorePlugin.log(e);
		}
	}

	private static void setNaturesIdsUsedOnCache(ICConfigurationDescription cfgDescription, String ids[]){
		ids = ids != null && ids.length != 0 ? (String[])ids.clone() : ids;
		cfgDescription.setSessionProperty(NATURES_USED_ON_CACHE_PROPERTY, ids);
	}

	private Configuration load(ICConfigurationDescription cfgDescription, ManagedProject mProj, boolean isPreference) throws CoreException{
		ICStorageElement rootElement = cfgDescription.getStorage(BUILD_SYSTEM_DATA_MODULE_NAME, true);
		ICStorageElement children[] = rootElement.getChildren();
		String version = rootElement.getAttribute(VERSION_ATTRIBUTE);
		Configuration cfg = null;

		for(int i = 0; i < children.length; i++){
			if(IConfiguration.CONFIGURATION_ELEMENT_NAME.equals(children[i].getName())){
				cfg = new Configuration(mProj, children[i], version, isPreference);
				ManagedBuildManager.performValueHandlerEvent(cfg, IManagedOptionValueHandler.EVENT_OPEN);
				break;
			}
		}
		return cfg;
	}

	protected CConfigurationData loadPreferences(ICConfigurationDescription cfgDescription)
								throws CoreException {

		Configuration cfg = load(cfgDescription, null, true);

		cfg = updatePreferenceOnLoad(cfg, cfgDescription);

		cfg.setConfigurationDescription(cfgDescription);

		return cfg.getConfigurationData();
	}

	public static Configuration getClearPreference(String id){
		Configuration cfg = createEmptyPrefConfiguration(id, null);

		cfg = adjustPreferenceConfig(cfg);

		return cfg;
	}

	private static Configuration updatePreferenceOnLoad(Configuration cfg, ICConfigurationDescription cfgDescription){
		if(cfg == null)
			cfg = createEmptyPrefConfiguration(cfgDescription.getId(), cfgDescription.getName());

		cfg = adjustPreferenceConfig(cfg);

		return cfg;
	}

	private static Configuration adjustPreferenceConfig(Configuration cfg){
		LanguageManager mngr = LanguageManager.getInstance();
		ILanguageDescriptor dess[] = mngr.getLanguageDescriptors();
		Map<String, ILanguageDescriptor[]> map = mngr.getContentTypeIdToLanguageDescriptionsMap();

		IResourceInfo[] rcInfos = cfg.getResourceInfos();
		for(int i = 0; i < rcInfos.length; i++){
			if(rcInfos[i] instanceof IFolderInfo){
				adjustFolderInfo((IFolderInfo)rcInfos[i], dess, new HashMap<Object, ILanguageDescriptor[]>(map));
			}
		}

		return cfg;
	}

	private static void adjustFolderInfo(IFolderInfo info, ILanguageDescriptor dess[], HashMap<Object, ILanguageDescriptor[]> map){
		IToolChain tch = info.getToolChain();
		Map<String, ILanguageDescriptor> langMap = new HashMap<String, ILanguageDescriptor>();
		for(int i = 0; i < dess.length; i++){
			langMap.put(dess[i].getId(), dess[i]);
		}
		if(PREF_TC_ID.equals(tch.getSuperClass().getId())){
			ITool[] tools = tch.getTools();
			for(int i = 0; i < tools.length; i++){
				Tool tool = (Tool)tools[i];
				IInputType types[] = tool.getAllInputTypes();
				for(int k = 0; k < types.length; k++){
					InputType type = (InputType)types[k];
					String langId = type.getLanguageId(tool);
					if(langId != null){
						ILanguageDescriptor des = langMap.remove(langId);
						if(des != null)
							adjustInputType(tool, type, des);
						continue;
					} else {
						IContentType[] cTypes = type.getSourceContentTypes();
						for(int c = 0; c < cTypes.length; c++){
							IContentType cType = cTypes[c];
							ILanguageDescriptor[] langs = map.remove(cType.getId());
							if(langs != null && langs.length != 0){
								for(int q = 0; q < langs.length; q++){
									langMap.remove(langs[q].getId());
								}

								adjustInputType(tool, type, langs[0]);
							}
						}
					}
				}
			}

			if(!langMap.isEmpty()){
				addTools(tch, langMap, map);
			}
		}
	}

	private static InputType adjustInputType(Tool tool, InputType type, ILanguageDescriptor des){
		String [] cTypeIds = des.getContentTypeIds();
		String srcIds[] = type.getSourceContentTypeIds();
		String hIds[] = type.getHeaderContentTypeIds();

		Set<String> landTypes = new HashSet<String>(Arrays.asList(cTypeIds));
		landTypes.removeAll(Arrays.asList(srcIds));
		landTypes.removeAll(Arrays.asList(hIds));

		if(landTypes.size() != 0){
			List<String> srcList = new ArrayList<String>();
			srcList.addAll(landTypes);
			type = (InputType)tool.getEditableInputType(type);
			type.setSourceContentTypeIds(srcList.toArray(new String[srcList.size()]));
		}

		if(!des.getId().equals(type.getLanguageId(tool))){
			type = (InputType)tool.getEditableInputType(type);
			type.setLanguageIdAttribute(des.getId());
			type.setLanguageNameAttribute(des.getName());
		}
		return type;
	}

	private static void addTools(IToolChain tc, Map<String, ILanguageDescriptor> langMap, Map<Object, ILanguageDescriptor[]> cTypeToLangMap){
		ITool extTool = ManagedBuildManager.getExtensionTool(PREF_TOOL_ID);
		List<ILanguageDescriptor> list = new ArrayList<ILanguageDescriptor>(langMap.values());
		ILanguageDescriptor des;
		while(list.size() != 0){
			des = list.remove(list.size() - 1);
			String[] ctypeIds = des.getContentTypeIds();
			boolean addLang = false;
			for(int i = 0; i < ctypeIds.length; i++){
				ILanguageDescriptor[] langs = cTypeToLangMap.remove(ctypeIds[i]);
				if(langs != null && langs.length != 0){
					addLang = true;
					for(int q = 0; q < langs.length; q++){
						list.remove(langs[q]);
					}
				}
			}

			if(addLang){
				String id = ManagedBuildManager.calculateChildId(extTool.getId(), null);
				String name = des.getName();
				Tool tool = (Tool)tc.createTool(extTool, id, name, false);
				InputType type = (InputType)tool.getInputTypes()[0];
				type = (InputType)tool.getEditableInputType(type);
				type.setSourceContentTypes(des.getContentTypes());
				type.setLanguageNameAttribute(des.getName());
				type.setName(des.getName());
				type.setLanguageIdAttribute(des.getId());
			}
		}
	}


	private static Configuration createEmptyPrefConfiguration(String id, String name){
		Configuration extCfg = (Configuration)ManagedBuildManager.getExtensionConfiguration(PREF_CFG_ID);
		Configuration emptyPrefCfg = null;
		if(extCfg != null){
			if(id == null)
				id = ManagedBuildManager.calculateChildId(extCfg.getId(), null);
			if(name == null)
				name = extCfg.getName();
			emptyPrefCfg = new Configuration(null, extCfg, id, false, true, true);
			emptyPrefCfg.setName(name);
			emptyPrefCfg.setPerRcTypeDiscovery(false);
		}

		return emptyPrefCfg;
	}

	@Override
	public CConfigurationData loadConfiguration(ICConfigurationDescription cfgDescription,
			IProgressMonitor monitor)
			throws CoreException {
		if(cfgDescription.isPreferenceConfiguration())
			return loadPreferences(cfgDescription);

		IManagedBuildInfo info = getBuildInfo(cfgDescription);
		Configuration cfg = load(cfgDescription, (ManagedProject)info.getManagedProject(), false);

		if(cfg != null){
			cfg.setConfigurationDescription(cfgDescription);
			info.setValid(true);
			setPersistedFlag(cfgDescription);
			cacheNaturesIdsUsedOnCache(cfgDescription);
			// Update the ManagedBuildInfo in the ManagedBuildManager map. Doing this creates a barrier for subsequent
			// ManagedBuildManager#getBuildInfo(...) see Bug 305146 for more
			ManagedBuildManager.setLoaddedBuildInfo(cfgDescription.getProjectDescription().getProject(), info);
			return cfg.getConfigurationData();
		}
		return null;
	}

	private boolean isPersistedCfg(ICConfigurationDescription cfgDescription){
		return cfgDescription.getSessionProperty(CFG_PERSISTED_PROPERTY) != null;
	}

	@Override
	public void settingsChanged(SettingsChangeEvent event) {
		BuildLanguageData datas[] = (BuildLanguageData[])event.getRcInfo().getCLanguageDatas();
		IOption option = event.getOption();

		try {
			int type = option.getValueType();
			for(int i = 0; i < datas.length; i++){
				datas[i].optionsChanged(type);
			}
		} catch (BuildException e) {
			ManagedBuilderCorePlugin.log(e);
		}
	}

	@Override
	public void removeConfiguration(ICConfigurationDescription cfgDescription,
			CConfigurationData data,
			IProgressMonitor monitor) {
		IConfiguration cfg = ((BuildConfigurationData)data).getConfiguration();
		ManagedBuildManager.performValueHandlerEvent(cfg, IManagedOptionValueHandler.EVENT_CLOSE);
		IManagedBuildInfo info = getBuildInfo(cfgDescription);
		IManagedProject mProj = info.getManagedProject();
		mProj.removeConfiguration(cfg.getId());
	}

	@Override
	public void dataCached(ICConfigurationDescription cfgDescription,
			CConfigurationData data,
			IProgressMonitor monitor) {
		BuildConfigurationData cfgData = (BuildConfigurationData)data;
		((Configuration)cfgData.getConfiguration()).setConfigurationDescription(cfgDescription);
		cfgData.clearCachedData();
	}

}

Back to the top