1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

1. Fix for [Bug 182711] [Project Model] CoreModel.create(IFile) cannot be used in jobs

2. External setting provider mechanism
3. other bug-fixes
This commit is contained in:
Mikhail Sennikovsky 2007-04-17 11:14:13 +00:00
parent f577ff3449
commit cb19d69cff
34 changed files with 615 additions and 58 deletions

View file

@ -0,0 +1,97 @@
/*******************************************************************************
* 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;
import java.util.Arrays;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
public class ExternalSettingsProviderTests extends BaseTestCase{
private static final String PROJ_NAME_PREFIX = "espt_";
ICProject p1;
public static TestSuite suite() {
return suite(ExternalSettingsProviderTests.class, "_");
}
protected void setUp() throws Exception {
p1 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "a", IPDOMManager.ID_NO_INDEXER);
}
public void testRefs() throws Exception {
CoreModel model = CoreModel.getDefault();
IProject project = p1.getProject();
ICProjectDescription des = model.getProjectDescription(project);
ICConfigurationDescription cfgDes = des.getConfigurations()[0];
ICLanguageSetting ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true);
ICLanguageSettingEntry[] entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
assertEquals(0, entries.length);
String[] extPIds = new String[]{CTestPlugin.PLUGIN_ID + ".testExtSettingsProvider"};
cfgDes.setExternalSettingsProviderIds(extPIds);
assertEquals(extPIds.length, cfgDes.getExternalSettingsProviderIds().length);
assertTrue(Arrays.equals(extPIds, cfgDes.getExternalSettingsProviderIds()));
entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
assertEquals(2, entries.length);
ICLanguageSettingEntry[] expectedEntries = new ICLanguageSettingEntry[]{
new CIncludePathEntry("ip_a", 0),
new CIncludePathEntry("ip_b", 0),
};
assertTrue(Arrays.equals(expectedEntries, entries));
ICLanguageSettingEntry[] newEntries = new ICLanguageSettingEntry[3];
newEntries[0] = expectedEntries[1];
newEntries[1] = new CIncludePathEntry("added", 0);
newEntries[2] = expectedEntries[0];
ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, newEntries);
entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
assertEquals(3, entries.length);
assertTrue(Arrays.equals(newEntries, entries));
newEntries = new ICLanguageSettingEntry[1];
newEntries[0] = expectedEntries[0];
ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, newEntries);
entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
assertEquals(1, entries.length);
assertTrue(Arrays.equals(newEntries, entries));
newEntries = new ICLanguageSettingEntry[0];
ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, newEntries);
entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
assertEquals(0, entries.length);
ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, (ICLanguageSettingEntry[])null);
entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
assertEquals(2, entries.length);
assertTrue(Arrays.equals(expectedEntries, entries));
}
protected void tearDown() throws Exception {
try {
p1.getProject().delete(true, null);
} catch (CoreException e){
}
}
}

View file

@ -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.core.settings.model;
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultConfigurationDataProvider;
public class TestCfgDataProvider extends CDefaultConfigurationDataProvider {
}

View file

@ -0,0 +1,43 @@
/*******************************************************************************
* 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;
import org.eclipse.cdt.core.settings.model.extension.CExternalSettingProvider;
import org.eclipse.core.resources.IProject;
public class TestExtSettingsProvider extends CExternalSettingProvider {
private static CExternalSetting[] SETTINGS = new CExternalSetting[]{
new CExternalSetting(null, null, null, new ICSettingEntry[]{
new CIncludePathEntry("ip_a", 0),
new CIncludePathEntry("ip_b", 0),
new CIncludeFileEntry("if_a", 0),
new CIncludeFileEntry("if_b", 0),
new CMacroEntry("m_a", "mv_a", 0),
new CMacroEntry("m_b", "mv_b", 0),
new CMacroFileEntry("mf_a", 0),
new CMacroFileEntry("mf_b", 0),
new CLibraryPathEntry("lp_a", 0),
new CLibraryPathEntry("lp_b", 0),
new CLibraryFileEntry("lf_a", 0),
new CLibraryFileEntry("lf_b", 0),
new CSourceEntry("sp_a", null, 0),
new CSourceEntry("sp_b", null, 0),
new COutputEntry("op_a", null, 0),
new COutputEntry("op_b", null, 0),
})
};
public CExternalSetting[] getSettings(IProject project,
ICConfigurationDescription cfg) {
return (CExternalSetting[])SETTINGS.clone();
}
}

View file

@ -449,6 +449,16 @@ class MockConfig implements ICConfigurationDescription {
public ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus) {
return null;
}
public String[] getExternalSettingsProviderIds() {
// TODO Auto-generated method stub
return null;
}
public void setExternalSettingsProviderIds(String[] ids) {
// TODO Auto-generated method stub
}
}
/*

View file

@ -45,5 +45,20 @@
class="org.eclipse.cdt.internal.pdom.tests.GeneratePDOMApplicationTest$TestProjectProvider4">
</ExportProjectProvider>
</extension>
<extension
point="org.eclipse.cdt.core.CConfigurationDataProvider"
id="testCfgDataProvider">
<provider
class="org.eclipse.cdt.core.settings.model.TestCfgDataProvider">
</provider>
</extension>
<extension
id="testExtSettingsProvider"
name="name"
point="org.eclipse.cdt.core.externalSettingsProvider">
<provider
class="org.eclipse.cdt.core.settings.model.TestExtSettingsProvider">
</provider>
</extension>
</plugin>

View file

@ -32,6 +32,9 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@ -104,6 +107,47 @@ public class CProjectHelper {
return newProject[0];
}
/**
* Creates a ICProject.
*/
public static ICProject createNewStileCProject(final String projectName, final String indexerID) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final ICProject newProject[] = new ICProject[1];
ws.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ws.getRoot();
IProject project = root.getProject(projectName);
if (indexerID != null) {
IndexerPreferences.set(project, IndexerPreferences.KEY_INDEX_ALL_FILES, "true");
IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, indexerID);
}
if (!project.exists()) {
project.create(null);
} else {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
if (!project.isOpen()) {
project.open(null);
}
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
String cfgProviderId = CTestPlugin.PLUGIN_ID + ".testCfgDataProvider";
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
ICConfigurationDescription prefCfg = CCorePlugin.getDefault().getPreferenceConfiguration(cfgProviderId);
ICProjectDescription projDes = CCorePlugin.getDefault().createProjectDescription(project, false);
projDes.createConfiguration(CDataUtil.genId(null), CDataUtil.genId("test"), prefCfg);
CCorePlugin.getDefault().setProjectDescription(project, projDes);
// CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
}
newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project);
}
}, null);
return newProject[0];
}
private static String getMessage(IStatus status) {
StringBuffer message = new StringBuffer("[");
message.append(status.getMessage());

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
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.ICProjectDescriptionListener;
import org.eclipse.cdt.core.settings.model.WriteAccessException;
import org.eclipse.cdt.internal.core.model.APathEntry;
import org.eclipse.cdt.internal.core.model.BatchOperation;
@ -1421,4 +1422,12 @@ public class CoreModel {
public boolean isNewStyleProject(ICProjectDescription des){
return descriptionManager.isNewStyleProject(des);
}
public void addCProjectDescriptionListener(ICProjectDescriptionListener listener, int eventTypes){
descriptionManager.addListener(listener, eventTypes);
}
public void removeCProjectDescriptionListener(ICProjectDescriptionListener listener){
descriptionManager.removeListener(listener);
}
}

View file

@ -8,11 +8,12 @@
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.settings.model;
package org.eclipse.cdt.core.settings.model;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICSettingObject;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescription;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionDelta;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
import org.eclipse.cdt.internal.core.settings.model.ICDescriptionDelta;
import org.eclipse.core.resources.IProject;
public final class CProjectDescriptionEvent {

View file

@ -361,4 +361,8 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin
* @return ICLanguageSetting or null if not found
*/
ICLanguageSetting getLanguageSettingForFile(IPath path, boolean ignoreExludeStatus);
void setExternalSettingsProviderIds(String ids[]);
String[] getExternalSettingsProviderIds();
}

View file

@ -8,7 +8,8 @@
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.settings.model;
package org.eclipse.cdt.core.settings.model;
public interface ICProjectDescriptionListener {
void handleEvent(CProjectDescriptionEvent event);

View file

@ -10,14 +10,14 @@
*******************************************************************************/
package org.eclipse.cdt.core.settings.model.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
public class CEntriesSet {
private HashMap fEntriesMap = new HashMap();
private LinkedHashMap fEntriesMap = new LinkedHashMap();
public CEntriesSet(){
}

View file

@ -34,7 +34,16 @@ public class KindBasedStore implements Cloneable {
| ICLanguageSettingEntry.LIBRARY_PATH
| ICLanguageSettingEntry.LIBRARY_FILE;
public static final int ORED_ALL_ENTRY_KINDS =
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 LANG_ENTRY_KINDS[] = new int[]{
ICLanguageSettingEntry.INCLUDE_PATH,
ICLanguageSettingEntry.INCLUDE_FILE,

View file

@ -148,9 +148,11 @@ public class LanguageSettingEntriesSerializer {
public static void serializeEntries(ICSettingEntry entries[], ICStorageElement element){
ICStorageElement child;
for(int i = 0; i < entries.length; i++){
child = element.createChild(ELEMENT_ENTRY);
serializeEntry(entries[i], child);
if(entries != null){
for(int i = 0; i < entries.length; i++){
child = element.createChild(ELEMENT_ENTRY);
serializeEntry(entries[i], child);
}
}
}

View file

@ -19,9 +19,9 @@ import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.internal.core.settings.model.AbstractCExtensionProxy;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.internal.core.settings.model.ConfigBasedPathEntryStore;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;

View file

@ -11,8 +11,10 @@
package org.eclipse.cdt.internal.core.settings.model;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
import org.eclipse.cdt.internal.core.CConfigBasedDescriptor;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;

View file

@ -790,4 +790,21 @@ public class CConfigurationDescription extends CDataProxyContainer implements IC
}
}
public String[] getExternalSettingsProviderIds() {
try {
return getSpecSettings().getExternalSettingsProviderIds();
} catch (CoreException e) {
CCorePlugin.log(e);
}
return new String[0];
}
public void setExternalSettingsProviderIds(String[] ids) {
try {
getSpecSettings().setExternalSettingsProviderIds(ids);
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
}

View file

@ -472,4 +472,14 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData
return CDataUtil.isExcluded(path, fProjSourceEntries);
}
public String[] getExternalSettingsProviderIds() {
return fSpecSettings.getExternalSettingsProviderIds();
}
public void setExternalSettingsProviderIds(String[] ids) {
if(!fInitializing)
throw ExceptionFactory.createIsReadOnlyException();
fSpecSettings.setExternalSettingsProviderIds(ids);
}
}

View file

@ -919,4 +919,13 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
return true;
}
public String[] getExternalSettingsProviderIds(){
return ExtensionContainerFactory.getReferencedProviderIds(fCfg);
}
public void setExternalSettingsProviderIds(String ids[]){
ExtensionContainerFactory.setReferencedProviderIds(fCfg, ids);
}
}

View file

@ -29,52 +29,80 @@ 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[]){
static boolean applyDelta(ICConfigurationDescription des, ExtSettingsDelta deltas[]){
return applyDelta(des, deltas, KindBasedStore.ORED_ALL_ENTRY_KINDS);
}
static boolean applyDelta(ICConfigurationDescription des, ExtSettingsDelta deltas[], int kindMask){
ICResourceDescription rcDess[] = des.getResourceDescriptions();
boolean changed = false;
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);
}
if(applyDelta(rcDes, deltas, kindMask))
changed = true;
}
return changed;
}
private static void applyDelta(ICFileDescription des, ExtSettingsDelta deltas[]){
static boolean applyDelta(ICResourceDescription rcDes, ExtSettingsDelta deltas[], int kindMask){
if(rcDes.getType() == ICSettingBase.SETTING_FOLDER){
return applyDelta((ICFolderDescription)rcDes, deltas, kindMask);
}
return applyDelta((ICFileDescription)rcDes, deltas, kindMask);
}
static boolean applyDelta(ICFileDescription des, ExtSettingsDelta deltas[], int kindMask){
ICLanguageSetting setting = des.getLanguageSetting();
if(setting == null)
return;
return false;
boolean changed = false;
for(int i = 0; i < deltas.length; i++){
if(isSettingCompatible(setting, deltas[i].fSetting)){
applyDelta(setting, deltas[i]);
if(applyDelta(setting, deltas[i], kindMask))
changed = true;
}
}
return changed;
}
private static void applyDelta(ICFolderDescription des, ExtSettingsDelta deltas[]){
static boolean applyDelta(ICFolderDescription des, ExtSettingsDelta deltas[], int kindMask){
ICLanguageSetting settings[] = des.getLanguageSettings();
if(settings == null || settings.length == 0)
return;
return false;
ICLanguageSetting setting;
boolean changed = false;
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]);
}
if(applyDelta(setting, deltas, kindMask))
changed = true;
}
return changed;
}
static boolean applyDelta(ICLanguageSetting setting, ExtSettingsDelta[] deltas, int kindMask){
boolean changed = false;
for(int i = 0; i < deltas.length; i++){
if(isSettingCompatible(setting, deltas[i].fSetting)){
if(applyDelta(setting, deltas[i], kindMask))
changed = true;
}
}
return changed;
}
private static void applyDelta(ICLanguageSetting setting, ExtSettingsDelta delta){
static boolean applyDelta(ICLanguageSetting setting, ExtSettingsDelta delta, int kindMask){
int kinds[] = KindBasedStore.getLanguageEntryKinds();
int kind;
ICLanguageSettingEntry entries[];
ICSettingEntry diff[][];
boolean changed = false;
for(int i = 0; i < kinds.length; i++){
kind = kinds[i];
if((kind & kindMask) == 0)
continue;
diff = delta.getEntriesDelta(kind);
if(diff == null)
continue;
@ -82,9 +110,12 @@ public class CExternalSettingsDeltaProcessor {
entries = setting.getSettingEntries(kind);
List list = calculateUpdatedEntries(entries, diff[0], diff[1]);
if(list != null)
if(list != null){
setting.setSettingEntries(kind, list);
changed = true;
}
}
return changed;
}
private static List calculateUpdatedEntries(ICSettingEntry current[], ICSettingEntry added[], ICSettingEntry removed[]){

View file

@ -69,9 +69,14 @@ public class CExternalSettingsHolder extends CExternalSettingsContainer {
return (CExternalSetting[])fSettingsMap.values().toArray(new CExternalSetting[fSettingsMap.size()]);
return EMPTY_EXT_SETTINGS_ARRAY;
}
void setExternallSettings(CExternalSetting[] settings){
removeExternalSettings();
setExternalSettings(settings, false);
}
void setExternalSettings(CExternalSetting[] settings, boolean add){
if(!add)
removeExternalSettings();
if(settings != null){
for(int i = 0; i < settings.length; i++){
@ -84,6 +89,10 @@ public class CExternalSettingsHolder extends CExternalSettingsContainer {
}
fIsModified = true;
}
void addExternalSettings(CExternalSetting[] settings){
setExternalSettings(settings, true);
}
public CExternalSetting createExternalSetting(String[] languageIDs,
String[] contentTypeIDs, String[] extensions,

View file

@ -20,8 +20,11 @@ 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.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.internal.core.settings.model.CExternalSettinsDeltaCalculator.ExtSettingsDelta;
import org.eclipse.core.resources.IProject;
@ -43,6 +46,23 @@ public class CExternalSettingsManager implements ICExternalSettingsListener, ICP
private Map fFactoryMap = new HashMap();
private static CExternalSettingsManager fInstance;
public static class SettingsUpdateStatus {
ICProjectDescription fDes;
boolean fIsChanged;
SettingsUpdateStatus(ICProjectDescription des, boolean isChanged){
fDes = des;
fIsChanged = isChanged;
}
public ICProjectDescription getCProjectDescription(){
return fDes;
}
public boolean isChanged(){
return fIsChanged;
}
}
private CExternalSettingsManager(){
}
@ -561,18 +581,18 @@ public class CExternalSettingsManager implements ICExternalSettingsListener, ICP
}
}
private void containerContentsChanged(ICfgContainer cr, CContainerRef ref, DeltaInfo deltaInfo){
processContainerChange(OP_CHANGED, cr, ref, deltaInfo);
private boolean containerContentsChanged(ICfgContainer cr, CContainerRef ref, DeltaInfo deltaInfo){
return processContainerChange(OP_CHANGED, cr, ref, deltaInfo);
}
private void processContainerChange(int op,
private boolean processContainerChange(int op,
ICfgContainer cr,
CContainerRef crInfo,
DeltaInfo deltaInfo){
processContainerChange(op, cr, new CfgContainerRefInfoContainer(cr), crInfo, deltaInfo);
return processContainerChange(op, cr, new CfgContainerRefInfoContainer(cr), crInfo, deltaInfo);
}
private void processContainerChange(int op,
private boolean processContainerChange(int op,
ICfgContainer cr,
ICRefInfoContainer riContainer,
CContainerRef crInfo,
@ -584,13 +604,13 @@ public class CExternalSettingsManager implements ICExternalSettingsListener, ICP
cfg.getProjectDescription().getProject(), cfg, riContainer, crInfo);
if(deltas != null){
applyDeltas(cr, deltas);
return applyDeltas(cr, deltas);
}
return false;
}
private void applyDeltas(ICfgContainer cr, ExtSettingsDelta[] deltas){
CExternalSettingsDeltaProcessor.applyDelta(cr.getConfguration(true), deltas);
private boolean applyDeltas(ICfgContainer cr, ExtSettingsDelta[] deltas){
return CExternalSettingsDeltaProcessor.applyDelta(cr.getConfguration(true), deltas);
}
private static class RefInfoContainer{
@ -650,13 +670,17 @@ public class CExternalSettingsManager implements ICExternalSettingsListener, ICP
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);
}
final SettingsUpdateStatus status = update(event.getNewCProjectDescription());
if(status.isChanged()){
IWorkspaceRunnable r = new IWorkspaceRunnable(){
public void run(IProgressMonitor monitor) throws CoreException {
ICProjectDescription des = status.getCProjectDescription();
CProjectDescriptionManager.getInstance().setProjectDescription(des.getProject(), des);
}
};
CProjectDescriptionManager.getInstance().runWspModification(r, null);
}
break;
}
@ -701,17 +725,19 @@ public class CExternalSettingsManager implements ICExternalSettingsListener, ICP
return info.getReferences(factoryId);
}
public ICProjectDescription update(ICProjectDescription des){
public SettingsUpdateStatus update(ICProjectDescription des){
ProjDesCfgList list = new ProjDesCfgList(des, null);
boolean changed = false;
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);
if(containerContentsChanged(cfgCr, refs[k], null))
changed = true;
}
}
return list.fProjDes;
return new SettingsUpdateStatus(list.fProjDes, changed);
}
private ExtSettingsDelta[] checkExternalSettingsChange(int op,
@ -758,4 +784,15 @@ public class CExternalSettingsManager implements ICExternalSettingsListener, ICP
private CExternalSettinsDeltaCalculator getDeltaCalculator(){
return CExternalSettinsDeltaCalculator.getInstance();
}
public void restoreDefaults(ICLanguageSetting ls, int entryKinds){
ICConfigurationDescription cfg = ls.getConfiguration();
CfgContainer cr = new CfgContainer(cfg);
CfgContainerRefInfoContainer ric = new CfgContainerRefInfoContainer(cr);
CExternalSetting[] settings = ric.getRefInfo(false).createExternalSettings();
ExtSettingsDelta[] deltas = getDeltaCalculator().getSettingChange(settings, null);
if(deltas != null){
CExternalSettingsDeltaProcessor.applyDelta(ls, deltas, entryKinds);
}
}
}

View file

@ -330,8 +330,11 @@ public class CLanguageSetting extends CDataProxy implements
// int kinds[] = KindBasedStore.getSupportedKinds();
for(int i = 0; i < kinds.length; i++){
ICLanguageSettingEntry sortedEntries[] = store.containsEntriesList(kinds[i]) ? store.getEntries(kinds[i]) : null;
if((kind & kinds[i]) != 0)
if((kind & kinds[i]) != 0){
data.setEntries(kinds[i], sortedEntries);
if(sortedEntries == null)
CExternalSettingsManager.getInstance().restoreDefaults(this, kind);
}
}
}

View file

@ -15,7 +15,7 @@ import java.util.List;
import org.eclipse.cdt.core.settings.model.ICSettingObject;
class CProjectDescriptionDelta implements ICDescriptionDelta {
public class CProjectDescriptionDelta implements ICDescriptionDelta {
private List fChildList = new ArrayList();
private CProjectDescriptionDelta fParent;
private ICSettingObject fSetting;
@ -29,7 +29,7 @@ class CProjectDescriptionDelta implements ICDescriptionDelta {
private static final int KIND_MASK = 3;
private static final int FLAGS_OFFSET = 2;
CProjectDescriptionDelta(ICSettingObject newSetting, ICSettingObject oldSetting){
public CProjectDescriptionDelta(ICSettingObject newSetting, ICSettingObject oldSetting){
fNewSetting = newSetting;
fOldSetting = oldSetting;
if(newSetting != null){

View file

@ -46,12 +46,14 @@ 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.CProjectDescriptionEvent;
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.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.ICSettingBase;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
@ -635,6 +637,9 @@ public class CProjectDescriptionManager {
}
public Job runWspModification(final IWorkspaceRunnable runnable, IProgressMonitor monitor){
if(monitor == null)
monitor = new NullProgressMonitor();
final IWorkspace wsp = ResourcesPlugin.getWorkspace();
boolean scheduleRule = true;
if(!wsp.isTreeLocked()) {
@ -649,7 +654,8 @@ public class CProjectDescriptionManager {
CCorePlugin.log(e);
} catch (Exception e) {
} finally {
monitor.done();
if(!scheduleRule)
monitor.done();
mngr.endRule(rule);
}
}

View file

@ -16,6 +16,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.settings.model.CExternalSetting;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.internal.core.settings.model.CExternalSettingsManager.CContainerRef;
@ -100,5 +101,18 @@ class CSettingsRefInfo {
CRefSettingsHolder remove(CContainerRef cRef){
return (CRefSettingsHolder)fESHolderMap.remove(cRef);
}
CExternalSetting[] createExternalSettings(){
if(fESHolderMap.size() == 0)
return new CExternalSetting[0];
if(fESHolderMap.size() == 1)
return ((CRefSettingsHolder)fESHolderMap.values().iterator().next()).getExternalSettings();
CExternalSettingsHolder holder = new CExternalSettingsHolder();
for(Iterator iter = fESHolderMap.values().iterator(); iter.hasNext();){
CExternalSettingsHolder h = (CExternalSettingsHolder)iter.next();
holder.setExternalSettings(h.getExternalSettings(), true);
}
return holder.getExternalSettings();
}
}

View file

@ -19,9 +19,11 @@ 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.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
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;

View file

@ -25,9 +25,11 @@ import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.settings.model.util.PathEntryTranslator;
import org.eclipse.cdt.core.settings.model.util.PathEntryTranslator.PathEntryCollector;

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICFileDescription;
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
@ -29,6 +30,7 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingPathEntry;
import org.eclipse.cdt.core.settings.model.ICMacroEntry;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.ICSettingBase;
import org.eclipse.core.resources.IProject;

View file

@ -10,13 +10,18 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.settings.model;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import 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.cdt.internal.core.settings.model.CExternalSettingsManager.CContainerRef;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@ -60,17 +65,23 @@ public class ExtensionContainerFactory extends CExternalSettingContainerFactory
private IExtension fExtension;
private IConfigurationElement fProviderElement;
private String fId;
private String fName;
private CExternalSettingProvider fProvider;
CExtensionSettingProviderDescriptor(IExtension extension){
fId = extension.getUniqueIdentifier();
fName = extension.getLabel();
fExtension = extension;
}
public String getId(){
return fId;
}
public String getName(){
return fName;
}
private CExternalSettingProvider getProvider(){
if(fProvider == null){
try {
@ -157,4 +168,47 @@ public class ExtensionContainerFactory extends CExternalSettingContainerFactory
return dr.getContainer(project, cfgDes);
return CExternalSettingsManager.NullContainer.INSTANCE;
}
public static String[] getReferencedProviderIds(ICConfigurationDescription cfg){
CContainerRef[] refs = CExternalSettingsManager.getInstance().getReferences(cfg, FACTORY_ID);
String[] ids = new String[refs.length];
for(int i = 0; i < refs.length; i++){
ids[i] = refs[i].getContainerId();
}
return ids;
}
public static void setReferencedProviderIds(ICConfigurationDescription cfg, String ids[]){
Set newIdsSet = new HashSet(Arrays.asList(ids));
Set oldIdsSet = new HashSet(Arrays.asList(getReferencedProviderIds(cfg)));
Set newIdsSetCopy = new HashSet(newIdsSet);
newIdsSet.removeAll(oldIdsSet);
oldIdsSet.removeAll(newIdsSetCopy);
if(oldIdsSet.size() != 0){
for(Iterator iter = oldIdsSet.iterator(); iter.hasNext();){
removeReference(cfg, (String)iter.next());
}
}
if(newIdsSet.size() != 0){
for(Iterator iter = newIdsSet.iterator(); iter.hasNext();){
createReference(cfg, (String)iter.next());
}
}
}
private static void createReference(ICConfigurationDescription cfg, String id){
CContainerRef cr = createContainerRef(id);
CExternalSettingsManager.getInstance().addContainer(cfg, cr);
}
private static void removeReference(ICConfigurationDescription cfg, String id){
CContainerRef cr = createContainerRef(id);
CExternalSettingsManager.getInstance().removeContainer(cfg, cr);
}
private static CContainerRef createContainerRef(String id){
return new CContainerRef(FACTORY_ID, id);
}
}

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.resources.ScannerProvider;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;

View file

@ -14,6 +14,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.internal.core.model.CModelOperation;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager.CompositeWorkspaceRunnable;
import org.eclipse.core.resources.IProject;

View file

@ -47,6 +47,7 @@
<extension-point id="CConfigurationDataProvider" name="CConfigurationData provider" schema="schema/CConfigurationDataProvider.exsd"/>
<extension-point id="projectConverter" name="project converter" schema="schema/projectConverter.exsd"/>
<extension-point id="CIndex" name="CIndex" schema="schema/CIndex.exsd"/>
<extension-point id="externalSettingsProvider" name="External Settings provider" schema="schema/externalSettingsProvider.exsd"/>
<!-- =================================================================================== -->
<!-- Define the list of the Binary Parser provided by the CDT -->
<!-- =================================================================================== -->

View file

@ -0,0 +1,104 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.core">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.core" id="externalSettingsProvider" name="External Settings provider"/>
</appInfo>
<documentation>
The external settings provider would be used to specify provider of include/macro/libraryan settings to be used/applied for the build configuration associated with this provider.
Any number of setting providers can be associated with the build configurations.
This functionality might be used, e.g. by the External SDKs to allow automatic andjustment of the project settings for the projects using thes SDKs, e.g. adding include paths, symbols, etc.
</documentation>
</annotation>
<element name="extension">
<complexType>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="provider">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
Class implementing org.eclipse.cdt.core.settings.model.extension.CExternalSettingProvider
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.cdt.core.settings.model.extension.CExternalSettingProvider"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
4.0
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiInfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
</documentation>
</annotation>
</schema>

View file

@ -23,19 +23,19 @@ import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICDescriptorListener;
import org.eclipse.cdt.core.ICDescriptorManager;
import org.eclipse.cdt.core.ICDescriptorOperation;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
import org.eclipse.cdt.core.settings.model.ICSettingObject;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.internal.core.settings.model.CConfigurationDescription;
import org.eclipse.cdt.internal.core.settings.model.CConfigurationSpecSettings;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescription;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
import org.eclipse.cdt.internal.core.settings.model.CStorage;
import org.eclipse.cdt.internal.core.settings.model.ExceptionFactory;
import org.eclipse.cdt.internal.core.settings.model.ICDescriptionDelta;
import org.eclipse.cdt.internal.core.settings.model.ICProjectDescriptionListener;
import org.eclipse.cdt.internal.core.settings.model.IInternalCCfgInfo;
import org.eclipse.cdt.internal.core.settings.model.InternalXmlStorageElement;
import org.eclipse.cdt.internal.core.settings.model.PathEntryConfigurationDataProvider;