mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Serialization of LSE entries in workspace area
This commit is contained in:
parent
6088b4e980
commit
36c081996e
5 changed files with 941 additions and 321 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Andrew Gvozdev and others.
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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
|
||||
|
@ -17,6 +17,7 @@ import java.util.List;
|
|||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
|
@ -30,6 +31,7 @@ import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSetting
|
|||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
|
@ -38,6 +40,7 @@ import org.w3c.dom.Element;
|
|||
*/
|
||||
public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
||||
private static final String LANGUAGE_SETTINGS_PROJECT_XML = ".settings/language.settings.xml";
|
||||
private static final String LANGUAGE_SETTINGS_WORKSPACE_XML = "language.settings.xml";
|
||||
// Should match id of extension point defined in plugin.xml
|
||||
private static final String EXTENSION_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass";
|
||||
private static final String EXTENSION_PROVIDER_NAME = "Test Plugin Base Provider Subclass";
|
||||
|
@ -162,6 +165,16 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
return cfgDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testNoProviders() throws Exception {
|
||||
// serialize language settings of user defined providers (on workspace level)
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace();
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace();
|
||||
|
||||
// test passes if no exception was thrown
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception {
|
||||
|
@ -174,7 +187,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
LanguageSettingsSerializable extProvider = (LanguageSettingsSerializable) LanguageSettingsManager.getRawProvider(provider);
|
||||
assertNotNull(extProvider);
|
||||
assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, extProvider.getId());
|
||||
|
||||
|
||||
// add entries
|
||||
extProvider.setSettingEntries(null, null, null, entries);
|
||||
List<ICLanguageSettingEntry> actual = extProvider.getSettingEntries(null, null, null);
|
||||
|
@ -183,7 +196,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
|
||||
// serialize language settings of workspace providers
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace();
|
||||
|
||||
|
||||
// clear the provider
|
||||
extProvider.setSettingEntries(null, null, null, null);
|
||||
}
|
||||
|
@ -234,7 +247,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testWorkspacePersistence_ShadowedExtensionProvider() throws Exception {
|
||||
|
@ -263,18 +276,18 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, rawProvider.getName());
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// re-load to check serialization
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace();
|
||||
|
||||
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID);
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
assertTrue(rawProvider instanceof MockLanguageSettingsSerializableProvider);
|
||||
assertEquals(EXTENSION_PROVIDER_ID, rawProvider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, rawProvider.getName());
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// reset workspace providers, that will also serialize
|
||||
LanguageSettingsManager.setWorkspaceProviders(null);
|
||||
|
@ -290,7 +303,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
{
|
||||
// re-load to check serialization
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace();
|
||||
|
||||
|
||||
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_PROVIDER_ID);
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
assertTrue(rawProvider instanceof LanguageSettingsBaseProvider);
|
||||
|
@ -298,7 +311,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
assertEquals(EXTENSION_PROVIDER_NAME, rawProvider.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_SerializableProviderDOM() throws Exception {
|
||||
|
@ -317,6 +330,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
|
||||
LanguageSettingsSerializable serializableProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
serializableProvider.setSettingEntries(null, null, null, entries);
|
||||
serializableProvider.setStoringEntriesInProjectArea(true);
|
||||
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(serializableProvider);
|
||||
|
@ -326,12 +340,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
|
@ -378,6 +392,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
assertNotNull(cfgDescription1);
|
||||
assertEquals(CFG_ID, cfgDescription1.getId());
|
||||
LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
provider1.setStoringEntriesInProjectArea(true);
|
||||
provider1.setSettingEntries(null, null, null, entries);
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider1);
|
||||
|
@ -389,6 +404,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
assertNotNull(cfgDescription2);
|
||||
assertEquals(CFG_ID_2, cfgDescription2.getId());
|
||||
LanguageSettingsSerializable provider2 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
provider2.setStoringEntriesInProjectArea(true);
|
||||
provider2.setSettingEntries(null, null, null, entries2);
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(provider2);
|
||||
|
@ -433,7 +449,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-create a project description and re-load language settings for each configuration
|
||||
|
@ -443,7 +459,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
new MockConfigurationDescription(CFG_ID_2),
|
||||
});
|
||||
// load
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
|
@ -495,6 +511,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
|
||||
LanguageSettingsSerializable serializableProvider = new MockLanguageSettingsSerializableProvider(PROVIDER_0, PROVIDER_NAME_0);
|
||||
serializableProvider.setSettingEntries(null, null, null, entries);
|
||||
serializableProvider.setStoringEntriesInProjectArea(true);
|
||||
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(serializableProvider);
|
||||
|
@ -504,12 +521,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
|
@ -553,12 +570,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-load
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
|
@ -593,7 +610,8 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
assertNotNull(cfgDescription);
|
||||
|
||||
// populate with provider overriding the extension (must be SerializableLanguageSettingsProvider or a class from another extension)
|
||||
ILanguageSettingsProvider providerOverride = new MockLanguageSettingsSerializableProvider(idExt, PROVIDER_NAME_0);
|
||||
MockLanguageSettingsSerializableProvider providerOverride = new MockLanguageSettingsSerializableProvider(idExt, PROVIDER_NAME_0);
|
||||
providerOverride.setStoringEntriesInProjectArea(true);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(providerOverride);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
@ -603,12 +621,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-load
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
|
@ -658,9 +676,11 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
// 3. Providers defined in a configuration
|
||||
// 3.1
|
||||
LanguageSettingsSerializable mockProvider1 = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
mockProvider1.setStoringEntriesInProjectArea(true);
|
||||
mockProvider1.setSettingEntries(null, null, null, entries_31);
|
||||
// 3.2
|
||||
LanguageSettingsSerializable mockProvider2 = new MockLanguageSettingsSerializableProvider(PROVIDER_2, PROVIDER_NAME_2);
|
||||
mockProvider2.setStoringEntriesInProjectArea(true);
|
||||
mockProvider2.setSettingEntries(null, null, null, entries_32);
|
||||
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
|
@ -674,13 +694,13 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
XmlUtil.toString(doc);
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettings(rootElement, mockPrjDescription);
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(rootElement, null, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
|
@ -736,6 +756,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
|
||||
// create a provider
|
||||
LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
mockProvider.setStoringEntriesInProjectArea(true);
|
||||
mockProvider.setSettingEntries(cfgDescription, null, null, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(mockProvider);
|
||||
|
@ -772,6 +793,12 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
assertFalse(xmlFile.exists());
|
||||
assertTrue(xmlFileOut.exists());
|
||||
}
|
||||
{
|
||||
// Should not pollute workspace area with file with no meaningful data
|
||||
String xmlWspStorageFileLocation = getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML);
|
||||
java.io.File xmlStorageFileWsp = new java.io.File(xmlWspStorageFileLocation);
|
||||
assertFalse(xmlStorageFileWsp.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// clear configuration
|
||||
|
@ -836,5 +863,223 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_SplitStorageDOM() throws Exception {
|
||||
Element prjStorageElement = null;
|
||||
Element wspStorageElement = null;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
{
|
||||
// create a provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
LanguageSettingsSerializable serializableProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
serializableProvider.setSettingEntries(null, null, null, entries);
|
||||
// do not store entries inside project
|
||||
serializableProvider.setStoringEntriesInProjectArea(false);
|
||||
|
||||
ArrayList<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(serializableProvider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
// prepare DOM storage
|
||||
Document prjDoc = XmlUtil.newDocument();
|
||||
prjStorageElement = XmlUtil.appendElement(prjDoc, ELEM_TEST);
|
||||
Document wspDoc = XmlUtil.newDocument();
|
||||
wspStorageElement = XmlUtil.appendElement(wspDoc, ELEM_TEST);
|
||||
// serialize language settings to the DOM
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsInternal(prjStorageElement, wspStorageElement, mockPrjDescription);
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
MockProjectDescription mockPrjDescription = new MockProjectDescription(new MockConfigurationDescription(CFG_ID));
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsInternal(prjStorageElement, wspStorageElement, mockPrjDescription);
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = mockPrjDescription.getConfigurations();
|
||||
assertNotNull(cfgDescriptions);
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertNotNull(providers);
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertTrue(provider instanceof LanguageSettingsSerializable);
|
||||
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: refactor with ErrorParserManager
|
||||
*
|
||||
* @param store - name of the store
|
||||
* @return location of the store in the plug-in state area
|
||||
*/
|
||||
private static String getStoreLocationInWorkspaceArea(String store) {
|
||||
IPath location = CCorePlugin.getDefault().getStateLocation().append(store);
|
||||
return location.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProjectPersistence_RealProjectSplitStorage() throws Exception {
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
String xmlStorageFileLocation;
|
||||
String xmlOutOfTheWay;
|
||||
String xmlWspStorageFileLocation;
|
||||
String xmlWspOutOfTheWay;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
{
|
||||
// get project descriptions
|
||||
ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project);
|
||||
assertNotNull(writableProjDescription);
|
||||
ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
|
||||
// create a provider
|
||||
LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_0, PROVIDER_NAME_0);
|
||||
mockProvider.setStoringEntriesInProjectArea(false);
|
||||
mockProvider.setSettingEntries(cfgDescription, null, null, entries);
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
providers.add(mockProvider);
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
List<ILanguageSettingsProvider> storedProviders = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(1, storedProviders.size());
|
||||
|
||||
// write to project description
|
||||
coreModel.setProjectDescription(project, writableProjDescription);
|
||||
IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML);
|
||||
assertTrue(xmlStorageFile.exists());
|
||||
xmlStorageFileLocation = xmlStorageFile.getLocation().toOSString();
|
||||
// TODO - cleanup names
|
||||
xmlWspStorageFileLocation = getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML);
|
||||
java.io.File xmlStorageFileWsp = new java.io.File(xmlWspStorageFileLocation);
|
||||
assertTrue(xmlStorageFileWsp.exists());
|
||||
}
|
||||
{
|
||||
coreModel.getProjectDescription(project);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider provider = providers.get(0);
|
||||
assertTrue(provider instanceof LanguageSettingsSerializable);
|
||||
assertEquals(PROVIDER_0, provider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, provider.getName());
|
||||
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(cfgDescription, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
// Move storages out of the way
|
||||
{
|
||||
java.io.File xmlFile = new java.io.File(xmlStorageFileLocation);
|
||||
xmlOutOfTheWay = xmlStorageFileLocation+".out-of-the-way";
|
||||
java.io.File xmlFileOut = new java.io.File(xmlOutOfTheWay);
|
||||
xmlFile.renameTo(xmlFileOut);
|
||||
assertFalse(xmlFile.exists());
|
||||
assertTrue(xmlFileOut.exists());
|
||||
}
|
||||
{
|
||||
// TODO - workspace file
|
||||
java.io.File xmlStorageFileWsp = new java.io.File(xmlWspStorageFileLocation);
|
||||
assertTrue(xmlStorageFileWsp.exists());
|
||||
xmlWspOutOfTheWay = xmlWspStorageFileLocation+".out-of-the-way";
|
||||
java.io.File xmlWspFileOut = new java.io.File(xmlWspOutOfTheWay);
|
||||
boolean result = xmlStorageFileWsp.renameTo(xmlWspFileOut);
|
||||
assertTrue(result);
|
||||
assertFalse(xmlStorageFileWsp.exists());
|
||||
assertTrue(xmlWspFileOut.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// clear configuration
|
||||
ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project);
|
||||
ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations();
|
||||
assertEquals(1, cfgDescriptions.length);
|
||||
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||
assertNotNull(cfgDescription);
|
||||
|
||||
cfgDescription.setLanguageSettingProviders(new ArrayList<ILanguageSettingsProvider>());
|
||||
coreModel.setProjectDescription(project, writableProjDescription);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// re-check if it really took it
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
}
|
||||
{
|
||||
// close the project
|
||||
project.close(null);
|
||||
}
|
||||
{
|
||||
// open to double-check the data is not kept in some other kind of cache
|
||||
project.open(null);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(0, providers.size());
|
||||
// and close
|
||||
project.close(null);
|
||||
}
|
||||
|
||||
{
|
||||
// Move storage back
|
||||
java.io.File xmlFile = new java.io.File(xmlStorageFileLocation);
|
||||
xmlFile.delete();
|
||||
assertFalse("File "+xmlFile+ " still exist", xmlFile.exists());
|
||||
java.io.File xmlFileOut = new java.io.File(xmlOutOfTheWay);
|
||||
xmlFileOut.renameTo(xmlFile);
|
||||
assertTrue("File "+xmlFile+ " does not exist", xmlFile.exists());
|
||||
assertFalse("File "+xmlFileOut+ " still exist", xmlFileOut.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// TODO
|
||||
// Move storage back
|
||||
java.io.File xmlWspFile = new java.io.File(xmlWspStorageFileLocation);
|
||||
xmlWspFile.delete();
|
||||
assertFalse("File "+xmlWspFile+ " still exist", xmlWspFile.exists());
|
||||
java.io.File xmlWspFileOut = new java.io.File(xmlWspOutOfTheWay);
|
||||
xmlWspFileOut.renameTo(xmlWspFile);
|
||||
assertTrue("File "+xmlWspFile+ " does not exist", xmlWspFile.exists());
|
||||
assertFalse("File "+xmlWspFileOut+ " still exist", xmlWspFileOut.exists());
|
||||
}
|
||||
|
||||
{
|
||||
// Remove project from internal cache
|
||||
CProjectDescriptionManager.getInstance().projectClosedRemove(project);
|
||||
// open project and check if providers are loaded
|
||||
project.open(null);
|
||||
ICConfigurationDescription cfgDescription = getFirstConfigurationDescription(project);
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
assertEquals(1, providers.size());
|
||||
ILanguageSettingsProvider loadedProvider = providers.get(0);
|
||||
assertTrue(loadedProvider instanceof LanguageSettingsSerializable);
|
||||
assertEquals(PROVIDER_0, loadedProvider.getId());
|
||||
assertEquals(PROVIDER_NAME_0, loadedProvider.getName());
|
||||
|
||||
List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
assertEquals(entries.size(), actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
|||
import org.eclipse.cdt.core.testplugin.CModelMock;
|
||||
import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -43,12 +42,7 @@ import org.w3c.dom.Element;
|
|||
* Test cases testing LanguageSettingsProvider functionality
|
||||
*/
|
||||
public class LanguageSettingsSerializableTests extends TestCase {
|
||||
// Should match id of extension point defined in plugin.xml
|
||||
private static final String EXTENSION_SERIALIZABLE_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.serializable.language.settings.provider";
|
||||
|
||||
private static final String CFG_ID = "test.configuration.id";
|
||||
private static final String CFG_ID_1 = "test.configuration.id.1";
|
||||
private static final String CFG_ID_2 = "test.configuration.id.2";
|
||||
private static final ICConfigurationDescription MOCK_CFG = new CModelMock.DummyCConfigurationDescription(CFG_ID);
|
||||
private static final IResource MOCK_RC = ResourcesPlugin.getWorkspace().getRoot();
|
||||
private static final String LANG_ID = "test.lang.id";
|
||||
|
@ -101,7 +95,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testProvider() throws Exception {
|
||||
public void testProvider_SettersGetters() throws Exception {
|
||||
// benchmark data
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
@ -112,7 +106,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
LanguageSettingsSerializable mockProvider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
// test isEmpty()
|
||||
assertTrue(mockProvider.isEmpty());
|
||||
|
||||
|
||||
// test setters and getters
|
||||
mockProvider.setId(PROVIDER_2);
|
||||
assertEquals(PROVIDER_2, mockProvider.getId());
|
||||
|
@ -120,16 +114,16 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
assertEquals(PROVIDER_NAME_2, mockProvider.getName());
|
||||
mockProvider.setCustomParameter(CUSTOM_PARAMETER);
|
||||
assertEquals(CUSTOM_PARAMETER, mockProvider.getCustomParameter());
|
||||
|
||||
assertEquals(false, mockProvider.isEntriesStorageWithProject());
|
||||
mockProvider.setEntriesStorageWithProject(true);
|
||||
assertEquals(true, mockProvider.isEntriesStorageWithProject());
|
||||
|
||||
|
||||
assertEquals(false, mockProvider.isStoringEntriesInProjectArea());
|
||||
mockProvider.setStoringEntriesInProjectArea(true);
|
||||
assertEquals(true, mockProvider.isStoringEntriesInProjectArea());
|
||||
|
||||
mockProvider.setLanguageScope(languages);
|
||||
assertEquals(languages, mockProvider.getLanguageScope());
|
||||
mockProvider.setLanguageScope(null);
|
||||
assertEquals(null, mockProvider.getLanguageScope());
|
||||
|
||||
|
||||
mockProvider.setSettingEntries(null, MOCK_RC, LANG_ID, entries);
|
||||
List<ICLanguageSettingEntry> actual = mockProvider.getSettingEntries(null, MOCK_RC, LANG_ID);
|
||||
assertEquals(entries.get(0), actual.get(0));
|
||||
|
@ -143,17 +137,153 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testNoProviders() throws Exception {
|
||||
// serialize language settings of user defined providers (on workspace level)
|
||||
LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace();
|
||||
LanguageSettingsProvidersSerializer.loadLanguageSettingsWorkspace();
|
||||
public void testProvider_RegularDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
{
|
||||
// create customized provider
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider.setStoringEntriesInProjectArea(true);
|
||||
provider.setCustomParameter(CUSTOM_PARAMETER);
|
||||
|
||||
// test passes if no exception was thrown
|
||||
List<String> languageScope = new ArrayList<String>();
|
||||
languageScope.add(LANG_ID);
|
||||
provider.setLanguageScope(languageScope);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 1));
|
||||
provider.setSettingEntries(null, null, null, entries);
|
||||
|
||||
// serialize
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
elementProvider = provider.serialize(rootElement);
|
||||
// check XML
|
||||
String xmlString = XmlUtil.toString(doc);
|
||||
assertTrue(xmlString.contains(PROVIDER_1));
|
||||
assertTrue(xmlString.contains(PROVIDER_NAME_1));
|
||||
assertTrue(xmlString.contains(CUSTOM_PARAMETER));
|
||||
assertTrue(xmlString.contains(LANG_ID));
|
||||
assertTrue(xmlString.contains("path0"));
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider);
|
||||
assertEquals(PROVIDER_1, provider.getId());
|
||||
assertEquals(true, provider.isStoringEntriesInProjectArea());
|
||||
assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter());
|
||||
assertNotNull(provider.getLanguageScope());
|
||||
assertTrue(provider.getLanguageScope().size()>0);
|
||||
assertEquals(LANG_ID, provider.getLanguageScope().get(0));
|
||||
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, null);
|
||||
assertNotNull(entries);
|
||||
assertTrue(entries.size()>0);
|
||||
assertEquals(new CIncludePathEntry("path0", 1), entries.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testEmptyProvider() throws Exception {
|
||||
public void testProvider_serializeAttributesDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
{
|
||||
// create customized provider
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider.setStoringEntriesInProjectArea(true);
|
||||
provider.setCustomParameter(CUSTOM_PARAMETER);
|
||||
|
||||
List<String> languageScope = new ArrayList<String>();
|
||||
languageScope.add(LANG_ID);
|
||||
provider.setLanguageScope(languageScope);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 1));
|
||||
provider.setSettingEntries(null, null, null, entries);
|
||||
|
||||
// serialize
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
elementProvider = provider.serializeAttributes(rootElement);
|
||||
// check XML
|
||||
String xmlString = XmlUtil.toString(doc);
|
||||
assertTrue(xmlString.contains(PROVIDER_1));
|
||||
assertTrue(xmlString.contains(PROVIDER_NAME_1));
|
||||
assertTrue(xmlString.contains(CUSTOM_PARAMETER));
|
||||
assertTrue(xmlString.contains(LANG_ID));
|
||||
// no entries
|
||||
assertFalse(xmlString.contains("path0"));
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable();
|
||||
provider.loadAttributes(elementProvider);
|
||||
assertEquals(PROVIDER_1, provider.getId());
|
||||
assertEquals(true, provider.isStoringEntriesInProjectArea());
|
||||
assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter());
|
||||
assertNotNull(provider.getLanguageScope());
|
||||
assertTrue(provider.getLanguageScope().size()>0);
|
||||
assertEquals(LANG_ID, provider.getLanguageScope().get(0));
|
||||
// no entries should be loaded
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, null);
|
||||
assertNull(entries);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProvider_serializeEntriesDOM() throws Exception {
|
||||
Element rootElement;
|
||||
{
|
||||
// create customized provider
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider.setStoringEntriesInProjectArea(true);
|
||||
provider.setCustomParameter(CUSTOM_PARAMETER);
|
||||
|
||||
List<String> languageScope = new ArrayList<String>();
|
||||
languageScope.add(LANG_ID);
|
||||
provider.setLanguageScope(languageScope);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 1));
|
||||
provider.setSettingEntries(null, null, null, entries);
|
||||
|
||||
// serialize
|
||||
Document doc = XmlUtil.newDocument();
|
||||
rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
provider.serializeEntries(rootElement);
|
||||
// check XML
|
||||
String xmlString = XmlUtil.toString(doc);
|
||||
// no attributes
|
||||
assertFalse(xmlString.contains(PROVIDER_1));
|
||||
assertFalse(xmlString.contains(PROVIDER_NAME_1));
|
||||
assertFalse(xmlString.contains(CUSTOM_PARAMETER));
|
||||
assertFalse(xmlString.contains(LANG_ID));
|
||||
// entries should be present
|
||||
assertTrue(xmlString.contains("path0"));
|
||||
}
|
||||
{
|
||||
// re-load and check language settings of the newly loaded provider
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_2, PROVIDER_NAME_2);
|
||||
provider.loadEntries(rootElement);
|
||||
assertEquals(PROVIDER_2, provider.getId());
|
||||
assertEquals(PROVIDER_NAME_2, provider.getName());
|
||||
// no attributes should be loaded
|
||||
assertFalse(PROVIDER_1.equals(provider.getId()));
|
||||
assertFalse(PROVIDER_NAME_1.equals(provider.getName()));
|
||||
assertFalse(true==provider.isStoringEntriesInProjectArea());
|
||||
assertFalse(CUSTOM_PARAMETER.equals(provider.getCustomParameter()));
|
||||
assertNull(provider.getLanguageScope());
|
||||
// entries should be loaded
|
||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, null);
|
||||
assertNotNull(entries);
|
||||
assertTrue(entries.size()>0);
|
||||
assertEquals(new CIncludePathEntry("path0", 1), entries.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testProvider_EmptyDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
{
|
||||
// create null provider
|
||||
|
@ -180,7 +310,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testCustomParameter() throws Exception {
|
||||
public void testCustomParameterDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
{
|
||||
// create provider with custom parameter
|
||||
|
@ -203,15 +333,15 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testStoreEntriesWithProject() throws Exception {
|
||||
public void testStoreEntriesWithProjectDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
{
|
||||
// create provider with custom parameter
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
assertEquals(false, provider.isEntriesStorageWithProject());
|
||||
provider.setEntriesStorageWithProject(true);
|
||||
assertEquals(true, provider.isEntriesStorageWithProject());
|
||||
|
||||
assertEquals(false, provider.isStoringEntriesInProjectArea());
|
||||
provider.setStoringEntriesInProjectArea(true);
|
||||
assertEquals(true, provider.isStoringEntriesInProjectArea());
|
||||
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
elementProvider = provider.serialize(rootElement);
|
||||
|
@ -222,13 +352,13 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
{
|
||||
// re-load and check custom parameter of the newly loaded provider
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(elementProvider);
|
||||
assertEquals(true, provider.isEntriesStorageWithProject());
|
||||
assertEquals(true, provider.isStoringEntriesInProjectArea());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testLanguages() throws Exception {
|
||||
public void testLanguagesDOM() throws Exception {
|
||||
List<String> expectedLanguageIds = new ArrayList<String>();
|
||||
expectedLanguageIds.add(LANG_ID);
|
||||
expectedLanguageIds.add(LANG_ID_1);
|
||||
|
@ -259,19 +389,19 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
assertEquals(expectedLanguageIds.size(), actualIds.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testLanguageScope() throws Exception {
|
||||
public void testLanguageScopeDOM() throws Exception {
|
||||
// benchmark entries
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 0));
|
||||
|
||||
|
||||
// define the scope
|
||||
List<String> expectedLanguageIds = new ArrayList<String>();
|
||||
expectedLanguageIds.add(LANG_ID);
|
||||
expectedLanguageIds.add(LANG_ID_1);
|
||||
|
||||
|
||||
Element elementProvider;
|
||||
{
|
||||
// create provider with no scope by default
|
||||
|
@ -288,14 +418,14 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, LANG_ID_2);
|
||||
assertEquals(entries, actual);
|
||||
}
|
||||
|
||||
|
||||
// set the scope
|
||||
provider.setLanguageScope(expectedLanguageIds);
|
||||
List<String> actualIds = provider.getLanguageScope();
|
||||
assertEquals(LANG_ID, actualIds.get(0));
|
||||
assertEquals(LANG_ID_1, actualIds.get(1));
|
||||
assertEquals(2, actualIds.size());
|
||||
|
||||
|
||||
{
|
||||
// check for language scope itself
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
|
@ -311,7 +441,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, LANG_ID_2);
|
||||
assertNull(actual);
|
||||
}
|
||||
|
||||
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
elementProvider = provider.serialize(rootElement);
|
||||
|
@ -347,7 +477,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testNullConfiguration() throws Exception {
|
||||
public void testNullConfigurationDOM() throws Exception {
|
||||
// provider/configuration/language/resource/settingEntry
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
@ -376,7 +506,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testNullLanguage() throws Exception {
|
||||
public void testNullLanguageDOM() throws Exception {
|
||||
// provider/configuration/language/resource/settingEntry
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
@ -406,20 +536,20 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testNullLanguageScope() throws Exception {
|
||||
public void testNullLanguageScopeDOM() throws Exception {
|
||||
// define benchmark entries
|
||||
List<ICLanguageSettingEntry> entriesNullLanguage = new ArrayList<ICLanguageSettingEntry>();
|
||||
entriesNullLanguage.add(new CIncludePathEntry("path_null", 0));
|
||||
List<ICLanguageSettingEntry> entriesLanguage = new ArrayList<ICLanguageSettingEntry>();
|
||||
entriesLanguage.add(new CIncludePathEntry("path", 0));
|
||||
|
||||
|
||||
Element elementProvider;
|
||||
|
||||
{
|
||||
// create a provider
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
assertEquals(null, provider.getLanguageScope());
|
||||
|
||||
|
||||
// add null language
|
||||
provider.setSettingEntries(null, MOCK_RC, null, entriesNullLanguage);
|
||||
assertEquals(null, provider.getLanguageScope());
|
||||
|
@ -435,7 +565,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
assertEquals(entriesNullLanguage.get(0), actual.get(0));
|
||||
assertEquals(entriesNullLanguage.size(), actual.size());
|
||||
}
|
||||
|
||||
|
||||
// add non-null language
|
||||
provider.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, entriesLanguage);
|
||||
assertNull(provider.getLanguageScope());
|
||||
|
@ -451,12 +581,12 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
assertEquals(entriesLanguage.get(0), actual.get(0));
|
||||
assertEquals(entriesLanguage.size(), actual.size());
|
||||
}
|
||||
|
||||
|
||||
// provider/configuration/language/resource/settingEntry
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
|
||||
elementProvider = provider.serialize(rootElement);
|
||||
|
||||
|
||||
// verify that "language" element is saved in XML
|
||||
String xmlString = XmlUtil.toString(doc);
|
||||
assertTrue(xmlString.contains("<language")); // LanguageSettingsSerializable.ELEM_LANGUAGE;
|
||||
|
@ -478,10 +608,10 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testNullResource() throws Exception {
|
||||
public void testNullResourceDOM() throws Exception {
|
||||
// provider/configuration/language/resource/settingEntry
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
@ -510,7 +640,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testNullConfigurationLanguage() throws Exception {
|
||||
public void testNullConfigurationLanguageDOM() throws Exception {
|
||||
// provider/configuration/language/resource/settingEntry
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
@ -540,7 +670,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testNullConfigurationResource() throws Exception {
|
||||
public void testNullConfigurationResourceDOM() throws Exception {
|
||||
// provider/configuration/language/resource/settingEntry
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
@ -570,7 +700,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testNullLanguageResource() throws Exception {
|
||||
public void testNullLanguageResourceDOM() throws Exception {
|
||||
// provider/configuration/language/resource/settingEntry
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
@ -600,7 +730,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testNullConfigurationLanguageResourceFlag() throws Exception {
|
||||
public void testNullConfigurationLanguageResourceFlagDOM() throws Exception {
|
||||
// provider/configuration/language/resource/settingEntry
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
@ -633,7 +763,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testCIncludePathEntry() throws Exception {
|
||||
public void testCIncludePathEntryDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 1));
|
||||
|
@ -666,7 +796,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testCIncludeFileEntry() throws Exception {
|
||||
public void testCIncludeFileEntryDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludeFileEntry("name", 1));
|
||||
|
@ -698,7 +828,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testCMacroEntry() throws Exception {
|
||||
public void testCMacroEntryDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CMacroEntry("MACRO0", "value0",1));
|
||||
|
@ -730,7 +860,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testCMacroFileEntry() throws Exception {
|
||||
public void testCMacroFileEntryDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CMacroFileEntry("name", 1));
|
||||
|
@ -762,7 +892,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testCLibraryPathEntry() throws Exception {
|
||||
public void testCLibraryPathEntryDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CLibraryPathEntry("name", 1));
|
||||
|
@ -794,7 +924,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testCLibraryFileEntry() throws Exception {
|
||||
public void testCLibraryFileEntryDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CLibraryFileEntry("name", 1));
|
||||
|
@ -826,7 +956,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testMixedSettingEntries() throws Exception {
|
||||
public void testMixedSettingEntriesDOM() throws Exception {
|
||||
Element elementProvider;
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path0", 1));
|
||||
|
@ -856,7 +986,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testLanguageAndNull() throws Exception {
|
||||
public void testLanguageAndNullDOM() throws Exception {
|
||||
Element elementProvider = null;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
@ -892,7 +1022,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testTwoLanguages() throws Exception {
|
||||
public void testTwoLanguagesDOM() throws Exception {
|
||||
Element elementProvider = null;
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
|
@ -930,7 +1060,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
|
||||
/**
|
||||
*/
|
||||
public void testTwoResources() throws Exception {
|
||||
public void testTwoResourcesDOM() throws Exception {
|
||||
// Create resources
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
IFile rc1 = ResourceHelper.createFile(project, "rc1");
|
||||
|
@ -1043,8 +1173,8 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
LanguageSettingsSerializable provider1 = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider1.setLanguageScope(sampleLanguages);
|
||||
provider1.setCustomParameter(CUSTOM_PARAMETER);
|
||||
assertEquals(false, provider1.isEntriesStorageWithProject());
|
||||
provider1.setEntriesStorageWithProject(true);
|
||||
assertEquals(false, provider1.isStoringEntriesInProjectArea());
|
||||
provider1.setStoringEntriesInProjectArea(true);
|
||||
provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1);
|
||||
provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2);
|
||||
|
||||
|
@ -1070,8 +1200,8 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
assertFalse(provider1.equals(provider2));
|
||||
assertFalse(provider1.hashCode()==provider2.hashCode());
|
||||
|
||||
provider2.setEntriesStorageWithProject(true);
|
||||
|
||||
provider2.setStoringEntriesInProjectArea(true);
|
||||
|
||||
// All set now, so they should be equal
|
||||
assertTrue(provider1.equals(provider2));
|
||||
assertTrue(provider1.hashCode()==provider2.hashCode());
|
||||
|
@ -1120,8 +1250,8 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider1.setLanguageScope(sampleLanguages);
|
||||
provider1.setCustomParameter(CUSTOM_PARAMETER);
|
||||
assertEquals(false, provider1.isEntriesStorageWithProject());
|
||||
provider1.setEntriesStorageWithProject(true);
|
||||
assertEquals(false, provider1.isStoringEntriesInProjectArea());
|
||||
provider1.setStoringEntriesInProjectArea(true);
|
||||
provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1);
|
||||
provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2);
|
||||
|
||||
|
@ -1131,7 +1261,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
assertTrue(provider1.equals(providerClone));
|
||||
assertTrue(provider1.getClass()==providerClone.getClass());
|
||||
assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter());
|
||||
assertEquals(provider1.isEntriesStorageWithProject(), providerClone.isEntriesStorageWithProject());
|
||||
assertEquals(provider1.isStoringEntriesInProjectArea(), providerClone.isStoringEntriesInProjectArea());
|
||||
assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0));
|
||||
|
||||
List<ICLanguageSettingEntry> actual1 = providerClone.getSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID);
|
||||
|
@ -1153,7 +1283,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
// define sample data
|
||||
List<String> sampleLanguages = new ArrayList<String>();
|
||||
sampleLanguages.add(LANG_ID);
|
||||
|
||||
|
||||
// create a model provider
|
||||
class LanguageSettingsSerializableMock extends LanguageSettingsSerializable implements Cloneable {
|
||||
public LanguageSettingsSerializableMock(String id, String name) {
|
||||
|
@ -1163,31 +1293,31 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
public LanguageSettingsSerializableMock cloneShallow() throws CloneNotSupportedException {
|
||||
return (LanguageSettingsSerializableMock) super.cloneShallow();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider1.setLanguageScope(sampleLanguages);
|
||||
provider1.setCustomParameter(CUSTOM_PARAMETER);
|
||||
assertEquals(false, provider1.isEntriesStorageWithProject());
|
||||
provider1.setEntriesStorageWithProject(true);
|
||||
|
||||
assertEquals(false, provider1.isStoringEntriesInProjectArea());
|
||||
provider1.setStoringEntriesInProjectArea(true);
|
||||
|
||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||
entries.add(new CIncludePathEntry("path", 1));
|
||||
provider1.setSettingEntries(null, null, null, entries);
|
||||
|
||||
|
||||
// clone provider
|
||||
LanguageSettingsSerializableMock providerClone = provider1.cloneShallow();
|
||||
assertNotSame(provider1, providerClone);
|
||||
assertFalse(provider1.equals(providerClone));
|
||||
assertTrue(provider1.getClass()==providerClone.getClass());
|
||||
assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter());
|
||||
assertEquals(provider1.isEntriesStorageWithProject(), providerClone.isEntriesStorageWithProject());
|
||||
assertEquals(provider1.isStoringEntriesInProjectArea(), providerClone.isStoringEntriesInProjectArea());
|
||||
assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0));
|
||||
|
||||
|
||||
List<ICLanguageSettingEntry> actual = providerClone.getSettingEntries(null, null, null);
|
||||
assertNull(actual);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testSort_Kinds() throws Exception {
|
||||
|
@ -1204,7 +1334,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib2", 0);
|
||||
CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file1", 0);
|
||||
CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file2", 0);
|
||||
|
||||
|
||||
// place entries in unsorted list
|
||||
List<ICLanguageSettingEntry> unsortedEntries = new ArrayList<ICLanguageSettingEntry>();
|
||||
unsortedEntries.add(macroEntry1);
|
||||
|
@ -1223,7 +1353,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
// create a provider and set the entries
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider.setSettingEntries(null, null, null, unsortedEntries);
|
||||
|
||||
|
||||
// retrieve and check that language settings got sorted properly
|
||||
int i=0;
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
|
@ -1233,16 +1363,16 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
assertEquals(includeFileEntry2, actual.get(i++));
|
||||
assertEquals(macroEntry1, actual.get(i++));
|
||||
assertEquals(macroEntry2, actual.get(i++));
|
||||
assertEquals(macroFileEntry1, actual.get(i++));
|
||||
assertEquals(macroFileEntry2, actual.get(i++));
|
||||
assertEquals(macroFileEntry1, actual.get(i++));
|
||||
assertEquals(macroFileEntry2, actual.get(i++));
|
||||
assertEquals(libraryPathEntry1, actual.get(i++));
|
||||
assertEquals(libraryPathEntry2, actual.get(i++));
|
||||
assertEquals(libraryFileEntry1, actual.get(i++));
|
||||
assertEquals(libraryFileEntry2, actual.get(i++));
|
||||
|
||||
|
||||
assertEquals(unsortedEntries.size(), actual.size());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testSort_Entries() throws Exception {
|
||||
|
@ -1259,7 +1389,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
CLibraryPathEntry libraryPathEntry2 = new CLibraryPathEntry("lib_A", 0);
|
||||
CLibraryFileEntry libraryFileEntry1 = new CLibraryFileEntry("file_B", 0);
|
||||
CLibraryFileEntry libraryFileEntry2 = new CLibraryFileEntry("file_A", 0);
|
||||
|
||||
|
||||
// place entries in unsorted list
|
||||
List<ICLanguageSettingEntry> unsortedEntries = new ArrayList<ICLanguageSettingEntry>();
|
||||
// macros will be sorted by name
|
||||
|
@ -1276,11 +1406,11 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
unsortedEntries.add(libraryFileEntry2);
|
||||
unsortedEntries.add(libraryPathEntry1);
|
||||
unsortedEntries.add(libraryPathEntry2);
|
||||
|
||||
|
||||
// create a provider and set the entries
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider.setSettingEntries(null, null, null, unsortedEntries);
|
||||
|
||||
|
||||
// retrieve and check that language settings got sorted properly
|
||||
int i=0;
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
|
@ -1290,16 +1420,16 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
assertEquals(includeFileEntry2, actual.get(i++));
|
||||
assertEquals(macroEntry1, actual.get(i++));
|
||||
assertEquals(macroEntry2, actual.get(i++));
|
||||
assertEquals(macroFileEntry1, actual.get(i++));
|
||||
assertEquals(macroFileEntry2, actual.get(i++));
|
||||
assertEquals(macroFileEntry1, actual.get(i++));
|
||||
assertEquals(macroFileEntry2, actual.get(i++));
|
||||
assertEquals(libraryPathEntry1, actual.get(i++));
|
||||
assertEquals(libraryPathEntry2, actual.get(i++));
|
||||
assertEquals(libraryFileEntry1, actual.get(i++));
|
||||
assertEquals(libraryFileEntry2, actual.get(i++));
|
||||
|
||||
|
||||
assertEquals(unsortedEntries.size(), actual.size());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public void testSort_Undef() throws Exception {
|
||||
|
@ -1309,7 +1439,7 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
CMacroEntry macroEntry2B = new CMacroEntry("MACRO_2", null, 0);
|
||||
CMacroEntry macroEntry2C = new CMacroEntry("MACRO_2", null, ICSettingEntry.BUILTIN);
|
||||
CMacroEntry macroEntry3 = new CMacroEntry("MACRO_3", null, 0);
|
||||
|
||||
|
||||
// place entries in unsorted list
|
||||
List<ICLanguageSettingEntry> unsortedEntries = new ArrayList<ICLanguageSettingEntry>();
|
||||
// macros will be sorted by name and keep order for the same name
|
||||
|
@ -1318,11 +1448,11 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
unsortedEntries.add(macroEntry2B);
|
||||
unsortedEntries.add(macroEntry1);
|
||||
unsortedEntries.add(macroEntry2C);
|
||||
|
||||
|
||||
// create a provider and set the entries
|
||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||
provider.setSettingEntries(null, null, null, unsortedEntries);
|
||||
|
||||
|
||||
// retrieve and check that language settings got sorted properly
|
||||
int i=0;
|
||||
List<ICLanguageSettingEntry> actual = provider.getSettingEntries(null, null, null);
|
||||
|
@ -1331,10 +1461,10 @@ public class LanguageSettingsSerializableTests extends TestCase {
|
|||
assertEquals(macroEntry2B, actual.get(i++));
|
||||
assertEquals(macroEntry2C, actual.get(i++));
|
||||
assertEquals(macroEntry3, actual.get(i++));
|
||||
|
||||
|
||||
assertEquals(unsortedEntries.size(), actual.size());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,13 @@ import org.w3c.dom.Node;
|
|||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
||||
/**
|
||||
* This class is the base class for language settings providers able to serialize
|
||||
* into XML storage.
|
||||
*
|
||||
* TODO - more JavaDoc, info and hints about class hierarchy
|
||||
*
|
||||
*/
|
||||
public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
||||
public static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$
|
||||
private static final String ATTR_ID = "id"; //$NON-NLS-1$
|
||||
|
@ -53,29 +60,53 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
private static final String ATTR_STORE_ENTRIES = "store-entries"; //$NON-NLS-1$
|
||||
private static final String VALUE_WORKSPACE = "workspace"; //$NON-NLS-1$
|
||||
private static final String VALUE_PROJECT = "project"; //$NON-NLS-1$
|
||||
|
||||
private static WeakHashSet<List<ICLanguageSettingEntry>> lseListPool = new WeakHashSet<List<ICLanguageSettingEntry>>() {
|
||||
|
||||
/**
|
||||
* Pool of LSE lists implemented as WeakHashSet. That allows to gain memory savings
|
||||
* at the expense of CPU time. WeakHashSet handles garbage collection when a list is not
|
||||
* referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects.
|
||||
*/
|
||||
private static WeakHashSet<List<ICLanguageSettingEntry>> listPool = new WeakHashSet<List<ICLanguageSettingEntry>>() {
|
||||
@Override
|
||||
public synchronized List<ICLanguageSettingEntry> add(List<ICLanguageSettingEntry> list) {
|
||||
return super.add(list);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
private boolean isEntriesStorageWithProject = false;
|
||||
/** Tells if language settings entries are persisted with the project or in workspace area while serializing. */
|
||||
private boolean storeEntriesInProjectArea = false;
|
||||
|
||||
/**
|
||||
* Storage to keep settings entries. Note that it is not necessary to keep configuration in the maps
|
||||
* as the configuration is always the one provider belongs to.
|
||||
*/
|
||||
private Map<String, // languageId
|
||||
Map<String, // resource project path
|
||||
List<ICLanguageSettingEntry>>> fStorage = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||
|
||||
/**
|
||||
* Default constructor. This constructor has to be always followed with setting id and name of the provider.
|
||||
*/
|
||||
public LanguageSettingsSerializable() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param id - id of the provider.
|
||||
* @param name - name of the provider. Note that this name may show up in UI.
|
||||
*/
|
||||
public LanguageSettingsSerializable(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which allows to instantiate provider defined via XML markup.
|
||||
*
|
||||
* @param elementProvider
|
||||
*/
|
||||
public LanguageSettingsSerializable(Element elementProvider) {
|
||||
super();
|
||||
load(elementProvider);
|
||||
|
@ -104,10 +135,10 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
|
||||
/**
|
||||
* Set the language scope of the provider.
|
||||
*
|
||||
*
|
||||
* @param languages - the list of languages this provider provides for.
|
||||
* If {@code null}, the provider provides for any language.
|
||||
*
|
||||
*
|
||||
* @see #getLanguageScope()
|
||||
*/
|
||||
public void setLanguageScope(List <String> languages) {
|
||||
|
@ -117,6 +148,12 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
this.languageScope = new ArrayList<String>(languages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom parameter for the provider.
|
||||
* Subclasses are free to define how their behavior depends on custom parameter.
|
||||
*
|
||||
* @param customParameter
|
||||
*/
|
||||
public void setCustomParameter(String customParameter) {
|
||||
this.customParameter = customParameter;
|
||||
}
|
||||
|
@ -125,11 +162,11 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
* Tells if language settings entries are persisted with the project (under .settings folder)
|
||||
* or in workspace area. Persistence in the project area lets the entries migrate with the
|
||||
* project.
|
||||
*
|
||||
*
|
||||
* @return {@code true} if LSE persisted with the project or {@code false} if in the workspace.
|
||||
*/
|
||||
public boolean isEntriesStorageWithProject() {
|
||||
return isEntriesStorageWithProject;
|
||||
public boolean isStoringEntriesInProjectArea() {
|
||||
return storeEntriesInProjectArea;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,14 +174,20 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
* @param storeEntriesWithProject - {@code true} if with the project,
|
||||
* {@code false} if in workspace area.
|
||||
*/
|
||||
public void setEntriesStorageWithProject(boolean storeEntriesWithProject) {
|
||||
this.isEntriesStorageWithProject = storeEntriesWithProject;
|
||||
public void setStoringEntriesInProjectArea(boolean storeEntriesWithProject) {
|
||||
this.storeEntriesInProjectArea = storeEntriesWithProject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all the entries for all configurations, all resources and all languages.
|
||||
*/
|
||||
public void clear() {
|
||||
fStorage.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal convenience method to set language settings entries.
|
||||
*/
|
||||
private void setSettingEntriesInternal(String rcProjectPath, String languageId, List<ICLanguageSettingEntry> entries) {
|
||||
if (entries!=null) {
|
||||
Map<String, List<ICLanguageSettingEntry>> langMap = fStorage.get(languageId);
|
||||
|
@ -152,7 +195,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||
fStorage.put(languageId, langMap);
|
||||
}
|
||||
List<ICLanguageSettingEntry> sortedEntries = lseListPool.add(Collections.unmodifiableList(sortEntries(entries)));
|
||||
List<ICLanguageSettingEntry> sortedEntries = listPool.add(Collections.unmodifiableList(sortEntries(entries)));
|
||||
langMap.put(rcProjectPath, sortedEntries);
|
||||
} else {
|
||||
// do not keep nulls in the tables
|
||||
|
@ -166,11 +209,19 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Some providers may collect entries in pretty much random order. For the purposes of
|
||||
* predictability, UI usability and efficient storage the entries are sorted by kinds
|
||||
* and secondary by name for kinds where the secondary order is not significant.
|
||||
*
|
||||
* @param entries - list of entries to sort.
|
||||
* @return - sorted entries.
|
||||
*/
|
||||
protected List<ICLanguageSettingEntry> sortEntries(List<ICLanguageSettingEntry> entries) {
|
||||
List<ICLanguageSettingEntry> sortedEntries = new ArrayList<ICLanguageSettingEntry>(entries);
|
||||
Collections.sort(sortedEntries, new Comparator<ICLanguageSettingEntry>(){
|
||||
/**
|
||||
* This comparator sorts by kinds first and the macros are sorted additionally by name.
|
||||
* This comparator sorts by kinds first and the macros are sorted additionally by name.
|
||||
*/
|
||||
public int compare(ICLanguageSettingEntry entry0, ICLanguageSettingEntry entry1) {
|
||||
int kind0 = entry0.getKind();
|
||||
|
@ -178,17 +229,17 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
if (kind0==ICSettingEntry.MACRO && kind1==ICSettingEntry.MACRO) {
|
||||
return entry0.getName().compareTo(entry1.getName());
|
||||
}
|
||||
|
||||
|
||||
return kind0 - kind1;
|
||||
}});
|
||||
|
||||
return sortedEntries;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets language settings entries for the provider.
|
||||
* Note that the entries are not persisted at that point. To persist use TODO
|
||||
*
|
||||
*
|
||||
* @param cfgDescription - configuration description.
|
||||
* @param rc - resource such as file or folder.
|
||||
* @param languageId - language id. If {@code null}, then entries are considered to be defined for
|
||||
|
@ -202,8 +253,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* Note that this list is unmodifiable.
|
||||
* <br> Note that this list is <b>unmodifiable</b>. To modify the list copy it, change and use
|
||||
* {@link #setSettingEntries(ICConfigurationDescription, IResource, String, List)}.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||
|
@ -214,7 +266,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
if (entries!=null)
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
if (languageId!=null && (languageScope==null || languageScope.contains(languageId))) {
|
||||
List<ICLanguageSettingEntry> entries = getSettingEntries(cfgDescription, rc, null);
|
||||
return entries;
|
||||
|
@ -223,30 +275,44 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
<provider id="provider.id" ...>
|
||||
<language-scope id="lang.id"/>
|
||||
<language id="lang.id">
|
||||
<resource project-relative-path="/">
|
||||
<entry flags="" kind="includePath" name="path"/>
|
||||
</resource>
|
||||
</language>
|
||||
</provider>
|
||||
*/
|
||||
// provider/configuration/language/resource/entry
|
||||
/**
|
||||
* Serialize the provider under parent XML element.
|
||||
*
|
||||
* @param parentElement - element where to serialize.
|
||||
* @return - newly created <provider> element. That element will already be
|
||||
* attached to the parent element.
|
||||
*/
|
||||
public Element serialize(Element parentElement) {
|
||||
/*
|
||||
<provider id="provider.id" ...>
|
||||
<language-scope id="lang.id"/>
|
||||
<language id="lang.id">
|
||||
<resource project-relative-path="/">
|
||||
<entry flags="" kind="includePath" name="path"/>
|
||||
</resource>
|
||||
</language>
|
||||
</provider>
|
||||
*/
|
||||
Element elementProvider = serializeAttributes(parentElement);
|
||||
serializeEntries(elementProvider);
|
||||
return elementProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the provider attributes under parent XML element. That is
|
||||
* equivalent to serializing everything (including language scope) except entries.
|
||||
*
|
||||
* @param parentElement - element where to serialize.
|
||||
* @return - newly created <provider> element. That element will already be
|
||||
* attached to the parent element.
|
||||
*/
|
||||
public Element serializeAttributes(Element parentElement) {
|
||||
Element elementProvider = XmlUtil.appendElement(parentElement, ELEM_PROVIDER, new String[] {
|
||||
ATTR_ID, getId(),
|
||||
ATTR_NAME, getName(),
|
||||
ATTR_CLASS, getClass().getCanonicalName(),
|
||||
ATTR_PARAMETER, getCustomParameter(),
|
||||
ATTR_STORE_ENTRIES, isEntriesStorageWithProject() ? VALUE_PROJECT : VALUE_WORKSPACE,
|
||||
ATTR_STORE_ENTRIES, isStoringEntriesInProjectArea() ? VALUE_PROJECT : VALUE_WORKSPACE,
|
||||
});
|
||||
|
||||
if (languageScope!=null) {
|
||||
|
@ -256,13 +322,20 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
}
|
||||
return elementProvider;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serialize the provider entries under parent XML element.
|
||||
* @param elementProvider - element where to serialize the entries.
|
||||
*/
|
||||
public void serializeEntries(Element elementProvider) {
|
||||
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : fStorage.entrySet()) {
|
||||
serializeLanguage(elementProvider, entryLang);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the provider entries for a given language list.
|
||||
*/
|
||||
private void serializeLanguage(Element parentElement, Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang) {
|
||||
String langId = entryLang.getKey();
|
||||
if (langId!=null) {
|
||||
|
@ -274,6 +347,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the provider entries for a given resource list.
|
||||
*/
|
||||
private void serializeResource(Element parentElement, Entry<String, List<ICLanguageSettingEntry>> entryRc) {
|
||||
String rcProjectPath = entryRc.getKey();
|
||||
if (rcProjectPath!=null) {
|
||||
|
@ -283,6 +359,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
serializeSettingEntries(parentElement, entryRc.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize given settings entries.
|
||||
*/
|
||||
private void serializeSettingEntries(Element parentElement, List<ICLanguageSettingEntry> settingEntries) {
|
||||
for (ICLanguageSettingEntry entry : settingEntries) {
|
||||
Element elementSettingEntry = XmlUtil.appendElement(parentElement, ELEM_ENTRY, new String[] {
|
||||
|
@ -293,9 +372,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
case ICSettingEntry.MACRO:
|
||||
elementSettingEntry.setAttribute(ATTR_VALUE, entry.getValue());
|
||||
break;
|
||||
// case ICLanguageSettingEntry.LIBRARY_FILE:
|
||||
// TODO: sourceAttachment fields need to be covered
|
||||
// break;
|
||||
// case ICLanguageSettingEntry.LIBRARY_FILE:
|
||||
// // TODO: sourceAttachment fields may need to be covered
|
||||
// break;
|
||||
}
|
||||
int flags = entry.getFlags();
|
||||
if (flags!=0) {
|
||||
|
@ -307,6 +386,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a setting entry from XML element.
|
||||
*/
|
||||
private ICLanguageSettingEntry loadSettingEntry(Node parentElement) {
|
||||
String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND);
|
||||
String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME);
|
||||
|
@ -333,17 +415,25 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
}
|
||||
|
||||
|
||||
// provider/configuration/language/resource/entry
|
||||
/**
|
||||
* Load provider from XML provider element.
|
||||
* @param providerNode - XML element <provider> to load provider from.
|
||||
*/
|
||||
public void load(Element providerNode) {
|
||||
fStorage.clear();
|
||||
languageScope = null;
|
||||
|
||||
// provider/configuration/language/resource/entry
|
||||
if (providerNode!=null) {
|
||||
loadAttributes(providerNode);
|
||||
loadEntries(providerNode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load attributes from XML provider element.
|
||||
* @param providerNode - XML element <provider> to load attributes from.
|
||||
*/
|
||||
public void loadAttributes(Element providerNode) {
|
||||
String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID);
|
||||
String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME);
|
||||
|
@ -353,11 +443,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
this.setId(providerId);
|
||||
this.setName(providerName);
|
||||
this.setCustomParameter(providerParameter);
|
||||
this.setEntriesStorageWithProject(VALUE_PROJECT.equals(providerStoreEntries));
|
||||
}
|
||||
this.setStoringEntriesInProjectArea(VALUE_PROJECT.equals(providerStoreEntries));
|
||||
|
||||
public void loadEntries(Element providerNode) {
|
||||
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
||||
NodeList nodes = providerNode.getChildNodes();
|
||||
for (int i=0;i<nodes.getLength();i++) {
|
||||
Node elementNode = nodes.item(i);
|
||||
|
@ -366,7 +453,24 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
|
||||
if (ELEM_LANGUAGE_SCOPE.equals(elementNode.getNodeName())) {
|
||||
loadLanguageScopeElement(elementNode);
|
||||
} else if (ELEM_LANGUAGE.equals(elementNode.getNodeName())) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load provider entries from XML provider element.
|
||||
* @param providerNode - parent XML element <provider> where entries are defined.
|
||||
*/
|
||||
public void loadEntries(Element providerNode) {
|
||||
List<ICLanguageSettingEntry> settings = new ArrayList<ICLanguageSettingEntry>();
|
||||
NodeList nodes = providerNode.getChildNodes();
|
||||
for (int i=0;i<nodes.getLength();i++) {
|
||||
Node elementNode = nodes.item(i);
|
||||
if(elementNode.getNodeType() != Node.ELEMENT_NODE)
|
||||
continue;
|
||||
|
||||
if (ELEM_LANGUAGE.equals(elementNode.getNodeName())) {
|
||||
loadLanguageElement(elementNode, null);
|
||||
} else if (ELEM_RESOURCE.equals(elementNode.getNodeName())) {
|
||||
loadResourceElement(elementNode, null, null);
|
||||
|
@ -383,6 +487,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine and set language scope from given XML node.
|
||||
*/
|
||||
private void loadLanguageScopeElement(Node parentNode) {
|
||||
if (languageScope==null) {
|
||||
languageScope = new ArrayList<String>();
|
||||
|
@ -392,6 +499,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load entries defined in language element.
|
||||
*/
|
||||
private void loadLanguageElement(Node parentNode, String cfgId) {
|
||||
String langId = XmlUtil.determineAttributeValue(parentNode, ATTR_ID);
|
||||
if (langId.length()==0) {
|
||||
|
@ -420,6 +530,9 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load entries defined in resource element.
|
||||
*/
|
||||
private void loadResourceElement(Node parentNode, String cfgId, String langId) {
|
||||
String rcProjectPath = XmlUtil.determineAttributeValue(parentNode, ATTR_PROJECT_PATH);
|
||||
|
||||
|
@ -444,46 +557,47 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone storage for the entries. Copies references for lists of entries as a whole.
|
||||
* Note that is OK as the lists kept in storage are unmodifiable.
|
||||
*/
|
||||
private Map<String, Map<String, List<ICLanguageSettingEntry>>> cloneStorage() {
|
||||
Map<String, // languageId
|
||||
Map<String, // resource String
|
||||
Map<String, // resource
|
||||
List<ICLanguageSettingEntry>>> storageClone = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||
// Set<Entry<String, Map<String, Map<String, List<ICLanguageSettingEntry>>>>> entrySetCfg = fStorage.entrySet();
|
||||
// for (Entry<String, Map<String, Map<String, List<ICLanguageSettingEntry>>>> entryCfg : entrySetCfg) {
|
||||
// String cfgDescriptionId = entryCfg.getKey();
|
||||
// Map<String, Map<String, List<ICLanguageSettingEntry>>> mapLang = entryCfg.getValue();
|
||||
// Map<String, Map<String, List<ICLanguageSettingEntry>>> mapLangClone = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||
Set<Entry<String, Map<String, List<ICLanguageSettingEntry>>>> entrySetLang = fStorage.entrySet();
|
||||
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : entrySetLang) {
|
||||
String langId = entryLang.getKey();
|
||||
Map<String, List<ICLanguageSettingEntry>> mapRc = entryLang.getValue();
|
||||
Map<String, List<ICLanguageSettingEntry>> mapRcClone = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||
Set<Entry<String, List<ICLanguageSettingEntry>>> entrySetRc = mapRc.entrySet();
|
||||
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entrySetRc) {
|
||||
String rcProjectPath = entryRc.getKey();
|
||||
List<ICLanguageSettingEntry> lsEntries = entryRc.getValue();
|
||||
// don't need to clone entries, they are from the pool
|
||||
mapRcClone.put(rcProjectPath, lsEntries);
|
||||
}
|
||||
// mapLangClone.put(langId, mapRcClone);
|
||||
storageClone.put(langId, mapRcClone);
|
||||
Set<Entry<String, Map<String, List<ICLanguageSettingEntry>>>> entrySetLang = fStorage.entrySet();
|
||||
for (Entry<String, Map<String, List<ICLanguageSettingEntry>>> entryLang : entrySetLang) {
|
||||
String langId = entryLang.getKey();
|
||||
Map<String, List<ICLanguageSettingEntry>> mapRc = entryLang.getValue();
|
||||
Map<String, List<ICLanguageSettingEntry>> mapRcClone = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||
Set<Entry<String, List<ICLanguageSettingEntry>>> entrySetRc = mapRc.entrySet();
|
||||
for (Entry<String, List<ICLanguageSettingEntry>> entryRc : entrySetRc) {
|
||||
String rcProjectPath = entryRc.getKey();
|
||||
List<ICLanguageSettingEntry> lsEntries = entryRc.getValue();
|
||||
// don't need to clone entries, they are from the LSE pool
|
||||
mapRcClone.put(rcProjectPath, lsEntries);
|
||||
}
|
||||
// }
|
||||
storageClone.put(langId, mapRcClone);
|
||||
}
|
||||
return storageClone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shallow clone of the provider. "Shallow" is defined here as the exact copy except that
|
||||
* the copy will have zero language settings entries.
|
||||
*
|
||||
* @return shallow copy of the provider.
|
||||
* @throws CloneNotSupportedException in case {@link #clone()} throws the exception.
|
||||
*/
|
||||
protected LanguageSettingsSerializable cloneShallow() throws CloneNotSupportedException {
|
||||
LanguageSettingsSerializable clone = (LanguageSettingsSerializable)super.clone();
|
||||
if (languageScope!=null)
|
||||
clone.languageScope = new ArrayList<String>(languageScope);
|
||||
|
||||
|
||||
clone.fStorage = new HashMap<String, Map<String, List<ICLanguageSettingEntry>>>();
|
||||
return clone;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
protected LanguageSettingsSerializable clone() throws CloneNotSupportedException {
|
||||
LanguageSettingsSerializable clone = cloneShallow();
|
||||
|
@ -499,7 +613,7 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
||||
result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode());
|
||||
result = prime * result + ((customParameter == null) ? 0 : customParameter.hashCode());
|
||||
result = prime * result + (isEntriesStorageWithProject ? 0 : 1);
|
||||
result = prime * result + (storeEntriesInProjectArea ? 0 : 1);
|
||||
result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode());
|
||||
result = prime * result + getClass().hashCode();
|
||||
return result;
|
||||
|
@ -507,7 +621,6 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
|
||||
/**
|
||||
* @return {@code true} if the objects are equal, {@code false } otherwise.
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
|
@ -547,8 +660,8 @@ public class LanguageSettingsSerializable extends LanguageSettingsBaseProvider {
|
|||
return false;
|
||||
} else if (!customParameter.equals(other.customParameter))
|
||||
return false;
|
||||
|
||||
if (isEntriesStorageWithProject!=other.isEntriesStorageWithProject)
|
||||
|
||||
if (storeEntriesInProjectArea!=other.storeEntriesInProjectArea)
|
||||
return false;
|
||||
|
||||
if (fStorage == null) {
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009, 2011 Andrew Gvozdev 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:
|
||||
* Andrew Gvozdev - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.language.settings.providers;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -41,11 +52,12 @@ public class LanguageSettingsProvidersSerializer {
|
|||
private static final String ATTR_POINT = "point"; //$NON-NLS-1$
|
||||
private static final String ELEM_PROJECT = "project"; //$NON-NLS-1$
|
||||
private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$
|
||||
private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$
|
||||
private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$
|
||||
/** Cache of globally available providers to be consumed by calling clients */
|
||||
private static Map<String, ILanguageSettingsProvider> rawGlobalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
|
||||
private static Object serializingLock = new Object();
|
||||
|
||||
|
||||
private static class LanguageSettingsWorkspaceProvider implements ILanguageSettingsProvider {
|
||||
private String providerId;
|
||||
|
||||
|
@ -54,7 +66,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
Assert.isTrue(id.length()>0);
|
||||
providerId = id;
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return providerId;
|
||||
}
|
||||
|
@ -72,12 +84,12 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Do not cache the "raw" provider as workspace provider can be changed at any time.
|
||||
* Do not cache the "raw" provider as workspace provider can be changed at any time.
|
||||
*/
|
||||
private ILanguageSettingsProvider getRawProvider() {
|
||||
return LanguageSettingsProvidersSerializer.getRawWorkspaceProvider(providerId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof LanguageSettingsWorkspaceProvider) {
|
||||
|
@ -96,7 +108,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** static initializer */
|
||||
static {
|
||||
try {
|
||||
|
@ -104,9 +116,31 @@ public class LanguageSettingsProvidersSerializer {
|
|||
} catch (Throwable e) {
|
||||
CCorePlugin.log("Error loading workspace language settings providers", e); //$NON-NLS-1$
|
||||
} finally {
|
||||
// swallow any exception
|
||||
}
|
||||
}
|
||||
|
||||
private static IFile getStoreInProjectArea(IProject project) throws CoreException {
|
||||
IFolder folder = project.getFolder(SETTINGS_FOLDER_NAME);
|
||||
if (!folder.exists()) {
|
||||
folder.create(true, true, null);
|
||||
}
|
||||
IFile storage = folder.getFile(STORAGE_PROJECT_LANGUAGE_SETTINGS);
|
||||
return storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: refactor with ErrorParserManager ?
|
||||
*
|
||||
* @param store - name of the store
|
||||
* @return location of the store in the plug-in state area
|
||||
*/
|
||||
private static URI getStoreInWorkspaceArea(String store) {
|
||||
IPath location = CCorePlugin.getDefault().getStateLocation().append(store);
|
||||
URI uri = URIUtil.toURI(location);
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set and store in workspace area user defined providers.
|
||||
*
|
||||
|
@ -132,7 +166,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
rawWorkspaceProviders.put(rawExtensionProvider.getId(), rawExtensionProvider);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (providers!=null) {
|
||||
List<ILanguageSettingsProvider> rawProviders = new ArrayList<ILanguageSettingsProvider>();
|
||||
for (ILanguageSettingsProvider provider : providers) {
|
||||
|
@ -147,24 +181,12 @@ public class LanguageSettingsProvidersSerializer {
|
|||
rawWorkspaceProviders.put(provider.getId(), provider);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rawGlobalWorkspaceProviders = rawWorkspaceProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: refactor with ErrorParserManager
|
||||
*
|
||||
* @param store - name of the store
|
||||
* @return location of the store in the plug-in state area
|
||||
*/
|
||||
private static URI getStoreLocationInWorkspaceArea(String store) {
|
||||
IPath location = CCorePlugin.getDefault().getStateLocation().append(store);
|
||||
URI uri = URIUtil.toURI(location);
|
||||
return uri;
|
||||
}
|
||||
|
||||
public static void serializeLanguageSettingsWorkspace() throws CoreException {
|
||||
URI uriLocation = getStoreLocationInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
URI uriLocation = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
List<LanguageSettingsSerializable> serializableExtensionProviders = new ArrayList<LanguageSettingsSerializable>();
|
||||
for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) {
|
||||
if (provider instanceof LanguageSettingsSerializable) {
|
||||
|
@ -183,19 +205,19 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN);
|
||||
Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID});
|
||||
|
||||
|
||||
for (LanguageSettingsSerializable provider : serializableExtensionProviders) {
|
||||
provider.serialize(elementExtension);
|
||||
}
|
||||
|
||||
|
||||
synchronized (serializingLock) {
|
||||
XmlUtil.serializeXml(doc, uriLocation);
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
CCorePlugin.log("Internal error while trying to serialize language settings", e); //$NON-NLS-1$
|
||||
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e);
|
||||
|
@ -205,9 +227,9 @@ public class LanguageSettingsProvidersSerializer {
|
|||
|
||||
public static void loadLanguageSettingsWorkspace() throws CoreException {
|
||||
List <ILanguageSettingsProvider> providers = null;
|
||||
|
||||
URI uriLocation = getStoreLocationInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
|
||||
|
||||
URI uriLocation = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
|
||||
Document doc = null;
|
||||
try {
|
||||
synchronized (serializingLock) {
|
||||
|
@ -216,12 +238,12 @@ public class LanguageSettingsProvidersSerializer {
|
|||
} catch (Exception e) {
|
||||
CCorePlugin.log("Can't load preferences from file "+uriLocation, e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
if (doc!=null) {
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
NodeList providerNodes = rootElement.getElementsByTagName(LanguageSettingsSerializable.ELEM_PROVIDER);
|
||||
|
||||
List<String> userDefinedProvidersIds = new ArrayList<String>();
|
||||
|
||||
List<String> userDefinedProvidersIds = new ArrayList<String>();
|
||||
for (int i=0;i<providerNodes.getLength();i++) {
|
||||
Node providerNode = providerNodes.item(i);
|
||||
String providerId = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_ID);
|
||||
|
@ -231,12 +253,12 @@ public class LanguageSettingsProvidersSerializer {
|
|||
continue;
|
||||
}
|
||||
userDefinedProvidersIds.add(providerId);
|
||||
|
||||
|
||||
ILanguageSettingsProvider provider = loadProvider(providerNode);
|
||||
if (provider!=null) {
|
||||
if (providers==null)
|
||||
providers= new ArrayList<ILanguageSettingsProvider>();
|
||||
|
||||
|
||||
if (!LanguageSettingsExtensionManager.equalsExtensionProvider(provider)) {
|
||||
providers.add(provider);
|
||||
}
|
||||
|
@ -246,17 +268,24 @@ public class LanguageSettingsProvidersSerializer {
|
|||
setWorkspaceProvidersInternal(providers);
|
||||
}
|
||||
|
||||
public static void serializeLanguageSettings(Element parentElement, ICProjectDescription prjDescription) throws CoreException {
|
||||
/**
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
* It is public solely for benefit of JUnit testing.
|
||||
*/
|
||||
public static void serializeLanguageSettingsInternal(Element projectElementPrjStore, Element projectElementWspStore, ICProjectDescription prjDescription) throws CoreException {
|
||||
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations();
|
||||
for (ICConfigurationDescription cfgDescription : cfgDescriptions) {
|
||||
Element elementConfiguration = XmlUtil.appendElement(parentElement, ELEM_CONFIGURATION, new String[] {
|
||||
Element elementConfiguration = XmlUtil.appendElement(projectElementPrjStore, ELEM_CONFIGURATION, new String[] {
|
||||
LanguageSettingsExtensionManager.ATTR_ID, cfgDescription.getId(),
|
||||
LanguageSettingsExtensionManager.ATTR_NAME, cfgDescription.getName(),
|
||||
});
|
||||
Element elementConfigurationWsp = null;
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
if (providers.size()>0) {
|
||||
Element elementExtension = XmlUtil.appendElement(elementConfiguration, ELEM_EXTENSION, new String[] {
|
||||
ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID});
|
||||
Element elementExtensionWsp = null;
|
||||
for (ILanguageSettingsProvider provider : providers) {
|
||||
if (isWorkspaceProvider(provider)) {
|
||||
// Element elementProviderReference =
|
||||
|
@ -265,7 +294,29 @@ public class LanguageSettingsProvidersSerializer {
|
|||
continue;
|
||||
}
|
||||
if (provider instanceof LanguageSettingsSerializable) {
|
||||
((LanguageSettingsSerializable) provider).serialize(elementExtension);
|
||||
LanguageSettingsSerializable lss = (LanguageSettingsSerializable) provider;
|
||||
|
||||
boolean useWsp = projectElementWspStore!=null && projectElementPrjStore!=projectElementWspStore;
|
||||
if (lss.isStoringEntriesInProjectArea() || !useWsp) {
|
||||
lss.serialize(elementExtension);
|
||||
} else {
|
||||
lss.serializeAttributes(elementExtension);
|
||||
|
||||
// lazy initialization of elements - to avoid serialization of no-data file
|
||||
if (elementExtensionWsp==null) {
|
||||
if (elementConfigurationWsp==null) {
|
||||
elementConfigurationWsp = XmlUtil.appendElement(projectElementWspStore, ELEM_CONFIGURATION, new String[] {
|
||||
LanguageSettingsExtensionManager.ATTR_ID, cfgDescription.getId(),
|
||||
LanguageSettingsExtensionManager.ATTR_NAME, cfgDescription.getName(),
|
||||
});
|
||||
}
|
||||
elementExtensionWsp = XmlUtil.appendElement(elementConfigurationWsp, ELEM_EXTENSION, new String[] {
|
||||
ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID});
|
||||
}
|
||||
Element elementProviderWsp = XmlUtil.appendElement(elementExtensionWsp, ELEM_PROVIDER, new String[] {
|
||||
LanguageSettingsExtensionManager.ATTR_ID, provider.getId()});
|
||||
lss.serializeEntries(elementProviderWsp);
|
||||
}
|
||||
} else {
|
||||
// Element elementProvider =
|
||||
XmlUtil.appendElement(elementExtension, LanguageSettingsExtensionManager.ELEM_PROVIDER, new String[] {
|
||||
|
@ -279,27 +330,35 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
}
|
||||
|
||||
private static IFile getStorage(IProject project) throws CoreException {
|
||||
IFolder folder = project.getFolder(SETTINGS_FOLDER_NAME);
|
||||
if (!folder.exists()) {
|
||||
folder.create(true, true, null);
|
||||
}
|
||||
IFile storage = folder.getFile(STORAGE_PROJECT_LANGUAGE_SETTINGS);
|
||||
return storage;
|
||||
}
|
||||
|
||||
public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException {
|
||||
IProject project = prjDescription.getProject();
|
||||
try {
|
||||
Document doc = XmlUtil.newDocument();
|
||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_PROJECT);
|
||||
serializeLanguageSettings(rootElement, prjDescription);
|
||||
|
||||
IFile file = getStorage(project);
|
||||
// Document to store in project area
|
||||
Document docPrjStore = XmlUtil.newDocument();
|
||||
Element projectElementPrjStore = XmlUtil.appendElement(docPrjStore, ELEM_PROJECT);
|
||||
// Document to store in workspace area
|
||||
Document docWspStore = XmlUtil.newDocument();
|
||||
Element projectElementWspStore = XmlUtil.appendElement(docWspStore, ELEM_PROJECT);
|
||||
|
||||
serializeLanguageSettingsInternal(projectElementPrjStore, projectElementWspStore, prjDescription);
|
||||
|
||||
IFile filePrjStore = getStoreInProjectArea(project);
|
||||
URI uriWspStore = null;
|
||||
boolean isWorkspaceStoreEmpty = projectElementWspStore.getChildNodes().getLength() == 0;
|
||||
uriWspStore = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
|
||||
synchronized (serializingLock){
|
||||
XmlUtil.serializeXml(doc, file);
|
||||
// The project store should not be absent. Absent store means legacy project, not 0 providers.
|
||||
XmlUtil.serializeXml(docPrjStore, filePrjStore);
|
||||
|
||||
// project-specific location in workspace area
|
||||
if (!isWorkspaceStoreEmpty) {
|
||||
XmlUtil.serializeXml(docWspStore, uriWspStore);
|
||||
} else {
|
||||
new java.io.File(uriWspStore).delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Internal error while trying to serialize language settings", e);
|
||||
CCorePlugin.log(s);
|
||||
|
@ -307,7 +366,11 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
}
|
||||
|
||||
public static void loadLanguageSettings(Element parentElement, ICProjectDescription prjDescription) {
|
||||
/**
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
* It is public solely for benefit of JUnit testing.
|
||||
*/
|
||||
public static void loadLanguageSettingsInternal(Element projectElementPrj, Element projectElementWsp, ICProjectDescription prjDescription) {
|
||||
/*
|
||||
<project>
|
||||
<configuration id="cfg.id">
|
||||
|
@ -318,7 +381,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
</configuration>
|
||||
</project>
|
||||
*/
|
||||
NodeList configurationNodes = parentElement.getChildNodes();
|
||||
NodeList configurationNodes = projectElementPrj.getChildNodes();
|
||||
for (int ic=0;ic<configurationNodes.getLength();ic++) {
|
||||
Node cfgNode = configurationNodes.item(ic);
|
||||
if (!(cfgNode instanceof Element && cfgNode.getNodeName().equals(ELEM_CONFIGURATION)) )
|
||||
|
@ -327,27 +390,33 @@ public class LanguageSettingsProvidersSerializer {
|
|||
String cfgId = XmlUtil.determineAttributeValue(cfgNode, LanguageSettingsExtensionManager.ATTR_ID);
|
||||
@SuppressWarnings("unused")
|
||||
String cfgName = XmlUtil.determineAttributeValue(cfgNode, LanguageSettingsExtensionManager.ATTR_NAME);
|
||||
|
||||
|
||||
NodeList extensionAndReferenceNodes = cfgNode.getChildNodes();
|
||||
for (int ie=0;ie<extensionAndReferenceNodes.getLength();ie++) {
|
||||
Node extNode = extensionAndReferenceNodes.item(ie);
|
||||
if (!(extNode instanceof Element))
|
||||
continue;
|
||||
|
||||
|
||||
if (extNode.getNodeName().equals(ELEM_EXTENSION)) {
|
||||
NodeList providerNodes = extNode.getChildNodes();
|
||||
|
||||
|
||||
for (int i=0;i<providerNodes.getLength();i++) {
|
||||
Node providerNode = providerNodes.item(i);
|
||||
if (!(providerNode instanceof Element))
|
||||
continue;
|
||||
|
||||
|
||||
ILanguageSettingsProvider provider=null;
|
||||
if (providerNode.getNodeName().equals(ELEM_PROVIDER_REFERENCE)) {
|
||||
String providerId = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_ID);
|
||||
provider = getWorkspaceProvider(providerId);
|
||||
} else if (providerNode.getNodeName().equals(LanguageSettingsExtensionManager.ELEM_PROVIDER)) {
|
||||
provider = loadProvider(providerNode);
|
||||
if (provider instanceof LanguageSettingsSerializable) {
|
||||
LanguageSettingsSerializable lss = (LanguageSettingsSerializable) provider;
|
||||
if (!lss.isStoringEntriesInProjectArea() && projectElementWsp!=null) {
|
||||
loadProviderEntries(lss, cfgId, projectElementWsp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (provider!=null) {
|
||||
providers.add(provider);
|
||||
|
@ -355,17 +424,67 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ICConfigurationDescription cfgDescription = prjDescription.getConfigurationById(cfgId);
|
||||
if (cfgDescription!=null)
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadProviderEntries(LanguageSettingsSerializable provider, String cfgId, Element projectElementWsp) {
|
||||
/*
|
||||
<project>
|
||||
<configuration id="cfg.id">
|
||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider .../>
|
||||
<provider-reference id="..."/>
|
||||
</extension>
|
||||
</configuration>
|
||||
</project>
|
||||
*/
|
||||
NodeList configurationNodes = projectElementWsp.getChildNodes();
|
||||
for (int ic=0;ic<configurationNodes.getLength();ic++) {
|
||||
Node cfgNode = configurationNodes.item(ic);
|
||||
if (!(cfgNode instanceof Element && cfgNode.getNodeName().equals(ELEM_CONFIGURATION)) )
|
||||
continue;
|
||||
String cfgIdXml = XmlUtil.determineAttributeValue(cfgNode, LanguageSettingsExtensionManager.ATTR_ID);
|
||||
if (!cfgId.equals(cfgIdXml))
|
||||
continue;
|
||||
|
||||
NodeList extensionAndReferenceNodes = cfgNode.getChildNodes();
|
||||
for (int ie=0;ie<extensionAndReferenceNodes.getLength();ie++) {
|
||||
Node extNode = extensionAndReferenceNodes.item(ie);
|
||||
if (!(extNode instanceof Element))
|
||||
continue;
|
||||
|
||||
if (extNode.getNodeName().equals(ELEM_EXTENSION)) {
|
||||
NodeList providerNodes = extNode.getChildNodes();
|
||||
|
||||
for (int i=0;i<providerNodes.getLength();i++) {
|
||||
Node providerNode = providerNodes.item(i);
|
||||
if (!(providerNode instanceof Element))
|
||||
continue;
|
||||
if (!providerNode.getNodeName().equals(LanguageSettingsExtensionManager.ELEM_PROVIDER))
|
||||
continue;
|
||||
String providerIdXml = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_ID);
|
||||
if (!provider.getId().equals(providerIdXml))
|
||||
continue;
|
||||
|
||||
provider.loadEntries((Element) providerNode);
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static ILanguageSettingsProvider loadProvider(Node providerNode) {
|
||||
String attrClass = XmlUtil.determineAttributeValue(providerNode, LanguageSettingsExtensionManager.ATTR_CLASS);
|
||||
ILanguageSettingsProvider provider = LanguageSettingsExtensionManager.getProviderInstance(attrClass);
|
||||
|
||||
|
||||
if (provider instanceof LanguageSettingsSerializable)
|
||||
((LanguageSettingsSerializable)provider).load((Element) providerNode);
|
||||
|
||||
|
@ -388,15 +507,28 @@ public class LanguageSettingsProvidersSerializer {
|
|||
synchronized (serializingLock) {
|
||||
doc = XmlUtil.loadXml(file);
|
||||
}
|
||||
Element rootElement = doc.getDocumentElement(); // <project/>
|
||||
loadLanguageSettings(rootElement, prjDescription);
|
||||
Element rootElementPrj = doc.getDocumentElement(); // <project/>
|
||||
|
||||
URI uriLocation = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
Document docWsp = null;
|
||||
synchronized (serializingLock) {
|
||||
docWsp = XmlUtil.loadXml(uriLocation);
|
||||
}
|
||||
|
||||
Element rootElementWsp = null; // <project/>
|
||||
if (docWsp!=null) {
|
||||
rootElementWsp = docWsp.getDocumentElement();
|
||||
}
|
||||
|
||||
|
||||
loadLanguageSettingsInternal(rootElementPrj, rootElementWsp, prjDescription);
|
||||
} catch (Exception e) {
|
||||
CCorePlugin.log("Can't load preferences from file "+file.getLocation(), e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
if (doc!=null) {
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
// Already existing legacy projects
|
||||
ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations();
|
||||
|
@ -408,7 +540,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -433,7 +565,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
/**
|
||||
* TODO
|
||||
* @return ordered set of providers defined in the workspace which include contributed through extension + user defined ones
|
||||
*
|
||||
*
|
||||
*/
|
||||
public static List<ILanguageSettingsProvider> getWorkspaceProviders() {
|
||||
ArrayList<ILanguageSettingsProvider> workspaceProviders = new ArrayList<ILanguageSettingsProvider>();
|
||||
|
@ -448,9 +580,9 @@ public class LanguageSettingsProvidersSerializer {
|
|||
*
|
||||
* @param provider - provider to check.
|
||||
* @return {@code true} if the given provider is workspace provider, {@code false} otherwise.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public static boolean isWorkspaceProvider(ILanguageSettingsProvider provider) {
|
||||
return provider instanceof LanguageSettingsWorkspaceProvider;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,14 +102,14 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
MOVEUP_STR,
|
||||
MOVEDOWN_STR,
|
||||
};
|
||||
|
||||
|
||||
private final static String[] BUTTON_LABELS_PREF = {
|
||||
// RENAME_STR,
|
||||
// RUN_STR,
|
||||
CLEAR_STR,
|
||||
RESET_STR,
|
||||
};
|
||||
|
||||
|
||||
private static final int[] DEFAULT_CONFIGURE_SASH_WEIGHTS = new int[] { 50, 50 };
|
||||
private SashForm sashFormConfigure;
|
||||
|
||||
|
@ -118,14 +118,14 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
private Group groupOptionsPage;
|
||||
private ICOptionPage currentOptionsPage = null;
|
||||
private Composite compositeOptionsPage;
|
||||
|
||||
|
||||
private Button enableProvidersCheckBox;
|
||||
private StatusMessageLine fStatusLine;
|
||||
|
||||
private Button globalProviderCheckBox = null;
|
||||
private Link linkWorkspacePreferences = null;
|
||||
private Button projectStorageCheckBox = null;
|
||||
|
||||
|
||||
private Page_LanguageSettingsProviders masterPropertyPage = null;
|
||||
|
||||
/**
|
||||
|
@ -136,36 +136,36 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
private List<ILanguageSettingsProvider> presentedProviders = null;
|
||||
private final Map<String, ICOptionPage> optionsPageMap = new HashMap<String, ICOptionPage>();
|
||||
private Map<String, List<ILanguageSettingsProvider>> initialProvidersByCfg = new HashMap<String, List<ILanguageSettingsProvider>>();
|
||||
|
||||
|
||||
private boolean initialEnablement = false;
|
||||
|
||||
|
||||
/**
|
||||
* Returns current working copy of the provider. Creates one if it has not been created yet.
|
||||
* Used by option pages when there is a need to modify the provider.
|
||||
* Warning: Do not cache the result as the provider can be replaced at any time.
|
||||
* @param providerId
|
||||
*
|
||||
* @param providerId
|
||||
*
|
||||
* @return the provider
|
||||
*/
|
||||
public ILanguageSettingsProvider getWorkingCopy(String providerId) {
|
||||
ILanguageSettingsProvider provider = findProvider(providerId, presentedProviders);
|
||||
if (isWorkingCopy(provider))
|
||||
return provider;
|
||||
|
||||
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
Assert.isTrue(rawProvider instanceof ILanguageSettingsEditableProvider);
|
||||
|
||||
|
||||
ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider)rawProvider;
|
||||
try {
|
||||
ILanguageSettingsEditableProvider newProvider = editableProvider.clone();
|
||||
replaceSelectedProvider(newProvider);
|
||||
return newProvider;
|
||||
|
||||
|
||||
} catch (CloneNotSupportedException e) {
|
||||
CUIPlugin.log("Error cloning provider " + editableProvider.getId(), e);
|
||||
// TODO warning dialog for user?
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -173,19 +173,19 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
@Override
|
||||
protected String[] getOverlayKeys(ILanguageSettingsProvider provider) {
|
||||
String[] overlayKeys = super.getOverlayKeys(provider);
|
||||
|
||||
|
||||
ILanguageSettingsProvider rawProvider = page.isForPrefs() ? LanguageSettingsManager.getRawProvider(provider) : provider;
|
||||
if (LanguageSettingsManager_TBD.isReconfigured(rawProvider)) {
|
||||
overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING;
|
||||
}
|
||||
|
||||
|
||||
if (isWorkingCopy(provider)) {
|
||||
overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_EDITED;
|
||||
}
|
||||
return overlayKeys;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut for getting the current resource for the property page.
|
||||
*/
|
||||
|
@ -199,7 +199,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
private ICConfigurationDescription getConfigurationDescription() {
|
||||
if (page.isForPrefs())
|
||||
return null;
|
||||
|
||||
|
||||
ICConfigurationDescription cfgDescription = getResDesc().getConfiguration();
|
||||
return cfgDescription;
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
initialEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createControls(Composite parent) {
|
||||
super.createControls(parent);
|
||||
|
@ -239,7 +239,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
GridData gd = (GridData) usercomp.getLayoutData();
|
||||
// Discourage settings entry table from trying to show all its items at once, see bug 264330
|
||||
gd.heightHint =1;
|
||||
|
||||
|
||||
if (page instanceof Page_LanguageSettingsProviders) {
|
||||
masterPropertyPage = (Page_LanguageSettingsProviders) page;
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
|
||||
// SashForms for each mode
|
||||
createConfigureSashForm();
|
||||
|
||||
|
||||
// Status line
|
||||
fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2);
|
||||
|
||||
|
@ -290,7 +290,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
// Providers table
|
||||
Composite compositeSashForm = new Composite(sashFormConfigure, SWT.BORDER | SWT.SINGLE);
|
||||
compositeSashForm.setLayout(new GridLayout());
|
||||
|
||||
|
||||
// items checkboxes only for project properties page
|
||||
tableProviders = new Table(compositeSashForm, page.isForPrefs() ? SWT.NONE : SWT.CHECK);
|
||||
tableProviders.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
@ -353,14 +353,14 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
}
|
||||
if (newProvider!=null) {
|
||||
replaceSelectedProvider(newProvider);
|
||||
|
||||
|
||||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||
initializeOptionsPage(newProvider, cfgDescription);
|
||||
displaySelectedOptionPage();
|
||||
} else {
|
||||
newProvider = oldProvider;
|
||||
}
|
||||
|
||||
|
||||
return newProvider;
|
||||
}
|
||||
|
||||
|
@ -373,7 +373,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
ICConfigurationDescription cfgDescription = null;
|
||||
if (!page.isForPrefs()) {
|
||||
cfgDescription = getConfigurationDescription();
|
||||
|
||||
|
||||
List<ILanguageSettingsProvider> cfgProviders = new ArrayList<ILanguageSettingsProvider>(cfgDescription.getLanguageSettingProviders());
|
||||
pos = getProviderIndex(newProvider.getId(), cfgProviders);
|
||||
cfgProviders.set(pos, newProvider);
|
||||
|
@ -392,7 +392,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
groupOptionsPage = new Group(sashFormConfigure, SWT.SHADOW_ETCHED_IN);
|
||||
groupOptionsPage.setText("Language Settings Provider Options");
|
||||
groupOptionsPage.setLayout(new GridLayout(2, false));
|
||||
|
||||
|
||||
if (!page.isForPrefs()) {
|
||||
if (globalProviderCheckBox==null) {
|
||||
globalProviderCheckBox = new Button(groupOptionsPage, SWT.CHECK);
|
||||
|
@ -406,7 +406,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
provider = toggleGlobalProvider(provider, isGlobal);
|
||||
}
|
||||
projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializable
|
||||
&& ((LanguageSettingsSerializable) provider).isEntriesStorageWithProject());
|
||||
&& ((LanguageSettingsSerializable) provider).isStoringEntriesInProjectArea());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -415,7 +415,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
projectStorageCheckBox = new Button(groupOptionsPage, SWT.CHECK);
|
||||
projectStorageCheckBox.setText("Store entries in project settings folder (supporting project miration)");
|
||||
projectStorageCheckBox.addSelectionListener(new SelectionAdapter() {
|
||||
|
@ -424,7 +424,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
boolean isWithProject = projectStorageCheckBox.getSelection();
|
||||
ILanguageSettingsProvider provider = getWorkingCopy(getSelectedProvider().getId());
|
||||
Assert.isTrue(provider instanceof LanguageSettingsSerializable);
|
||||
((LanguageSettingsSerializable)provider).setEntriesStorageWithProject(isWithProject);
|
||||
((LanguageSettingsSerializable)provider).setStoringEntriesInProjectArea(isWithProject);
|
||||
refreshItem(provider);
|
||||
}
|
||||
|
||||
|
@ -434,7 +434,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
linkWorkspacePreferences = createLinkToPreferences(groupOptionsPage, 2);
|
||||
}
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
|
||||
private void enableSashForm(SashForm sashForm, boolean enable) {
|
||||
sashForm.setVisible(enable);
|
||||
// Some of woodoo to fill properties page vertically and still keep right border visible in preferences
|
||||
// Some of woodoo to fill properties page vertically and still keep right border visible in preferences
|
||||
GridData gd = new GridData(enable || page.isForPrefs() ? GridData.FILL_BOTH : SWT.NONE);
|
||||
gd.horizontalSpan = 2;
|
||||
gd.heightHint = enable ? SWT.DEFAULT : 0;
|
||||
|
@ -456,7 +456,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
sashFormConfigure.setEnabled(enable);
|
||||
tableProviders.setEnabled(enable);
|
||||
compositeOptionsPage.setEnabled(enable);
|
||||
|
||||
|
||||
buttoncomp.setEnabled(enable);
|
||||
|
||||
if (enable) {
|
||||
|
@ -468,7 +468,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
disableButtons();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Populate provider tables and their option pages which are used in Configure mode
|
||||
*/
|
||||
|
@ -484,7 +484,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
List<ILanguageSettingsProvider> cfgProviders = cfgDescription.getLanguageSettingProviders();
|
||||
tableProvidersViewer.setCheckedElements(cfgProviders.toArray(new ILanguageSettingsProvider[0]));
|
||||
}
|
||||
|
||||
|
||||
if (selectedId!=null) {
|
||||
for (int i=0; i<presentedProviders.size(); i++) {
|
||||
if (selectedId.equals(presentedProviders.get(i).getId())) {
|
||||
|
@ -493,7 +493,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
optionsPageMap.clear();
|
||||
for (ILanguageSettingsProvider provider : presentedProviders) {
|
||||
initializeOptionsPage(provider, cfgDescription);
|
||||
|
@ -518,9 +518,9 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
} else {
|
||||
providers = new ArrayList<ILanguageSettingsProvider>();
|
||||
}
|
||||
|
||||
|
||||
List<ILanguageSettingsProvider> workspaceProviders = LanguageSettingsManager.getWorkspaceProviders();
|
||||
|
||||
|
||||
// ensure sorting by name all unchecked providers
|
||||
Set<ILanguageSettingsProvider> allAvailableProvidersSet = new TreeSet<ILanguageSettingsProvider>(new Comparator<ILanguageSettingsProvider>() {
|
||||
public int compare(ILanguageSettingsProvider prov1, ILanguageSettingsProvider prov2) {
|
||||
|
@ -541,7 +541,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
idsList.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// renders better when using temporary
|
||||
presentedProviders = providers;
|
||||
tableProvidersViewer.setInput(presentedProviders);
|
||||
|
@ -559,20 +559,20 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
((AbstractLanguageSettingProviderOptionPage)optionsPage).init(this, provider.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return optionsPage;
|
||||
}
|
||||
|
||||
private void initializeOptionsPage(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription) {
|
||||
ICOptionPage optionsPage = createOptionsPage(provider, cfgDescription);
|
||||
|
||||
|
||||
if (optionsPage!=null) {
|
||||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider);
|
||||
boolean isEditableForProject = page.isForProject() && provider instanceof ILanguageSettingsEditableProvider;
|
||||
boolean isEditableForPrefs = page.isForPrefs() && rawProvider instanceof ILanguageSettingsEditableProvider;
|
||||
boolean isEditable = isEditableForProject || isEditableForPrefs;
|
||||
compositeOptionsPage.setEnabled(isEditable);
|
||||
|
||||
|
||||
String id = (provider!=null) ? provider.getId() : null;
|
||||
optionsPageMap.put(id, optionsPage);
|
||||
optionsPage.setContainer(page);
|
||||
|
@ -601,12 +601,12 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
globalProviderCheckBox.setSelection(isGlobal);
|
||||
globalProviderCheckBox.setEnabled(isChecked && isRawProviderEditable);
|
||||
globalProviderCheckBox.setVisible(provider!=null);
|
||||
|
||||
|
||||
projectStorageCheckBox.setEnabled(!isGlobal);
|
||||
projectStorageCheckBox.setVisible(rawProvider instanceof LanguageSettingsSerializable);
|
||||
projectStorageCheckBox.setSelection(provider instanceof LanguageSettingsSerializable
|
||||
&& ((LanguageSettingsSerializable)provider).isEntriesStorageWithProject());
|
||||
|
||||
&& ((LanguageSettingsSerializable)provider).isStoringEntriesInProjectArea());
|
||||
|
||||
boolean needPreferencesLink=isGlobal && currentOptionsPage!=null;
|
||||
// TODO: message
|
||||
final String linkMsg = needPreferencesLink ? "Options of global providers can be changed in <a href=\"workspace\">Workspace Settings</a>, Discovery Tab." : "";
|
||||
|
@ -614,7 +614,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
linkWorkspacePreferences.pack();
|
||||
linkWorkspacePreferences.setEnabled(isChecked);
|
||||
}
|
||||
|
||||
|
||||
if (currentOptionsPage != null) {
|
||||
boolean isEditableForProject = page.isForProject() && provider instanceof ILanguageSettingsEditableProvider;
|
||||
boolean isEditableForPrefs = page.isForPrefs() && rawProvider instanceof ILanguageSettingsEditableProvider;
|
||||
|
@ -638,7 +638,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
}
|
||||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||
cfgDescription.setLanguageSettingProviders(providers);
|
||||
|
||||
|
||||
if (selectedElement!=null) {
|
||||
tableProvidersViewer.update(selectedElement, null);
|
||||
if (selectedElement instanceof ILanguageSettingsProvider) {
|
||||
|
@ -682,15 +682,15 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
canClear = canForWorkspace || canForProject;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean canReset = false;
|
||||
if (rawProvider!=null && (canForWorkspace || canForProject)) {
|
||||
canReset = ! LanguageSettingsManager_TBD.isEqualExtensionProvider(rawProvider);
|
||||
}
|
||||
|
||||
|
||||
boolean canMoveUp = page.isForProject() && isProviderSelected && isRangeOk && pos!=0;
|
||||
boolean canMoveDown = page.isForProject() && isProviderSelected && isRangeOk && pos!=last;
|
||||
|
||||
|
||||
// buttonSetEnabled(BUTTON_RENAME, false);
|
||||
// buttonSetEnabled(BUTTON_RUN, false);
|
||||
buttonSetEnabled(BUTTON_CLEAR, canClear);
|
||||
|
@ -748,7 +748,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(selectedProvider);
|
||||
if (rawProvider instanceof ILanguageSettingsEditableProvider) {
|
||||
ILanguageSettingsEditableProvider editableProvider = (ILanguageSettingsEditableProvider) rawProvider;
|
||||
|
||||
|
||||
try {
|
||||
ILanguageSettingsEditableProvider newProvider = editableProvider.cloneShallow();
|
||||
replaceSelectedProvider(newProvider);
|
||||
|
@ -756,13 +756,13 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||
initializeOptionsPage(newProvider, cfgDescription);
|
||||
displaySelectedOptionPage();
|
||||
|
||||
|
||||
} catch (CloneNotSupportedException e) {
|
||||
CUIPlugin.log("Error cloning provider " + editableProvider.getId(), e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
updateButtons();
|
||||
}
|
||||
|
@ -787,7 +787,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
List<ILanguageSettingsProvider> initialProviders = initialProvidersByCfg.get(cfgDescription.getId());
|
||||
isWorkingCopy = ! initialProviders.contains(provider);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return isWorkingCopy;
|
||||
}
|
||||
|
@ -809,10 +809,10 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
|
||||
private void moveProvider(int oldPos, int newPos) {
|
||||
Collections.swap(presentedProviders, oldPos, newPos);
|
||||
|
||||
|
||||
updateProvidersTable();
|
||||
tableProviders.setSelection(newPos);
|
||||
|
||||
|
||||
saveCheckedProviders(null);
|
||||
updateButtons();
|
||||
}
|
||||
|
@ -847,7 +847,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
} else {
|
||||
setAllVisible(true, null);
|
||||
}
|
||||
|
||||
|
||||
if (masterPropertyPage!=null) {
|
||||
boolean enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled();
|
||||
enableProvidersCheckBox.setSelection(enabled);
|
||||
|
@ -868,12 +868,12 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
protected void performDefaults() {
|
||||
if (enableProvidersCheckBox==null || enableProvidersCheckBox.getSelection()==false)
|
||||
return;
|
||||
|
||||
|
||||
if (page.isForPrefs() || page.isForProject()) {
|
||||
if (MessageDialog.openQuestion(usercomp.getShell(),
|
||||
Messages.LanguageSettingsProviderTab_TitleResetProviders,
|
||||
Messages.LanguageSettingsProviderTab_AreYouSureToResetProviders)) {
|
||||
|
||||
|
||||
if (page.isForProject()) {
|
||||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||
List<ILanguageSettingsProvider> cfgProviders = new ArrayList<ILanguageSettingsProvider>(cfgDescription.getLanguageSettingProviders());
|
||||
|
@ -889,7 +889,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
if (atLeastOneChanged) {
|
||||
cfgDescription.setLanguageSettingProviders(cfgProviders);
|
||||
}
|
||||
|
||||
|
||||
} else if (page.isForPrefs()) {
|
||||
int pos = tableProviders.getSelectionIndex();
|
||||
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(presentedProviders);
|
||||
|
@ -905,11 +905,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
presentedProviders = providers;
|
||||
tableProvidersViewer.setInput(presentedProviders);
|
||||
tableProviders.setSelection(pos);
|
||||
|
||||
|
||||
updateButtons();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
updateData(getResDesc());
|
||||
}
|
||||
}
|
||||
|
@ -934,7 +934,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
|
||||
destCfgDescription.setLanguageSettingProviders(destProviders);
|
||||
}
|
||||
|
||||
|
||||
if (!page.isForPrefs()) {
|
||||
ICConfigurationDescription sd = srcRcDescription.getConfiguration();
|
||||
ICConfigurationDescription dd = destRcDescription.getConfiguration();
|
||||
|
@ -952,7 +952,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
ICResourceDescription rcDesc = getResDesc();
|
||||
IResource rc = getResource();
|
||||
ICConfigurationDescription cfgDescription = rcDesc.getConfiguration();
|
||||
|
||||
|
||||
List<ILanguageSettingsProvider> destProviders = new ArrayList<ILanguageSettingsProvider>();
|
||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||
for (ILanguageSettingsProvider pro : providers) {
|
||||
|
@ -961,7 +961,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
}
|
||||
cfgDescription.setLanguageSettingProviders(destProviders);
|
||||
}
|
||||
|
||||
|
||||
// Build Settings page
|
||||
if (page.isForPrefs()) {
|
||||
try {
|
||||
|
@ -971,7 +971,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
}
|
||||
initializeProviders();
|
||||
}
|
||||
|
||||
|
||||
if (page.isForProject() && enableProvidersCheckBox!=null) {
|
||||
boolean enabled = enableProvidersCheckBox.getSelection();
|
||||
if (masterPropertyPage!=null)
|
||||
|
@ -979,7 +979,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
LanguageSettingsManager.setLanguageSettingsProvidersEnabled(page.getProject(), enabled);
|
||||
enableProvidersCheckBox.setSelection(enabled);
|
||||
}
|
||||
|
||||
|
||||
Collection<ICOptionPage> optionPages = optionsPageMap.values();
|
||||
for (ICOptionPage op : optionPages) {
|
||||
try {
|
||||
|
@ -1006,7 +1006,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
return false;
|
||||
if (page.isForPrefs())
|
||||
return true;
|
||||
|
||||
|
||||
if (!page.isForProject())
|
||||
return false;
|
||||
|
||||
|
@ -1035,7 +1035,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
newProvidersList = cfgDescription.getLanguageSettingProviders();
|
||||
}
|
||||
boolean newEnablement = LanguageSettingsManager.isLanguageSettingsProvidersEnabled(page.getProject());
|
||||
|
||||
|
||||
// TODO
|
||||
boolean isEqualList = false;
|
||||
// boolean isEqualList = (newProvidersList==initialProvidersMap) || (newProvidersList!=null && newProvidersList.equals(initialProvidersMap));
|
||||
|
@ -1060,11 +1060,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public ILanguageSettingsProvider getProvider(String id) {
|
||||
return findProvider(id, presentedProviders);
|
||||
}
|
||||
|
||||
|
||||
private int getProviderIndex(String id, List<ILanguageSettingsProvider> providers) {
|
||||
int pos = 0;
|
||||
for (ILanguageSettingsProvider p : providers) {
|
||||
|
|
Loading…
Add table
Reference in a new issue