1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

external settings mechanism fixes

This commit is contained in:
Mikhail Sennikovsky 2007-04-19 17:22:26 +00:00
parent 7e9fd939f3
commit b7c570bd81
6 changed files with 139 additions and 3 deletions

View file

@ -45,6 +45,12 @@ public class ExternalSettingsProviderTests extends BaseTestCase{
ICLanguageSetting ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true);
ICLanguageSettingEntry[] entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
assertEquals(0, entries.length);
ICSourceEntry[] sourceEntries = cfgDes.getSourceEntries();
ICSourceEntry[] expectedSourceEntries = new ICSourceEntry[]{
new CSourceEntry(project.getFullPath(), null, ICSettingEntry.RESOLVED)
};
assertEquals(1, sourceEntries.length);
assertTrue(Arrays.equals(expectedSourceEntries, sourceEntries));
String[] extPIds = new String[]{CTestPlugin.PLUGIN_ID + ".testExtSettingsProvider"};
cfgDes.setExternalSettingsProviderIds(extPIds);
assertEquals(extPIds.length, cfgDes.getExternalSettingsProviderIds().length);
@ -56,6 +62,13 @@ public class ExternalSettingsProviderTests extends BaseTestCase{
new CIncludePathEntry("ip_b", 0),
};
assertTrue(Arrays.equals(expectedEntries, entries));
sourceEntries = cfgDes.getSourceEntries();
assertEquals(2, sourceEntries.length);
ICSourceEntry[] newExpectedSourceEntries = new ICSourceEntry[]{
new CSourceEntry(project.getFullPath().append("sp_a"), null, 0),
new CSourceEntry(project.getFullPath().append("sp_b"), null, 0),
};
assertTrue(Arrays.equals(newExpectedSourceEntries, sourceEntries));
ICLanguageSettingEntry[] newEntries = new ICLanguageSettingEntry[3];
newEntries[0] = expectedEntries[1];

View file

@ -117,7 +117,7 @@ public final class CExternalSetting implements ICExternalSetting {
public ICSettingEntry[] getEntries() {
List result = new ArrayList();
int kinds[] = KindBasedStore.getLanguageEntryKinds();
int kinds[] = KindBasedStore.getAllEntryKinds();
for(int i = 0; i < kinds.length; i++){
CEntriesSet list = getEntriesSet(kinds[i], false);
if(list != null)

View file

@ -20,7 +20,7 @@ public final class CSourceEntry extends ACExclusionFilterEntry implements ICSour
}
public CSourceEntry(IFolder rc, IPath exclusionPatterns[], int flags) {
super(rc, exclusionPatterns, flags);
super(rc, exclusionPatterns, flags | VALUE_WORKSPACE_PATH);
}
public CSourceEntry(String value, IPath exclusionPatterns[], int flags) {

View file

@ -14,19 +14,26 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.settings.model.CExternalSetting;
import org.eclipse.cdt.core.settings.model.CSourceEntry;
import org.eclipse.cdt.core.settings.model.ICBuildSetting;
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.ICOutputEntry;
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.WriteAccessException;
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;
import org.eclipse.core.runtime.CoreException;
public class CExternalSettingsDeltaProcessor {
static boolean applyDelta(ICConfigurationDescription des, ExtSettingsDelta deltas[]){
@ -41,9 +48,74 @@ public class CExternalSettingsDeltaProcessor {
if(applyDelta(rcDes, deltas, kindMask))
changed = true;
}
if((kindMask & ICSettingEntry.SOURCE_PATH) != 0){
if(applySourceEntriesChange(des, deltas))
changed = true;
}
if((kindMask & ICSettingEntry.OUTPUT_PATH) != 0){
if(applyOutputEntriesChange(des, deltas))
changed = true;
}
return changed;
}
static boolean applySourceEntriesChange(ICConfigurationDescription cfgDes, ExtSettingsDelta[] deltas){
ICSettingEntry[][] diff = CExternalSettinsDeltaCalculator.getAllEntries(deltas, ICSettingEntry.SOURCE_PATH);
if(diff == null)
return false;
ICSourceEntry[] current = cfgDes.getSourceEntries();
if(current.length == 1){
ICSourceEntry cur = current[0];
if(cur.getFullPath().segmentCount() == 1 && cur.getExclusionPatterns().length == 0){
current = new ICSourceEntry[0];
}
}
List newEntries = calculateUpdatedEntries(current, diff[0], diff[1]);
if(newEntries != null){
try {
cfgDes.setSourceEntries((ICSourceEntry[])newEntries.toArray(new ICSourceEntry[newEntries.size()]));
} catch (WriteAccessException e) {
CCorePlugin.log(e);
} catch (CoreException e) {
CCorePlugin.log(e);
}
return true;
}
return false;
}
static boolean applyOutputEntriesChange(ICConfigurationDescription cfgDes, ExtSettingsDelta[] deltas){
ICSettingEntry[][] diff = CExternalSettinsDeltaCalculator.getAllEntries(deltas, ICSettingEntry.OUTPUT_PATH);
if(diff == null)
return false;
ICBuildSetting bs = cfgDes.getBuildSetting();
if(bs == null)
return false;
ICOutputEntry[] current = bs.getOutputDirectories();
if(current.length == 1){
ICOutputEntry cur = current[0];
if(cur.getFullPath().segmentCount() == 1 && cur.getExclusionPatterns().length == 0){
current = new ICOutputEntry[0];
}
}
List newEntries = calculateUpdatedEntries(current, diff[0], diff[1]);
if(newEntries != null){
try {
bs.setOutputDirectories((ICOutputEntry[])newEntries.toArray(new ICOutputEntry[newEntries.size()]));
} catch (WriteAccessException e) {
CCorePlugin.log(e);
}
return true;
}
return false;
}
static boolean applyDelta(ICResourceDescription rcDes, ExtSettingsDelta deltas[], int kindMask){
if(rcDes.getType() == ICSettingBase.SETTING_FOLDER){
return applyDelta((ICFolderDescription)rcDes, deltas, kindMask);

View file

@ -46,7 +46,7 @@ class CExternalSettinsDeltaCalculator {
ExtSettingsDelta(CExternalSetting setting){
fSetting = setting;
fEntryChangeStore = new KindBasedStore();
fEntryChangeStore = new KindBasedStore(false);
}
ExtSettingsDelta(CExternalSetting setting, boolean added){
@ -278,5 +278,39 @@ class CExternalSettinsDeltaCalculator {
return set;
}
static ICSettingEntry[][] getAllEntries(ExtSettingsDelta[] deltas, int kind){
if(deltas == null || deltas.length == 0)
return null;
Map addedMap = new LinkedHashMap();
Map removedMap = new LinkedHashMap();
for(int i = 0; i < deltas.length; i++){
ICSettingEntry[][] change = deltas[i].getEntriesDelta(kind);
if(change == null)
continue;
if(change[0] != null){
CDataUtil.fillEntriesMapByNameKey(addedMap, change[0]);
}
if(change[1] != null){
CDataUtil.fillEntriesMapByNameKey(removedMap, change[1]);
}
removedMap.keySet().removeAll(addedMap.keySet());
}
if(addedMap.size() == 0 && removedMap.size() == 0)
return null;
ICSettingEntry[][] result = new ICSettingEntry[2][];
if(addedMap.size() != 0){
result[0] = (ICSettingEntry[])addedMap.values().toArray(new ICSettingEntry[addedMap.size()]);
}
if(removedMap.size() != 0){
result[1] = (ICSettingEntry[])removedMap.values().toArray(new ICSettingEntry[removedMap.size()]);
}
return result;
}
}

View file

@ -13,11 +13,14 @@ package org.eclipse.cdt.internal.core.settings.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
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.internal.core.settings.model.CExternalSettingsManager.CContainerRef;
class CSettingsRefInfo {
@ -114,5 +117,19 @@ class CSettingsRefInfo {
}
return holder.getExternalSettings();
}
ICSettingEntry[] getAllEntries(int kind){
Map map = new LinkedHashMap();
for(Iterator iter = fESHolderMap.entrySet().iterator(); iter.hasNext();){
Map.Entry entry = (Map.Entry)iter.next();
CRefSettingsHolder h = (CRefSettingsHolder)entry.getValue();
CExternalSetting[] settings = h.getExternalSettings();
for(int i = 0; i < settings.length; i++){
ICSettingEntry[] entries = settings[i].getEntries(kind);
CDataUtil.fillEntriesMapByNameKey(map, entries);
}
}
return (ICSettingEntry[])map.values().toArray(new ICSettingEntry[map.size()]);
}
}