mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Fixes for the external settings provider mechanism
This commit is contained in:
parent
69ee033a1a
commit
9368a57266
9 changed files with 232 additions and 35 deletions
|
@ -27,7 +27,7 @@ import org.eclipse.core.runtime.Path;
|
|||
|
||||
public class ExternalSettingsProviderTests extends BaseTestCase{
|
||||
private static final String PROJ_NAME_PREFIX = "espt_";
|
||||
ICProject p1, p2;
|
||||
ICProject p1, p2, p3;
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(ExternalSettingsProviderTests.class, "_");
|
||||
|
@ -36,9 +36,11 @@ public class ExternalSettingsProviderTests extends BaseTestCase{
|
|||
protected void setUp() throws Exception {
|
||||
p1 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "a", IPDOMManager.ID_NO_INDEXER);
|
||||
p2 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "b", IPDOMManager.ID_NO_INDEXER);
|
||||
p3 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "c", IPDOMManager.ID_NO_INDEXER);
|
||||
}
|
||||
|
||||
public void testRefs() throws Exception {
|
||||
TestExtSettingsProvider.setVariantNum(0);
|
||||
CoreModel model = CoreModel.getDefault();
|
||||
IProject project = p1.getProject();
|
||||
|
||||
|
@ -104,6 +106,7 @@ public class ExternalSettingsProviderTests extends BaseTestCase{
|
|||
}
|
||||
|
||||
public void testCreateCfg() throws Exception {
|
||||
TestExtSettingsProvider.setVariantNum(0);
|
||||
CoreModel model = CoreModel.getDefault();
|
||||
IProject project = p2.getProject();
|
||||
|
||||
|
@ -148,6 +151,58 @@ public class ExternalSettingsProviderTests extends BaseTestCase{
|
|||
|
||||
}
|
||||
|
||||
public void testProviderUpdate() throws Exception {
|
||||
TestExtSettingsProvider.setVariantNum(0);
|
||||
|
||||
CoreModel model = CoreModel.getDefault();
|
||||
ICProjectDescriptionManager mngr = model.getProjectDescriptionManager();
|
||||
IProject project = p2.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);
|
||||
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);
|
||||
|
||||
|
||||
ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true);
|
||||
entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
|
||||
ICLanguageSettingEntry[] expectedEntries = new ICLanguageSettingEntry[]{
|
||||
new CIncludePathEntry("ip_a", 0),
|
||||
new CIncludePathEntry("ip_b", 0),
|
||||
};
|
||||
assertTrue(Arrays.equals(expectedEntries, entries));
|
||||
|
||||
model.setProjectDescription(project, des);
|
||||
|
||||
des = model.getProjectDescription(project);
|
||||
cfgDes = des.getConfigurations()[0];
|
||||
ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true);
|
||||
entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
|
||||
assertTrue(Arrays.equals(expectedEntries, entries));
|
||||
|
||||
ICLanguageSettingEntry[] expectedEntries2 = new ICLanguageSettingEntry[]{
|
||||
new CIncludePathEntry("ip_a2", 0),
|
||||
new CIncludePathEntry("ip_b2", 0),
|
||||
};
|
||||
TestExtSettingsProvider.setVariantNum(1);
|
||||
|
||||
mngr.updateExternalSettingsProviders(extPIds, null);
|
||||
des = model.getProjectDescription(project);
|
||||
cfgDes = des.getConfigurations()[0];
|
||||
ls = cfgDes.getLanguageSettingForFile(new Path("a.c"), true);
|
||||
entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
|
||||
assertTrue(Arrays.equals(expectedEntries2, entries));
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
p1.getProject().delete(true, null);
|
||||
|
@ -157,6 +212,9 @@ public class ExternalSettingsProviderTests extends BaseTestCase{
|
|||
p2.getProject().delete(true, null);
|
||||
} catch (CoreException e){
|
||||
}
|
||||
|
||||
try {
|
||||
p3.getProject().delete(true, null);
|
||||
} catch (CoreException e){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ 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[]{
|
||||
private static CExternalSetting[] SETTINGS_1 = new CExternalSetting[]{
|
||||
new CExternalSetting(null, null, null, new ICSettingEntry[]{
|
||||
new CIncludePathEntry("ip_a", 0),
|
||||
new CIncludePathEntry("ip_b", 0),
|
||||
|
@ -35,9 +35,50 @@ public class TestExtSettingsProvider extends CExternalSettingProvider {
|
|||
})
|
||||
};
|
||||
|
||||
private static CExternalSetting[] SETTINGS_2 = new CExternalSetting[]{
|
||||
new CExternalSetting(null, null, null, new ICSettingEntry[]{
|
||||
new CIncludePathEntry("ip_a2", 0),
|
||||
new CIncludePathEntry("ip_b2", 0),
|
||||
new CIncludeFileEntry("if_a2", 0),
|
||||
new CIncludeFileEntry("if_b2", 0),
|
||||
new CMacroEntry("m_a2", "mv_a2", 0),
|
||||
new CMacroEntry("m_b2", "mv_b2", 0),
|
||||
new CMacroFileEntry("mf_a2", 0),
|
||||
new CMacroFileEntry("mf_b2", 0),
|
||||
new CLibraryPathEntry("lp_a2", 0),
|
||||
new CLibraryPathEntry("lp_b2", 0),
|
||||
new CLibraryFileEntry("lf_a2", 0),
|
||||
new CLibraryFileEntry("lf_b2", 0),
|
||||
new CSourceEntry("sp_a2", null, 0),
|
||||
new CSourceEntry("sp_b2", null, 0),
|
||||
new COutputEntry("op_a2", null, 0),
|
||||
new COutputEntry("op_b2", null, 0),
|
||||
})
|
||||
};
|
||||
|
||||
private static CExternalSetting[][] SETTINGS_VARIANTS = new CExternalSetting[][]{
|
||||
SETTINGS_1,
|
||||
SETTINGS_2};
|
||||
|
||||
private static int variantNum;
|
||||
|
||||
public CExternalSetting[] getSettings(IProject project,
|
||||
ICConfigurationDescription cfg) {
|
||||
return (CExternalSetting[])SETTINGS.clone();
|
||||
return (CExternalSetting[])SETTINGS_VARIANTS[variantNum].clone();
|
||||
}
|
||||
|
||||
public static void setVariantNum(int num){
|
||||
if(num < 0 || num >= SETTINGS_VARIANTS.length)
|
||||
throw new IllegalArgumentException();
|
||||
variantNum = num;
|
||||
}
|
||||
|
||||
public static int getVariantNum(){
|
||||
return variantNum;
|
||||
}
|
||||
|
||||
public static int getMaxVariantNum(){
|
||||
return SETTINGS_VARIANTS.length - 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -384,6 +384,8 @@ public interface ICConfigurationDescription extends ICSettingContainer, ICSettin
|
|||
* those ids will be ignored and will NOT be added to the configuration settings
|
||||
*
|
||||
* @param ids the ids of externalSettinsProvider extensions
|
||||
*
|
||||
* @see ICProjectDescriptionManager#updateExternalSettingsProviders(String[])
|
||||
*/
|
||||
void updateExternalSettingsProviders(String[] ids) throws WriteAccessException;
|
||||
}
|
||||
|
|
|
@ -138,4 +138,16 @@ public interface ICProjectDescriptionManager {
|
|||
* @return
|
||||
*/
|
||||
boolean setProjectDescriptionWorkspacePreferences(ICProjectDescriptionWorkspacePreferences prefs, boolean updateProjects, IProgressMonitor monitor);
|
||||
|
||||
/**
|
||||
* forces the external settings providers of the specified IDs to be rescanned
|
||||
* and all configurations referencing the specified providers to be updated
|
||||
*
|
||||
* @param ids the ids of externalSettinsProvider extensions
|
||||
*
|
||||
* @see ICConfigurationDescription#getExternalSettingsProviderIds()
|
||||
* @see ICConfigurationDescription#setExternalSettingsProviderIds(String[])
|
||||
* @see ICConfigurationDescription#updateExternalSettingsProviders(String[])
|
||||
*/
|
||||
void updateExternalSettingsProviders(String[] ids, IProgressMonitor monitor);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
import org.eclipse.core.runtime.ListenerList;
|
||||
|
||||
|
||||
public abstract class CExternalSettingContainerFactoryWithListener extends
|
||||
CExternalSettingContainerFactory {
|
||||
private ListenerList fListenerList;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected void notifySettingsChange(IProject project, String cfgId, 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(project, cfgId, event);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -454,6 +454,11 @@ public class CExternalSettingsManager implements ICExternalSettingsListener, ICP
|
|||
return dr;
|
||||
}
|
||||
|
||||
CExternalSettingContainerFactory getFactory(String id){
|
||||
FactoryDescriptor dr = getFactoryDescriptor(id);
|
||||
return dr.getFactory();
|
||||
}
|
||||
|
||||
private ContainerDescriptor createDescriptor(String factoryId,
|
||||
String containerId,
|
||||
IProject project,
|
||||
|
|
|
@ -3399,4 +3399,8 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
|
|||
return el.createChild(PREFERENCES_ELEMENT);
|
||||
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.14")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void updateExternalSettingsProviders(String[] ids, IProgressMonitor monitor){
|
||||
ExtensionContainerFactory.updateReferencedProviderIds(ids, monitor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,10 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.ListenerList;
|
||||
|
||||
public class CfgExportSettingContainerFactory extends
|
||||
CExternalSettingContainerFactory implements ICProjectDescriptionListener {
|
||||
CExternalSettingContainerFactoryWithListener implements ICProjectDescriptionListener {
|
||||
static final String FACTORY_ID = CCorePlugin.PLUGIN_ID + ".cfg.export.settings.sipplier"; //$NON-NLS-1$
|
||||
private static final char DELIMITER = ';';
|
||||
private ListenerList fListenerList;
|
||||
// private ListenerList fListenerList;
|
||||
|
||||
private static CfgExportSettingContainerFactory fInstance;
|
||||
|
||||
|
@ -175,19 +175,19 @@ public class CfgExportSettingContainerFactory extends
|
|||
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 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()){
|
||||
|
@ -204,7 +204,7 @@ public class CfgExportSettingContainerFactory extends
|
|||
new CContainerRef(FACTORY_ID, ids[i]),
|
||||
null);
|
||||
}
|
||||
notifySettingsChange(changeInfos);
|
||||
notifySettingsChange(null, null, changeInfos);
|
||||
}
|
||||
}
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -273,18 +273,18 @@ public class CfgExportSettingContainerFactory extends
|
|||
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);
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -27,9 +27,10 @@ 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.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
public class ExtensionContainerFactory extends CExternalSettingContainerFactory {
|
||||
public class ExtensionContainerFactory extends CExternalSettingContainerFactoryWithListener {
|
||||
static final String FACTORY_ID = CCorePlugin.PLUGIN_ID + ".extension.container.factory"; //$NON-NLS-1$
|
||||
private static final String EXTENSION_ID = CCorePlugin.PLUGIN_ID + ".externalSettingsProvider"; //$NON-NLS-1$
|
||||
|
||||
|
@ -161,6 +162,13 @@ public class ExtensionContainerFactory extends CExternalSettingContainerFactory
|
|||
return fInstance;
|
||||
}
|
||||
|
||||
public static ExtensionContainerFactory getInstanceInitialized(){
|
||||
CExternalSettingContainerFactory f = CExternalSettingsManager.getInstance().getFactory(FACTORY_ID);
|
||||
if(f instanceof ExtensionContainerFactory)
|
||||
return (ExtensionContainerFactory)f;
|
||||
return getInstance();
|
||||
}
|
||||
|
||||
public CExternalSettingsContainer createContainer(String id,
|
||||
IProject project, ICConfigurationDescription cfgDes) throws CoreException {
|
||||
CExtensionSettingProviderDescriptor dr = (CExtensionSettingProviderDescriptor)getProviderDescriptorMap().get(id);
|
||||
|
@ -198,6 +206,24 @@ public class ExtensionContainerFactory extends CExternalSettingContainerFactory
|
|||
}
|
||||
}
|
||||
|
||||
public static void updateReferencedProviderIds(String ids[], IProgressMonitor monitor){
|
||||
ExtensionContainerFactory instance = getInstanceInitialized();
|
||||
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);
|
||||
}
|
||||
|
||||
instance.notifySettingsChange(null, null, changeInfos);
|
||||
|
||||
if(monitor != null)
|
||||
monitor.done();
|
||||
}
|
||||
|
||||
public static void updateReferencedProviderIds(ICConfigurationDescription cfg, String ids[]){
|
||||
Set newIdsSet = new HashSet(Arrays.asList(ids));
|
||||
Set oldIdsSet = new HashSet(Arrays.asList(getReferencedProviderIds(cfg)));
|
||||
|
|
Loading…
Add table
Reference in a new issue