mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 06:45:43 +02:00
Fix for the external settings functionality
This commit is contained in:
parent
457924ff1c
commit
333081f3c5
40 changed files with 2463 additions and 1427 deletions
|
@ -507,7 +507,7 @@
|
|||
</page>
|
||||
|
||||
<!--page
|
||||
class="org.eclipse.cdt.ui.newui.Page_ExpPathAndSymb"
|
||||
class="org.eclipse.cdt.managedbuilder.ui.properties.Page_ExpPathAndSymb"
|
||||
id="org.eclipse.cdt.ui.newui.Page_ExpPathAndSymb"
|
||||
category="org.eclipse.cdt.ui.newui.Page_head_general"
|
||||
name="%CDTExpPathSymbolsProperty.name"
|
||||
|
|
|
@ -38,10 +38,10 @@ import org.eclipse.cdt.core.settings.model.ICExternalSetting;
|
|||
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingContainer;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingObject;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
|
@ -340,7 +340,7 @@ class MockConfig implements ICConfigurationDescription {
|
|||
|
||||
public ICExternalSetting createExternalSetting(String[] languageIDs,
|
||||
String[] contentTypeIds, String[] extensions,
|
||||
ICLanguageSettingEntry[] entries) throws WriteAccessException {
|
||||
ICSettingEntry[] entries) throws WriteAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public abstract class ACExclusionFilterEntry extends ACLanguageSettingPathEntry
|
|||
return super.hashCode() + exclusionPatterns.hashCode();
|
||||
}
|
||||
|
||||
public boolean equalsByContents(ICLanguageSettingEntry entry) {
|
||||
public boolean equalsByContents(ICSettingEntry entry) {
|
||||
if(!super.equalsByContents(entry))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public abstract class ACLanguageSettingEntry implements ICLanguageSettingEntry {
|
|||
return fFlags;
|
||||
}
|
||||
|
||||
public boolean equalsByContents(ICLanguageSettingEntry entry) {
|
||||
public boolean equalsByContents(ICSettingEntry entry) {
|
||||
return equalsByName(entry);
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public abstract class ACLanguageSettingEntry implements ICLanguageSettingEntry {
|
|||
return (fFlags & (~ (BUILTIN | READONLY)));
|
||||
}
|
||||
|
||||
public final boolean equalsByName(ICLanguageSettingEntry entry) {
|
||||
public final boolean equalsByName(ICSettingEntry entry) {
|
||||
if(entry == this)
|
||||
return true;
|
||||
|
||||
|
@ -106,8 +106,12 @@ public abstract class ACLanguageSettingEntry implements ICLanguageSettingEntry {
|
|||
return true;
|
||||
}
|
||||
|
||||
public int codeForNameKey(){
|
||||
public final int codeForNameKey(){
|
||||
return getKind() + getByNameMatchFlags() + fName.hashCode();
|
||||
}
|
||||
|
||||
public int codeForContentsKey(){
|
||||
return codeForNameKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,54 +8,23 @@
|
|||
* Contributors:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.settings.model;
|
||||
package org.eclipse.cdt.core.settings.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
import org.eclipse.cdt.core.settings.model.util.CEntriesSet;
|
||||
import org.eclipse.cdt.core.settings.model.util.KindBasedStore;
|
||||
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
|
||||
|
||||
public class CExternalSetting implements ICExternalSetting {
|
||||
static final String ELEMENT_SETTING_INFO = "externalSetting"; //$NON-NLS-1$
|
||||
// private static final String ATTRIBUTE_ID = "id";
|
||||
private static final String ATTRIBUTE_EXTENSIONS = "extensions"; //$NON-NLS-1$
|
||||
private static final String ATTRIBUTE_CONTENT_TYPE_IDS = "contentTypes"; //$NON-NLS-1$
|
||||
private static final String ATTRIBUTE_LANGUAGE_IDS = "languages"; //$NON-NLS-1$
|
||||
// private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
private static final String SEPARATOR = ":"; //$NON-NLS-1$
|
||||
|
||||
public final class CExternalSetting implements ICExternalSetting {
|
||||
// private EntryStore fEntryStore = new EntryStore();
|
||||
private KindBasedStore fStore = new KindBasedStore();
|
||||
private KindBasedStore fStore = new KindBasedStore(false);
|
||||
private String[] fContentTypeIds;
|
||||
private String[] fLanguageIds;
|
||||
private String[] fExtensions;
|
||||
// private String fId;
|
||||
|
||||
public CExternalSetting(ICStorageElement element){
|
||||
// fId = element.getAttribute(ATTRIBUTE_ID);
|
||||
String tmp = element.getAttribute(ATTRIBUTE_LANGUAGE_IDS);
|
||||
if(tmp != null)
|
||||
fLanguageIds = tmp.split(SEPARATOR);
|
||||
|
||||
tmp = element.getAttribute(ATTRIBUTE_CONTENT_TYPE_IDS);
|
||||
if(tmp != null)
|
||||
fContentTypeIds = tmp.split(SEPARATOR);
|
||||
|
||||
tmp = element.getAttribute(ATTRIBUTE_EXTENSIONS);
|
||||
if(tmp != null)
|
||||
fExtensions = tmp.split(ATTRIBUTE_EXTENSIONS);
|
||||
|
||||
List entriesList = LanguageSettingEntriesSerializer.loadEntriesList(element, KindBasedStore.ORED_LANG_ENTRY_KINDS);
|
||||
ICLanguageSettingEntry[] entries = (ICLanguageSettingEntry[])entriesList.toArray(new ICLanguageSettingEntry[entriesList.size()]);
|
||||
initEntryStore(entries);
|
||||
}
|
||||
|
||||
public CExternalSetting(ICExternalSetting base){
|
||||
fLanguageIds = base.getCompatibleLanguageIds();
|
||||
fContentTypeIds = base.getCompatibleContentTypeIds();
|
||||
|
@ -65,7 +34,7 @@ public class CExternalSetting implements ICExternalSetting {
|
|||
initEntryStore(base.getEntries());
|
||||
}
|
||||
|
||||
public CExternalSetting(ICExternalSetting base, ICLanguageSettingEntry entries[]){
|
||||
public CExternalSetting(ICExternalSetting base, ICSettingEntry entries[]){
|
||||
this(base);
|
||||
|
||||
initEntryStore(entries);
|
||||
|
@ -73,7 +42,7 @@ public class CExternalSetting implements ICExternalSetting {
|
|||
|
||||
public CExternalSetting(String[] languageIDs,
|
||||
String[] contentTypeIds, String[] extensions,
|
||||
ICLanguageSettingEntry[] entries){
|
||||
ICSettingEntry[] entries){
|
||||
if(languageIDs != null)
|
||||
fLanguageIds = (String[])languageIDs.clone();
|
||||
if(contentTypeIds != null)
|
||||
|
@ -84,8 +53,8 @@ public class CExternalSetting implements ICExternalSetting {
|
|||
initEntryStore(entries);
|
||||
}
|
||||
|
||||
private void initEntryStore(ICLanguageSettingEntry entries[]){
|
||||
ICLanguageSettingEntry entry;
|
||||
private void initEntryStore(ICSettingEntry entries[]){
|
||||
ICSettingEntry entry;
|
||||
for(int i = 0; i < entries.length; i++){
|
||||
entry = entries[i];
|
||||
|
||||
|
@ -95,7 +64,7 @@ public class CExternalSetting implements ICExternalSetting {
|
|||
// trimToSize();
|
||||
}
|
||||
|
||||
private void addEntry(ICLanguageSettingEntry entry){
|
||||
private void addEntry(ICSettingEntry entry){
|
||||
getEntriesSet(entry.getKind(), true).addEntry(entry);
|
||||
}
|
||||
|
||||
|
@ -135,18 +104,18 @@ public class CExternalSetting implements ICExternalSetting {
|
|||
return null;
|
||||
}
|
||||
|
||||
public ICLanguageSettingEntry[] getEntries(int kind) {
|
||||
public ICSettingEntry[] getEntries(int kind) {
|
||||
CEntriesSet set = getEntriesSet(kind, false);
|
||||
if(set != null)
|
||||
return set.toArray();
|
||||
return new ICLanguageSettingEntry[0];
|
||||
return new ICSettingEntry[0];
|
||||
}
|
||||
|
||||
// public String getId(){
|
||||
// return fId;
|
||||
// }
|
||||
|
||||
public ICLanguageSettingEntry[] getEntries() {
|
||||
public ICSettingEntry[] getEntries() {
|
||||
List result = new ArrayList();
|
||||
int kinds[] = KindBasedStore.getLanguageEntryKinds();
|
||||
for(int i = 0; i < kinds.length; i++){
|
||||
|
@ -155,29 +124,6 @@ public class CExternalSetting implements ICExternalSetting {
|
|||
result.addAll(Arrays.asList(list.toArray()));
|
||||
}
|
||||
|
||||
return (ICLanguageSettingEntry[])result.toArray(new ICLanguageSettingEntry[result.size()]);
|
||||
}
|
||||
|
||||
|
||||
private String composeString(String array[]){
|
||||
StringBuffer buf = new StringBuffer(array[0]);
|
||||
for(int i = 1; i < array.length; i++){
|
||||
buf.append(SEPARATOR).append(array[i]);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public void serialize(ICStorageElement el){
|
||||
if(fLanguageIds != null && fLanguageIds.length != 0)
|
||||
el.setAttribute(ATTRIBUTE_LANGUAGE_IDS, composeString(fLanguageIds));
|
||||
|
||||
if(fContentTypeIds != null && fContentTypeIds.length != 0)
|
||||
el.setAttribute(ATTRIBUTE_CONTENT_TYPE_IDS, composeString(fContentTypeIds));
|
||||
|
||||
|
||||
if(fExtensions != null && fExtensions.length != 0)
|
||||
el.setAttribute(ATTRIBUTE_EXTENSIONS, composeString(fExtensions));
|
||||
|
||||
LanguageSettingEntriesSerializer.serializeEntries(getEntries(), el);
|
||||
return (ICSettingEntry[])result.toArray(new ICSettingEntry[result.size()]);
|
||||
}
|
||||
}
|
|
@ -40,7 +40,7 @@ public final class CMacroEntry extends ACLanguageSettingEntry implements ICMacro
|
|||
return super.hashCode() + fValue.hashCode();
|
||||
}
|
||||
|
||||
public boolean equalsByContents(ICLanguageSettingEntry entry) {
|
||||
public boolean equalsByContents(ICSettingEntry entry) {
|
||||
if(!super.equalsByContents(entry))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -263,7 +263,7 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin
|
|||
ICExternalSetting createExternalSetting(String languageIDs[],
|
||||
String contentTypeIds[],
|
||||
String extensions[],
|
||||
ICLanguageSettingEntry entries[]) throws WriteAccessException;
|
||||
ICSettingEntry entries[]) throws WriteAccessException;
|
||||
|
||||
/**
|
||||
* removes external setting from this configuration
|
||||
|
|
|
@ -17,7 +17,7 @@ public interface ICExternalSetting {
|
|||
|
||||
String[] getCompatibleExtensions();
|
||||
|
||||
ICLanguageSettingEntry[] getEntries(int kind);
|
||||
ICSettingEntry[] getEntries(int kind);
|
||||
|
||||
ICLanguageSettingEntry[] getEntries();
|
||||
ICSettingEntry[] getEntries();
|
||||
}
|
||||
|
|
|
@ -39,9 +39,9 @@ public interface ICSettingEntry {
|
|||
|
||||
boolean isResolved();
|
||||
|
||||
boolean equalsByName(ICLanguageSettingEntry entry);
|
||||
boolean equalsByName(ICSettingEntry entry);
|
||||
|
||||
boolean equalsByContents(ICLanguageSettingEntry entry);
|
||||
boolean equalsByContents(ICSettingEntry entry);
|
||||
|
||||
int getFlags();
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.settings.model.extension;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
public abstract class CExternalSettingProvider {
|
||||
public abstract CExternalSetting[] getSettings(IProject project, ICConfigurationDescription cfg);
|
||||
}
|
|
@ -704,4 +704,27 @@ public class CDataUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Map fillEntriesMapByNameKey(Map map, ICSettingEntry[] entries){
|
||||
if(map == null)
|
||||
map = new LinkedHashMap();
|
||||
|
||||
for(int i = 0; i < entries.length; i++){
|
||||
ICSettingEntry entry = entries[i];
|
||||
map.put(new EntryNameKey(entry), entry);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Map fillEntriesMapByContentsKey(Map map, ICSettingEntry[] entries){
|
||||
if(map == null)
|
||||
map = new LinkedHashMap();
|
||||
|
||||
for(int i = 0; i < entries.length; i++){
|
||||
ICSettingEntry entry = entries[i];
|
||||
map.put(new EntryContentsKey(entry), entry);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
|
||||
public class CEntriesSet {
|
||||
private HashMap fEntriesMap = new HashMap();
|
||||
|
@ -26,7 +26,7 @@ public class CEntriesSet {
|
|||
setEntries(list);
|
||||
}
|
||||
|
||||
public CEntriesSet(ICLanguageSettingEntry entries[]){
|
||||
public CEntriesSet(ICSettingEntry entries[]){
|
||||
setEntries(entries);
|
||||
}
|
||||
|
||||
|
@ -41,16 +41,16 @@ public class CEntriesSet {
|
|||
return entry;
|
||||
}
|
||||
*/
|
||||
public ICLanguageSettingEntry[] toArray() {
|
||||
return (ICLanguageSettingEntry[])fEntriesMap.values().toArray(new ICLanguageSettingEntry[fEntriesMap.size()]);
|
||||
public ICSettingEntry[] toArray() {
|
||||
return (ICSettingEntry[])fEntriesMap.values().toArray(new ICSettingEntry[fEntriesMap.size()]);
|
||||
}
|
||||
|
||||
protected Object getKey(ICLanguageSettingEntry entry){
|
||||
protected Object getKey(ICSettingEntry entry){
|
||||
return entry;
|
||||
}
|
||||
|
||||
public ICLanguageSettingEntry addEntry(ICLanguageSettingEntry entry) {
|
||||
return (ICLanguageSettingEntry)fEntriesMap.put(getKey(entry), entry);
|
||||
public ICSettingEntry addEntry(ICSettingEntry entry) {
|
||||
return (ICSettingEntry)fEntriesMap.put(getKey(entry), entry);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
@ -61,17 +61,17 @@ public class CEntriesSet {
|
|||
clear();
|
||||
for(Iterator iter = list.iterator(); iter.hasNext();){
|
||||
Object obj = iter.next();
|
||||
if(obj instanceof ICLanguageSettingEntry){
|
||||
ICLanguageSettingEntry entry = (ICLanguageSettingEntry)obj;
|
||||
if(obj instanceof ICSettingEntry){
|
||||
ICSettingEntry entry = (ICSettingEntry)obj;
|
||||
addEntry(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setEntries(ICLanguageSettingEntry[] entries) {
|
||||
public void setEntries(ICSettingEntry[] entries) {
|
||||
clear();
|
||||
for(int i = 0; i < entries.length; i++){
|
||||
ICLanguageSettingEntry entry = entries[i];
|
||||
ICSettingEntry entry = entries[i];
|
||||
if(entry != null){
|
||||
addEntry(entry);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.settings.model.util;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ACLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
|
||||
public class EntryContentsKey {
|
||||
ICSettingEntry fEntry;
|
||||
|
||||
public EntryContentsKey(ICSettingEntry entry){
|
||||
fEntry = entry;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if(this == obj)
|
||||
return true;
|
||||
|
||||
if(!(obj instanceof EntryContentsKey))
|
||||
return false;
|
||||
return fEntry.equalsByContents(((EntryContentsKey)obj).fEntry);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return ((ACLanguageSettingEntry)fEntry).codeForContentsKey();
|
||||
}
|
||||
|
||||
public ICSettingEntry getEntry(){
|
||||
return fEntry;
|
||||
}
|
||||
}
|
|
@ -11,12 +11,12 @@
|
|||
package org.eclipse.cdt.core.settings.model.util;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ACLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
|
||||
public class EntryNameKey {
|
||||
ICLanguageSettingEntry fEntry;
|
||||
ICSettingEntry fEntry;
|
||||
|
||||
public EntryNameKey(ICLanguageSettingEntry entry){
|
||||
public EntryNameKey(ICSettingEntry entry){
|
||||
fEntry = entry;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class EntryNameKey {
|
|||
return ((ACLanguageSettingEntry)fEntry).codeForNameKey();
|
||||
}
|
||||
|
||||
public ICLanguageSettingEntry getEntry(){
|
||||
public ICSettingEntry getEntry(){
|
||||
return fEntry;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,17 @@ public class KindBasedStore implements Cloneable {
|
|||
ICLanguageSettingEntry.LIBRARY_FILE,
|
||||
};
|
||||
|
||||
private static final int ALL_ENTRY_KINDS[] = new int[]{
|
||||
ICLanguageSettingEntry.INCLUDE_PATH,
|
||||
ICLanguageSettingEntry.INCLUDE_FILE,
|
||||
ICLanguageSettingEntry.MACRO,
|
||||
ICLanguageSettingEntry.MACRO_FILE,
|
||||
ICLanguageSettingEntry.LIBRARY_PATH,
|
||||
ICLanguageSettingEntry.LIBRARY_FILE,
|
||||
ICLanguageSettingEntry.SOURCE_PATH,
|
||||
ICLanguageSettingEntry.OUTPUT_PATH,
|
||||
};
|
||||
|
||||
// private static final int INEXISTENT_INDEX = -1;
|
||||
|
||||
private Object[] fEntryStorage;
|
||||
|
@ -89,6 +100,10 @@ public class KindBasedStore implements Cloneable {
|
|||
return (int[])LANG_ENTRY_KINDS.clone();
|
||||
}
|
||||
|
||||
public static int[] getAllEntryKinds(){
|
||||
return (int[])ALL_ENTRY_KINDS.clone();
|
||||
}
|
||||
|
||||
private int indexToKind(int index){
|
||||
switch (index){
|
||||
case INDEX_INCLUDE_PATH:
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.model.IMacroFileEntry;
|
|||
import org.eclipse.cdt.core.model.IPathEntry;
|
||||
import org.eclipse.cdt.core.model.ISourceEntry;
|
||||
import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CLibraryFileEntry;
|
||||
|
@ -68,7 +69,6 @@ import org.eclipse.cdt.internal.core.model.APathEntry;
|
|||
import org.eclipse.cdt.internal.core.model.CModelStatus;
|
||||
import org.eclipse.cdt.internal.core.model.PathEntry;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescriptionCache;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo;
|
||||
import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
|
|
|
@ -24,10 +24,10 @@ import org.eclipse.cdt.core.settings.model.ICExternalSetting;
|
|||
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingBase;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
import org.eclipse.cdt.core.settings.model.ICTargetPlatformSetting;
|
||||
|
@ -632,14 +632,15 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC
|
|||
|
||||
public void setReferenceInfo(Map refs) {
|
||||
try {
|
||||
ExternalSettingsManager.getInstance().updateReferenceInfo(this, refs);
|
||||
CConfigurationSpecSettings specs = getSpecSettings();
|
||||
specs.setReferenceInfo(refs);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public ICExternalSetting createExternalSetting(String[] languageIDs,
|
||||
String[] contentTypeIDs, String[] extensions,
|
||||
ICLanguageSettingEntry[] entries) {
|
||||
ICSettingEntry[] entries) {
|
||||
try {
|
||||
return getSpecSettings().createExternalSetting(languageIDs, contentTypeIDs, extensions, entries);
|
||||
} catch (CoreException e) {
|
||||
|
|
|
@ -23,11 +23,11 @@ import org.eclipse.cdt.core.settings.model.ICExternalSetting;
|
|||
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingBase;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingContainer;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingObject;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
|
@ -377,7 +377,7 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData
|
|||
|
||||
public ICExternalSetting createExternalSetting(String[] languageIDs,
|
||||
String[] contentTypeIds, String[] extensions,
|
||||
ICLanguageSettingEntry[] entries) {
|
||||
ICSettingEntry[] entries) {
|
||||
if(!fInitializing)
|
||||
throw ExceptionFactory.createIsReadOnlyException();
|
||||
|
||||
|
|
|
@ -19,11 +19,12 @@ 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.ICLanguageSettingEntry;
|
||||
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;
|
||||
|
@ -40,7 +41,7 @@ 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 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$
|
||||
|
@ -65,8 +66,9 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
private String fId;
|
||||
private StorableCdtVariables fMacros;
|
||||
private StorableEnvironment fEnvironment;
|
||||
private HashMap fRefInfoMap;
|
||||
private CExternalSettingProvider fExtSettingsProvider = new CExternalSettingProvider();
|
||||
// private HashMap fRefInfoMap;
|
||||
private Map fRefMapCache;
|
||||
private CExternalSettingsHolder fExtSettingsProvider = new CExternalSettingsHolder();
|
||||
private boolean fIsModified;
|
||||
private HashMap fSessionPropertiesMap;
|
||||
private HashMap fExtMap;
|
||||
|
@ -94,10 +96,10 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
|
||||
if(StorableCdtVariables.MACROS_ELEMENT_NAME.equals(name)){
|
||||
fMacros = new StorableCdtVariables(child, fCfg.isReadOnly());
|
||||
} else if(ELEMENT_REFERENCES.equals(name)){
|
||||
}/* else if(ELEMENT_REFERENCES.equals(name)){
|
||||
loadReferences(child);
|
||||
} else if (CExternalSettingProvider.ELEMENT_EXT_SETTINGS_CONTAINER.equals(name)){
|
||||
fExtSettingsProvider = new CExternalSettingProvider(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)){
|
||||
|
@ -134,13 +136,13 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
fName = base.fName;
|
||||
fId = base.fId;
|
||||
|
||||
copyRefInfos(base.fRefInfoMap);
|
||||
// copyRefInfos(base.fRefInfoMap);
|
||||
|
||||
if(base.fMacros != null)
|
||||
fMacros = new StorableCdtVariables(base.fMacros, des.isReadOnly());
|
||||
|
||||
if(base.fExtSettingsProvider != null)
|
||||
fExtSettingsProvider = new CExternalSettingProvider(base.fExtSettingsProvider);
|
||||
fExtSettingsProvider = new CExternalSettingsHolder(base.fExtSettingsProvider);
|
||||
|
||||
if(base.fSessionPropertiesMap != null)
|
||||
fSessionPropertiesMap = (HashMap)base.fSessionPropertiesMap.clone();
|
||||
|
@ -154,20 +156,20 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
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));
|
||||
}
|
||||
}
|
||||
// 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)
|
||||
|
@ -181,23 +183,23 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
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 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();){
|
||||
|
@ -333,18 +335,18 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
}
|
||||
|
||||
if(fExtSettingsProvider != null){
|
||||
ICStorageElement child = settings.createChild(CExternalSettingProvider.ELEMENT_EXT_SETTINGS_CONTAINER);
|
||||
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);
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
|
@ -369,50 +371,57 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
}
|
||||
|
||||
public Map getReferenceInfo(){
|
||||
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;
|
||||
if(!fCfg.isReadOnly())
|
||||
return CfgExportSettingContainerFactory.getReferenceMap(fCfg);
|
||||
if(fRefMapCache == null)
|
||||
fRefMapCache = CfgExportSettingContainerFactory.getReferenceMap(fCfg);
|
||||
return 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);
|
||||
// public Map getProjectRefInfoMap(){
|
||||
// if(fRefInfoMap == null || fRefInfoMap.size() == 0)
|
||||
// return new HashMap(0);
|
||||
//
|
||||
// return (Map)fRefInfoMap.clone();
|
||||
// }
|
||||
|
||||
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;
|
||||
// }
|
||||
}
|
||||
|
||||
public void setProjectRefInfoMap(Map map){
|
||||
if(map == null && map.size() == 0)
|
||||
fRefInfoMap = null;
|
||||
|
||||
fRefInfoMap = new HashMap(map);
|
||||
fIsModified = true;
|
||||
}
|
||||
|
||||
/* public void setReferenceInfo(Map 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)
|
||||
|
@ -437,12 +446,12 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
|
|||
|
||||
public ICExternalSetting createExternalSetting(String[] languageIDs,
|
||||
String[] contentTypeIDs, String[] extensions,
|
||||
ICLanguageSettingEntry[] entries) {
|
||||
ICSettingEntry[] entries) {
|
||||
return fExtSettingsProvider.createExternalSetting(languageIDs, contentTypeIDs, extensions, entries);
|
||||
}
|
||||
|
||||
public void removeExternalSetting(ICExternalSetting setting) {
|
||||
fExtSettingsProvider.removeExternalSetting(setting);
|
||||
fExtSettingsProvider.removeExternalSetting((CExternalSetting)setting);
|
||||
}
|
||||
|
||||
public void removeExternalSettings() {
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
* 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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class CExternalSettingChangeEvent {
|
||||
private List fChangeInfoList = new ArrayList();
|
||||
|
||||
CExternalSettingChangeEvent(CExternalSettingsContainerChangeInfo[] infos){
|
||||
fChangeInfoList.addAll(Arrays.asList(infos));
|
||||
}
|
||||
|
||||
// void add(CExternalSettingsContainerChangeInfo info){
|
||||
// fChangeInfoList.add(info);
|
||||
// }
|
||||
|
||||
public CExternalSettingsContainerChangeInfo[] getChangeInfos(){
|
||||
return (CExternalSettingsContainerChangeInfo[])fChangeInfoList.toArray(
|
||||
new CExternalSettingsContainerChangeInfo[fChangeInfoList.size()]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public abstract class CExternalSettingContainerFactory {
|
||||
|
||||
public abstract CExternalSettingsContainer createContainer(
|
||||
String id,
|
||||
IProject project,
|
||||
ICConfigurationDescription cfgDes) throws CoreException;
|
||||
|
||||
public void addListener(ICExternalSettingsListener listener){
|
||||
}
|
||||
|
||||
public void removeListener(ICExternalSettingsListener listener){
|
||||
}
|
||||
|
||||
public void startup(){
|
||||
}
|
||||
|
||||
public void shutdown(){
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*******************************************************************************
|
||||
* 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.List;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.core.settings.model.util.KindBasedStore;
|
||||
import org.eclipse.cdt.core.settings.model.util.LanguageSettingEntriesSerializer;
|
||||
|
||||
public class CExternalSettingSerializer {
|
||||
static final String ELEMENT_SETTING_INFO = "externalSetting"; //$NON-NLS-1$
|
||||
// private static final String ATTRIBUTE_ID = "id";
|
||||
private static final String ATTRIBUTE_EXTENSIONS = "extensions"; //$NON-NLS-1$
|
||||
private static final String ATTRIBUTE_CONTENT_TYPE_IDS = "contentTypes"; //$NON-NLS-1$
|
||||
private static final String ATTRIBUTE_LANGUAGE_IDS = "languages"; //$NON-NLS-1$
|
||||
// private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
private static final String SEPARATOR = ":"; //$NON-NLS-1$
|
||||
|
||||
public static CExternalSetting load(ICStorageElement element){
|
||||
String langIds[] = null;
|
||||
String cTypeIds[] = null;
|
||||
String exts[] = null;
|
||||
String tmp = element.getAttribute(ATTRIBUTE_LANGUAGE_IDS);
|
||||
if(tmp != null)
|
||||
langIds = CDataUtil.stringToArray(tmp, SEPARATOR);
|
||||
|
||||
tmp = element.getAttribute(ATTRIBUTE_CONTENT_TYPE_IDS);
|
||||
if(tmp != null )
|
||||
cTypeIds = CDataUtil.stringToArray(tmp, SEPARATOR);
|
||||
|
||||
tmp = element.getAttribute(ATTRIBUTE_EXTENSIONS);
|
||||
if(tmp != null)
|
||||
exts = CDataUtil.stringToArray(tmp, SEPARATOR);
|
||||
|
||||
List entriesList = LanguageSettingEntriesSerializer.loadEntriesList(element, KindBasedStore.ORED_LANG_ENTRY_KINDS);
|
||||
ICSettingEntry[] entries = (ICSettingEntry[])entriesList.toArray(new ICSettingEntry[entriesList.size()]);
|
||||
return new CExternalSetting(langIds, cTypeIds, exts, entries);
|
||||
}
|
||||
|
||||
public static void store(CExternalSetting setting, ICStorageElement el){
|
||||
String[] tmp;
|
||||
tmp = setting.getCompatibleLanguageIds();
|
||||
if(tmp != null)
|
||||
el.setAttribute(ATTRIBUTE_LANGUAGE_IDS, CDataUtil.arrayToString(tmp, SEPARATOR));
|
||||
|
||||
tmp = setting.getCompatibleContentTypeIds();
|
||||
if(tmp != null)
|
||||
el.setAttribute(ATTRIBUTE_CONTENT_TYPE_IDS, CDataUtil.arrayToString(tmp, SEPARATOR));
|
||||
|
||||
tmp = setting.getCompatibleExtensions();
|
||||
if(tmp != null)
|
||||
el.setAttribute(ATTRIBUTE_EXTENSIONS, CDataUtil.arrayToString(tmp, SEPARATOR));
|
||||
|
||||
LanguageSettingEntriesSerializer.serializeEntries(setting.getEntries(), el);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
|
||||
|
||||
public abstract class CExternalSettingsContainer {
|
||||
|
||||
public abstract CExternalSetting[] getExternalSettings();
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.cdt.internal.core.settings.model.CExternalSettingsManager.CContainerRef;
|
||||
|
||||
public class CExternalSettingsContainerChangeInfo {
|
||||
public static final int CHANGED = 1;
|
||||
|
||||
public static final int CONTAINED_ID = 1;
|
||||
public static final int CONTAINER_CONTENTS = 1 << 1;
|
||||
|
||||
private int fFlags;
|
||||
private String fOldId;
|
||||
private CContainerRef fCRef;
|
||||
// private Map fIncludeMap, fExcludeMap;
|
||||
|
||||
// private class ProjChangeInfo {
|
||||
// private String fProjName;
|
||||
// private Set fCfgIds;
|
||||
// }
|
||||
// private CExternalSettingsContainer fContainer;
|
||||
// private ExtSettingsDelta[] fDeltas;
|
||||
|
||||
CExternalSettingsContainerChangeInfo(int flags,
|
||||
CContainerRef cr,
|
||||
// CExternalSettingsContainer container,
|
||||
String oldId/*,
|
||||
ExtSettingsDelta[] deltas*/
|
||||
){
|
||||
this.fFlags = flags;
|
||||
this.fCRef = cr;
|
||||
// this.fContainer = container;
|
||||
this.fOldId = oldId;
|
||||
// this.fIncludeMap = includeMap;
|
||||
// this.fExcludeMap = exludeMap;
|
||||
// this.fDeltas = deltas;
|
||||
}
|
||||
|
||||
public int getEventType(){
|
||||
return CHANGED;
|
||||
}
|
||||
|
||||
public int getChangeFlags(){
|
||||
return fFlags;
|
||||
}
|
||||
|
||||
// public CExternalSettingsContainer getContainer(){
|
||||
// return fContainer;
|
||||
// }
|
||||
|
||||
// public ExtSettingsDelta[] getDeltas(){
|
||||
// return fDeltas;
|
||||
// }
|
||||
|
||||
public String getOldId(){
|
||||
return fOldId;
|
||||
}
|
||||
|
||||
public String getNewId(){
|
||||
return fCRef.getContainerId();
|
||||
}
|
||||
|
||||
public CContainerRef getContainerInfo(){
|
||||
return fCRef;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
/*******************************************************************************
|
||||
* 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.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingBase;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.core.settings.model.util.EntryContentsKey;
|
||||
import org.eclipse.cdt.core.settings.model.util.KindBasedStore;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CExternalSettinsDeltaCalculator.ExtSettingsDelta;
|
||||
|
||||
public class CExternalSettingsDeltaProcessor {
|
||||
static void applyDelta(ICConfigurationDescription des, ExtSettingsDelta deltas[]){
|
||||
ICResourceDescription rcDess[] = des.getResourceDescriptions();
|
||||
for(int i = 0; i < rcDess.length; i++){
|
||||
ICResourceDescription rcDes = rcDess[i];
|
||||
if(rcDes.getType() == ICSettingBase.SETTING_FOLDER){
|
||||
applyDelta((ICFolderDescription)rcDes, deltas);
|
||||
} else {
|
||||
applyDelta((ICFileDescription)rcDes, deltas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyDelta(ICFileDescription des, ExtSettingsDelta deltas[]){
|
||||
ICLanguageSetting setting = des.getLanguageSetting();
|
||||
if(setting == null)
|
||||
return;
|
||||
for(int i = 0; i < deltas.length; i++){
|
||||
if(isSettingCompatible(setting, deltas[i].fSetting)){
|
||||
applyDelta(setting, deltas[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyDelta(ICFolderDescription des, ExtSettingsDelta deltas[]){
|
||||
ICLanguageSetting settings[] = des.getLanguageSettings();
|
||||
if(settings == null || settings.length == 0)
|
||||
return;
|
||||
|
||||
ICLanguageSetting setting;
|
||||
for(int k = 0; k < settings.length; k++){
|
||||
setting = settings[k];
|
||||
for(int i = 0; i < deltas.length; i++){
|
||||
if(isSettingCompatible(setting, deltas[i].fSetting)){
|
||||
applyDelta(setting, deltas[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyDelta(ICLanguageSetting setting, ExtSettingsDelta delta){
|
||||
int kinds[] = KindBasedStore.getLanguageEntryKinds();
|
||||
int kind;
|
||||
ICLanguageSettingEntry entries[];
|
||||
ICSettingEntry diff[][];
|
||||
for(int i = 0; i < kinds.length; i++){
|
||||
kind = kinds[i];
|
||||
diff = delta.getEntriesDelta(kind);
|
||||
if(diff == null)
|
||||
continue;
|
||||
|
||||
entries = setting.getSettingEntries(kind);
|
||||
List list = calculateUpdatedEntries(entries, diff[0], diff[1]);
|
||||
|
||||
if(list != null)
|
||||
setting.setSettingEntries(kind, list);
|
||||
}
|
||||
}
|
||||
|
||||
private static List calculateUpdatedEntries(ICSettingEntry current[], ICSettingEntry added[], ICSettingEntry removed[]){
|
||||
LinkedHashMap map = new LinkedHashMap();
|
||||
boolean changed = false;
|
||||
if(added != null){
|
||||
CDataUtil.fillEntriesMapByContentsKey(map, added);
|
||||
}
|
||||
if(current != null){
|
||||
CDataUtil.fillEntriesMapByContentsKey(map, current);
|
||||
if(current.length != map.size()){
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
if(map.size() != 0){
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if(removed != null){
|
||||
for(int i = 0; i < removed.length; i++){
|
||||
ICSettingEntry entry = removed[i];
|
||||
EntryContentsKey cKey = new EntryContentsKey(entry);
|
||||
ICSettingEntry cur = (ICSettingEntry)map.get(cKey);
|
||||
if(cur != null && !cur.isBuiltIn()){
|
||||
map.remove(cKey);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed ? new ArrayList(map.values()) : null;
|
||||
}
|
||||
|
||||
private static boolean isSettingCompatible(ICLanguageSetting setting, CExternalSetting provider){
|
||||
String ids[] = provider.getCompatibleLanguageIds();
|
||||
String id;
|
||||
if(ids != null && ids.length > 0){
|
||||
id = setting.getLanguageId();
|
||||
if(id != null){
|
||||
if(contains(ids, id))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ids = provider.getCompatibleContentTypeIds();
|
||||
if(ids != null && ids.length > 0){
|
||||
String[] cTypeIds = setting.getSourceContentTypeIds();
|
||||
if(cTypeIds.length != 0){
|
||||
for(int i = 0; i < cTypeIds.length; i++){
|
||||
id = cTypeIds[i];
|
||||
if(contains(ids, id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ids = provider.getCompatibleExtensions();
|
||||
if(ids != null && ids.length > 0){
|
||||
String [] srcIds = setting.getSourceExtensions();
|
||||
if(srcIds.length != 0){
|
||||
for(int i = 0; i < srcIds.length; i++){
|
||||
id = srcIds[i];
|
||||
if(contains(ids, id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean contains(Object array[], Object value){
|
||||
for(int i = 0; i < array.length; i++){
|
||||
if(array[i].equals(value))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -16,41 +16,41 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
import org.eclipse.cdt.internal.core.settings.model.ExternalSettingsManager.ExtSettingMapKey;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CExternalSettinsDeltaCalculator.ExtSettingMapKey;
|
||||
|
||||
public class CExternalSettingProvider {
|
||||
private Map fSettingsMap;;
|
||||
public class CExternalSettingsHolder extends CExternalSettingsContainer {
|
||||
private Map fSettingsMap;
|
||||
static final String ELEMENT_EXT_SETTINGS_CONTAINER = "externalSettings"; //$NON-NLS-1$
|
||||
static final CExternalSetting[] EMPTY_EXT_SETTINGS_ARRAY = new CExternalSetting[0];
|
||||
|
||||
private boolean fIsModified;
|
||||
|
||||
CExternalSettingProvider(){
|
||||
CExternalSettingsHolder(){
|
||||
|
||||
}
|
||||
|
||||
CExternalSettingProvider(ICStorageElement element){
|
||||
CExternalSettingsHolder(ICStorageElement element){
|
||||
ICStorageElement children[] = element.getChildren();
|
||||
List externalSettingList = null;
|
||||
for(int i = 0; i < children.length; i++){
|
||||
ICStorageElement child = children[i];
|
||||
String name = child.getName();
|
||||
|
||||
if(CExternalSetting.ELEMENT_SETTING_INFO.equals(name)){
|
||||
if(CExternalSettingSerializer.ELEMENT_SETTING_INFO.equals(name)){
|
||||
if(externalSettingList == null)
|
||||
externalSettingList = new ArrayList();
|
||||
|
||||
CExternalSetting setting = new CExternalSetting(child);
|
||||
CExternalSetting setting = CExternalSettingSerializer.load(child);
|
||||
externalSettingList.add(setting);
|
||||
}
|
||||
}
|
||||
|
||||
if(externalSettingList != null && externalSettingList.size() != 0){
|
||||
for(int i = 0; i < externalSettingList.size(); i++){
|
||||
ICExternalSetting setting = (ICExternalSetting)externalSettingList.get(i);
|
||||
CExternalSetting setting = (CExternalSetting)externalSettingList.get(i);
|
||||
createExternalSetting(setting.getCompatibleLanguageIds(),
|
||||
setting.getCompatibleContentTypeIds(),
|
||||
setting.getCompatibleExtensions(),
|
||||
|
@ -59,40 +59,43 @@ public class CExternalSettingProvider {
|
|||
}
|
||||
}
|
||||
|
||||
CExternalSettingProvider(CExternalSettingProvider base){
|
||||
CExternalSettingsHolder(CExternalSettingsHolder base){
|
||||
if(base.fSettingsMap != null)
|
||||
fSettingsMap = new HashMap(base.fSettingsMap);
|
||||
}
|
||||
|
||||
public ICExternalSetting[] getExternalSettings(){
|
||||
public CExternalSetting[] getExternalSettings(){
|
||||
if(fSettingsMap != null)
|
||||
return (ICExternalSetting[])fSettingsMap.values().toArray(new ICExternalSetting[fSettingsMap.size()]);
|
||||
return (CExternalSetting[])fSettingsMap.values().toArray(new CExternalSetting[fSettingsMap.size()]);
|
||||
return EMPTY_EXT_SETTINGS_ARRAY;
|
||||
}
|
||||
|
||||
void setExternallSetting(ICExternalSetting[] settings){
|
||||
void setExternallSettings(CExternalSetting[] settings){
|
||||
removeExternalSettings();
|
||||
|
||||
if(settings != null){
|
||||
for(int i = 0; i < settings.length; i++){
|
||||
ICExternalSetting setting = settings[i];
|
||||
CExternalSetting setting = settings[i];
|
||||
createExternalSetting(setting.getCompatibleLanguageIds(),
|
||||
setting.getCompatibleContentTypeIds(),
|
||||
setting.getCompatibleExtensions(),
|
||||
setting.getEntries());
|
||||
}
|
||||
}
|
||||
fIsModified = true;
|
||||
}
|
||||
|
||||
public ICExternalSetting createExternalSetting(String[] languageIDs,
|
||||
public CExternalSetting createExternalSetting(String[] languageIDs,
|
||||
String[] contentTypeIDs, String[] extensions,
|
||||
ICLanguageSettingEntry[] entries) {
|
||||
ICSettingEntry[] entries) {
|
||||
return createExternalSetting(new CExternalSetting(languageIDs, contentTypeIDs, extensions, entries));
|
||||
}
|
||||
|
||||
private ICExternalSetting createExternalSetting(ICExternalSetting setting){
|
||||
private CExternalSetting createExternalSetting(CExternalSetting setting){
|
||||
ExtSettingMapKey key = new ExtSettingMapKey(setting);
|
||||
CExternalSetting newSetting;
|
||||
if(fSettingsMap != null){
|
||||
CExternalSetting newSetting = (CExternalSetting)fSettingsMap.get(key);
|
||||
newSetting = (CExternalSetting)fSettingsMap.get(key);
|
||||
if(newSetting == null){
|
||||
newSetting = new CExternalSetting(setting);
|
||||
} else {
|
||||
|
@ -101,20 +104,19 @@ public class CExternalSettingProvider {
|
|||
|
||||
fSettingsMap.put(key, newSetting);
|
||||
} else {
|
||||
CExternalSetting newSetting = new CExternalSetting(setting);
|
||||
newSetting = new CExternalSetting(setting);
|
||||
fSettingsMap = new HashMap();
|
||||
fSettingsMap.put(key, newSetting);
|
||||
}
|
||||
fIsModified = true;
|
||||
return setting;
|
||||
|
||||
return newSetting;
|
||||
}
|
||||
|
||||
public void removeExternalSetting(ICExternalSetting setting) {
|
||||
public void removeExternalSetting(CExternalSetting setting) {
|
||||
if(fSettingsMap != null){
|
||||
|
||||
ExtSettingMapKey key = new ExtSettingMapKey(setting);
|
||||
ICExternalSetting settingToRemove = (ICExternalSetting)fSettingsMap.get(key);
|
||||
CExternalSetting settingToRemove = (CExternalSetting)fSettingsMap.get(key);
|
||||
if(setting.equals(settingToRemove)){
|
||||
fSettingsMap.remove(key);
|
||||
fIsModified = true;
|
||||
|
@ -134,8 +136,8 @@ public class CExternalSettingProvider {
|
|||
if(fSettingsMap != null && fSettingsMap.size() != 0){
|
||||
for(Iterator iter = fSettingsMap.values().iterator(); iter.hasNext();){
|
||||
CExternalSetting setting = (CExternalSetting)iter.next();
|
||||
ICStorageElement child = el.createChild(CExternalSetting.ELEMENT_SETTING_INFO);
|
||||
setting.serialize(child);
|
||||
ICStorageElement child = el.createChild(CExternalSettingSerializer.ELEMENT_SETTING_INFO);
|
||||
CExternalSettingSerializer.store(setting, child);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,761 @@
|
|||
/*******************************************************************************
|
||||
* 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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CExternalSettinsDeltaCalculator.ExtSettingsDelta;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
|
||||
public class CExternalSettingsManager implements ICExternalSettingsListener, ICProjectDescriptionListener{
|
||||
private static final int OP_CHANGED = 1;
|
||||
private static final int OP_ADDED = 2;
|
||||
private static final int OP_REMOVED = 3;
|
||||
|
||||
private static final QualifiedName EXTERNAL_SETTING_PROPERTY = new QualifiedName(CCorePlugin.PLUGIN_ID, "externalSettings");
|
||||
private static final String EXTERNAL_SETTING_STORAGE_ID = CCorePlugin.PLUGIN_ID + ".externalSettings";
|
||||
|
||||
private Map fFactoryMap = new HashMap();
|
||||
private static CExternalSettingsManager fInstance;
|
||||
|
||||
private CExternalSettingsManager(){
|
||||
}
|
||||
|
||||
public void startup(){
|
||||
CProjectDescriptionManager.getInstance().addListener(this, CProjectDescriptionEvent.DATA_APPLIED
|
||||
| CProjectDescriptionEvent.LOADDED);
|
||||
}
|
||||
|
||||
public void shutdown(){
|
||||
for(Iterator iter = fFactoryMap.values().iterator(); iter.hasNext();){
|
||||
FactoryDescriptor dr = (FactoryDescriptor)iter.next();
|
||||
dr.shutdown();
|
||||
}
|
||||
fFactoryMap.clear();
|
||||
|
||||
CProjectDescriptionManager.getInstance().removeListener(this);
|
||||
}
|
||||
|
||||
|
||||
public static CExternalSettingsManager getInstance(){
|
||||
if(fInstance == null){
|
||||
fInstance = new CExternalSettingsManager();
|
||||
}
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
public final static class CContainerRef {
|
||||
private String fFactoryId;
|
||||
private String fContainerId;
|
||||
|
||||
public CContainerRef(String factoryId, String containerId){
|
||||
fFactoryId = factoryId;
|
||||
fContainerId = containerId;
|
||||
}
|
||||
|
||||
public String getFactoryId() {
|
||||
return fFactoryId;
|
||||
}
|
||||
|
||||
public String getContainerId() {
|
||||
return fContainerId;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == this)
|
||||
return true;
|
||||
|
||||
if(obj == null)
|
||||
return false;
|
||||
|
||||
if(!(obj instanceof CContainerRef))
|
||||
return false;
|
||||
|
||||
CContainerRef other = (CContainerRef)obj;
|
||||
|
||||
if(!fContainerId.equals(other.fContainerId))
|
||||
return false;
|
||||
|
||||
return fFactoryId.equals(other.fFactoryId);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return fFactoryId.hashCode() + fContainerId.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return fFactoryId.toString() + " : " + fContainerId.toString();
|
||||
}
|
||||
}
|
||||
private static class ContainerDescriptor {
|
||||
private FactoryDescriptor fFactoryDr;
|
||||
// private String fContainerId;
|
||||
// private String fProjectName;
|
||||
// private String fCfgId;
|
||||
private CExternalSettingsHolder fHolder;
|
||||
|
||||
private CExternalSettingsContainer fContainer;
|
||||
|
||||
private ContainerDescriptor(FactoryDescriptor factoryDr,
|
||||
String containerId,
|
||||
IProject project,
|
||||
ICConfigurationDescription cfgDes){
|
||||
fFactoryDr = factoryDr;
|
||||
// fContainerId = containerId;
|
||||
// fProjectName = project.getName();
|
||||
// fCfgId = cfgDes.getId();
|
||||
try {
|
||||
fContainer = fFactoryDr.getFactory().createContainer(containerId, project, cfgDes);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
if(fContainer == null)
|
||||
fContainer = NullContainer.INSTANCE;
|
||||
}
|
||||
|
||||
public CExternalSetting[] getExternalSettings(){
|
||||
if(fHolder == null){
|
||||
fHolder = new CExternalSettingsHolder();
|
||||
fHolder.setExternallSettings(fContainer.getExternalSettings());
|
||||
}
|
||||
return fHolder.getExternalSettings();
|
||||
}
|
||||
|
||||
// public CExternalSettingsContainer getContainer(){
|
||||
// if(fContainer == null){
|
||||
// IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(fProjectName);
|
||||
// try {
|
||||
// fContainer = fFactoryDr.getFactory().createContainer(fContainerId, project, fCfgId);
|
||||
// } catch (CoreException e) {
|
||||
// CCorePlugin.log(e);
|
||||
// }
|
||||
// if(fContainer == null)
|
||||
// fContainer = NullContainer.INSTANCE;
|
||||
// }
|
||||
// return fContainer;
|
||||
// }
|
||||
}
|
||||
|
||||
static class NullContainer extends CExternalSettingsContainer {
|
||||
static final NullContainer INSTANCE = new NullContainer();
|
||||
|
||||
public CExternalSetting[] getExternalSettings() {
|
||||
return new CExternalSetting[0];
|
||||
}
|
||||
}
|
||||
|
||||
private static class NullFactory extends CExternalSettingContainerFactory {
|
||||
static NullFactory INSTANCE = new NullFactory();
|
||||
|
||||
public void addListener(ICExternalSettingsListener listener) {
|
||||
}
|
||||
|
||||
public CExternalSettingsContainer createContainer(String id,
|
||||
IProject project, ICConfigurationDescription cfgDes) throws CoreException {
|
||||
return NullContainer.INSTANCE;
|
||||
}
|
||||
|
||||
public String[] getSupplierIds() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeListener(ICExternalSettingsListener listener) {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
}
|
||||
|
||||
public void startup() {
|
||||
}
|
||||
}
|
||||
|
||||
private class FactoryDescriptor {
|
||||
private CExternalSettingContainerFactory fFactory;
|
||||
private String fId;
|
||||
// private Map fContainerMap;
|
||||
|
||||
private FactoryDescriptor(String id){
|
||||
fId = id;
|
||||
}
|
||||
|
||||
private CExternalSettingContainerFactory getFactory(){
|
||||
if(fFactory == null){
|
||||
fFactory = createFactory(fId);
|
||||
fFactory.startup();
|
||||
fFactory.addListener(CExternalSettingsManager.this);
|
||||
}
|
||||
return fFactory;
|
||||
}
|
||||
|
||||
private CExternalSettingContainerFactory createFactory(String id) {
|
||||
if(id.equals(CfgExportSettingContainerFactory.FACTORY_ID))
|
||||
return CfgExportSettingContainerFactory.getInstance();
|
||||
else if(id.equals(ExtensionContainerFactory.FACTORY_ID))
|
||||
return ExtensionContainerFactory.getInstance();
|
||||
return NullFactory.INSTANCE;
|
||||
}
|
||||
|
||||
public String getId(){
|
||||
return fId;
|
||||
}
|
||||
|
||||
public void shutdown(){
|
||||
if(fFactory != null){
|
||||
fFactory.removeListener(CExternalSettingsManager.this);
|
||||
fFactory.shutdown();
|
||||
fFactory = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private interface ICfgContainer {
|
||||
ICConfigurationDescription getConfguration(boolean write);
|
||||
|
||||
// boolean isWritable();
|
||||
}
|
||||
|
||||
private class CfgContainer implements ICfgContainer {
|
||||
private ICConfigurationDescription fCfgDes;
|
||||
|
||||
CfgContainer(ICConfigurationDescription cfgDes){
|
||||
fCfgDes = cfgDes;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription getConfguration(boolean write) {
|
||||
return fCfgDes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private interface ICRefInfoContainer {
|
||||
CSettingsRefInfo getRefInfo(boolean write);
|
||||
}
|
||||
|
||||
private class CfgContainerRefInfoContainer implements ICRefInfoContainer{
|
||||
private ICfgContainer fCfgContainer;
|
||||
private CSettingsRefInfo fRefInfo;
|
||||
private boolean fWriteWasRequested;
|
||||
|
||||
CfgContainerRefInfoContainer(ICfgContainer container){
|
||||
fCfgContainer = container;
|
||||
}
|
||||
|
||||
public CSettingsRefInfo getRefInfo(boolean write) {
|
||||
if(fRefInfo == null
|
||||
|| (write && !fWriteWasRequested)){
|
||||
ICConfigurationDescription cfg = fCfgContainer.getConfguration(write);
|
||||
fRefInfo = CExternalSettingsManager.this.getRefInfo(cfg, write);
|
||||
fWriteWasRequested |= write;
|
||||
}
|
||||
return fRefInfo;
|
||||
}
|
||||
}
|
||||
|
||||
// private class CfgRefInfoContainer implements ICRefInfoContainer{
|
||||
// private CSettingsRefInfo fRefInfo;
|
||||
// private ICConfigurationDescription fCfgDes;
|
||||
// private boolean fWriteWasRequested;
|
||||
//
|
||||
// CfgRefInfoContainer(ICConfigurationDescription cfg){
|
||||
// fCfgDes = cfg;
|
||||
// }
|
||||
//
|
||||
// public CSettingsRefInfo getRefInfo(boolean write) {
|
||||
// if(fRefInfo == null
|
||||
// || (write && !fWriteWasRequested)){
|
||||
// ICConfigurationDescription cfg = fCfgDes;
|
||||
// fRefInfo = CExternalSettingsManager.this.getRefInfo(cfg, write);
|
||||
// fWriteWasRequested |= write;
|
||||
// }
|
||||
// return fRefInfo;
|
||||
// }
|
||||
// }
|
||||
|
||||
private class HolderContainer {
|
||||
private ICRefInfoContainer fRIContainer;
|
||||
private CRefSettingsHolder fHolder;
|
||||
private boolean fWriteWasRequested;
|
||||
private CContainerRef fCRef;
|
||||
|
||||
HolderContainer(ICRefInfoContainer cr, CContainerRef cref){
|
||||
fRIContainer = cr;
|
||||
fCRef = cref;
|
||||
}
|
||||
|
||||
CRefSettingsHolder getHolder(boolean write){
|
||||
if(fHolder == null
|
||||
|| (write && !fWriteWasRequested)){
|
||||
CSettingsRefInfo ri = fRIContainer.getRefInfo(write);
|
||||
fHolder = ri.get(fCRef);
|
||||
fWriteWasRequested |= write;
|
||||
}
|
||||
return fHolder;
|
||||
}
|
||||
|
||||
void setHolder(CRefSettingsHolder holder){
|
||||
fRIContainer.getRefInfo(true).put(holder);
|
||||
fWriteWasRequested = true;
|
||||
fHolder = holder;
|
||||
}
|
||||
|
||||
void removeHolder(){
|
||||
fWriteWasRequested = true;
|
||||
fHolder = null;
|
||||
fRIContainer.getRefInfo(true).remove(fCRef);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CfgListCfgContainer implements ICfgContainer{
|
||||
private ICfgList fList;
|
||||
private int fNum;
|
||||
|
||||
CfgListCfgContainer(ICfgList list, int num){
|
||||
fList = list;
|
||||
fNum = num;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription getConfguration(boolean write) {
|
||||
return fList.get(fNum, write);
|
||||
}
|
||||
|
||||
// public boolean isWritable() {
|
||||
// return !getConfguration(false).isReadOnly();
|
||||
// }
|
||||
}
|
||||
|
||||
private interface ICfgList {
|
||||
ICConfigurationDescription get(int num, boolean write);
|
||||
|
||||
int size();
|
||||
}
|
||||
|
||||
private static class ProjDesCfgList implements ICfgList{
|
||||
private ICProjectDescription fProjDes;
|
||||
private List fCfgList = new ArrayList();
|
||||
|
||||
public ProjDesCfgList(ICProjectDescription des, Set idSet){
|
||||
fProjDes = des;
|
||||
ICConfigurationDescription[] cfgs = des.getConfigurations();
|
||||
for(int i = 0; i < cfgs.length; i++){
|
||||
if(idSet == null || idSet.contains(cfgs[i].getId()))
|
||||
fCfgList.add(cfgs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWritable(){
|
||||
return !fProjDes.isReadOnly();
|
||||
}
|
||||
|
||||
public ICConfigurationDescription get(int num, boolean write) {
|
||||
if(write && fProjDes.isReadOnly()){
|
||||
makeWritable();
|
||||
}
|
||||
return (ICConfigurationDescription)fCfgList.get(num);
|
||||
}
|
||||
|
||||
private void makeWritable(){
|
||||
ICProjectDescription writeDes = CProjectDescriptionManager.getInstance().getProjectDescription(fProjDes.getProject());
|
||||
fProjDes = writeDes;
|
||||
for(int i = 0; i < fCfgList.size(); i++){
|
||||
ICConfigurationDescription cfg = (ICConfigurationDescription)fCfgList.get(i);
|
||||
cfg = writeDes.getConfigurationById(cfg.getId());
|
||||
if(cfg != null)
|
||||
fCfgList.set(i, cfg);
|
||||
else
|
||||
fCfgList.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
public int getNumForId(String id){
|
||||
for(int i = 0; i < fCfgList.size(); i++){
|
||||
ICConfigurationDescription cfg = (ICConfigurationDescription)fCfgList.get(i);
|
||||
if(id.equals(cfg.getId()))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public ICConfigurationDescription getConfigurationById(String id, boolean write){
|
||||
ICConfigurationDescription cfg = fProjDes.getConfigurationById(id);
|
||||
if(cfg == null)
|
||||
return null;
|
||||
if(write && fProjDes.isReadOnly()){
|
||||
makeWritable();
|
||||
cfg = fProjDes.getConfigurationById(id);
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return fCfgList.size();
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeltaInfo{
|
||||
private boolean fCalculated;
|
||||
private ExtSettingsDelta[] fDeltas;
|
||||
|
||||
void setDelta(ExtSettingsDelta[] deltas){
|
||||
fDeltas = deltas;
|
||||
fCalculated = true;
|
||||
}
|
||||
}
|
||||
|
||||
private FactoryDescriptor getFactoryDescriptor(String id){
|
||||
FactoryDescriptor dr = (FactoryDescriptor)fFactoryMap.get(id);
|
||||
if(dr == null){
|
||||
dr = new FactoryDescriptor(id);
|
||||
fFactoryMap.put(id, dr);
|
||||
}
|
||||
return dr;
|
||||
}
|
||||
|
||||
private ContainerDescriptor createDescriptor(String factoryId,
|
||||
String containerId,
|
||||
IProject project,
|
||||
ICConfigurationDescription cfgDes
|
||||
) {
|
||||
FactoryDescriptor dr = getFactoryDescriptor(factoryId);
|
||||
return new ContainerDescriptor(dr, containerId, project, cfgDes);
|
||||
}
|
||||
|
||||
public void settingsChanged(IProject project, String cfgId,
|
||||
CExternalSettingChangeEvent event) {
|
||||
ProjDesCfgList[] lists = null;
|
||||
CExternalSettingsContainerChangeInfo[] infos = event.getChangeInfos();
|
||||
for(int i = 0; i < infos.length; i++){
|
||||
CExternalSettingsContainerChangeInfo info = infos[i];
|
||||
switch(info.getEventType()){
|
||||
case CExternalSettingsContainerChangeInfo.CHANGED:
|
||||
int flags = info.getChangeFlags();
|
||||
if((flags & CExternalSettingsContainerChangeInfo.CONTAINER_CONTENTS) != 0){
|
||||
if(lists == null)
|
||||
lists = createCfgListsForEvent(project, cfgId);
|
||||
containerContentsChanged(lists, info.getContainerInfo(), null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(lists != null)
|
||||
applyLists(lists);
|
||||
}
|
||||
|
||||
private void applyLists(ProjDesCfgList[] lists){
|
||||
final List list = getModifiedProjDesList(lists);
|
||||
if(list.size() != 0){
|
||||
IWorkspaceRunnable r = new IWorkspaceRunnable(){
|
||||
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
ICProjectDescription des = (ICProjectDescription)list.get(i);
|
||||
CProjectDescriptionManager.getInstance().setProjectDescription(des.getProject(), des, false, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CProjectDescriptionManager.getInstance().runWspModification(r, new NullProgressMonitor());
|
||||
}
|
||||
}
|
||||
|
||||
private List getModifiedProjDesList(ProjDesCfgList[] lists){
|
||||
List list = new ArrayList();
|
||||
for(int i = 0; i < lists.length; i++){
|
||||
if(lists[i].isWritable())
|
||||
list.add(lists[i].fProjDes);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void containerContentsChanged(ProjDesCfgList[] lists, CContainerRef ref, DeltaInfo deltaInfo){
|
||||
for(int i = 0; i < lists.length; i++){
|
||||
containerContentsChanged(lists[i], null, ref, deltaInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private ProjDesCfgList[] createCfgListsForEvent(IProject project, String cfgId){
|
||||
ProjDesCfgList lists[];
|
||||
if(project != null){
|
||||
ProjDesCfgList l = createCfgList(project, cfgId);
|
||||
if(l != null){
|
||||
lists = new ProjDesCfgList[1];
|
||||
lists[0] = l;
|
||||
} else {
|
||||
lists = new ProjDesCfgList[0];
|
||||
}
|
||||
} else {
|
||||
lists = createCfgLists();
|
||||
}
|
||||
return lists;
|
||||
}
|
||||
|
||||
private ProjDesCfgList[] createCfgLists(){
|
||||
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
List list = new ArrayList();
|
||||
for(int i = 0; i < projects.length; i++){
|
||||
ProjDesCfgList l = createCfgList(projects[i], (Set)null);
|
||||
if(l != null)
|
||||
list.add(l);
|
||||
}
|
||||
return (ProjDesCfgList[])list.toArray(new ProjDesCfgList[list.size()]);
|
||||
}
|
||||
|
||||
private ProjDesCfgList createCfgList(IProject project, String cfgId){
|
||||
Set set = null;
|
||||
if(cfgId != null){
|
||||
set = new HashSet();
|
||||
set.add(cfgId);
|
||||
}
|
||||
|
||||
return createCfgList(project, set);
|
||||
}
|
||||
|
||||
private ProjDesCfgList createCfgList(IProject project, Set cfgIdSet){
|
||||
ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
if(des == null)
|
||||
return null;
|
||||
|
||||
return new ProjDesCfgList(des, cfgIdSet);
|
||||
}
|
||||
|
||||
private void containerContentsChanged(ProjDesCfgList list, String[]cfgIds, CContainerRef ref, DeltaInfo deltaInfo){
|
||||
if(cfgIds != null && cfgIds.length != 0){
|
||||
for(int i = 0; i < cfgIds.length; i++){
|
||||
int num = list.getNumForId(cfgIds[i]);
|
||||
if(num >= 0){
|
||||
CfgListCfgContainer cr = new CfgListCfgContainer(list, num);
|
||||
containerContentsChanged(cr, ref, deltaInfo);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
CfgListCfgContainer cr = new CfgListCfgContainer(list, i);
|
||||
containerContentsChanged(cr, ref, deltaInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void containerContentsChanged(ICfgContainer cr, CContainerRef ref, DeltaInfo deltaInfo){
|
||||
processContainerChange(OP_CHANGED, cr, ref, deltaInfo);
|
||||
}
|
||||
|
||||
private void processContainerChange(int op,
|
||||
ICfgContainer cr,
|
||||
CContainerRef crInfo,
|
||||
DeltaInfo deltaInfo){
|
||||
processContainerChange(op, cr, new CfgContainerRefInfoContainer(cr), crInfo, deltaInfo);
|
||||
}
|
||||
|
||||
private void processContainerChange(int op,
|
||||
ICfgContainer cr,
|
||||
ICRefInfoContainer riContainer,
|
||||
CContainerRef crInfo,
|
||||
DeltaInfo deltaInfo){
|
||||
|
||||
ICConfigurationDescription cfg = cr.getConfguration(false);
|
||||
|
||||
ExtSettingsDelta[] deltas = checkExternalSettingsChange(op,
|
||||
cfg.getProjectDescription().getProject(), cfg, riContainer, crInfo);
|
||||
|
||||
if(deltas != null){
|
||||
applyDeltas(cr, deltas);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void applyDeltas(ICfgContainer cr, ExtSettingsDelta[] deltas){
|
||||
CExternalSettingsDeltaProcessor.applyDelta(cr.getConfguration(true), deltas);
|
||||
}
|
||||
|
||||
private static class RefInfoContainer{
|
||||
CSettingsRefInfo fRefInfo;
|
||||
int fInstanceId;
|
||||
|
||||
RefInfoContainer(CSettingsRefInfo ri, int id){
|
||||
fRefInfo = ri;
|
||||
fInstanceId = id;
|
||||
}
|
||||
}
|
||||
|
||||
private CSettingsRefInfo getRefInfo(ICConfigurationDescription cfg, boolean write){
|
||||
if(write && cfg.isReadOnly())
|
||||
throw new IllegalArgumentException("writable ref info is requested for the read only config");
|
||||
|
||||
RefInfoContainer cr = (RefInfoContainer)cfg.getSessionProperty(EXTERNAL_SETTING_PROPERTY);
|
||||
CSettingsRefInfo ri;
|
||||
boolean setCr = false;
|
||||
if(cr == null){
|
||||
ri = load(cfg);
|
||||
if(ri == null)
|
||||
ri = new CSettingsRefInfo();
|
||||
setCr = true;
|
||||
} else if (write && cr.fInstanceId != cfg.hashCode()){
|
||||
ri = new CSettingsRefInfo(cr.fRefInfo);
|
||||
setCr = true;
|
||||
} else {
|
||||
ri = cr.fRefInfo;
|
||||
setCr = false;
|
||||
}
|
||||
|
||||
if(setCr){
|
||||
cr = new RefInfoContainer(ri, cfg.hashCode());
|
||||
cfg.setSessionProperty(EXTERNAL_SETTING_PROPERTY, cr);
|
||||
}
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
private CSettingsRefInfo load(ICConfigurationDescription cfg){
|
||||
try {
|
||||
ICStorageElement el = cfg.getStorage(EXTERNAL_SETTING_STORAGE_ID, false);
|
||||
if(el != null){
|
||||
CSettingsRefInfo ri = new CSettingsRefInfo(el);
|
||||
return ri;
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handleEvent(CProjectDescriptionEvent event) {
|
||||
switch(event.getEventType()){
|
||||
case CProjectDescriptionEvent.DATA_APPLIED:
|
||||
checkStore(event.getNewCProjectDescription());
|
||||
break;
|
||||
case CProjectDescriptionEvent.LOADDED:
|
||||
ICProjectDescription des = update(event.getNewCProjectDescription());
|
||||
if(des.isModified()){
|
||||
try {
|
||||
CProjectDescriptionManager.getInstance().setProjectDescription(des.getProject(), des);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStore(ICProjectDescription des){
|
||||
ICConfigurationDescription[] cfgs = des.getConfigurations();
|
||||
for(int i = 0; i < cfgs.length; i++){
|
||||
checkStore(cfgs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStore(ICConfigurationDescription cfg){
|
||||
RefInfoContainer cr = (RefInfoContainer)cfg.getSessionProperty(EXTERNAL_SETTING_PROPERTY);
|
||||
if(cr != null/* && cr.fInstanceId != cfg.hashCode()*/){
|
||||
store(cfg, cr.fRefInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void store(ICConfigurationDescription cfg, CSettingsRefInfo ri){
|
||||
try {
|
||||
ICStorageElement el = cfg.getStorage(EXTERNAL_SETTING_STORAGE_ID, true);
|
||||
el.clear();
|
||||
ri.serialize(el);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addContainer(ICConfigurationDescription cfg, CContainerRef cr){
|
||||
CfgContainer ccr = new CfgContainer(cfg);
|
||||
processContainerChange(OP_ADDED, ccr, cr, null);
|
||||
}
|
||||
|
||||
public void removeContainer(ICConfigurationDescription cfg, CContainerRef cr){
|
||||
CfgContainer ccr = new CfgContainer(cfg);
|
||||
processContainerChange(OP_REMOVED, ccr, cr, null);
|
||||
}
|
||||
|
||||
public CContainerRef[] getReferences(ICConfigurationDescription cfg, String factoryId){
|
||||
CSettingsRefInfo info = getRefInfo(cfg, false);
|
||||
return info.getReferences(factoryId);
|
||||
}
|
||||
|
||||
public ICProjectDescription update(ICProjectDescription des){
|
||||
ProjDesCfgList list = new ProjDesCfgList(des, null);
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
CfgListCfgContainer cfgCr = new CfgListCfgContainer(list, i);
|
||||
CfgContainerRefInfoContainer ric = new CfgContainerRefInfoContainer(cfgCr);
|
||||
CContainerRef[] refs = ric.getRefInfo(false).getReferences();
|
||||
for(int k = 0; k < refs.length; k++){
|
||||
containerContentsChanged(cfgCr, refs[k], null);
|
||||
}
|
||||
}
|
||||
return list.fProjDes;
|
||||
}
|
||||
|
||||
private ExtSettingsDelta[] checkExternalSettingsChange(int op,
|
||||
IProject proj,
|
||||
ICConfigurationDescription cfgDes,
|
||||
ICRefInfoContainer riContainer,
|
||||
CContainerRef cr){
|
||||
HolderContainer hCr = new HolderContainer(riContainer, cr);
|
||||
CRefSettingsHolder holder = hCr.getHolder(false);
|
||||
if(holder == null && op == OP_ADDED){
|
||||
holder = new CRefSettingsHolder(cr);
|
||||
hCr.setHolder(holder);
|
||||
}
|
||||
|
||||
if(holder == null)
|
||||
return null;
|
||||
|
||||
ExtSettingsDelta[] deltas = reconsile(proj, cfgDes, op != OP_REMOVED, hCr, cr);
|
||||
|
||||
if(op == OP_REMOVED)
|
||||
hCr.removeHolder();
|
||||
return deltas;
|
||||
}
|
||||
|
||||
private ExtSettingsDelta[] reconsile(IProject proj, ICConfigurationDescription cfgDes, boolean add, HolderContainer hCr, CContainerRef cr){
|
||||
// if(holder.isReconsiled())
|
||||
// return;
|
||||
CExternalSetting[] newSettings = null;
|
||||
CExternalSetting[] oldSettings = hCr.getHolder(false).getExternalSettings();
|
||||
if(add){
|
||||
ContainerDescriptor cdr = createDescriptor(cr.getFactoryId(), cr.getContainerId(), proj, cfgDes);
|
||||
newSettings = cdr.getExternalSettings();
|
||||
}
|
||||
|
||||
ExtSettingsDelta[] deltas = getDeltaCalculator().getSettingChange(newSettings, oldSettings);
|
||||
if(deltas != null){
|
||||
CRefSettingsHolder holder = hCr.getHolder(true);
|
||||
holder.setExternallSettings(newSettings);
|
||||
holder.setReconsiled(true);
|
||||
}
|
||||
return deltas;
|
||||
}
|
||||
|
||||
private CExternalSettinsDeltaCalculator getDeltaCalculator(){
|
||||
return CExternalSettinsDeltaCalculator.getInstance();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,282 @@
|
|||
/*******************************************************************************
|
||||
* 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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.core.settings.model.util.KindBasedStore;
|
||||
|
||||
class CExternalSettinsDeltaCalculator {
|
||||
static private CExternalSettinsDeltaCalculator fInstance;
|
||||
|
||||
private CExternalSettinsDeltaCalculator(){
|
||||
}
|
||||
|
||||
public static CExternalSettinsDeltaCalculator getInstance(){
|
||||
if(fInstance == null)
|
||||
fInstance = new CExternalSettinsDeltaCalculator();
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
|
||||
static class ExtSettingsDelta {
|
||||
CExternalSetting fSetting;
|
||||
boolean fAdded;
|
||||
KindBasedStore fEntryChangeStore;
|
||||
|
||||
ExtSettingsDelta(CExternalSetting setting){
|
||||
fSetting = setting;
|
||||
fEntryChangeStore = new KindBasedStore();
|
||||
}
|
||||
|
||||
ExtSettingsDelta(CExternalSetting setting, boolean added){
|
||||
fSetting = setting;
|
||||
fAdded = added;
|
||||
}
|
||||
|
||||
boolean isChange(){
|
||||
return fEntryChangeStore != null;
|
||||
}
|
||||
|
||||
boolean isAdded(){
|
||||
return fAdded;
|
||||
}
|
||||
|
||||
CExternalSetting getSetting(){
|
||||
return fSetting;
|
||||
}
|
||||
|
||||
ICSettingEntry[][] getEntriesDelta(int kind){
|
||||
if(fEntryChangeStore != null)
|
||||
return (ICSettingEntry[][])fEntryChangeStore.get(kind);
|
||||
ICSettingEntry [] entries = fSetting.getEntries(kind);
|
||||
if(entries == null || entries.length == 0)
|
||||
return null;
|
||||
|
||||
ICSettingEntry[][] delta = new ICSettingEntry[2][];
|
||||
if(fAdded)
|
||||
delta[0] = entries;
|
||||
else
|
||||
delta[1] = entries;
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
ICSettingEntry[][] getEntriesDelta(){
|
||||
int kinds[] = KindBasedStore.getLanguageEntryKinds();
|
||||
List added = new ArrayList();
|
||||
List removed = new ArrayList();
|
||||
for(int i = 0; i < kinds.length; i++){
|
||||
ICSettingEntry[][] d = getEntriesDelta(kinds[i]);
|
||||
if(d == null)
|
||||
continue;
|
||||
|
||||
if(d[0] != null){
|
||||
added.addAll(Arrays.asList(d[0]));
|
||||
}
|
||||
if(d[1] != null){
|
||||
removed.addAll(Arrays.asList(d[1]));
|
||||
}
|
||||
}
|
||||
|
||||
ICSettingEntry[][] delta = new ICSettingEntry[2][];
|
||||
|
||||
if(added.size() != 0){
|
||||
delta[0] = (ICSettingEntry[])added.toArray(new ICSettingEntry[added.size()]);
|
||||
}
|
||||
if(removed.size() != 0){
|
||||
delta[1] = (ICSettingEntry[])removed.toArray(new ICSettingEntry[removed.size()]);
|
||||
}
|
||||
|
||||
return delta;
|
||||
}
|
||||
}
|
||||
|
||||
static class ExtSettingMapKey {
|
||||
private ICExternalSetting fSetting;
|
||||
public ExtSettingMapKey(ICExternalSetting setting){
|
||||
fSetting = setting;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == this)
|
||||
return true;
|
||||
|
||||
if(!(obj instanceof ExtSettingMapKey))
|
||||
return false;
|
||||
|
||||
ExtSettingMapKey other = (ExtSettingMapKey)obj;
|
||||
return settingsMatch(fSetting, other.fSetting);
|
||||
}
|
||||
public int hashCode() {
|
||||
return code(fSetting.getCompatibleLanguageIds())
|
||||
+ code(fSetting.getCompatibleContentTypeIds())
|
||||
+ code(fSetting.getCompatibleExtensions());
|
||||
}
|
||||
|
||||
private int code(String[] arr){
|
||||
if(arr == null || arr.length == 0)
|
||||
return 0;
|
||||
|
||||
int code = 0;
|
||||
|
||||
for(int i = 0; i < arr.length; i++){
|
||||
code += arr[i].hashCode();
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
public ICExternalSetting getSetting(){
|
||||
return fSetting;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static ExtSettingsDelta createDelta(CExternalSetting setting1, CExternalSetting setting2){
|
||||
|
||||
int kind;
|
||||
int kinds[] = KindBasedStore.getAllEntryKinds();
|
||||
ExtSettingsDelta extDelta = null;
|
||||
for(int i = 0; i < kinds.length; i++){
|
||||
kind = kinds[i];
|
||||
ICSettingEntry entries1[] = setting1.getEntries(kind);
|
||||
ICSettingEntry entries2[] = setting2.getEntries(kind);
|
||||
Map map1 = CDataUtil.fillEntriesMapByContentsKey(new LinkedHashMap(), entries1);
|
||||
Map map2 = CDataUtil.fillEntriesMapByContentsKey(new LinkedHashMap(), entries2);
|
||||
Map map1Copy = new LinkedHashMap(map1);
|
||||
// Set set1 = new HashSet(Arrays.asList(entries1));
|
||||
// Set set2 = new HashSet(Arrays.asList(entries2));
|
||||
// Set set1Copy = new HashSet(set1);
|
||||
map1.keySet().removeAll(map2.keySet());
|
||||
map2.keySet().removeAll(map1Copy.keySet());
|
||||
|
||||
ICSettingEntry entriesAdded[] = null, entriesRemoved[] = null;
|
||||
|
||||
if(map1.size() != 0)
|
||||
entriesAdded = (ICSettingEntry[])map1.values().toArray(new ICSettingEntry[map1.size()]);
|
||||
|
||||
if(map2.size() != 0)
|
||||
entriesRemoved = (ICSettingEntry[])map2.values().toArray(new ICSettingEntry[map2.size()]);
|
||||
|
||||
if(entriesAdded == null && entriesRemoved == null)
|
||||
continue;
|
||||
|
||||
if(extDelta == null){
|
||||
extDelta = new ExtSettingsDelta(setting1);
|
||||
}
|
||||
extDelta.fEntryChangeStore.put(kind, new ICSettingEntry[][]{entriesAdded, entriesRemoved});
|
||||
}
|
||||
|
||||
return extDelta;
|
||||
}
|
||||
|
||||
static boolean settingsMatch(ICExternalSetting setting1, ICExternalSetting setting2) {
|
||||
if(setting1.equals(setting2))
|
||||
return true;
|
||||
|
||||
return settingsMatch(setting1,
|
||||
setting2.getCompatibleLanguageIds(),
|
||||
setting2.getCompatibleContentTypeIds(),
|
||||
setting2.getCompatibleExtensions());
|
||||
}
|
||||
|
||||
static boolean settingsMatch(ICExternalSetting setting,
|
||||
String languageIDs[], String contentTypeIDs[], String extensions[]){
|
||||
if(!Arrays.equals(setting.getCompatibleLanguageIds(), languageIDs))
|
||||
return false;
|
||||
if(!Arrays.equals(setting.getCompatibleContentTypeIds(), contentTypeIDs))
|
||||
return false;
|
||||
if(!Arrays.equals(setting.getCompatibleExtensions(), extensions))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Map toSettingsKeyMap(ICExternalSetting[] settings){
|
||||
Map map = new HashMap();
|
||||
for(int i = 0; i < settings.length; i++){
|
||||
if(map.put(new ExtSettingMapKey(settings[i]), settings[i]) != null)
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
ExtSettingsDelta[] getSettingChange(CExternalSetting newSettings[],
|
||||
CExternalSetting oldSettings[]){
|
||||
|
||||
|
||||
if(newSettings == null || newSettings.length == 0)
|
||||
return createDeltas(oldSettings, false);
|
||||
if(oldSettings == null || oldSettings.length == 0)
|
||||
return createDeltas(newSettings, true);
|
||||
|
||||
List deltaList = new ArrayList();
|
||||
|
||||
Map newMap= toSettingsKeyMap(newSettings);
|
||||
Map oldMap = toSettingsKeyMap(oldSettings);
|
||||
for(Iterator iter = newMap.entrySet().iterator(); iter.hasNext();){
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
CExternalSetting newSetting = (CExternalSetting)entry.getValue();
|
||||
CExternalSetting oldSetting = (CExternalSetting)oldMap.remove(entry.getKey());
|
||||
if(oldSetting == null){
|
||||
deltaList.add(new ExtSettingsDelta(newSetting, true));
|
||||
} else {
|
||||
ExtSettingsDelta delta = createDelta(newSetting, oldSetting);
|
||||
if(delta != null)
|
||||
deltaList.add(delta);
|
||||
}
|
||||
}
|
||||
|
||||
for(Iterator iter = oldMap.values().iterator(); iter.hasNext();){
|
||||
CExternalSetting oldSettng = (CExternalSetting)iter.next();
|
||||
deltaList.add(new ExtSettingsDelta(oldSettng, false));
|
||||
}
|
||||
|
||||
if(deltaList.size() == 0)
|
||||
return null;
|
||||
return (ExtSettingsDelta[])deltaList.toArray(new ExtSettingsDelta[deltaList.size()]);
|
||||
}
|
||||
|
||||
private static ExtSettingsDelta[] createDeltas(CExternalSetting settings[], boolean added){
|
||||
if(settings == null || settings.length == 0)
|
||||
return null;
|
||||
|
||||
ExtSettingsDelta deltas[] = new ExtSettingsDelta[settings.length];
|
||||
for(int i = 0; i < settings.length; i++){
|
||||
deltas[i] = new ExtSettingsDelta(settings[i], added);
|
||||
}
|
||||
|
||||
return deltas;
|
||||
}
|
||||
|
||||
Set calculateUpdatedEntries(ICSettingEntry current[], ICSettingEntry added[], ICSettingEntry removed[]){
|
||||
// EntryComparator comparator = new EntryComparator();
|
||||
LinkedHashSet set = new LinkedHashSet();
|
||||
set.addAll(Arrays.asList(current));
|
||||
set.addAll(Arrays.asList(added));
|
||||
set.removeAll(Arrays.asList(removed));
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingObject;
|
||||
import org.eclipse.cdt.internal.core.settings.model.ExternalSettingsManager.ExtSettingsDelta;
|
||||
|
||||
class CProjectDescriptionDelta implements ICDescriptionDelta {
|
||||
private List fChildList = new ArrayList();
|
||||
|
@ -26,7 +25,6 @@ class CProjectDescriptionDelta implements ICDescriptionDelta {
|
|||
private int fAddedLanguageEntriesKinds;
|
||||
private int fRemovedLanguageEntriesKinds;
|
||||
private int fReorderedLanguageEntriesKinds;
|
||||
private ExtSettingsDelta[] fExtSettingsDeltas;
|
||||
|
||||
private static final int KIND_MASK = 3;
|
||||
private static final int FLAGS_OFFSET = 2;
|
||||
|
@ -146,13 +144,4 @@ class CProjectDescriptionDelta implements ICDescriptionDelta {
|
|||
else
|
||||
removeChangeFlags(SETTING_ENTRIES);
|
||||
}
|
||||
|
||||
public ExtSettingsDelta[] getExtSettingsDeltas(){
|
||||
return fExtSettingsDeltas;
|
||||
}
|
||||
|
||||
public void setExtSettingsDeltas(ExtSettingsDelta[] deltas){
|
||||
fExtSettingsDeltas = deltas;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.eclipse.cdt.core.model.CModelException;
|
|||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFileDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
|
@ -53,6 +54,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
|||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingBase;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingObject;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingsStorage;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
|
@ -76,6 +78,7 @@ import org.eclipse.cdt.internal.core.CConfigBasedDescriptorManager;
|
|||
import org.eclipse.cdt.internal.core.envvar.ContributedEnvironment;
|
||||
import org.eclipse.cdt.internal.core.model.CElementDelta;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CExternalSettinsDeltaCalculator.ExtSettingsDelta;
|
||||
import org.eclipse.core.filesystem.EFS;
|
||||
import org.eclipse.core.filesystem.IFileStore;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -321,6 +324,8 @@ public class CProjectDescriptionManager {
|
|||
fDescriptorManager.startup();
|
||||
}
|
||||
|
||||
CExternalSettingsManager.getInstance().startup();
|
||||
|
||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
Job rcJob = new Job(SettingsModelMessages.getString("CProjectDescriptionManager.0")){ //$NON-NLS-1$
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
|
@ -362,6 +367,8 @@ public class CProjectDescriptionManager {
|
|||
}
|
||||
|
||||
public void shutdown(){
|
||||
CExternalSettingsManager.getInstance().shutdown();
|
||||
|
||||
if(fDescriptorManager != null){
|
||||
fDescriptorManager.shutdown();
|
||||
}
|
||||
|
@ -458,13 +465,13 @@ public class CProjectDescriptionManager {
|
|||
|
||||
des = getLoaddedDescription(project);
|
||||
|
||||
ICProjectDescription updatedDes = ExternalSettingsManager.getInstance().updateReferencedSettings(des);
|
||||
if(updatedDes != des){
|
||||
try {
|
||||
setProjectDescription(project, updatedDes);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
// ICProjectDescription updatedDes = ExternalSettingsManager.getInstance().updateReferencedSettings(des);
|
||||
// if(updatedDes != des){
|
||||
// try {
|
||||
// setProjectDescription(project, updatedDes);
|
||||
// } catch (CoreException e) {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2080,7 +2087,7 @@ public class CProjectDescriptionManager {
|
|||
}
|
||||
|
||||
|
||||
ExternalSettingsManager.getInstance().calculateCfgExtSettingsDelta(delta);
|
||||
calculateCfgExtSettingsDelta(delta);
|
||||
|
||||
int drFlags = calculateDescriptorFlags(newCfg, oldCfg);
|
||||
if(drFlags != 0)
|
||||
|
@ -2090,6 +2097,78 @@ public class CProjectDescriptionManager {
|
|||
return delta.isEmpty() ? null : delta;
|
||||
}
|
||||
|
||||
private void calculateCfgExtSettingsDelta(CProjectDescriptionDelta delta){
|
||||
ICConfigurationDescription newDes = (ICConfigurationDescription)delta.getNewSetting();
|
||||
ICConfigurationDescription oldDes = (ICConfigurationDescription)delta.getOldSetting();
|
||||
ExtSettingsDelta[] deltas = getSettingChange(newDes, oldDes);
|
||||
int flags = 0;
|
||||
int addedRemoved = ICDescriptionDelta.EXTERNAL_SETTINGS_ADDED | ICDescriptionDelta.EXTERNAL_SETTINGS_REMOVED;
|
||||
if(deltas != null ){
|
||||
for(int i = 0; i < deltas.length; i++){
|
||||
ICSettingEntry[][] d = deltas[i].getEntriesDelta();
|
||||
if(d[0] != null)
|
||||
flags |= ICDescriptionDelta.EXTERNAL_SETTINGS_ADDED;
|
||||
if(d[1] != null)
|
||||
flags |= ICDescriptionDelta.EXTERNAL_SETTINGS_REMOVED;
|
||||
|
||||
if((flags & (addedRemoved)) == addedRemoved)
|
||||
break;
|
||||
}
|
||||
// delta.setExtSettingsDeltas(deltas);
|
||||
if(flags != 0)
|
||||
delta.addChangeFlags(flags);
|
||||
}
|
||||
|
||||
int cfgRefFlags = calcRefChangeFlags(newDes, oldDes);
|
||||
if(cfgRefFlags != 0)
|
||||
delta.addChangeFlags(cfgRefFlags);
|
||||
}
|
||||
|
||||
private int calcRefChangeFlags(ICConfigurationDescription newDes, ICConfigurationDescription oldDes){
|
||||
Map newMap = newDes != null ? newDes.getReferenceInfo() : null;
|
||||
Map oldMap = oldDes != null ? oldDes.getReferenceInfo() : null;
|
||||
|
||||
int flags = 0;
|
||||
if(newMap == null || newMap.size() == 0){
|
||||
if(oldMap != null && oldMap.size() != 0){
|
||||
flags = ICDescriptionDelta.CFG_REF_REMOVED;
|
||||
}
|
||||
} else {
|
||||
if(oldMap == null || oldMap.size() == 0){
|
||||
flags = ICDescriptionDelta.CFG_REF_ADDED;
|
||||
} else {
|
||||
boolean stop = false;
|
||||
for(Iterator iter = newMap.entrySet().iterator(); iter.hasNext();){
|
||||
Map.Entry newEntry = (Map.Entry)iter.next();
|
||||
Object newProj = newEntry.getKey();
|
||||
Object newCfg = newEntry.getValue();
|
||||
Object oldCfg = oldMap.remove(newProj);
|
||||
if(!newCfg.equals(oldCfg)){
|
||||
flags |= ICDescriptionDelta.CFG_REF_ADDED;
|
||||
if(oldCfg != null){
|
||||
flags |= ICDescriptionDelta.CFG_REF_REMOVED;
|
||||
stop = true;
|
||||
}
|
||||
if(stop)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!oldMap.isEmpty())
|
||||
flags |= ICDescriptionDelta.CFG_REF_REMOVED;
|
||||
}
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
private ExtSettingsDelta[] getSettingChange(ICConfigurationDescription newDes, ICConfigurationDescription oldDes){
|
||||
CExternalSetting[] newSettings = newDes != null ? (CExternalSetting[])newDes.getExternalSettings() : null;
|
||||
CExternalSetting[] oldSettings = oldDes != null ? (CExternalSetting[])oldDes.getExternalSettings() : null;
|
||||
return CExternalSettinsDeltaCalculator.getInstance().getSettingChange(newSettings, oldSettings);
|
||||
}
|
||||
|
||||
private CProjectDescriptionDelta createDelta(ICFolderDescription newFo, ICFolderDescription oldFo){
|
||||
CProjectDescriptionDelta delta = new CProjectDescriptionDelta(newFo, oldFo);
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CExternalSettingsManager.CContainerRef;
|
||||
|
||||
public class CRefSettingsHolder extends CExternalSettingsHolder {
|
||||
private static final String ATTR_FACTORY_ID = "factoryId";
|
||||
private static final String ATTR_CONTAINER_ID = "containerId";
|
||||
private CContainerRef fContainerRef;
|
||||
private boolean fIsReconsiled;
|
||||
|
||||
public CRefSettingsHolder(CContainerRef ref) {
|
||||
super();
|
||||
|
||||
fContainerRef = ref;
|
||||
}
|
||||
|
||||
public CRefSettingsHolder(CRefSettingsHolder base) {
|
||||
super(base);
|
||||
|
||||
fContainerRef = base.fContainerRef;
|
||||
fIsReconsiled = base.fIsReconsiled;
|
||||
}
|
||||
|
||||
public CRefSettingsHolder(ICStorageElement element) {
|
||||
super(element);
|
||||
|
||||
String factoryId = element.getAttribute(ATTR_FACTORY_ID);
|
||||
String containerId = element.getAttribute(ATTR_CONTAINER_ID);
|
||||
|
||||
fContainerRef = new CContainerRef(factoryId, containerId);
|
||||
}
|
||||
|
||||
public CContainerRef getContainerInfo(){
|
||||
return fContainerRef;
|
||||
}
|
||||
|
||||
public boolean isReconsiled(){
|
||||
return fIsReconsiled;
|
||||
}
|
||||
|
||||
public void setReconsiled(boolean s){
|
||||
fIsReconsiled = s;
|
||||
}
|
||||
|
||||
public void serialize(ICStorageElement el) {
|
||||
super.serialize(el);
|
||||
el.setAttribute(ATTR_FACTORY_ID, fContainerRef.getFactoryId());
|
||||
el.setAttribute(ATTR_CONTAINER_ID, fContainerRef.getContainerId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*******************************************************************************
|
||||
* 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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CExternalSettingsManager.CContainerRef;
|
||||
|
||||
class CSettingsRefInfo {
|
||||
final static String ELEMENT_REFERENCE_INFO = "referenceInfo"; //$NON-NLS-1$
|
||||
private HashMap fESHolderMap = new HashMap();
|
||||
|
||||
CSettingsRefInfo(){
|
||||
}
|
||||
|
||||
CSettingsRefInfo(ICStorageElement el){
|
||||
|
||||
ICStorageElement children[] = el.getChildren();
|
||||
for(int i = 0; i < children.length; i++){
|
||||
ICStorageElement child = children[i];
|
||||
String name = child.getName();
|
||||
if(CRefSettingsHolder.ELEMENT_EXT_SETTINGS_CONTAINER.equals(name)){
|
||||
CRefSettingsHolder h = new CRefSettingsHolder(child);
|
||||
CContainerRef r = h.getContainerInfo();
|
||||
fESHolderMap.put(r, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CSettingsRefInfo(CSettingsRefInfo base){
|
||||
fESHolderMap = (HashMap)base.fESHolderMap.clone();
|
||||
for(Iterator iter = fESHolderMap.entrySet().iterator(); iter.hasNext();){
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
CRefSettingsHolder h = (CRefSettingsHolder)entry.getValue();
|
||||
h = new CRefSettingsHolder(h);
|
||||
entry.setValue(h);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Map getContainerMapForFactory(String id){
|
||||
// Map map = new HashMap();
|
||||
// for(Iterator iter = fESHolderMap.entrySet().iterator(); iter.hasNext();){
|
||||
// Map.Entry entry = (Map.Entry)iter.next();
|
||||
// CContainerRef r = (CContainerRef)entry.getKey();
|
||||
// if(r.getFactoryId().equals(id))
|
||||
// map.put(r.getContainerId(), r);
|
||||
// }
|
||||
// return map;
|
||||
// }
|
||||
|
||||
// Map getContainerMapCopy(){
|
||||
// return new HashMap(fESHolderMap);
|
||||
// }
|
||||
|
||||
CContainerRef[] getReferences(String factoryId){
|
||||
List list = new ArrayList();
|
||||
for(Iterator iter = fESHolderMap.keySet().iterator(); iter.hasNext();){
|
||||
CContainerRef r = (CContainerRef)iter.next();
|
||||
if(r.getFactoryId().equals(factoryId))
|
||||
list.add(r);
|
||||
}
|
||||
return (CContainerRef[])list.toArray(new CContainerRef[list.size()]);
|
||||
}
|
||||
|
||||
CContainerRef[] getReferences(){
|
||||
return (CContainerRef[])fESHolderMap.keySet().toArray(new CContainerRef[fESHolderMap.size()]);
|
||||
}
|
||||
|
||||
CRefSettingsHolder get(CContainerRef cRef){
|
||||
return (CRefSettingsHolder)fESHolderMap.get(cRef);
|
||||
}
|
||||
|
||||
void serialize(ICStorageElement element){
|
||||
for(Iterator iter = fESHolderMap.entrySet().iterator(); iter.hasNext();){
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
CRefSettingsHolder h = (CRefSettingsHolder)entry.getValue();
|
||||
ICStorageElement child = element.createChild(CRefSettingsHolder.ELEMENT_EXT_SETTINGS_CONTAINER);
|
||||
h.serialize(child);
|
||||
}
|
||||
}
|
||||
|
||||
void put(CRefSettingsHolder holder){
|
||||
fESHolderMap.put(holder.getContainerInfo(), holder);
|
||||
}
|
||||
|
||||
CRefSettingsHolder remove(CContainerRef cRef){
|
||||
return (CRefSettingsHolder)fESHolderMap.remove(cRef);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,287 @@
|
|||
/*******************************************************************************
|
||||
* 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.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
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.internal.core.settings.model.CExternalSettingsManager.CContainerRef;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CExternalSettingsManager.NullContainer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.ListenerList;
|
||||
|
||||
public class CfgExportSettingContainerFactory extends
|
||||
CExternalSettingContainerFactory implements ICProjectDescriptionListener {
|
||||
static final String FACTORY_ID = CCorePlugin.PLUGIN_ID + ".cfg.export.settings.sipplier";
|
||||
private static final char DELIMITER = ';';
|
||||
private ListenerList fListenerList;
|
||||
|
||||
private static CfgExportSettingContainerFactory fInstance;
|
||||
|
||||
private CfgExportSettingContainerFactory(){
|
||||
}
|
||||
|
||||
public static CfgExportSettingContainerFactory getInstance(){
|
||||
if(fInstance == null)
|
||||
fInstance = new CfgExportSettingContainerFactory();
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
public void startup(){
|
||||
CProjectDescriptionManager.getInstance().addListener(this,
|
||||
CProjectDescriptionEvent.APPLIED
|
||||
| CProjectDescriptionEvent.LOADDED);
|
||||
}
|
||||
|
||||
public void shutdown(){
|
||||
CProjectDescriptionManager.getInstance().removeListener(this);
|
||||
}
|
||||
|
||||
private class CfgRefContainer extends CExternalSettingsContainer {
|
||||
private String fProjName, fCfgId;
|
||||
|
||||
CfgRefContainer(String projName, String cfgId){
|
||||
fProjName = projName;
|
||||
fCfgId = cfgId;
|
||||
}
|
||||
|
||||
public CExternalSetting[] getExternalSettings() {
|
||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(fProjName);
|
||||
if(project.exists() && project.isOpen()){
|
||||
ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
|
||||
if(des != null){
|
||||
ICConfigurationDescription cfg = fCfgId.length() != 0 ?
|
||||
des.getConfigurationById(fCfgId) : des.getActiveConfiguration();
|
||||
|
||||
if(cfg != null){
|
||||
ICExternalSetting[] ies = cfg.getExternalSettings();
|
||||
if(ies instanceof CExternalSetting[])
|
||||
return (CExternalSetting[])ies;
|
||||
CExternalSetting[] es = new CExternalSetting[ies.length];
|
||||
System.arraycopy(ies, 0, es, 0, es.length);
|
||||
return es;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new CExternalSetting[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CExternalSettingsContainer createContainer(String id,
|
||||
IProject project, ICConfigurationDescription cfgDes) {
|
||||
try {
|
||||
String[] r = parseId(id);
|
||||
return new CfgRefContainer(r[0], r[1]);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return new NullContainer();
|
||||
}
|
||||
|
||||
private static void createReference(ICConfigurationDescription cfg, String projName, String cfgId){
|
||||
CContainerRef cr = createContainerRef(projName, cfgId);
|
||||
CExternalSettingsManager.getInstance().addContainer(cfg, cr);
|
||||
}
|
||||
|
||||
private static void removeReference(ICConfigurationDescription cfg, String projName, String cfgId){
|
||||
CContainerRef cr = createContainerRef(projName, cfgId);
|
||||
CExternalSettingsManager.getInstance().removeContainer(cfg, cr);
|
||||
}
|
||||
|
||||
private static CContainerRef createContainerRef(String projName, String cfgId){
|
||||
return new CContainerRef(FACTORY_ID, createId(projName, cfgId));
|
||||
}
|
||||
|
||||
public static Map getReferenceMap(ICConfigurationDescription cfg){
|
||||
CContainerRef[] refs = CExternalSettingsManager.getInstance().getReferences(cfg, FACTORY_ID);
|
||||
Map map = new HashMap();
|
||||
for(int i = 0; i < refs.length; i++){
|
||||
try {
|
||||
String[] r = parseId(refs[i].getContainerId());
|
||||
map.put(r[0], r[1]);
|
||||
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void setReferenceMap(ICConfigurationDescription cfg, Map map){
|
||||
Map cur = getReferenceMap(cfg);
|
||||
Map newCopy = new HashMap(map);
|
||||
|
||||
for(Iterator iter = cur.entrySet().iterator(); iter.hasNext();){
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
Object projName = entry.getKey();
|
||||
if(newCopy.containsKey(projName) && entry.getValue().equals(newCopy.get(projName))){
|
||||
iter.remove();
|
||||
newCopy.remove(projName);
|
||||
}
|
||||
}
|
||||
for(Iterator iter = cur.entrySet().iterator(); iter.hasNext();){
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
removeReference(cfg, (String)entry.getKey(), (String)entry.getValue());
|
||||
}
|
||||
for(Iterator iter = newCopy.entrySet().iterator(); iter.hasNext();){
|
||||
Map.Entry entry = (Map.Entry)iter.next();
|
||||
createReference(cfg, (String)entry.getKey(), (String)entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private static String createId(String projName, String cfgId){
|
||||
return new StringBuffer().append(projName).append(DELIMITER).append(cfgId).toString();
|
||||
}
|
||||
private static String[] parseId(String id) throws CoreException {
|
||||
if(id == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
String projName, cfgId;
|
||||
int index = id.indexOf(DELIMITER);
|
||||
if(index != -1){
|
||||
projName = id.substring(0, index);
|
||||
cfgId = id.substring(index + 1);
|
||||
} else {
|
||||
projName = id;
|
||||
cfgId = "";
|
||||
}
|
||||
|
||||
if((projName = projName.trim()).length() == 0)
|
||||
throw ExceptionFactory.createCoreException("invalid id: project name not specified");
|
||||
|
||||
return new String[]{projName, cfgId};
|
||||
}
|
||||
|
||||
public void addListener(ICExternalSettingsListener listener){
|
||||
if(fListenerList == null)
|
||||
fListenerList = new ListenerList();
|
||||
|
||||
fListenerList.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(ICExternalSettingsListener listener){
|
||||
if(fListenerList == null)
|
||||
return;
|
||||
|
||||
fListenerList.remove(listener);
|
||||
}
|
||||
|
||||
public void handleEvent(CProjectDescriptionEvent event) {
|
||||
switch(event.getEventType()){
|
||||
case CProjectDescriptionEvent.LOADDED:
|
||||
case CProjectDescriptionEvent.APPLIED:
|
||||
String[] ids = getContainerIds(event.getProjectDelta());
|
||||
if(ids.length != 0){
|
||||
CExternalSettingsContainerChangeInfo[] changeInfos =
|
||||
new CExternalSettingsContainerChangeInfo[ids.length];
|
||||
|
||||
for(int i = 0; i < changeInfos.length; i++){
|
||||
changeInfos[i] = new CExternalSettingsContainerChangeInfo(
|
||||
CExternalSettingsContainerChangeInfo.CONTAINER_CONTENTS,
|
||||
new CContainerRef(FACTORY_ID, ids[i]),
|
||||
null);
|
||||
}
|
||||
notifySettingsChange(changeInfos);
|
||||
}
|
||||
}
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private String[] getContainerIds(ICDescriptionDelta delta){
|
||||
if(delta == null)
|
||||
return new String[0];
|
||||
int deltaKind = delta.getDeltaKind();
|
||||
|
||||
List cfgIds = new ArrayList();
|
||||
switch(deltaKind){
|
||||
case ICDescriptionDelta.ADDED:
|
||||
case ICDescriptionDelta.REMOVED:
|
||||
ICProjectDescription des = (ICProjectDescription)delta.getSetting();
|
||||
ICConfigurationDescription[] cfgs = des.getConfigurations();
|
||||
if(cfgs.length != 0){
|
||||
for(int i = 0; i < cfgs.length; i++){
|
||||
cfgIds.add(cfgs[i].getId());
|
||||
}
|
||||
cfgIds.add("");
|
||||
}
|
||||
|
||||
case ICDescriptionDelta.CHANGED:
|
||||
ICDescriptionDelta[] children = delta.getChildren();
|
||||
collectCfgIds(children, cfgIds);
|
||||
if((delta.getChangeFlags() & ICDescriptionDelta.ACTIVE_CFG) != 0)
|
||||
cfgIds.add("");
|
||||
}
|
||||
|
||||
|
||||
String[] ids = new String[cfgIds.size()];
|
||||
if(ids.length != 0){
|
||||
String projName = ((ICProjectDescription)delta.getSetting()).getProject().getName();
|
||||
for(int i = 0; i < ids.length; i++){
|
||||
ids[i] = createId(projName, (String)cfgIds.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
public Collection collectCfgIds(ICDescriptionDelta[] deltas, Collection c){
|
||||
if(c == null)
|
||||
c = new ArrayList();
|
||||
for(int i = 0; i < deltas.length; i++){
|
||||
ICDescriptionDelta delta = deltas[i];
|
||||
int deltaKind = delta.getDeltaKind();
|
||||
|
||||
switch(deltaKind){
|
||||
case ICDescriptionDelta.ADDED:
|
||||
case ICDescriptionDelta.REMOVED:
|
||||
c.add(delta.getSetting().getId());
|
||||
break;
|
||||
case ICDescriptionDelta.CHANGED:
|
||||
int changeFlags = delta.getChangeFlags();
|
||||
if((changeFlags &
|
||||
(ICDescriptionDelta.EXTERNAL_SETTINGS_ADDED
|
||||
| ICDescriptionDelta.EXTERNAL_SETTINGS_REMOVED)) != 0){
|
||||
c.add(delta.getSetting().getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
protected void notifySettingsChange(CExternalSettingsContainerChangeInfo[] infos){
|
||||
if(fListenerList == null)
|
||||
return;
|
||||
|
||||
if(infos.length == 0)
|
||||
return;
|
||||
|
||||
CExternalSettingChangeEvent event = new CExternalSettingChangeEvent(infos);
|
||||
|
||||
Object[] listeners = fListenerList.getListeners();
|
||||
for(int i = 0; i < listeners.length; i++){
|
||||
((ICExternalSettingsListener)listeners[i]).settingsChanged(null, null, event);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
/*******************************************************************************
|
||||
* 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.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CExternalSettingProvider;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
public class ExtensionContainerFactory extends CExternalSettingContainerFactory {
|
||||
static final String FACTORY_ID = CCorePlugin.PLUGIN_ID + ".extension.container.factory";
|
||||
private static final String EXTENSION_ID = CCorePlugin.PLUGIN_ID + ".externalSettingsProvider";
|
||||
|
||||
private static ExtensionContainerFactory fInstance;
|
||||
private Map fDescriptorMap;
|
||||
|
||||
private static class NullProvider extends CExternalSettingProvider {
|
||||
private static final NullProvider INSTANCE = new NullProvider();
|
||||
|
||||
public CExternalSetting[] getSettings(IProject project, ICConfigurationDescription cfg) {
|
||||
return new CExternalSetting[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class CESContainer extends CExternalSettingsContainer {
|
||||
private CExternalSetting[] fSettings;
|
||||
|
||||
CESContainer(CExternalSetting[] settings){
|
||||
fSettings = (CExternalSetting[])settings.clone();
|
||||
}
|
||||
|
||||
public CExternalSetting[] getExternalSettings() {
|
||||
return (CExternalSetting[])fSettings.clone();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class CExtensionSettingProviderDescriptor {
|
||||
private static final String PROVIDER = "provider";
|
||||
private static final String CLASS = "class";
|
||||
|
||||
private IExtension fExtension;
|
||||
private IConfigurationElement fProviderElement;
|
||||
private String fId;
|
||||
private CExternalSettingProvider fProvider;
|
||||
|
||||
CExtensionSettingProviderDescriptor(IExtension extension){
|
||||
fId = extension.getUniqueIdentifier();
|
||||
fExtension = extension;
|
||||
}
|
||||
|
||||
public String getId(){
|
||||
return fId;
|
||||
}
|
||||
|
||||
private CExternalSettingProvider getProvider(){
|
||||
if(fProvider == null){
|
||||
try {
|
||||
fProvider = createProvider();
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
if(fProvider == null){
|
||||
fProvider = NullProvider.INSTANCE;
|
||||
}
|
||||
}
|
||||
return fProvider;
|
||||
}
|
||||
|
||||
CExternalSettingsContainer getContainer(IProject project, ICConfigurationDescription cfg){
|
||||
return new CESContainer(getProvider().getSettings(project, cfg));
|
||||
}
|
||||
|
||||
CExternalSettingProvider createProvider() throws CoreException{
|
||||
IConfigurationElement el = getProviderElement();
|
||||
if(el != null){
|
||||
Object obj = el.createExecutableExtension(CLASS);
|
||||
if(obj instanceof CExternalSettingProvider){
|
||||
return (CExternalSettingProvider)obj;
|
||||
} else
|
||||
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("invalid setting provider class specified"));
|
||||
}
|
||||
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("provider element not specified"));
|
||||
}
|
||||
|
||||
private IConfigurationElement getProviderElement(){
|
||||
if(fProviderElement == null)
|
||||
fProviderElement = getProviderElement(fExtension);
|
||||
return fProviderElement;
|
||||
}
|
||||
|
||||
private static IConfigurationElement getProviderElement(IExtension ext){
|
||||
IConfigurationElement els[] = ext.getConfigurationElements();
|
||||
for(int i = 0; i < els.length; i++){
|
||||
IConfigurationElement el = els[i];
|
||||
String name = el.getName();
|
||||
if(PROVIDER.equals(name))
|
||||
return el;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Map getProviderDescriptorMap(){
|
||||
if(fDescriptorMap == null){
|
||||
initProviderInfoSynch();
|
||||
}
|
||||
return fDescriptorMap;
|
||||
}
|
||||
|
||||
private synchronized void initProviderInfoSynch(){
|
||||
if(fDescriptorMap != null)
|
||||
return;
|
||||
|
||||
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_ID);
|
||||
IExtension exts[] = extensionPoint.getExtensions();
|
||||
fDescriptorMap = new HashMap();
|
||||
|
||||
for(int i = 0; i < exts.length; i++){
|
||||
CExtensionSettingProviderDescriptor dr = new CExtensionSettingProviderDescriptor(exts[i]);
|
||||
fDescriptorMap.put(dr.getId(), dr);
|
||||
}
|
||||
}
|
||||
|
||||
private ExtensionContainerFactory(){
|
||||
}
|
||||
|
||||
public static ExtensionContainerFactory getInstance(){
|
||||
if(fInstance == null){
|
||||
fInstance = new ExtensionContainerFactory();
|
||||
}
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
public CExternalSettingsContainer createContainer(String id,
|
||||
IProject project, ICConfigurationDescription cfgDes) throws CoreException {
|
||||
CExtensionSettingProviderDescriptor dr = (CExtensionSettingProviderDescriptor)getProviderDescriptorMap().get(id);
|
||||
if(dr != null)
|
||||
return dr.getContainer(project, cfgDes);
|
||||
return CExternalSettingsManager.NullContainer.INSTANCE;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,17 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.core.resources.IProject;
|
||||
|
||||
public interface ICExternalSettingsListener {
|
||||
void settingsChanged(IProject project, String cfgId, CExternalSettingChangeEvent event);
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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 org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||
|
||||
class ProjectRefInfo {
|
||||
private final static String ATTRIBUTE_REF_PROJECT = "project"; //$NON-NLS-1$
|
||||
private final static String ATTRIBUTE_REF_CFG_ID = "configuration"; //$NON-NLS-1$
|
||||
final static String ELEMENT_REFERENCE = "reference"; //$NON-NLS-1$
|
||||
private String fProjectName;
|
||||
private String fCfgId;
|
||||
private CExternalSettingProvider fProvider;
|
||||
private boolean fIsSynchronized;
|
||||
|
||||
ProjectRefInfo(ICStorageElement el){
|
||||
fProjectName = el.getAttribute(ATTRIBUTE_REF_PROJECT);
|
||||
fCfgId = el.getAttribute(ATTRIBUTE_REF_CFG_ID);
|
||||
if(fCfgId == null)
|
||||
fCfgId = ""; //$NON-NLS-1$
|
||||
|
||||
ICStorageElement children[] = el.getChildren();
|
||||
for(int i = 0; i < children.length; i++){
|
||||
ICStorageElement child = children[i];
|
||||
String name = child.getName();
|
||||
if(CExternalSettingProvider.ELEMENT_EXT_SETTINGS_CONTAINER.equals(name)){
|
||||
fProvider = new CExternalSettingProvider(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProjectRefInfo(String projName, String cfgId){
|
||||
fProjectName = projName;
|
||||
fCfgId = cfgId;
|
||||
}
|
||||
|
||||
ProjectRefInfo(ProjectRefInfo base){
|
||||
fProjectName = base.fProjectName;
|
||||
fCfgId = base.fCfgId;
|
||||
|
||||
if(base.fProvider != null)
|
||||
fProvider = new CExternalSettingProvider(base.fProvider);
|
||||
|
||||
fIsSynchronized = base.fIsSynchronized;
|
||||
}
|
||||
|
||||
void serialize(ICStorageElement element){
|
||||
element.setAttribute(ATTRIBUTE_REF_PROJECT, fProjectName);
|
||||
if(fCfgId.length() != 0)
|
||||
element.setAttribute(ATTRIBUTE_REF_CFG_ID, fCfgId);
|
||||
|
||||
if(fProvider != null){
|
||||
ICStorageElement child = element.createChild(CExternalSettingProvider.ELEMENT_EXT_SETTINGS_CONTAINER);
|
||||
fProvider.serialize(child);
|
||||
}
|
||||
}
|
||||
|
||||
public String getProjectName() {
|
||||
return fProjectName;
|
||||
}
|
||||
|
||||
public String getCfgId() {
|
||||
return fCfgId;
|
||||
}
|
||||
|
||||
public CExternalSettingProvider getProvider() {
|
||||
if(fProvider == null)
|
||||
fProvider = new CExternalSettingProvider();
|
||||
return fProvider;
|
||||
}
|
||||
|
||||
public void setProvider(CExternalSettingProvider provider) {
|
||||
fProvider = provider;
|
||||
}
|
||||
|
||||
public boolean isSynchronized(){
|
||||
return fIsSynchronized;
|
||||
}
|
||||
|
||||
public void setSynchronized(boolean s){
|
||||
fIsSynchronized = s;
|
||||
}
|
||||
|
||||
}
|
|
@ -100,7 +100,7 @@ public class SetCProjectDescriptionOperation extends CModelOperation {
|
|||
|
||||
cProject.close();
|
||||
|
||||
ExternalSettingsManager.getInstance().updateDepentents(delta);
|
||||
// ExternalSettingsManager.getInstance().updateDepentents(delta);
|
||||
|
||||
try {
|
||||
((InternalXmlStorageElement)fNewDescriptionCache.getRootStorageElement()).setReadOnly(true);
|
||||
|
|
|
@ -146,7 +146,7 @@ public abstract class AbstractExportTab extends AbstractCPropertyTab {
|
|||
boolean x = i != -1;
|
||||
boolean y = x;
|
||||
if (x) {
|
||||
ICLanguageSettingEntry ent = ((ExtData)(table.getItem(i).getData())).entry;
|
||||
ICSettingEntry ent = ((ExtData)(table.getItem(i).getData())).entry;
|
||||
if (ent.isReadOnly()) x = false;
|
||||
if (ent.isBuiltIn() || ent.isReadOnly()) y = false;
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public abstract class AbstractExportTab extends AbstractCPropertyTab {
|
|||
return;
|
||||
}
|
||||
for (int i=0; i<vals.length; i++) {
|
||||
ICLanguageSettingEntry[] ents = vals[i].getEntries(getKind());
|
||||
ICSettingEntry[] ents = vals[i].getEntries(getKind());
|
||||
if (ents == null || ents.length == 0) continue;
|
||||
for (int j=0; j<ents.length; j++) {
|
||||
lst.add(new ExtData(vals[i], ents[j]));
|
||||
|
@ -249,8 +249,8 @@ public abstract class AbstractExportTab extends AbstractCPropertyTab {
|
|||
getKind(), names_ls, names_ts, null, isWsp);
|
||||
if (dlg.open()) {
|
||||
ent[0] = doEdit(dlg.text1.trim(), dlg.text2.trim(), dlg.check2);
|
||||
ICLanguageSettingEntry[] ls = old.setting.getEntries(getKind());
|
||||
ICLanguageSettingEntry[] ls2 = new ICLanguageSettingEntry[ls.length];
|
||||
ICSettingEntry[] ls = old.setting.getEntries(getKind());
|
||||
ICSettingEntry[] ls2 = new ICLanguageSettingEntry[ls.length];
|
||||
for (int x=0; x<ls.length; x++)
|
||||
if (ls[x].equals(old.entry)) ls2[x] = ent[0];
|
||||
else ls2[x] = ls[x];
|
||||
|
@ -268,7 +268,7 @@ public abstract class AbstractExportTab extends AbstractCPropertyTab {
|
|||
if (checked[t] || its[t] == null) continue;
|
||||
old = (ExtData)(its[t].getData());
|
||||
if (old.entry.isReadOnly() || old.entry.isBuiltIn()) continue;
|
||||
ICLanguageSettingEntry[] ls = old.setting.getEntries(getKind());
|
||||
ICSettingEntry[] ls = old.setting.getEntries(getKind());
|
||||
ArrayList lst = new ArrayList();
|
||||
outer:
|
||||
for (int x=0; x<ls.length; x++) {
|
||||
|
@ -401,9 +401,9 @@ outer:
|
|||
*/
|
||||
static class ExtData {
|
||||
ICExternalSetting setting;
|
||||
ICLanguageSettingEntry entry;
|
||||
ICSettingEntry entry;
|
||||
|
||||
ExtData(ICExternalSetting _s, ICLanguageSettingEntry _e) {
|
||||
ExtData(ICExternalSetting _s, ICSettingEntry _e) {
|
||||
setting = _s;
|
||||
entry = _e;
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
ICExternalSetting[] vals = getResDesc().getConfiguration().getExternalSettings();
|
||||
if (!(vals == null || vals.length == 0)) {
|
||||
for (int i=0; i<vals.length; i++) {
|
||||
ICLanguageSettingEntry[] ents = vals[i].getEntries(getKind());
|
||||
ICSettingEntry[] ents = vals[i].getEntries(getKind());
|
||||
if (ents == null || ents.length == 0) continue;
|
||||
for (int j=0; j<ents.length; j++)
|
||||
exported.add(ents[j]);
|
||||
|
|
Loading…
Add table
Reference in a new issue