Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 852bfc4e5c0d606b75ac72555db2cca9c6a7d35f (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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
/*******************************************************************************
 * Copyright (c) 2007 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.internal.core.settings.model;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.settings.model.CExternalSetting;
import org.eclipse.cdt.core.settings.model.ICBuildSetting;
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.ICSettingsStorage;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.core.settings.model.ICTargetPlatformSetting;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.internal.core.CConfigBasedDescriptorManager;
import org.eclipse.cdt.internal.core.CExtensionInfo;
import org.eclipse.cdt.internal.core.COwner;
import org.eclipse.cdt.internal.core.COwnerConfiguration;
import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables;
import org.eclipse.cdt.utils.envvar.StorableEnvironment;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;

public class CConfigurationSpecSettings implements ICSettingsStorage{
	static final String BUILD_SYSTEM_ID = "buildSystemId";	//$NON-NLS-1$
//	private final static String ELEMENT_REFERENCES = "references";  //$NON-NLS-1$
	private static final String PROJECT_EXTENSION_ATTR_POINT = "point"; //$NON-NLS-1$
	private static final String PROJECT_EXTENSION_ATTR_ID = "id"; //$NON-NLS-1$
	private static final String PROJECT_EXTENSION_ATTRIBUTE = "attribute"; //$NON-NLS-1$
	private static final String PROJECT_EXTENSION_ATTRIBUTE_KEY = "key"; //$NON-NLS-1$
	private static final String PROJECT_EXTENSION_ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
	private static final String PROJECT_EXTENSION = "extension"; //$NON-NLS-1$
	private static final String PROJECT_DATA = "data"; //$NON-NLS-1$
	private static final String PROJECT_DATA_ITEM = "item"; //$NON-NLS-1$
	private static final String PROJECT_DATA_ID = "id"; //$NON-NLS-1$
	private static final String PROJECT_EXTENSIONS = "extensions"; //$NON-NLS-1$
	private static final String OWNER_ID = "owner"; //$NON-NLS-1$
	private static final String OLD_OWNER_ID = "id"; //$NON-NLS-1$

	static final String ID = "id";	//$NON-NLS-1$
	static final String NAME = "name";	//$NON-NLS-1$
	private ICConfigurationDescription fCfg;
	private ICStorageElement fRootStorageElement;
	private ICStorageElement fSettingsStorageElement;
	private CStorage fStorage;
	private String fBuildSystemId;
	private String fName;
	private String fId;
	private StorableCdtVariables fMacros;
	private StorableEnvironment fEnvironment;
//	private HashMap fRefInfoMap;
	private Map fRefMapCache;
	private CExternalSettingsHolder fExtSettingsProvider = new CExternalSettingsHolder();
	private boolean fIsModified;
	private HashMap fSessionPropertiesMap;
	private HashMap fExtMap;
	private HashMap fExtInfoMap = new HashMap();
	private String fOwnerId;
	private COwner fOwner;
//	private CConfigBasedDescriptor fDescriptor;
//	private Map fExternalSettingsProviderMap;
	
	public CConfigurationSpecSettings(ICConfigurationDescription des, ICStorageElement storage) throws CoreException{
		fCfg = des;
		fRootStorageElement = storage;
		ICStorageElement settings = getSettingsStorageElement();
		
		fBuildSystemId = settings.getAttribute(BUILD_SYSTEM_ID);
		fName = settings.getAttribute(NAME);
		fId = settings.getAttribute(ID);
		
		setCOwner(settings.getAttribute(OWNER_ID));
		
		ICStorageElement children[] = settings.getChildren();
		for(int i = 0; i < children.length; i++){
			ICStorageElement child = children[i];
			String name = child.getName();
			
			if(StorableCdtVariables.MACROS_ELEMENT_NAME.equals(name)){
				fMacros = new StorableCdtVariables(child, fCfg.isReadOnly());
			}/* else if(ELEMENT_REFERENCES.equals(name)){
				loadReferences(child);
			} */else if (CExternalSettingsHolder.ELEMENT_EXT_SETTINGS_CONTAINER.equals(name)){
				fExtSettingsProvider = new CExternalSettingsHolder(child);
			} else if(StorableEnvironment.ENVIRONMENT_ELEMENT_NAME.equals(name)){
				fEnvironment = new StorableEnvironment(child, fCfg.isReadOnly());
			} else if(PROJECT_EXTENSIONS.equals(name)){
				loadExtensionInfo(child, false);
			}
		}
		
//		if(fMacros == null)
//			fMacros = new StorableMacros(des.isReadOnly());
		

	}

	public CConfigurationSpecSettings(ICConfigurationDescription des, ICStorageElement storage, ICStorageElement oldInfo) throws CoreException{
		fCfg = des;
		fRootStorageElement = storage;
		
		loadOldStileDescription(oldInfo);
			
	}
	private void loadOldStileDescription(ICStorageElement storage) throws CoreException{
		setCOwner(storage.getAttribute(OLD_OWNER_ID));

		loadExtensionInfo(storage, true);
	}
	public CConfigurationSpecSettings(ICConfigurationDescription des, CConfigurationSpecSettings base){
		this(des, base, null);
	}

	public CConfigurationSpecSettings(ICConfigurationDescription des, CConfigurationSpecSettings base, ICStorageElement rootEl){
		fCfg = des;
		fRootStorageElement = rootEl;
		fBuildSystemId = base.fBuildSystemId;
		fName = base.fName;
		fId = base.fId;
		
//		copyRefInfos(base.fRefInfoMap);
		
		if(base.fMacros != null)
			fMacros = new StorableCdtVariables(base.fMacros, des.isReadOnly());
		
		if(base.fExtSettingsProvider != null)
			fExtSettingsProvider = new CExternalSettingsHolder(base.fExtSettingsProvider);
		
		if(base.fSessionPropertiesMap != null)
			fSessionPropertiesMap = (HashMap)base.fSessionPropertiesMap.clone();
		
		if(base.fEnvironment != null)
			fEnvironment = new StorableEnvironment(base.fEnvironment, des.isReadOnly());
		
		fOwnerId = base.fOwnerId;
		fOwner = base.fOwner;

		copyExtensionInfo(base);
	}
	
//	private void copyRefInfos(Map infosMap){
//		if(infosMap == null || infosMap.size() == 0){
//			fRefInfoMap = null;
//			return;
//		}
//		
//		fRefInfoMap = new HashMap(infosMap.size());
//		for(Iterator iter = infosMap.entrySet().iterator(); iter.hasNext();){
//			Map.Entry entry = (Map.Entry)iter.next();
//			String projName = (String)entry.getKey();
//			ProjectRefInfo info = (ProjectRefInfo)entry.getValue();
//			fRefInfoMap.put(projName, new ProjectRefInfo(info));
//		}
//	}
	
	public void setCOwner(String ownerId) throws CoreException{
		if(ownerId == null)
			ownerId = CConfigBasedDescriptorManager.NULL_OWNER_ID;
	
		if(ownerId.equals(fOwnerId))
			return;
		
		fOwnerId = ownerId;
		COwnerConfiguration cfg = CProjectDescriptionManager.getInstance().getDescriptorManager().getOwnerConfiguration(fOwnerId);
		fOwner = new COwner(cfg);
	}
	
//	private void loadReferences(ICStorageElement el){
//		fRefInfoMap = new HashMap();
//		ICStorageElement children[] = el.getChildren();
//		
//		for(int i = 0; i < children.length; i++){
//			ICStorageElement child = children[i];
//			String name = child.getName();
//
//			if(ProjectRefInfo.ELEMENT_REFERENCE.equals(name)){
//				ProjectRefInfo info = new ProjectRefInfo(child);
//				fRefInfoMap.put(info.getProjectName(), info);
//			}
//		}
//		
//		if(fRefInfoMap.size() == 0)
//			fRefInfoMap = null;
//	}
	
//	 private Map normalizeRefs(Map ref){
//			for(Iterator iter = ref.entrySet().iterator(); iter.hasNext();){
//				Map.Entry entry = (Map.Entry)iter.next();
//				Object projObj = entry.getKey();
//				Object cfgObj = entry.getValue();
//				if(projObj instanceof String && (cfgObj == null || cfgObj instanceof String)){
//					String proj = ((String)projObj).trim();
//					String cfg = (String)cfgObj;
//					if(cfg == null)
//						cfg = EMPTY_STRING;
//					else 
//						cfg = cfg.trim();
//					
//					if(proj.length() > 0){
//						entry.setValue(cfg);
//					} else {
//						iter.remove();
//					}
//				}
//			}
//			return ref;
//		}

//	 private String[] normalizeRef(String projName, String cfgId){
//		if(projName == null || (projName = projName.trim()).length() == 0)
//			return null;
//		if(cfgId == null)
//			cfgId = EMPTY_STRING;
//		else 
//			cfgId = cfgId.trim();
//					
//		return new String[] {projName, cfgId};
//	}

	private ICStorageElement getSettingsStorageElement() throws CoreException{
		if(fSettingsStorageElement == null)
			fSettingsStorageElement =getStorage(CProjectDescriptionManager.MODULE_ID, true);
		return fSettingsStorageElement;
	}
	
	public ICStorageElement getStorage(String id,boolean create) throws CoreException {
		return getStorageBase().getStorage(id, create);
	}
	
	public void removeStorage(String id) throws CoreException {
		getStorageBase().removeStorage(id);
	}

	public boolean containsStorage(String id) throws CoreException {
		return getStorageBase().containsStorage(id);
	}

	ICStorageElement getRootStorageElement() throws CoreException{
		if(fRootStorageElement == null){
			if(fCfg.isPreferenceConfiguration()){
				fRootStorageElement = CProjectDescriptionManager.getInstance().getBuildSystemConfigPreferenceStorage(fBuildSystemId);
			} else {
				fRootStorageElement = CProjectDescriptionManager.getInstance().createStorage(fCfg.getProjectDescription(), fCfg.getId());
			}
		}
		return fRootStorageElement;
	}
	
	void removeConfiguration() throws CoreException{
		CProjectDescriptionManager.getInstance().removeStorage(fCfg.getProjectDescription(), fCfg.getId());
	}
	private CStorage getStorageBase() throws CoreException{
		if(fStorage == null){
			fStorage = new CStorage((InternalXmlStorageElement)getRootStorageElement());
//			if(fDescriptor != null)
//				reconsileDescriptor(fStorage, fDescriptor);
		}
		return fStorage;
	}
	
	void doneInitialization(){
		if(isReadOnly()){
			if(fRootStorageElement != null)
				((InternalXmlStorageElement)fRootStorageElement).setReadOnly(true, false);
			if(fSettingsStorageElement != null)
				((InternalXmlStorageElement)fSettingsStorageElement).setReadOnly(true, false);
			if(fStorage != null)
				fStorage.setReadOnly(true, false);
		}
	}
	
	public String getBuildSystemId(){
		return fBuildSystemId;
	}
	
	public ICConfigurationDescription getConfigurarion(){
		return fCfg;
	}
	
	public String getName() {
		return fName;
	}

	public void setName(String name){
		if(isReadOnly())
			throw ExceptionFactory.createIsReadOnlyException();
		if(!CDataUtil.objectsEqual(fName, name)){
			fName = name;
			fIsModified = true;
		}
	}
	
	public String getId() {
		return fId;
	}

	public void setId(String id){
		if(isReadOnly())
			throw ExceptionFactory.createIsReadOnlyException();
		if(!CDataUtil.objectsEqual(fId, id)){
			fId = id;
			fIsModified = true;
		}
	}
	
	void setBuildSystemId(String id){
		if(isReadOnly())
			throw ExceptionFactory.createIsReadOnlyException();
		if(!CDataUtil.objectsEqual(fBuildSystemId, id)){
			fBuildSystemId = id;
			fIsModified = true;
		}
	}
	
	void serializeId() throws CoreException {
		fId = fCfg.getId();
		ICStorageElement settings = getSettingsStorageElement();
		settings.setAttribute(ID, fId);
	}

	void serialize() throws CoreException {
		fId = fCfg.getId();
		fName = fCfg.getName();
		ICStorageElement settings = getSettingsStorageElement();
		settings.clear();
		
		settings.setAttribute(ID, fId);
		settings.setAttribute(NAME, fName);
		settings.setAttribute(BUILD_SYSTEM_ID, fBuildSystemId);
		
		if(fMacros != null && !fMacros.isEmpty()){
			ICStorageElement macrosEl = settings.createChild(StorableCdtVariables.MACROS_ELEMENT_NAME);
			fMacros.serialize(macrosEl);
		}
		
		if(fExtSettingsProvider != null){
			ICStorageElement child = settings.createChild(CExternalSettingsHolder.ELEMENT_EXT_SETTINGS_CONTAINER);
			fExtSettingsProvider.serialize(child);
		}
		
//		if(fRefInfoMap != null && fRefInfoMap.size() != 0){
//			ICStorageElement el = settings.createChild(ELEMENT_REFERENCES);
//			for(Iterator iter = fRefInfoMap.values().iterator(); iter.hasNext();){
//				ProjectRefInfo info = (ProjectRefInfo)iter.next();
//				ICStorageElement child = el.createChild(ProjectRefInfo.ELEMENT_REFERENCE);
//				info.serialize(child);
//			}
//		}
		
		ICStorageElement extEl = settings.createChild(PROJECT_EXTENSIONS);
		encodeProjectExtensions(extEl);
	}
	
	public boolean isReadOnly(){
		return fCfg.isReadOnly();
	}
	
	public StorableCdtVariables getMacros(){
		if(fMacros == null)
			fMacros = new StorableCdtVariables(isReadOnly());
		return fMacros;
	}
	
	public StorableEnvironment getEnvironment(){
		return fEnvironment;
	}

	public void setEnvironment(StorableEnvironment environment){
		fEnvironment = environment;
	}
	
	public Map getReferenceInfo(){
		if(!fCfg.isReadOnly())
			return CfgExportSettingContainerFactory.getReferenceMap(fCfg);
		if(fRefMapCache == null)
			fRefMapCache = CfgExportSettingContainerFactory.getReferenceMap(fCfg);
		return new HashMap(fRefMapCache);
//		if(fRefInfoMap == null || fRefInfoMap.size() == 0)
//			return new HashMap(0);
//		
//		Map map = (HashMap)fRefInfoMap.clone();
//		for(Iterator iter = map.entrySet().iterator(); iter.hasNext();){
//			Map.Entry entry = (Map.Entry)iter.next();
//			ProjectRefInfo info = (ProjectRefInfo)entry.getValue();
//			entry.setValue(info.getCfgId());
//		}
//		return map;
	}
	
//	public Map getProjectRefInfoMap(){
//		if(fRefInfoMap == null || fRefInfoMap.size() == 0)
//			return new HashMap(0);
//		
//		return (Map)fRefInfoMap.clone();
//	}
	
//	public void setProjectRefInfoMap(Map map){
//		if(map == null && map.size() == 0)
//			fRefInfoMap = null;
//		
//		fRefInfoMap = new HashMap(map);
//		fIsModified = true;
//	}

	public void setReferenceInfo(Map ref){
		fRefMapCache = null;
		CfgExportSettingContainerFactory.setReferenceMap(fCfg, ref);
//		if(isReadOnly())
//			throw ExceptionFactory.createIsReadOnlyException();
//
//		List removed = null, added = null;
//		if(fRefInfos != null){
//			for(int i = 0; i < fRefInfos.length; i++){
//				String cfgId
//			}
//		}
//		if(ref != null && CProjectDescriptionManager.getInstance().normalizeRefs(ref).size() != 0){
//			fReferenceInfo = new HashMap(ref);
//		} else {
//			fReferenceInfo = null;
//		}
	}

/*	
	private Map getExternalSettingsProviderMap(boolean create){
		if(fExternalSettingsProviderMap == null && create)
			fExternalSettingsProviderMap = new HashMap();
		return fExternalSettingsProviderMap;
	}
	
	public ExternalSettingInfo getExternalSettingsProviderInfo(String id){
		Map map = getExternalSettingsProviderMap(false);
		if(map != null)
			return (ExternalSettingInfo)map.get(id);
		return null;
	}

	public void setExternalSettingsProviderInfo(ExternalSettingInfo info){
		getExternalSettingsProviderMap(true).put(info.fProvider.getId(), info.fProvider);
	}
*/	
	public ICExternalSetting[] getExternalSettings(){
		return fExtSettingsProvider.getExternalSettings();
	}
	
	public ICExternalSetting createExternalSetting(String[] languageIDs,
			String[] contentTypeIDs, String[] extensions,
			ICSettingEntry[] entries) {
		return fExtSettingsProvider.createExternalSetting(languageIDs, contentTypeIDs, extensions, entries);
	}

	public void removeExternalSetting(ICExternalSetting setting) {
		fExtSettingsProvider.removeExternalSetting((CExternalSetting)setting);
	}

	public void removeExternalSettings() {
		fExtSettingsProvider.removeExternalSettings();
	}

	public boolean isModified(){
		if(fIsModified)
			return true;
		
		if(fMacros != null && fMacros.isDirty())
			return true;
		
		if(fEnvironment != null && fEnvironment.isDirty())
			return true;
		
		return fExtSettingsProvider.isModified();
	}

	void setModified(boolean modified){
		if(isReadOnly())
			throw ExceptionFactory.createIsReadOnlyException();
		fIsModified = modified;
		
		if(!modified){
			if(fMacros != null)
				fMacros.setDirty(false);
			
			if(fEnvironment != null)
				fEnvironment.setDirty(false);
		}
	}

	void setModified(){
		setModified(true);
	}
	
	private Map getSessionPropertiesMap(boolean create){
		if(fSessionPropertiesMap == null && create)
			fSessionPropertiesMap = new HashMap();
		return fSessionPropertiesMap;
	}
	
	public Object getSettionProperty(QualifiedName name){
		Map map = getSessionPropertiesMap(false);
		return map != null ? map.get(name) : null;
	}

	public void setSettionProperty(QualifiedName name, Object value){
//		if(isReadOnly())
//			throw ExceptionFactory.createIsReadOnlyException();
		Map map = getSessionPropertiesMap(true);
		if(value != null)
			map.put(name, value);
		else
			map.remove(name);
		fIsModified = true;
	}
	

	//extension reference info
	private HashMap getExtMap(){
		if(fExtMap == null)
			fExtMap = new HashMap();
		return fExtMap;
	}
	
	public Map getExtensionMapCopy(){
		return (HashMap)getExtMap().clone();
	}
	
	private ICConfigExtensionReference[] doGet(String extensionPointID){
		return (CConfigExtensionReference[])getExtMap().get(extensionPointID);
	}
	
	
	public ICConfigExtensionReference[] get(String extensionPointID) {
		checkReconsile(extensionPointID, true);
		
		ICConfigExtensionReference refs[] = doGet(extensionPointID);
		if (refs == null)
			return new ICConfigExtensionReference[0];
		return (ICConfigExtensionReference[])refs.clone();
	}
	
	private void checkReconsile(String extensionPointID, boolean toExt){
		if(toExt){
			Set[] delta = getReferenceDelta(extensionPointID);
			if(delta != null){
				if(delta[0] != null){
					for(Iterator iter = delta[0].iterator(); iter.hasNext();){
						ICConfigExtensionReference ref = (ICConfigExtensionReference)iter.next();
						try {
							doRemove(ref);
						} catch (CoreException e) {
							CCorePlugin.log(e);
						}
					}
				}
				if(delta[1] != null){
					for(Iterator iter = delta[1].iterator(); iter.hasNext();){
						String id = (String)iter.next();
						try {
							doCreate(extensionPointID, id);
						} catch (CoreException e) {
							CCorePlugin.log(e);
						}
					}
				}
			}
		} else {
			if(CCorePlugin.BINARY_PARSER_UNIQ_ID.equals(extensionPointID)){
				ICTargetPlatformSetting tp = fCfg.getTargetPlatformSetting();
				if(tp != null){
					tp.setBinaryParserIds(getIds(doGet(extensionPointID)));
				}
			} else if(CCorePlugin.ERROR_PARSER_UNIQ_ID.equals(extensionPointID)){
				ICBuildSetting bs = fCfg.getBuildSetting();
				if(bs != null){
					bs.setErrorParserIDs(getIds(doGet(extensionPointID)));
				}
			}
		}
	}
	
	private String[] getIds(ICConfigExtensionReference refs[]){
		if(refs == null || refs.length == 0)
			return new String[0];
		
		String[] ids = new String[refs.length];
		for(int i = 0; i < refs.length; i++){
			ids[i] = refs[i].getID();
		}
		return ids;
	}

	void reconsileExtensionSettings(boolean toExts){
		checkReconsile(CCorePlugin.BINARY_PARSER_UNIQ_ID, toExts);
		checkReconsile(CCorePlugin.ERROR_PARSER_UNIQ_ID, toExts);
	}
	
//	private boolean checkReconsile(String extPointId, ICConfigExtensionReference refs[], boolean get){
//		if(!get || !(((IInternalCCfgInfo)fCfg).getConfigurationData(false) instanceof CConfigurationDescriptionCache)){
//			if(CCorePlugin.BINARY_PARSER_UNIQ_ID.equals(extPointId))
//				return CProjectDescriptionManager.getInstance().reconsileBinaryParserExtRefs(fCfg, refs, get);
//			else if(CCorePlugin.ERROR_PARSER_UNIQ_ID.equals(extPointId))
//				return CProjectDescriptionManager.getInstance().reconsileErrorParserExtRefs(fCfg, refs, get);
//		}
//		return false;
//	}

//	synchronized private ICConfigExtensionReference[] get(String extensionID, boolean update) throws CoreException {
//		ICConfigExtensionReference[] refs = get(extensionID);
//		if (refs.length == 0 && update) {
//			boolean oldIsInitializing = isInitializing;
//			isInitializing = true;
//			fOwner.update(fProject, this, extensionID);
//			isInitializing = oldIsInitializing;
//			updateIfDirty();
//			refs = get(extensionID);
//		}
//		return refs;
//	}

	private CConfigExtensionReference createRef(String extensionPoint, String extension) {
		CConfigExtensionReference extensions[] = (CConfigExtensionReference[])getExtMap().get(extensionPoint);
		if (extensions == null) {
			extensions = new CConfigExtensionReference[1];
			getExtMap().put(extensionPoint, extensions);
		} else {
			CConfigExtensionReference[] newExtensions = new CConfigExtensionReference[extensions.length + 1];
			System.arraycopy(extensions, 0, newExtensions, 0, extensions.length);
			extensions = newExtensions;
			getExtMap().put(extensionPoint, extensions);
		}
		extensions[extensions.length - 1] = new CConfigExtensionReference(this, extensionPoint, extension);
		return extensions[extensions.length - 1];
	}
	
	private ICConfigExtensionReference doCreate(String extensionPoint, String extension) throws CoreException {
		ICConfigExtensionReference extRef = createRef(extensionPoint, extension);
		return extRef;
	}

	public ICConfigExtensionReference create(String extensionPoint, String extension) throws CoreException {
//		boolean fireEvent = false;
		checkReconsile(extensionPoint, true);
		
		ICConfigExtensionReference[] refs = doGet(extensionPoint);
		ICConfigExtensionReference extRef = null;
		
		if (refs != null && refs.length != 0){
			for(int i = 0; i < refs.length; i++){
				if(refs[i].getID().equals(extension)){
					extRef = refs[i];
					break;
				}
			}
		}
		
		if(extRef == null){
			extRef = createRef(extensionPoint, extension);
			checkReconsile(extensionPoint, false);
			fIsModified = true;
		}
		return extRef;
	}

	public void doRemove(ICConfigExtensionReference ext) throws CoreException {
//		boolean fireEvent = false;
//		synchronized (this) {
			CConfigExtensionReference extensions[] = (CConfigExtensionReference[])getExtMap().get(ext.getExtensionPoint());
			for (int i = 0; i < extensions.length; i++) {
				if (extensions[i] == ext) {
//					System.arraycopy(extensions, i, extensions, i + 1, extensions.length - 1 - i);
					System.arraycopy(extensions, i + 1, extensions, i, extensions.length - 1 - i);
					if (extensions.length > 1) {
						CConfigExtensionReference[] newExtensions = new CConfigExtensionReference[extensions.length - 1];
						System.arraycopy(extensions, 0, newExtensions, 0, newExtensions.length);
						getExtMap().put(ext.getExtensionPoint(), newExtensions);
					} else {
						getExtMap().remove(ext.getExtensionPoint());
					}
//					updateOnDisk();
//					if (!isInitializing) {
//						fireEvent = true;
//					}
				}
			}
//		}
//		if (fireEvent) {
//			fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
//		}
	}

	public void remove(ICConfigExtensionReference ext) throws CoreException {
		doRemove(ext);
		
		fIsModified = true;
	}

	private boolean doRemove(String extensionPoint) throws CoreException {
//		boolean fireEvent = false;
//		synchronized (this) {
			CConfigExtensionReference extensions[] = (CConfigExtensionReference[])getExtMap().get(extensionPoint);
			if (extensions != null) {
				getExtMap().remove(extensionPoint);
				return true;
//				updateOnDisk();
//				if (!isInitializing) {
//					fireEvent = true;
//				}
			}
			return false;
//		}
//		if (fireEvent) {
//			fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
//		}
	}

	public void remove(String extensionPoint) throws CoreException {
		
		boolean changed = doRemove(extensionPoint);
		
		checkReconsile(extensionPoint, false);
		
		if(changed)
			fIsModified = true;
	}

	CExtensionInfo getInfo(CConfigExtensionReference cProjectExtension) {
		CExtensionInfo info = (CExtensionInfo)fExtInfoMap.get(cProjectExtension);
		if (info == null) {
			info = new CExtensionInfo();
			fExtInfoMap.put(cProjectExtension, info);
		}
		return info;
	}

	private void loadExtensionInfo(ICStorageElement node, boolean oldData) {
		ICStorageElement childNode;
		ICStorageElement list[] = node.getChildren();
		for (int i = 0; i < list.length; i++) {
			childNode = list[i];
//			if (childNode.getNodeType() == Node.ELEMENT_NODE) {
				if (childNode.getName().equals(PROJECT_EXTENSION)) {
					try {
						decodeProjectExtension(childNode);
					} catch (CoreException e) {
						CCorePlugin.log(e);
					}
				} else if (oldData && childNode.getName().equals(PROJECT_DATA)) {
					try {
						decodeProjectData(childNode);
					} catch (CoreException e) {
						CCorePlugin.log(e);
					}
				}
//			}
		}
	}

	private void decodeProjectExtension(ICStorageElement element) throws CoreException {
		String point = element.getAttribute(PROJECT_EXTENSION_ATTR_POINT);
		String id = element.getAttribute(PROJECT_EXTENSION_ATTR_ID);
		CConfigExtensionReference ext = createRef(point, id);
		ICStorageElement extAttrib[] = element.getChildren();
		for (int j = 0; j < extAttrib.length; j++) {
			if (extAttrib[j].getName().equals(PROJECT_EXTENSION_ATTRIBUTE)) {
//				NamedNodeMap attrib = extAttrib.item(j).getAttributes();
				getInfo(ext).setAttribute(extAttrib[j].getAttribute(PROJECT_EXTENSION_ATTRIBUTE_KEY),
						extAttrib[j].getAttribute(PROJECT_EXTENSION_ATTRIBUTE_VALUE));
			}
		}
	}

	private void encodeProjectExtensions(ICStorageElement configRootElement) {
		ICStorageElement element;
		Iterator extIterator = getExtMap().values().iterator();
		while (extIterator.hasNext()) {
			CConfigExtensionReference extension[] = (CConfigExtensionReference[])extIterator.next();
			for (int i = 0; i < extension.length; i++) {
				element = configRootElement.createChild(PROJECT_EXTENSION);
				element.setAttribute(PROJECT_EXTENSION_ATTR_POINT, extension[i].getExtensionPoint());
				element.setAttribute(PROJECT_EXTENSION_ATTR_ID, extension[i].getID());
				CExtensionInfo info = (CExtensionInfo)fExtInfoMap.get(extension[i]);
				if (info != null) {
					Iterator attribIterator = info.getAttributes().entrySet().iterator();
					while (attribIterator.hasNext()) {
						Entry entry = (Entry)attribIterator.next();
						ICStorageElement extAttributes = element.createChild(PROJECT_EXTENSION_ATTRIBUTE);
						extAttributes.setAttribute(PROJECT_EXTENSION_ATTRIBUTE_KEY, (String)entry.getKey());
						extAttributes.setAttribute(PROJECT_EXTENSION_ATTRIBUTE_VALUE, (String)entry.getValue());
					}
				}
			}
		}
	}

	private void decodeProjectData(ICStorageElement data) throws CoreException {
		ICStorageElement[] nodes = data.getChildren();
		for (int i = 0; i < nodes.length; ++i) {
			if(PROJECT_DATA_ITEM.equals(nodes[i].getName())){
				ICStorageElement element = nodes[i];
				String dataId = element.getAttribute(PROJECT_DATA_ID);
				if (dataId != null){
					element.removeAttribute(PROJECT_DATA_ID);
					try {
						importStorage(dataId, element);
					} catch(CoreException e){
					}
				}
			}
		}
	}
	
	public void importStorage(String id, ICStorageElement el) throws CoreException{
		CStorage storage = getStorageBase();
		
		storage.importStorage(id, el);
	}
	
	private void copyExtensionInfo(CConfigurationSpecSettings other){
		other.reconsileExtensionSettings(true);
		if(other.fExtMap != null && other.fExtMap.size() != 0){
			fExtMap = (HashMap)other.fExtMap.clone();
			for(Iterator iter = fExtMap.entrySet().iterator(); iter.hasNext();){
				Map.Entry entry = (Map.Entry)iter.next();
				CConfigExtensionReference refs[] = (CConfigExtensionReference[])entry.getValue();
				refs = (CConfigExtensionReference[])refs.clone();
				for(int i = 0; i < refs.length; i++){
					refs[i] = new CConfigExtensionReference(this, refs[i]);
				}
				entry.setValue(refs);
			}
		}
		
		if(other.fExtInfoMap != null && other.fExtInfoMap.size() != 0){
			fExtInfoMap = (HashMap)other.fExtInfoMap.clone();
			for(Iterator iter = fExtInfoMap.entrySet().iterator(); iter.hasNext();){
				Map.Entry entry = (Map.Entry)iter.next();
				CExtensionInfo info = (CExtensionInfo)entry.getValue();
				info = new CExtensionInfo(info);
				entry.setValue(info);
			}
		}
	}
	
	public COwner getCOwner(){
		return fOwner;
	}
	
	public String getCOwnerId(){
		return fOwnerId;
	}
	
	private static boolean usesCache(ICConfigurationDescription cfg){
		CConfigurationData data = ((IInternalCCfgInfo)cfg).getConfigurationData(false);
		if(data instanceof CConfigurationDescriptionCache){
			return ((CConfigurationDescriptionCache)data).isReadOnly();
		}
		return false;
	}
	private Set[] getReferenceDelta(String extPointId){
		if(!usesCache(fCfg)){
			if(CCorePlugin.BINARY_PARSER_UNIQ_ID.equals(extPointId)){
				ICTargetPlatformSetting tp = fCfg.getTargetPlatformSetting();
				if(tp != null){
					String ids[] = tp.getBinaryParserIds();
					ICConfigExtensionReference[] refs = doGet(extPointId);
					return getReferenceDelta(refs, ids);
				}
			} else if(CCorePlugin.ERROR_PARSER_UNIQ_ID.equals(extPointId)){
				ICBuildSetting bs = fCfg.getBuildSetting();
				if(bs != null){
					String ids[] = bs.getErrorParserIDs();
					ICConfigExtensionReference[] refs = doGet(extPointId);
					return getReferenceDelta(refs, ids);
				}
			}
		}
		return null;
	}
	
	
	private Set[] getReferenceDelta(ICConfigExtensionReference refs[], String[] extIds){
		if(refs == null || refs.length == 0){
			if(extIds == null || extIds.length == 0)
				return null;
			return new Set[]{null, new HashSet(Arrays.asList(extIds))};
		} else if(extIds == null || extIds.length == 0){
			Map map = createRefMap(refs);
			return new Set[]{new HashSet(map.values()), null};
		}
			
		Set idSet = new HashSet(Arrays.asList(extIds));
		Set idSetCopy = new HashSet(idSet); 
		Map refsMap = createRefMap(refs);
		
		idSet.removeAll(refsMap.keySet());
		refsMap.keySet().removeAll(idSetCopy);
		
		Set extSet = new HashSet(refsMap.values());
		
		return new Set[]{extSet, idSet};
	}
	
	private Map createRefMap(ICConfigExtensionReference refs[]){
		Map refsMap = new HashMap(refs.length);
		for(int i = 0; i < refs.length; i++){
			refsMap.put(refs[i].getID(), refs[i]);
		}
		return refsMap;
	}
	
	boolean extRefSettingsEqual(CConfigurationSpecSettings other){
		if(fExtMap == null || fExtMap.size() == 0)
			return other.fExtMap == null || other.fExtMap.size() == 0;
		if(other.fExtMap == null || other.fExtMap.size() == 0)
			return false;
		
		if(fExtMap.size() != other.fExtMap.size())
			return false;
		
		for(Iterator iter = fExtMap.entrySet().iterator(); iter.hasNext();){
			Map.Entry entry = (Map.Entry)iter.next();
			ICConfigExtensionReference[] thisRefs = (ICConfigExtensionReference[])entry.getValue();
			ICConfigExtensionReference[] otherRefs = (ICConfigExtensionReference[])other.fExtMap.get(entry.getKey());
			if(otherRefs == null)
				return thisRefs.length == 0;
			if(thisRefs.length != otherRefs.length)
				return false;
			
			Map map = createRefMap(thisRefs);
			map.entrySet().removeAll(createRefMap(otherRefs).entrySet());
			if(map.size() != 0)
				return false;
		}
		
		return true;
	}
	
	public String[] getExternalSettingsProviderIds(){
		return ExtensionContainerFactory.getReferencedProviderIds(fCfg);
	}
	
	public void setExternalSettingsProviderIds(String ids[]){
		ExtensionContainerFactory.setReferencedProviderIds(fCfg, ids);
	}
	
	public void updateExternalSettingsProviders(String[] ids){
		ExtensionContainerFactory.updateReferencedProviderIds(fCfg, ids);
	}
}

Back to the top