1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Move properties to LanguageSettingsBaseProvider, keep "parameter"

attribute in properties
This commit is contained in:
Andrew Gvozdev 2011-12-05 18:04:21 -05:00
parent 9a66dd7b79
commit c37cfaa6b4
15 changed files with 433 additions and 326 deletions

View file

@ -13,7 +13,9 @@
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
@ -47,9 +49,11 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
private static final String PROVIDER_NAME = "provider name"; private static final String PROVIDER_NAME = "provider name";
private static final String LANGUAGE_ID = "language.test.id"; private static final String LANGUAGE_ID = "language.test.id";
private static final String CUSTOM_PARAMETER = "customParameter"; private static final String CUSTOM_PARAMETER = "customParameter";
private static final String CUSTOM_PARAMETER_2 = "customParameter2";
private static final String ELEM_TEST = "test"; private static final String ELEM_TEST = "test";
// those attributes must match that in AbstractBuiltinSpecsDetector // those attributes must match that in AbstractBuiltinSpecsDetector
private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$
private class MockBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { private class MockBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector {
@ -143,36 +147,46 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception { public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception {
{ {
// provider configured with null parameters // provider configured with null parameters
MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag();
detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null); provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null);
assertEquals(PROVIDER_ID, detector.getId()); assertEquals(PROVIDER_ID, provider.getId());
assertEquals(PROVIDER_NAME, detector.getName()); assertEquals(PROVIDER_NAME, provider.getName());
assertEquals(null, detector.getLanguageScope()); assertEquals(null, provider.getLanguageScope());
assertEquals(null, detector.getSettingEntries(null, null, null)); assertEquals(null, provider.getSettingEntries(null, null, null));
assertEquals(null, detector.getCustomParameter()); assertEquals(null, provider.getCommand());
assertEquals(false, detector.isExecuted()); assertEquals(false, provider.isExecuted());
assertEquals(false, provider.isConsoleEnabled());
} }
{ {
// provider configured with non-null parameters // provider configured with non-null parameters
MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag();
List<String> languages = new ArrayList<String>(); List<String> languages = new ArrayList<String>();
languages.add(LANGUAGE_ID); languages.add(LANGUAGE_ID);
Map<String, String> properties = new HashMap<String, String>();
properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER);
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>(); List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
entries.add(entry); entries.add(entry);
detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, properties);
assertEquals(PROVIDER_ID, detector.getId()); assertEquals(PROVIDER_ID, provider.getId());
assertEquals(PROVIDER_NAME, detector.getName()); assertEquals(PROVIDER_NAME, provider.getName());
assertEquals(languages, detector.getLanguageScope()); assertEquals(languages, provider.getLanguageScope());
assertEquals(entries, detector.getSettingEntries(null, null, null)); assertEquals(entries, provider.getSettingEntries(null, null, null));
assertEquals(CUSTOM_PARAMETER, detector.getCustomParameter()); assertEquals(CUSTOM_PARAMETER, provider.getCommand());
assertEquals(false, detector.isExecuted()); assertEquals(false, provider.isConsoleEnabled());
assertEquals(false, provider.isExecuted());
detector.execute(); // setters
assertEquals(true, detector.isExecuted()); provider.setCommand(CUSTOM_PARAMETER_2);
assertEquals(CUSTOM_PARAMETER_2, provider.getCommand());
provider.setConsoleEnabled(true);
assertEquals(true, provider.isConsoleEnabled());
provider.execute();
assertEquals(true, provider.isExecuted());
} }
} }
@ -190,7 +204,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
} }
// create instance to compare to // create instance to compare to
MockDetectorCloneable detector = new MockDetectorCloneable(); MockDetectorCloneable provider = new MockDetectorCloneable();
List<String> languages = new ArrayList<String>(); List<String> languages = new ArrayList<String>();
languages.add(LANGUAGE_ID); languages.add(LANGUAGE_ID);
@ -199,73 +213,75 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
entries.add(entry); entries.add(entry);
// check clone after initialization // check clone after initialization
MockDetectorCloneable clone0 = detector.clone(); MockDetectorCloneable clone0 = provider.clone();
assertTrue(detector.equals(clone0)); assertTrue(provider.equals(clone0));
// configure provider // configure provider
detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, CUSTOM_PARAMETER); Map<String, String> properties = new HashMap<String, String>();
assertEquals(false, detector.isConsoleEnabled()); properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER);
detector.setConsoleEnabled(true); provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, properties);
detector.execute(); assertEquals(false, provider.isConsoleEnabled());
assertEquals(true, detector.isExecuted()); provider.setConsoleEnabled(true);
assertFalse(detector.equals(clone0)); provider.execute();
assertEquals(true, provider.isExecuted());
assertFalse(provider.equals(clone0));
// check another clone after configuring // check another clone after configuring
{ {
MockDetectorCloneable clone = detector.clone(); MockDetectorCloneable clone = provider.clone();
assertTrue(detector.equals(clone)); assertTrue(provider.equals(clone));
} }
// check custom parameter // check custom parameter
{ {
MockDetectorCloneable clone = detector.clone(); MockDetectorCloneable clone = provider.clone();
clone.setCustomParameter("changed"); clone.setCommand("changed");
assertFalse(detector.equals(clone)); assertFalse(provider.equals(clone));
} }
// check language scope // check language scope
{ {
MockDetectorCloneable clone = detector.clone(); MockDetectorCloneable clone = provider.clone();
clone.setLanguageScope(null); clone.setLanguageScope(null);
assertFalse(detector.equals(clone)); assertFalse(provider.equals(clone));
} }
// check console flag // check console flag
{ {
MockDetectorCloneable clone = detector.clone(); MockDetectorCloneable clone = provider.clone();
boolean isConsoleEnabled = clone.isConsoleEnabled(); boolean isConsoleEnabled = clone.isConsoleEnabled();
clone.setConsoleEnabled( ! isConsoleEnabled ); clone.setConsoleEnabled( ! isConsoleEnabled );
assertFalse(detector.equals(clone)); assertFalse(provider.equals(clone));
} }
// check isExecuted flag // check isExecuted flag
{ {
MockDetectorCloneable clone = detector.clone(); MockDetectorCloneable clone = provider.clone();
assertEquals(true, clone.isExecuted()); assertEquals(true, clone.isExecuted());
clone.clear(); clone.clear();
assertEquals(false, clone.isExecuted()); assertEquals(false, clone.isExecuted());
assertFalse(detector.equals(clone)); assertFalse(provider.equals(clone));
} }
// check entries // check entries
{ {
MockDetectorCloneable clone = detector.clone(); MockDetectorCloneable clone = provider.clone();
clone.setSettingEntries(null, null, null, null); clone.setSettingEntries(null, null, null, null);
assertFalse(detector.equals(clone)); assertFalse(provider.equals(clone));
} }
// check cloneShallow() // check cloneShallow()
{ {
MockDetectorCloneable detector2 = detector.clone(); MockDetectorCloneable provider2 = provider.clone();
MockDetectorCloneable clone = detector2.cloneShallow(); MockDetectorCloneable clone = provider2.cloneShallow();
assertEquals(false, clone.isExecuted()); assertEquals(false, clone.isExecuted());
assertFalse(detector2.equals(clone)); assertFalse(provider2.equals(clone));
detector2.setSettingEntries(null, null, null, null); provider2.setSettingEntries(null, null, null, null);
assertFalse(detector2.equals(clone)); assertFalse(provider2.equals(clone));
clone.execute(); clone.execute();
assertTrue(detector2.equals(clone)); assertTrue(provider2.equals(clone));
} }
} }
@ -278,54 +294,54 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
// load it to new provider // load it to new provider
MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag();
detector.load(rootElement); provider.load(rootElement);
assertEquals(false, detector.isConsoleEnabled()); assertEquals(false, provider.isConsoleEnabled());
} }
Element elementProvider; Element elementProvider;
{ {
// define mock detector // define mock detector
MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag();
assertEquals(false, detector.isConsoleEnabled()); assertEquals(false, provider.isConsoleEnabled());
// redefine the settings // redefine the settings
detector.setConsoleEnabled(true); provider.setConsoleEnabled(true);
assertEquals(true, detector.isConsoleEnabled()); assertEquals(true, provider.isConsoleEnabled());
// serialize in XML // serialize in XML
Document doc = XmlUtil.newDocument(); Document doc = XmlUtil.newDocument();
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
elementProvider = detector.serialize(rootElement); elementProvider = provider.serialize(rootElement);
String xmlString = XmlUtil.toString(doc); String xmlString = XmlUtil.toString(doc);
assertTrue(xmlString.contains(ATTR_CONSOLE)); assertTrue(xmlString.contains(ATTR_CONSOLE));
} }
{ {
// create another instance of the provider // create another instance of the provider
MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag(); MockBuiltinSpecsDetectorExecutedFlag provider = new MockBuiltinSpecsDetectorExecutedFlag();
assertEquals(false, detector.isConsoleEnabled()); assertEquals(false, provider.isConsoleEnabled());
// load element // load element
detector.load(elementProvider); provider.load(elementProvider);
assertEquals(true, detector.isConsoleEnabled()); assertEquals(true, provider.isConsoleEnabled());
} }
} }
public void testAbstractBuiltinSpecsDetector_Nulls() throws Exception { public void testAbstractBuiltinSpecsDetector_Nulls() throws Exception {
{ {
// test AbstractBuiltinSpecsDetector.processLine(...) flow // test AbstractBuiltinSpecsDetector.processLine(...) flow
MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector(); MockBuiltinSpecsDetector provider = new MockBuiltinSpecsDetector();
detector.startup(null); provider.startup(null);
detector.startupForLanguage(null); provider.startupForLanguage(null);
detector.processLine(null, null); provider.processLine(null, null);
detector.shutdownForLanguage(); provider.shutdownForLanguage();
detector.shutdown(); provider.shutdown();
} }
{ {
// test AbstractBuiltinSpecsDetector.processLine(...) flow // test AbstractBuiltinSpecsDetector.processLine(...) flow
MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector();
detector.runForEachLanguage(null, null, null, null); provider.runForEachLanguage(null, null, null, null);
} }
} }
@ -336,28 +352,28 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector();
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID);}}); provider.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID);}});
detector.runForEachLanguage(cfgDescription, null, null, null); provider.runForEachLanguage(cfgDescription, null, null, null);
assertFalse(detector.isEmpty()); assertFalse(provider.isEmpty());
List<ICLanguageSettingEntry> noentries = detector.getSettingEntries(null, null, null); List<ICLanguageSettingEntry> noentries = provider.getSettingEntries(null, null, null);
assertNull(noentries); assertNull(noentries);
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(cfgDescription, null, LANGUAGE_ID); List<ICLanguageSettingEntry> entries = provider.getSettingEntries(cfgDescription, null, LANGUAGE_ID);
ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
assertEquals(expected, entries.get(0)); assertEquals(expected, entries.get(0));
} }
public void testAbstractBuiltinSpecsDetector_RunGlobal() throws Exception { public void testAbstractBuiltinSpecsDetector_RunGlobal() throws Exception {
MockConsoleBuiltinSpecsDetector detector = new MockConsoleBuiltinSpecsDetector(); MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector();
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID);}}); provider.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID);}});
detector.runForEachLanguage(null, null, null, null); provider.runForEachLanguage(null, null, null, null);
assertFalse(detector.isEmpty()); assertFalse(provider.isEmpty());
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, LANGUAGE_ID); List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, LANGUAGE_ID);
ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
assertEquals(expected, entries.get(0)); assertEquals(expected, entries.get(0));
} }
@ -378,7 +394,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
final CLibraryFileEntry libraryFile_2 = new CLibraryFileEntry("lib_2.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); final CLibraryFileEntry libraryFile_2 = new CLibraryFileEntry("lib_2.a", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
// Define mock detector adding unorganized entries // Define mock detector adding unorganized entries
MockBuiltinSpecsDetector detector = new MockBuiltinSpecsDetector() { MockBuiltinSpecsDetector provider = new MockBuiltinSpecsDetector() {
@Override @Override
public boolean processLine(String line, ErrorParserManager epm) { public boolean processLine(String line, ErrorParserManager epm) {
detectedSettingEntries.add(libraryFile_1); detectedSettingEntries.add(libraryFile_1);
@ -399,14 +415,14 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
}; };
// run specs detector // run specs detector
detector.startup(null); provider.startup(null);
detector.startupForLanguage(null); provider.startupForLanguage(null);
detector.processLine("", null); provider.processLine("", null);
detector.shutdownForLanguage(); provider.shutdownForLanguage();
detector.shutdown(); provider.shutdown();
// compare benchmarks, expected well-sorted // compare benchmarks, expected well-sorted
List<ICLanguageSettingEntry> entries = detector.getSettingEntries(null, null, null); List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, null);
int i=0; int i=0;
assertEquals(includePath_1, entries.get(i++)); assertEquals(includePath_1, entries.get(i++));

View file

@ -57,11 +57,17 @@ import org.w3c.dom.Element;
public class GCCBuildCommandParserTest extends BaseTestCase { public class GCCBuildCommandParserTest extends BaseTestCase {
// ID of the parser taken from the extension point // ID of the parser taken from the extension point
private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$ private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$
private static final String PROVIDER_ID = "provider.id";
private static final String PROVIDER_NAME = "provider name";
private static final String LANGUAGE_ID = "language.test.id";
private static final String CUSTOM_PARAMETER = "customParameter";
private static final String CUSTOM_PARAMETER_2 = "customParameter2";
private static final String ELEM_TEST = "test"; private static final String ELEM_TEST = "test";
private static final String LANG_CPP = GPPLanguage.ID; private static final String LANG_CPP = GPPLanguage.ID;
// those attributes must match that in AbstractBuiltinSpecsDetector // those attributes must match that in AbstractBuildCommandParser
private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
private static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$ private static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$
private class MockBuildCommandParser extends AbstractBuildCommandParser implements Cloneable { private class MockBuildCommandParser extends AbstractBuildCommandParser implements Cloneable {
@ -140,12 +146,12 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
// configuration description // configuration description
ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations(); ICConfigurationDescription[] cfgDescriptions = projectDescription.getConfigurations();
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
final ICConfigurationDescription cfgDescriptionReferenced = getConfigurationDescriptions(projectReferenced)[0]; final ICConfigurationDescription cfgDescriptionReferenced = getConfigurationDescriptions(projectReferenced)[0];
cfgDescription.setReferenceInfo(new HashMap<String, String>() {{ put(projectReferenced.getName(), cfgDescriptionReferenced.getId()); }}); cfgDescription.setReferenceInfo(new HashMap<String, String>() {{ put(projectReferenced.getName(), cfgDescriptionReferenced.getId()); }});
coreModel.setProjectDescription(project, projectDescription); coreModel.setProjectDescription(project, projectDescription);
} }
{ {
// doublecheck that it's set as expected // doublecheck that it's set as expected
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
@ -157,7 +163,44 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
} }
} }
public void testAbstractBuildCommandParser_GettersSetters() throws Exception {
{
// provider configured with null parameters
MockBuildCommandParser provider = new MockBuildCommandParser();
provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null);
assertEquals(PROVIDER_ID, provider.getId());
assertEquals(PROVIDER_NAME, provider.getName());
assertEquals(null, provider.getLanguageScope());
assertEquals(null, provider.getSettingEntries(null, null, null));
assertEquals(null, provider.getCompilerPattern());
}
{
// provider configured with non-null parameters
MockBuildCommandParser provider = new MockBuildCommandParser();
List<String> languages = new ArrayList<String>();
languages.add(LANGUAGE_ID);
Map<String, String> properties = new HashMap<String, String>();
properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER);
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY);
entries.add(entry);
provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, properties);
assertEquals(PROVIDER_ID, provider.getId());
assertEquals(PROVIDER_NAME, provider.getName());
assertEquals(languages, provider.getLanguageScope());
assertEquals(entries, provider.getSettingEntries(null, null, null));
assertEquals(CUSTOM_PARAMETER, provider.getCompilerPattern());
// setters
provider.setCompilerPattern(CUSTOM_PARAMETER_2);
assertEquals(CUSTOM_PARAMETER_2, provider.getCompilerPattern());
}
}
public void testAbstractBuildCommandParser_CloneAndEquals() throws Exception { public void testAbstractBuildCommandParser_CloneAndEquals() throws Exception {
// create instance to compare to // create instance to compare to
@ -824,7 +867,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc -I/path0 missing.cpp"); parser.processLine("gcc -I/path0 missing.cpp");
parser.shutdown(); parser.shutdown();
// check entries // check entries
assertTrue(parser.isEmpty()); assertTrue(parser.isEmpty());
} }
@ -838,13 +881,13 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IFile file=ResourceHelper.createFile(project, "file.cpp"); IFile file=ResourceHelper.createFile(project, "file.cpp");
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc " parser.processLine("gcc "
@ -852,7 +895,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ "-I. " + "-I. "
+ file.getLocation().toOSString()); + file.getLocation().toOSString());
parser.shutdown(); parser.shutdown();
// check entries // check entries
IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice());
{ {
@ -861,7 +904,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1));
} }
} }
/** /**
*/ */
public void testFileAbsolutePath_NoProject() throws Exception { public void testFileAbsolutePath_NoProject() throws Exception {
@ -871,13 +914,13 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IFile file=ResourceHelper.createFile(project, "file.cpp"); IFile file=ResourceHelper.createFile(project, "file.cpp");
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
// parse line // parse line
parser.startup(null); parser.startup(null);
parser.processLine("gcc " parser.processLine("gcc "
@ -885,7 +928,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ "-I. " + "-I. "
+ file.getLocation().toOSString()); + file.getLocation().toOSString());
parser.shutdown(); parser.shutdown();
// check entries // check entries
IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice());
{ {
@ -894,7 +937,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
assertEquals(new CIncludePathEntry(file.getParent().getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); assertEquals(new CIncludePathEntry(file.getParent().getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1));
} }
} }
/** /**
*/ */
public void testFileWithSpaces() throws Exception { public void testFileWithSpaces() throws Exception {
@ -960,17 +1003,17 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IFile file=ResourceHelper.createFile(project, "Folder1/Folder2/file.cpp"); IFile file=ResourceHelper.createFile(project, "Folder1/Folder2/file.cpp");
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
ErrorParserManager epm = new ErrorParserManager(project, null); ErrorParserManager epm = new ErrorParserManager(project, null);
// Shift build directory, that could happen if Make Target from folder1 was run // Shift build directory, that could happen if Make Target from folder1 was run
IFolder buildDir = folder1; IFolder buildDir = folder1;
epm.pushDirectoryURI(buildDir.getLocationURI()); epm.pushDirectoryURI(buildDir.getLocationURI());
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc " parser.processLine("gcc "
@ -979,7 +1022,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ "Folder1/Folder2/file.cpp", + "Folder1/Folder2/file.cpp",
epm); epm);
parser.shutdown(); parser.shutdown();
// check entries // check entries
IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice());
{ {
@ -989,7 +1032,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); assertEquals(new CIncludePathEntry(project.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1));
} }
} }
/** /**
*/ */
public void testEndOfLine() throws Exception { public void testEndOfLine() throws Exception {
@ -998,23 +1041,23 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
IFile file0=ResourceHelper.createFile(project, "file0.cpp"); IFile file0=ResourceHelper.createFile(project, "file0.cpp");
IFile file1=ResourceHelper.createFile(project, "file1.cpp"); IFile file1=ResourceHelper.createFile(project, "file1.cpp");
IFile file2=ResourceHelper.createFile(project, "file2.cpp"); IFile file2=ResourceHelper.createFile(project, "file2.cpp");
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file0.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file0.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc -I/path0 file0.cpp"); parser.processLine("gcc -I/path0 file0.cpp");
parser.processLine("gcc -I/path0 file1.cpp\n"); parser.processLine("gcc -I/path0 file1.cpp\n");
parser.processLine("gcc -I/path0 file2.cpp\r\n"); parser.processLine("gcc -I/path0 file2.cpp\r\n");
parser.shutdown(); parser.shutdown();
// check populated entries // check populated entries
IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice()); IPath path0 = new Path("/path0").setDevice(project.getLocation().getDevice());
{ {
@ -1043,33 +1086,33 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
// do not test on non-windows systems where drive letters are not supported // do not test on non-windows systems where drive letters are not supported
if (! Platform.getOS().equals(Platform.OS_WIN32)) if (! Platform.getOS().equals(Platform.OS_WIN32))
return; return;
// Create model project and accompanied descriptions // Create model project and accompanied descriptions
String projectName = getName(); String projectName = getName();
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
IFile file=ResourceHelper.createFile(project, "file.cpp"); IFile file=ResourceHelper.createFile(project, "file.cpp");
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
parser.setResolvingPaths(true); parser.setResolvingPaths(true);
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc " parser.processLine("gcc "
+ " -IX:\\path" + " -IX:\\path"
+ " file.cpp"); + " file.cpp");
parser.shutdown(); parser.shutdown();
// check populated entries // check populated entries
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId); List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId);
assertEquals(new CIncludePathEntry(new Path("X:\\path"), 0), entries.get(0)); assertEquals(new CIncludePathEntry(new Path("X:\\path"), 0), entries.get(0));
} }
/** /**
*/ */
public void testPathEntry_ExpandRelativePath() throws Exception { public void testPathEntry_ExpandRelativePath() throws Exception {
@ -1189,7 +1232,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
IFolder buildDir=ResourceHelper.createFolder(project, "BuildDir"); IFolder buildDir=ResourceHelper.createFolder(project, "BuildDir");
IFolder folder=ResourceHelper.createFolder(project, "BuildDir/Folder"); IFolder folder=ResourceHelper.createFolder(project, "BuildDir/Folder");
IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp"); IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp");
@ -1197,12 +1240,12 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IFile fakeFile=ResourceHelper.createFile(project, "file.cpp"); IFile fakeFile=ResourceHelper.createFile(project, "file.cpp");
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
ErrorParserManager epm = new ErrorParserManager(project, null); ErrorParserManager epm = new ErrorParserManager(project, null);
epm.pushDirectoryURI(buildDir.getLocationURI()); epm.pushDirectoryURI(buildDir.getLocationURI());
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc " parser.processLine("gcc "
@ -1214,7 +1257,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ " file.cpp", + " file.cpp",
epm); epm);
parser.shutdown(); parser.shutdown();
// check populated entries // check populated entries
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId); List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId);
{ {
@ -1225,7 +1268,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("MissingFolder"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(4)); assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("MissingFolder"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(4));
} }
} }
/** /**
*/ */
public void testPathEntry_GuessCWD() throws Exception { public void testPathEntry_GuessCWD() throws Exception {
@ -1382,7 +1425,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("MissingFolder2"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(4)); assertEquals(new CIncludePathEntry(buildDir.getFullPath().append("MissingFolder2"), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(4));
} }
} }
/** /**
*/ */
public void testPathEntry_MappedFolderInProject() throws Exception { public void testPathEntry_MappedFolderInProject() throws Exception {
@ -1391,7 +1434,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp"); IFile file=ResourceHelper.createFile(project, "BuildDir/file.cpp");
IFolder mappedFolder=ResourceHelper.createFolder(project, "Mapped/Folder"); IFolder mappedFolder=ResourceHelper.createFolder(project, "Mapped/Folder");
IFolder folder=ResourceHelper.createFolder(project, "Mapped/Folder/Subfolder"); IFolder folder=ResourceHelper.createFolder(project, "Mapped/Folder/Subfolder");
@ -1399,14 +1442,14 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IFolder ambiguousFolder1=ResourceHelper.createFolder(project, "One/Ambiguous/Folder"); IFolder ambiguousFolder1=ResourceHelper.createFolder(project, "One/Ambiguous/Folder");
@SuppressWarnings("unused") @SuppressWarnings("unused")
IFolder ambiguousFolder2=ResourceHelper.createFolder(project, "Another/Ambiguous/Folder"); IFolder ambiguousFolder2=ResourceHelper.createFolder(project, "Another/Ambiguous/Folder");
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
ErrorParserManager epm = new ErrorParserManager(project, null); ErrorParserManager epm = new ErrorParserManager(project, null);
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc " parser.processLine("gcc "
@ -1417,7 +1460,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ " file.cpp", + " file.cpp",
epm); epm);
parser.shutdown(); parser.shutdown();
// check populated entries // check populated entries
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId); List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId);
{ {
@ -1442,7 +1485,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
// create files and folders // create files and folders
IFile file=ResourceHelper.createFile(project, "file.cpp"); IFile file=ResourceHelper.createFile(project, "file.cpp");
// another project // another project
@ -1453,14 +1496,14 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
@SuppressWarnings("unused") @SuppressWarnings("unused")
IFolder ambiguousFolder2=ResourceHelper.createFolder(anotherProject, "Another/Ambiguous/Folder"); IFolder ambiguousFolder2=ResourceHelper.createFolder(anotherProject, "Another/Ambiguous/Folder");
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
ErrorParserManager epm = new ErrorParserManager(project, null); ErrorParserManager epm = new ErrorParserManager(project, null);
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc " parser.processLine("gcc "
@ -1470,7 +1513,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ " file.cpp", + " file.cpp",
epm); epm);
parser.shutdown(); parser.shutdown();
// check populated entries // check populated entries
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId); List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId);
{ {
@ -1485,22 +1528,22 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
assertEquals(new CIncludePathEntry(path, 0), entries.get(2)); assertEquals(new CIncludePathEntry(path, 0), entries.get(2));
} }
} }
/** /**
*/ */
public void testPathEntry_MappedFolderInReferencedProject() throws Exception { public void testPathEntry_MappedFolderInReferencedProject() throws Exception {
// Create model project and accompanied descriptions // Create model project and accompanied descriptions
String projectName = getName(); String projectName = getName();
// create main project // create main project
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
IFile file=ResourceHelper.createFile(project, "file.cpp"); IFile file=ResourceHelper.createFile(project, "file.cpp");
// create another project (non-referenced) // create another project (non-referenced)
IProject anotherProject = ResourceHelper.createCDTProjectWithConfig(projectName+"-another"); IProject anotherProject = ResourceHelper.createCDTProjectWithConfig(projectName+"-another");
@SuppressWarnings("unused") @SuppressWarnings("unused")
IFolder folderInAnotherProject=ResourceHelper.createFolder(anotherProject, "Mapped/Folder/Subfolder"); IFolder folderInAnotherProject=ResourceHelper.createFolder(anotherProject, "Mapped/Folder/Subfolder");
// create referenced project // create referenced project
IProject referencedProject = ResourceHelper.createCDTProjectWithConfig(projectName+"-referenced"); IProject referencedProject = ResourceHelper.createCDTProjectWithConfig(projectName+"-referenced");
IFolder folderInReferencedProject=ResourceHelper.createFolder(referencedProject, "Mapped/Folder/Subfolder"); IFolder folderInReferencedProject=ResourceHelper.createFolder(referencedProject, "Mapped/Folder/Subfolder");
@ -1508,7 +1551,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IFolder ambiguousFolder1=ResourceHelper.createFolder(referencedProject, "One/Ambiguous/Folder"); IFolder ambiguousFolder1=ResourceHelper.createFolder(referencedProject, "One/Ambiguous/Folder");
@SuppressWarnings("unused") @SuppressWarnings("unused")
IFolder ambiguousFolder2=ResourceHelper.createFolder(referencedProject, "Another/Ambiguous/Folder"); IFolder ambiguousFolder2=ResourceHelper.createFolder(referencedProject, "Another/Ambiguous/Folder");
setReference(project, referencedProject); setReference(project, referencedProject);
// get cfgDescription and language to work with // get cfgDescription and language to work with
@ -1516,11 +1559,11 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
ErrorParserManager epm = new ErrorParserManager(project, null); ErrorParserManager epm = new ErrorParserManager(project, null);
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc " parser.processLine("gcc "
@ -1529,7 +1572,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ " file.cpp", + " file.cpp",
epm); epm);
parser.shutdown(); parser.shutdown();
// check populated entries // check populated entries
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId); List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId);
{ {
@ -1680,16 +1723,16 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IFolder includeDir=ResourceHelper.createFolder(project, "BuildDir/include"); IFolder includeDir=ResourceHelper.createFolder(project, "BuildDir/include");
// Change build dir // Change build dir
setBuilderCWD(project, buildDir.getLocation()); setBuilderCWD(project, buildDir.getLocation());
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc " parser.processLine("gcc "
@ -1698,16 +1741,16 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ " " + file.getLocation().toOSString() + " " + file.getLocation().toOSString()
); );
parser.shutdown(); parser.shutdown();
// check populated entries // check populated entries
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId); List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId);
{ {
assertEquals(new CIncludePathEntry(buildDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0)); assertEquals(new CIncludePathEntry(buildDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(0));
assertEquals(new CIncludePathEntry(includeDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1)); assertEquals(new CIncludePathEntry(includeDir.getFullPath(), ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED), entries.get(1));
} }
} }
public void testContentType_None() throws Exception { public void testContentType_None() throws Exception {
MockBuildCommandParser parser = new MockBuildCommandParser() { MockBuildCommandParser parser = new MockBuildCommandParser() {
@Override @Override
@ -1718,11 +1761,11 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
parser.startup(null); parser.startup(null);
parser.processLine("gcc file.wrong-content-type"); parser.processLine("gcc file.wrong-content-type");
parser.shutdown(); parser.shutdown();
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(null, null, null); List<ICLanguageSettingEntry> entries = parser.getSettingEntries(null, null, null);
assertNull(entries); assertNull(entries);
} }
/** /**
*/ */
public void testContentType_Mismatch() throws Exception { public void testContentType_Mismatch() throws Exception {
@ -1732,7 +1775,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
ResourceHelper.createFile(project, "file.c"); ResourceHelper.createFile(project, "file.c");
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
// restrict the parser's language scope to C++ only // restrict the parser's language scope to C++ only
@ -1742,7 +1785,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc -I/path0 file.c"); parser.processLine("gcc -I/path0 file.c");
parser.shutdown(); parser.shutdown();
assertTrue(parser.isEmpty()); assertTrue(parser.isEmpty());
} }
@ -1863,7 +1906,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
// create folder structure // create folder structure
@SuppressWarnings("unused") @SuppressWarnings("unused")
IFolder buildDir=ResourceHelper.createEfsFolder(project, "BuildDir", new URI("mem:/EfsProject/BuildDir")); IFolder buildDir=ResourceHelper.createEfsFolder(project, "BuildDir", new URI("mem:/EfsProject/BuildDir"));
@ -1902,7 +1945,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName); IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project); ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
// create folder structure // create folder structure
@SuppressWarnings("unused") @SuppressWarnings("unused")
IFolder buildDir=ResourceHelper.createEfsFolder(project, "BuildDir", new URI("mem:/MappedEfsProject/BuildDir")); IFolder buildDir=ResourceHelper.createEfsFolder(project, "BuildDir", new URI("mem:/MappedEfsProject/BuildDir"));
@ -1911,11 +1954,11 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
IFile file=ResourceHelper.createEfsFile(project, "BuildDir/file.cpp", new URI("mem:/MappedEfsProject/BuildDir/file.cpp")); IFile file=ResourceHelper.createEfsFile(project, "BuildDir/file.cpp", new URI("mem:/MappedEfsProject/BuildDir/file.cpp"));
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true); ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId(); String languageId = ls.getLanguageId();
// create GCCBuildCommandParser // create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
ErrorParserManager epm = new ErrorParserManager(project, null); ErrorParserManager epm = new ErrorParserManager(project, null);
// parse line // parse line
parser.startup(cfgDescription); parser.startup(cfgDescription);
parser.processLine("gcc " parser.processLine("gcc "
@ -1923,7 +1966,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ " file.cpp", + " file.cpp",
epm); epm);
parser.shutdown(); parser.shutdown();
// check populated entries // check populated entries
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId); List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, file, languageId);
{ {

View file

@ -45,8 +45,8 @@ import org.eclipse.core.runtime.jobs.Job;
*/ */
public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner
implements ICConsoleParser, IErrorParser { implements ICConsoleParser, IErrorParser {
public static final Object JOB_FAMILY_BUILD_COMMAND_PARSER = "org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser"; public static final Object JOB_FAMILY_BUILD_COMMAND_PARSER = "org.eclipse.cdt.make.core.scannerconfig.AbstractBuildCommandParser";
private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
private static final String LEADING_PATH_PATTERN = "\\S+[/\\\\]"; //$NON-NLS-1$ private static final String LEADING_PATH_PATTERN = "\\S+[/\\\\]"; //$NON-NLS-1$
private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$
@ -63,22 +63,43 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting
private static final int FILE_GROUP = 2; private static final int FILE_GROUP = 2;
/**
* The compiler command pattern without specifying compiler options.
* The options are intended to be handled with option parsers,
* see {@link #getOptionParsers()}.
* This is regular expression pattern.
*
* @return the compiler command pattern.
*/
public String getCompilerPattern() {
return getProperty(ATTR_PARAMETER);
}
/**
* Set compiler command pattern for the provider. See {@link #getCompilerPattern()}.
* @param commandPattern - value of the command pattern to set.
* This is regular expression pattern.
*/
public void setCompilerPattern(String commandPattern) {
setProperty(ATTR_PARAMETER, commandPattern);
}
@SuppressWarnings("nls") @SuppressWarnings("nls")
private String getCompilerCommandPattern() { private String getCompilerPatternExtended() {
String parameter = getCustomParameter(); String compilerPattern = getCompilerPattern();
return "\\s*\"?("+LEADING_PATH_PATTERN+")?(" + parameter + ")\"?"; return "\\s*\"?("+LEADING_PATH_PATTERN+")?(" + compilerPattern + ")\"?";
} }
private int adjustFileGroup() { private int adjustFileGroup() {
return countGroups(getCompilerCommandPattern()) + FILE_GROUP; return countGroups(getCompilerPatternExtended()) + FILE_GROUP;
} }
private String makePattern(String template) { private String makePattern(String template) {
@SuppressWarnings("nls") @SuppressWarnings("nls")
String pattern = template String pattern = template
.replace("${COMPILER_PATTERN}", getCompilerCommandPattern()) .replace("${COMPILER_PATTERN}", getCompilerPatternExtended())
.replace("${EXTENSIONS_PATTERN}", getPatternFileExtensions()) .replace("${EXTENSIONS_PATTERN}", getPatternFileExtensions())
.replace("${COMPILER_GROUPS+1}", new Integer(countGroups(getCompilerCommandPattern()) + 1).toString()); .replace("${COMPILER_GROUPS+1}", new Integer(countGroups(getCompilerPatternExtended()) + 1).toString());
return pattern; return pattern;
} }

View file

@ -80,6 +80,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
private static final String PLUGIN_CDT_MAKE_UI_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$ private static final String PLUGIN_CDT_MAKE_UI_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$
private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$ private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$
private static final String PATH_ENV = "PATH"; //$NON-NLS-1$ private static final String PATH_ENV = "PATH"; //$NON-NLS-1$
private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$
protected static final String COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$ protected static final String COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$
@ -182,6 +183,30 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
} }
} }
/**
* The command to run. Some macros could be specified in there:
* <ul>
* <b>${COMMAND}</b> - compiler command taken from the toolchain.<br>
* <b>${INPUTS}</b> - path to spec file which will be placed in workspace area.<br>
* <b>${EXT}</b> - file extension calculated from language ID.
* </ul>
* The parameter could be taken from the extension
* in {@code plugin.xml} or from property file.
*
* @return the command to run.
*/
public String getCommand() {
return getProperty(ATTR_PARAMETER);
}
/**
* Set custom command for the provider. See {@link #getCommand()}.
* @param command - value of custom command to set.
*/
public void setCommand(String command) {
setProperty(ATTR_PARAMETER, command);
}
public void setConsoleEnabled(boolean enable) { public void setConsoleEnabled(boolean enable) {
isConsoleEnabled = enable; isConsoleEnabled = enable;
} }
@ -191,7 +216,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
} }
protected String resolveCommand(String languageId) throws CoreException { protected String resolveCommand(String languageId) throws CoreException {
String cmd = getCustomParameter(); String cmd = getCommand();
if (cmd!=null && (cmd.contains(COMPILER_MACRO) || cmd.contains(SPEC_FILE_MACRO) || cmd.contains(SPEC_EXT_MACRO))) { if (cmd!=null && (cmd.contains(COMPILER_MACRO) || cmd.contains(SPEC_FILE_MACRO) || cmd.contains(SPEC_EXT_MACRO))) {
if (cmd.contains(COMPILER_MACRO)) { if (cmd.contains(COMPILER_MACRO)) {
String compiler = getCompilerCommand(languageId); String compiler = getCompilerCommand(languageId);

View file

@ -184,7 +184,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
/** /**
* Parse the line returning the resource name as appears in the output. * Parse the line returning the resource name as appears in the output.
* This is the resource where {@link ICLanguageSettingEntry} list is being added. * This is the resource where {@link ICLanguageSettingEntry} list is being added.
* *
* @param line - one input line from the output stripped from end of line characters. * @param line - one input line from the output stripped from end of line characters.
* @return the resource name as appears in the output or {@code null}. * @return the resource name as appears in the output or {@code null}.
* Note that {@code null} can have different semantics and can mean "no resource found" * Note that {@code null} can have different semantics and can mean "no resource found"
@ -198,7 +198,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
* the option parsers. It is assumed that each substring presents one * the option parsers. It is assumed that each substring presents one
* {@link ICLanguageSettingEntry} (for example compiler options {@code -I/path} or * {@link ICLanguageSettingEntry} (for example compiler options {@code -I/path} or
* {@code -DMACRO=1}. * {@code -DMACRO=1}.
* *
* @param line - one input line from the output stripped from end of line characters. * @param line - one input line from the output stripped from end of line characters.
* @return list of substrings representing language settings entries. * @return list of substrings representing language settings entries.
*/ */
@ -240,7 +240,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
errorParserManager = epm; errorParserManager = epm;
parsedResourceName = parseForResourceName(line); parsedResourceName = parseForResourceName(line);
currentResource = findResource(parsedResourceName); currentResource = findResource(parsedResourceName);
currentLanguageId = determineLanguage(); currentLanguageId = determineLanguage();
if (!isLanguageInScope(currentLanguageId)) if (!isLanguageInScope(currentLanguageId))
return false; return false;
@ -251,7 +251,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
* it can be different filesystem (and different URI schema). * it can be different filesystem (and different URI schema).
*/ */
URI buildDirURI = null; URI buildDirURI = null;
/** /**
* Where source tree starts if mapped. This kind of mapping is useful for example in cases when * Where source tree starts if mapped. This kind of mapping is useful for example in cases when
* the absolute path to the source file on the remote system is simulated inside a project in the * the absolute path to the source file on the remote system is simulated inside a project in the
@ -260,14 +260,14 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
* (or even URI schema) does not have to match that of buildDirURI. * (or even URI schema) does not have to match that of buildDirURI.
*/ */
URI mappedRootURI = null; URI mappedRootURI = null;
if (isResolvingPaths) { if (isResolvingPaths) {
mappedRootURI = getMappedRootURI(currentResource, parsedResourceName); mappedRootURI = getMappedRootURI(currentResource, parsedResourceName);
buildDirURI = getBuildDirURI(mappedRootURI); buildDirURI = getBuildDirURI(mappedRootURI);
} }
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>(); List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
List<String> options = parseForOptions(line); List<String> options = parseForOptions(line);
if (options!=null) { if (options!=null) {
for (String option : options) { for (String option : options) {
@ -283,7 +283,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
} else { } else {
entry = optionParser.createEntry(optionParser.parsedName, optionParser.parsedValue, 0); entry = optionParser.createEntry(optionParser.parsedName, optionParser.parsedValue, 0);
} }
if (entry != null && !entries.contains(entry)) { if (entry != null && !entries.contains(entry)) {
entries.add(entry); entries.add(entry);
break; break;
@ -319,7 +319,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
protected void setSettingEntries(List<ICLanguageSettingEntry> entries) { protected void setSettingEntries(List<ICLanguageSettingEntry> entries) {
setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries); setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries);
LanguageSettingsLogger.logInfo(getPrefixForLog() LanguageSettingsLogger.logInfo(getPrefixForLog()
+ getClass().getSimpleName() + " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource); + getClass().getSimpleName() + " collected " + (entries!=null ? ("" + entries.size()) : "null") + " entries for " + currentResource);
} }
@ -331,10 +331,10 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
// use handle; resource does not need to exist // use handle; resource does not need to exist
rc = currentProject.getFile("__" + fileName); rc = currentProject.getFile("__" + fileName);
} }
if (rc == null) if (rc == null)
return null; return null;
List<String> languageIds = LanguageSettingsManager.getLanguages(rc, currentCfgDescription); List<String> languageIds = LanguageSettingsManager.getLanguages(rc, currentCfgDescription);
if (languageIds.isEmpty()) if (languageIds.isEmpty())
return null; return null;
@ -349,26 +349,26 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
protected String getPatternFileExtensions() { protected String getPatternFileExtensions() {
IContentTypeManager manager = Platform.getContentTypeManager(); IContentTypeManager manager = Platform.getContentTypeManager();
Set<String> fileExts = new HashSet<String>(); Set<String> fileExts = new HashSet<String>();
IContentType contentTypeCpp = manager.getContentType("org.eclipse.cdt.core.cxxSource"); //$NON-NLS-1$ IContentType contentTypeCpp = manager.getContentType("org.eclipse.cdt.core.cxxSource"); //$NON-NLS-1$
fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
IContentType contentTypeC = manager.getContentType("org.eclipse.cdt.core.cSource"); //$NON-NLS-1$ IContentType contentTypeC = manager.getContentType("org.eclipse.cdt.core.cSource"); //$NON-NLS-1$
fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));
String pattern = expressionLogicalOr(fileExts); String pattern = expressionLogicalOr(fileExts);
return pattern; return pattern;
} }
private ICLanguageSettingEntry createResolvedPathEntry(AbstractOptionParser optionParser, private ICLanguageSettingEntry createResolvedPathEntry(AbstractOptionParser optionParser,
String parsedPath, int flag, URI baseURI) { String parsedPath, int flag, URI baseURI) {
ICLanguageSettingEntry entry; ICLanguageSettingEntry entry;
String resolvedPath = null; String resolvedPath = null;
URI uri = determineMappedURI(parsedPath, baseURI); URI uri = determineMappedURI(parsedPath, baseURI);
IResource rc = null; IResource rc = null;
if (uri != null && uri.isAbsolute()) { if (uri != null && uri.isAbsolute()) {
@ -400,7 +400,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
resolvedPath = path.toString(); resolvedPath = path.toString();
} }
} }
if (resolvedPath==null) { if (resolvedPath==null) {
resolvedPath = parsedPath; resolvedPath = parsedPath;
} }
@ -412,9 +412,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
private IResource findResource(String parsedResourceName) { private IResource findResource(String parsedResourceName) {
if (parsedResourceName==null) if (parsedResourceName==null)
return null; return null;
IResource sourceFile = null; IResource sourceFile = null;
// try ErrorParserManager // try ErrorParserManager
if (errorParserManager != null) { if (errorParserManager != null) {
sourceFile = errorParserManager.findFileName(parsedResourceName); sourceFile = errorParserManager.findFileName(parsedResourceName);
@ -442,7 +442,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
protected URI getBuildDirURI(URI mappedRootURI) { protected URI getBuildDirURI(URI mappedRootURI) {
URI buildDirURI = null; URI buildDirURI = null;
URI cwdURI = null; URI cwdURI = null;
if (currentResource!=null && parsedResourceName!=null && !new Path(parsedResourceName).isAbsolute()) { if (currentResource!=null && parsedResourceName!=null && !new Path(parsedResourceName).isAbsolute()) {
cwdURI = findBaseLocationURI(currentResource.getLocationURI(), parsedResourceName); cwdURI = findBaseLocationURI(currentResource.getLocationURI(), parsedResourceName);
@ -450,14 +450,14 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
if (cwdURI == null && errorParserManager != null) { if (cwdURI == null && errorParserManager != null) {
cwdURI = errorParserManager.getWorkingDirectoryURI(); cwdURI = errorParserManager.getWorkingDirectoryURI();
} }
String cwdPath = cwdURI != null ? EFSExtensionManager.getDefault().getPathFromURI(cwdURI) : null; String cwdPath = cwdURI != null ? EFSExtensionManager.getDefault().getPathFromURI(cwdURI) : null;
if (cwdPath != null && mappedRootURI != null) { if (cwdPath != null && mappedRootURI != null) {
buildDirURI = EFSExtensionManager.getDefault().append(mappedRootURI, cwdPath); buildDirURI = EFSExtensionManager.getDefault().append(mappedRootURI, cwdPath);
} else { } else {
buildDirURI = cwdURI; buildDirURI = cwdURI;
} }
if (buildDirURI == null && currentCfgDescription != null) { if (buildDirURI == null && currentCfgDescription != null) {
IPath pathBuilderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD(); IPath pathBuilderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD();
if (pathBuilderCWD != null) { if (pathBuilderCWD != null) {
@ -472,11 +472,11 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD); buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD);
} }
} }
if (buildDirURI == null && currentProject != null) { if (buildDirURI == null && currentProject != null) {
buildDirURI = currentProject.getLocationURI(); buildDirURI = currentProject.getLocationURI();
} }
if (buildDirURI == null && currentResource != null) { if (buildDirURI == null && currentResource != null) {
IContainer container; IContainer container;
if (currentResource instanceof IContainer) { if (currentResource instanceof IContainer) {
@ -491,14 +491,14 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
/** /**
* Determine URI on the local filesystem considering possible mapping. * Determine URI on the local filesystem considering possible mapping.
* *
* @param pathStr - path to the resource, can be absolute or relative * @param pathStr - path to the resource, can be absolute or relative
* @param baseURI - base {@link URI} where path to the resource is rooted * @param baseURI - base {@link URI} where path to the resource is rooted
* @return {@link URI} of the resource * @return {@link URI} of the resource
*/ */
private static URI determineMappedURI(String pathStr, URI baseURI) { private static URI determineMappedURI(String pathStr, URI baseURI) {
URI uri = null; URI uri = null;
if (baseURI==null) { if (baseURI==null) {
if (new Path(pathStr).isAbsolute()) { if (new Path(pathStr).isAbsolute()) {
uri = resolvePathFromBaseLocation(pathStr, Path.ROOT); uri = resolvePathFromBaseLocation(pathStr, Path.ROOT);
@ -519,7 +519,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
} }
} }
} }
if (uri == null) { if (uri == null) {
// if everything fails just wrap string to URI // if everything fails just wrap string to URI
uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr); uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr);
@ -532,7 +532,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
if (path.equals(new Path(".")) || path.equals(new Path(".."))) { //$NON-NLS-1$ //$NON-NLS-2$ if (path.equals(new Path(".")) || path.equals(new Path(".."))) { //$NON-NLS-1$ //$NON-NLS-2$
return null; return null;
} }
// prefer current project // prefer current project
if (preferredProject!=null) { if (preferredProject!=null) {
List<IResource> result = findPathInFolder(path, preferredProject); List<IResource> result = findPathInFolder(path, preferredProject);
@ -543,9 +543,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
return null; return null;
} }
} }
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
// then prefer referenced projects // then prefer referenced projects
if (referencedProjectsNames.size() > 0) { if (referencedProjectsNames.size() > 0) {
IResource rc = null; IResource rc = null;
@ -567,7 +567,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
return rc; return rc;
} }
} }
// then check all other projects in workspace // then check all other projects in workspace
IProject[] projects = root.getProjects(); IProject[] projects = root.getProjects();
if (projects.length > 0) { if (projects.length > 0) {
@ -589,7 +589,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
return rc; return rc;
} }
} }
// not found or ambiguous // not found or ambiguous
return null; return null;
} }
@ -600,7 +600,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
if (resource != null) { if (resource != null) {
paths.add(resource); paths.add(resource);
} }
try { try {
for (IResource res : folder.members()) { for (IResource res : folder.members()) {
if (res instanceof IContainer) { if (res instanceof IContainer) {
@ -610,7 +610,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
} catch (CoreException e) { } catch (CoreException e) {
// ignore // ignore
} }
return paths; return paths;
} }
@ -637,9 +637,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
private static URI findBaseLocationURI(URI fileURI, String relativeFileName) { private static URI findBaseLocationURI(URI fileURI, String relativeFileName) {
URI cwdURI = null; URI cwdURI = null;
String path = fileURI.getPath(); String path = fileURI.getPath();
String[] segments = relativeFileName.split("[/\\\\]"); //$NON-NLS-1$ String[] segments = relativeFileName.split("[/\\\\]"); //$NON-NLS-1$
// start removing segments from the end of the path // start removing segments from the end of the path
for (int i = segments.length - 1; i >= 0; i--) { for (int i = segments.length - 1; i >= 0; i--) {
String lastSegment = segments[i]; String lastSegment = segments[i];
@ -659,7 +659,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
} }
} }
} }
try { try {
cwdURI = new URI(fileURI.getScheme(), fileURI.getUserInfo(), fileURI.getHost(), cwdURI = new URI(fileURI.getScheme(), fileURI.getUserInfo(), fileURI.getHost(),
fileURI.getPort(), path + '/', fileURI.getQuery(), fileURI.getFragment()); fileURI.getPort(), path + '/', fileURI.getQuery(), fileURI.getFragment());
@ -667,7 +667,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
// It should be valid URI here or something is wrong // It should be valid URI here or something is wrong
MakeCorePlugin.log(e); MakeCorePlugin.log(e);
} }
return cwdURI; return cwdURI;
} }
@ -676,7 +676,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
* this function will try to figure mapping and return "mapped root", * this function will try to figure mapping and return "mapped root",
* i.e URI where the root path would be mapped. The mapped root will be * i.e URI where the root path would be mapped. The mapped root will be
* used to prepend to other "absolute" paths where appropriate. * used to prepend to other "absolute" paths where appropriate.
* *
* @param sourceFile - a resource referred by parsed path * @param sourceFile - a resource referred by parsed path
* @param parsedResourceName - path as appears in the output * @param parsedResourceName - path as appears in the output
* @return mapped path as URI * @return mapped path as URI
@ -685,10 +685,10 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
if (currentResource==null) { if (currentResource==null) {
return null; return null;
} }
URI fileURI = sourceFile.getLocationURI(); URI fileURI = sourceFile.getLocationURI();
String mappedRoot = "/"; //$NON-NLS-1$ String mappedRoot = "/"; //$NON-NLS-1$
if (parsedResourceName!=null) { if (parsedResourceName!=null) {
IPath parsedSrcPath = new Path(parsedResourceName); IPath parsedSrcPath = new Path(parsedResourceName);
if (parsedSrcPath.isAbsolute()) { if (parsedSrcPath.isAbsolute()) {
@ -723,7 +723,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
if (device != null && device.length() > 0) { if (device != null && device.length() > 0) {
pathName = pathName.substring(device.length()); pathName = pathName.substring(device.length());
} }
baseLocation = baseLocation.addTrailingSeparator(); baseLocation = baseLocation.addTrailingSeparator();
if (pathName.startsWith("/")) { //$NON-NLS-1$ if (pathName.startsWith("/")) { //$NON-NLS-1$
pathName = pathName.substring(1); pathName = pathName.substring(1);
@ -731,7 +731,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
pathName = baseLocation.toString() + pathName; pathName = baseLocation.toString() + pathName;
} }
} }
try { try {
File file = new File(pathName); File file = new File(pathName);
file = file.getCanonicalFile(); file = file.getCanonicalFile();
@ -739,7 +739,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
} catch (IOException e) { } catch (IOException e) {
// if error just leave it as is // if error just leave it as is
} }
URI uri = org.eclipse.core.filesystem.URIUtil.toURI(pathName); URI uri = org.eclipse.core.filesystem.URIUtil.toURI(pathName);
return uri; return uri;
} }
@ -747,9 +747,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
private static IResource findResourceForLocationURI(URI uri, int kind, IProject preferredProject) { private static IResource findResourceForLocationURI(URI uri, int kind, IProject preferredProject) {
if (uri==null) if (uri==null)
return null; return null;
IResource resource = null; IResource resource = null;
switch (kind) { switch (kind) {
case ICSettingEntry.INCLUDE_PATH: case ICSettingEntry.INCLUDE_PATH:
case ICSettingEntry.LIBRARY_PATH: case ICSettingEntry.LIBRARY_PATH:
@ -760,7 +760,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
resource = findFileForLocationURI(uri, preferredProject); resource = findFileForLocationURI(uri, preferredProject);
break; break;
} }
return resource; return resource;
} }
@ -788,11 +788,11 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
private static IPath getFilesystemLocation(URI uri) { private static IPath getFilesystemLocation(URI uri) {
if (uri==null) if (uri==null)
return null; return null;
// EFSExtensionManager mapping // EFSExtensionManager mapping
String pathStr = EFSExtensionManager.getDefault().getMappedPath(uri); String pathStr = EFSExtensionManager.getDefault().getMappedPath(uri);
uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr); uri = org.eclipse.core.filesystem.URIUtil.toURI(pathStr);
try { try {
File file = new java.io.File(uri); File file = new java.io.File(uri);
String canonicalPathStr = file.getCanonicalPath(); String canonicalPathStr = file.getCanonicalPath();
@ -818,7 +818,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
pattern += ")"; pattern += ")";
return pattern; return pattern;
} }
protected static int countGroups(String str) { protected static int countGroups(String str) {
@SuppressWarnings("nls") @SuppressWarnings("nls")
int count = str.replaceAll("[^\\(]", "").length(); int count = str.replaceAll("[^\\(]", "").length();
@ -831,16 +831,16 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
elementProvider.setAttribute(ATTR_EXPAND_RELATIVE_PATHS, Boolean.toString(isResolvingPaths)); elementProvider.setAttribute(ATTR_EXPAND_RELATIVE_PATHS, Boolean.toString(isResolvingPaths));
return elementProvider; return elementProvider;
} }
@Override @Override
public void loadAttributes(Element providerNode) { public void loadAttributes(Element providerNode) {
super.loadAttributes(providerNode); super.loadAttributes(providerNode);
String expandRelativePathsValue = XmlUtil.determineAttributeValue(providerNode, ATTR_EXPAND_RELATIVE_PATHS); String expandRelativePathsValue = XmlUtil.determineAttributeValue(providerNode, ATTR_EXPAND_RELATIVE_PATHS);
if (expandRelativePathsValue!=null) if (expandRelativePathsValue!=null)
isResolvingPaths = Boolean.parseBoolean(expandRelativePathsValue); isResolvingPaths = Boolean.parseBoolean(expandRelativePathsValue);
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;

View file

@ -88,8 +88,8 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti
{ {
inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER); inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER);
String customParameter = provider.getCustomParameter(); String compilerPattern = provider.getCompilerPattern();
inputCommand.setText(customParameter!=null ? customParameter : ""); inputCommand.setText(compilerPattern!=null ? compilerPattern : "");
GridData gd = new GridData(); GridData gd = new GridData();
gd.horizontalSpan = 1; gd.horizontalSpan = 1;
@ -103,9 +103,9 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
String text = inputCommand.getText(); String text = inputCommand.getText();
AbstractBuildCommandParser provider = getRawProvider(); AbstractBuildCommandParser provider = getRawProvider();
if (!text.equals(provider.getCustomParameter())) { if (!text.equals(provider.getCompilerPattern())) {
AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId); AbstractBuildCommandParser selectedProvider = getWorkingCopy(providerId);
selectedProvider.setCustomParameter(text); selectedProvider.setCompilerPattern(text);
providerTab.refreshItem(selectedProvider); providerTab.refreshItem(selectedProvider);
} }
} }

View file

@ -84,17 +84,17 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin
{ {
inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER); inputCommand = ControlFactory.createTextField(composite, SWT.SINGLE | SWT.BORDER);
String customParameter = provider.getCustomParameter(); String command = provider.getCommand();
inputCommand.setText(customParameter!=null ? customParameter : ""); inputCommand.setText(command!=null ? command : "");
inputCommand.setEnabled(fEditable); inputCommand.setEnabled(fEditable);
inputCommand.addModifyListener(new ModifyListener() { inputCommand.addModifyListener(new ModifyListener() {
@Override @Override
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
String text = inputCommand.getText(); String text = inputCommand.getText();
AbstractBuiltinSpecsDetector provider = getRawProvider(); AbstractBuiltinSpecsDetector provider = getRawProvider();
if (!text.equals(provider.getCustomParameter())) { if (!text.equals(provider.getCommand())) {
AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId); AbstractBuiltinSpecsDetector selectedProvider = getWorkingCopy(providerId);
selectedProvider.setCustomParameter(text); selectedProvider.setCommand(text);
providerTab.refreshItem(selectedProvider); providerTab.refreshItem(selectedProvider);
} }
} }

View file

@ -88,7 +88,7 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase {
{ {
MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal(); MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal();
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}}); detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
detector.setCustomParameter("${COMMAND} -E -P -v -dD ${INPUTS}"); detector.setCommand("${COMMAND} -E -P -v -dD ${INPUTS}");
String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C); String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C);
assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD ")); assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD "));
@ -97,7 +97,7 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase {
{ {
MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal(); MockGCCBuiltinSpecsDetectorLocal detector = new MockGCCBuiltinSpecsDetectorLocal();
detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}}); detector.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID_C);}});
detector.setCustomParameter("${COMMAND} -E -P -v -dD file.${EXT}"); detector.setCommand("${COMMAND} -E -P -v -dD file.${EXT}");
String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C); String resolvedCommand = detector.resolveCommand(LANGUAGE_ID_C);
assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD ")); assertTrue(resolvedCommand.startsWith("gcc -E -P -v -dD "));

View file

@ -39,6 +39,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase {
/*package*/ static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Mock Language Settings Base Provider"; /*package*/ static final String EXTENSION_BASE_PROVIDER_NAME = "Test Plugin Mock Language Settings Base Provider";
/*package*/ static final String EXTENSION_BASE_PROVIDER_LANG_ID = "org.eclipse.cdt.core.tests.language.id"; /*package*/ static final String EXTENSION_BASE_PROVIDER_LANG_ID = "org.eclipse.cdt.core.tests.language.id";
/*package*/ static final String EXTENSION_BASE_PROVIDER_PARAMETER = "custom parameter"; /*package*/ static final String EXTENSION_BASE_PROVIDER_PARAMETER = "custom parameter";
/*package*/ static final String EXTENSION_BASE_PROVIDER_ATTR_PARAMETER = "parameter";
/*package*/ static final String EXTENSION_CUSTOM_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.language.settings.provider"; /*package*/ static final String EXTENSION_CUSTOM_PROVIDER_ID = "org.eclipse.cdt.core.tests.custom.language.settings.provider";
/*package*/ static final String EXTENSION_CUSTOM_PROVIDER_NAME = "Test Plugin Mock Language Settings Provider"; /*package*/ static final String EXTENSION_CUSTOM_PROVIDER_NAME = "Test Plugin Mock Language Settings Provider";
/*package*/ static final String EXTENSION_BASE_SUBCLASS_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass"; /*package*/ static final String EXTENSION_BASE_SUBCLASS_PROVIDER_ID = "org.eclipse.cdt.core.tests.language.settings.base.provider.subclass";
@ -122,7 +123,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase {
LanguageSettingsBaseProvider provider = (LanguageSettingsBaseProvider)rawProvider; LanguageSettingsBaseProvider provider = (LanguageSettingsBaseProvider)rawProvider;
assertEquals(EXTENSION_BASE_PROVIDER_ID, provider.getId()); assertEquals(EXTENSION_BASE_PROVIDER_ID, provider.getId());
assertEquals(EXTENSION_BASE_PROVIDER_NAME, provider.getName()); assertEquals(EXTENSION_BASE_PROVIDER_NAME, provider.getName());
assertEquals(EXTENSION_BASE_PROVIDER_PARAMETER, provider.getCustomParameter()); assertEquals(EXTENSION_BASE_PROVIDER_PARAMETER, provider.getProperty(EXTENSION_BASE_PROVIDER_ATTR_PARAMETER));
// attempt to get entries for wrong language // attempt to get entries for wrong language
assertNull(provider.getSettingEntries(null, FILE_0, LANG_ID)); assertNull(provider.getSettingEntries(null, FILE_0, LANG_ID));
@ -263,7 +264,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase {
LanguageSettingsSerializableProvider provider = (LanguageSettingsSerializableProvider) rawProvider; LanguageSettingsSerializableProvider provider = (LanguageSettingsSerializableProvider) rawProvider;
assertEquals(null, provider.getLanguageScope()); assertEquals(null, provider.getLanguageScope());
assertEquals("", provider.getCustomParameter()); assertEquals("", provider.getProperty(EXTENSION_BASE_PROVIDER_ATTR_PARAMETER));
List<ICLanguageSettingEntry> expected = new ArrayList<ICLanguageSettingEntry>(); List<ICLanguageSettingEntry> expected = new ArrayList<ICLanguageSettingEntry>();
expected.add(new CMacroEntry("MACRO", "value", 0)); expected.add(new CMacroEntry("MACRO", "value", 0));

View file

@ -54,8 +54,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
private static final String PROVIDER_2 = "test.provider.2.id"; private static final String PROVIDER_2 = "test.provider.2.id";
private static final String PROVIDER_NAME_0 = "test.provider.0.name"; private static final String PROVIDER_NAME_0 = "test.provider.0.name";
private static final String PROVIDER_NAME_2 = "test.provider.2.name"; private static final String PROVIDER_NAME_2 = "test.provider.2.name";
private static final String PROVIDER_ID_WSP = "test.provider.workspace.id"; private static final String ATTR_PARAMETER = "parameter";
private static final String PROVIDER_NAME_WSP = "test.provider.workspace.name";
private static final String CUSTOM_PARAMETER = "custom parameter"; private static final String CUSTOM_PARAMETER = "custom parameter";
private static final String ELEM_TEST = "test"; private static final String ELEM_TEST = "test";
@ -349,8 +348,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, rawProvider.getId()); assertEquals(EXTENSION_SERIALIZABLE_PROVIDER_ID, rawProvider.getId());
// customize provider // customize provider
rawProvider.setCustomParameter(CUSTOM_PARAMETER); rawProvider.setProperty(ATTR_PARAMETER, CUSTOM_PARAMETER);
assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter()); assertEquals(CUSTOM_PARAMETER, rawProvider.getProperty(ATTR_PARAMETER));
} }
{ {
// save workspace provider (as opposed to raw provider) // save workspace provider (as opposed to raw provider)
@ -363,7 +362,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
// check that it has not cleared // check that it has not cleared
ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID); ILanguageSettingsProvider provider = LanguageSettingsManager.getWorkspaceProvider(EXTENSION_SERIALIZABLE_PROVIDER_ID);
LanguageSettingsSerializableProvider rawProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider); LanguageSettingsSerializableProvider rawProvider = (LanguageSettingsSerializableProvider) LanguageSettingsManager.getRawProvider(provider);
assertEquals(CUSTOM_PARAMETER, rawProvider.getCustomParameter()); assertEquals(CUSTOM_PARAMETER, rawProvider.getProperty(ATTR_PARAMETER));
} }
} }

View file

@ -54,7 +54,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
private static final String PROVIDER_NAME_NULL = "test.provider.null.name"; private static final String PROVIDER_NAME_NULL = "test.provider.null.name";
private static final String PROVIDER_NAME_1 = "test.provider.1.name"; private static final String PROVIDER_NAME_1 = "test.provider.1.name";
private static final String PROVIDER_NAME_2 = "test.provider.2.name"; private static final String PROVIDER_NAME_2 = "test.provider.2.name";
private static final String CUSTOM_PARAMETER = "custom.parameter"; private static final String ATTR_PARAMETER = "parameter";
private static final String VALUE_PARAMETER = "custom.parameter";
private static final String ATTR_STORE_ENTRIES = "store-entries"; private static final String ATTR_STORE_ENTRIES = "store-entries";
private static final String VALUE_PROJECT = "project"; private static final String VALUE_PROJECT = "project";
private static final String ELEM_TEST = "test"; private static final String ELEM_TEST = "test";
@ -113,14 +114,8 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
assertEquals(PROVIDER_2, mockProvider.getId()); assertEquals(PROVIDER_2, mockProvider.getId());
mockProvider.setName(PROVIDER_NAME_2); mockProvider.setName(PROVIDER_NAME_2);
assertEquals(PROVIDER_NAME_2, mockProvider.getName()); assertEquals(PROVIDER_NAME_2, mockProvider.getName());
mockProvider.setCustomParameter(CUSTOM_PARAMETER); mockProvider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER);
assertEquals(CUSTOM_PARAMETER, mockProvider.getCustomParameter()); assertEquals(VALUE_PARAMETER, mockProvider.getProperty(ATTR_PARAMETER));
assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(mockProvider));
LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, true);
assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(mockProvider));
LanguageSettingsManager.setStoringEntriesInProjectArea(mockProvider, false);
assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(mockProvider));
mockProvider.setLanguageScope(languages); mockProvider.setLanguageScope(languages);
assertEquals(languages, mockProvider.getLanguageScope()); assertEquals(languages, mockProvider.getLanguageScope());
@ -138,6 +133,19 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
assertTrue(mockProvider.isEmpty()); assertTrue(mockProvider.isEmpty());
} }
/**
*/
public void testProvider_SetStoringEntriesInProjectArea() throws Exception {
// create a provider
LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider));
LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true);
assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider));
LanguageSettingsManager.setStoringEntriesInProjectArea(provider, false);
assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider));
}
/** /**
*/ */
public void testProvider_RegularDOM() throws Exception { public void testProvider_RegularDOM() throws Exception {
@ -146,7 +154,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
// create customized provider // create customized provider
LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true);
provider.setCustomParameter(CUSTOM_PARAMETER); provider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER);
List<String> languageScope = new ArrayList<String>(); List<String> languageScope = new ArrayList<String>();
languageScope.add(LANG_ID); languageScope.add(LANG_ID);
@ -164,7 +172,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
String xmlString = XmlUtil.toString(doc); String xmlString = XmlUtil.toString(doc);
assertTrue(xmlString.contains(PROVIDER_1)); assertTrue(xmlString.contains(PROVIDER_1));
assertTrue(xmlString.contains(PROVIDER_NAME_1)); assertTrue(xmlString.contains(PROVIDER_NAME_1));
assertTrue(xmlString.contains(CUSTOM_PARAMETER)); assertTrue(xmlString.contains(VALUE_PARAMETER));
assertTrue(xmlString.contains(LANG_ID)); assertTrue(xmlString.contains(LANG_ID));
assertTrue(xmlString.contains("path0")); assertTrue(xmlString.contains("path0"));
} }
@ -173,7 +181,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider);
assertEquals(PROVIDER_1, provider.getId()); assertEquals(PROVIDER_1, provider.getId());
assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider));
assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); assertEquals(VALUE_PARAMETER, provider.getProperty(ATTR_PARAMETER));
assertNotNull(provider.getLanguageScope()); assertNotNull(provider.getLanguageScope());
assertTrue(provider.getLanguageScope().size()>0); assertTrue(provider.getLanguageScope().size()>0);
assertEquals(LANG_ID, provider.getLanguageScope().get(0)); assertEquals(LANG_ID, provider.getLanguageScope().get(0));
@ -193,7 +201,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
// create customized provider // create customized provider
LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true);
provider.setCustomParameter(CUSTOM_PARAMETER); provider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER);
List<String> languageScope = new ArrayList<String>(); List<String> languageScope = new ArrayList<String>();
languageScope.add(LANG_ID); languageScope.add(LANG_ID);
@ -211,7 +219,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
String xmlString = XmlUtil.toString(doc); String xmlString = XmlUtil.toString(doc);
assertTrue(xmlString.contains(PROVIDER_1)); assertTrue(xmlString.contains(PROVIDER_1));
assertTrue(xmlString.contains(PROVIDER_NAME_1)); assertTrue(xmlString.contains(PROVIDER_NAME_1));
assertTrue(xmlString.contains(CUSTOM_PARAMETER)); assertTrue(xmlString.contains(VALUE_PARAMETER));
assertTrue(xmlString.contains(LANG_ID)); assertTrue(xmlString.contains(LANG_ID));
// no entries // no entries
assertFalse(xmlString.contains("path0")); assertFalse(xmlString.contains("path0"));
@ -222,7 +230,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
provider.loadAttributes(elementProvider); provider.loadAttributes(elementProvider);
assertEquals(PROVIDER_1, provider.getId()); assertEquals(PROVIDER_1, provider.getId());
assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); assertEquals(true, LanguageSettingsManager.isStoringEntriesInProjectArea(provider));
assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); assertEquals(VALUE_PARAMETER, provider.getProperty(ATTR_PARAMETER));
assertNotNull(provider.getLanguageScope()); assertNotNull(provider.getLanguageScope());
assertTrue(provider.getLanguageScope().size()>0); assertTrue(provider.getLanguageScope().size()>0);
assertEquals(LANG_ID, provider.getLanguageScope().get(0)); assertEquals(LANG_ID, provider.getLanguageScope().get(0));
@ -240,7 +248,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
// create customized provider // create customized provider
LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true); LanguageSettingsManager.setStoringEntriesInProjectArea(provider, true);
provider.setCustomParameter(CUSTOM_PARAMETER); provider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER);
List<String> languageScope = new ArrayList<String>(); List<String> languageScope = new ArrayList<String>();
languageScope.add(LANG_ID); languageScope.add(LANG_ID);
@ -259,7 +267,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
// no attributes // no attributes
assertFalse(xmlString.contains(PROVIDER_1)); assertFalse(xmlString.contains(PROVIDER_1));
assertFalse(xmlString.contains(PROVIDER_NAME_1)); assertFalse(xmlString.contains(PROVIDER_NAME_1));
assertFalse(xmlString.contains(CUSTOM_PARAMETER)); assertFalse(xmlString.contains(VALUE_PARAMETER));
assertFalse(xmlString.contains(LANG_ID)); assertFalse(xmlString.contains(LANG_ID));
// entries should be present // entries should be present
assertTrue(xmlString.contains("path0")); assertTrue(xmlString.contains("path0"));
@ -274,7 +282,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
assertFalse(PROVIDER_1.equals(provider.getId())); assertFalse(PROVIDER_1.equals(provider.getId()));
assertFalse(PROVIDER_NAME_1.equals(provider.getName())); assertFalse(PROVIDER_NAME_1.equals(provider.getName()));
assertFalse(true==LanguageSettingsManager.isStoringEntriesInProjectArea(provider)); assertFalse(true==LanguageSettingsManager.isStoringEntriesInProjectArea(provider));
assertFalse(CUSTOM_PARAMETER.equals(provider.getCustomParameter())); assertFalse(VALUE_PARAMETER.equals(provider.getProperty(ATTR_PARAMETER)));
assertNull(provider.getLanguageScope()); assertNull(provider.getLanguageScope());
// entries should be loaded // entries should be loaded
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, null); List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, null);
@ -318,19 +326,19 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
{ {
// create provider with custom parameter // create provider with custom parameter
LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
provider.setCustomParameter(CUSTOM_PARAMETER); provider.setProperty(ATTR_PARAMETER, VALUE_PARAMETER);
assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); assertEquals(VALUE_PARAMETER, provider.getProperty(ATTR_PARAMETER));
Document doc = XmlUtil.newDocument(); Document doc = XmlUtil.newDocument();
Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST); Element rootElement = XmlUtil.appendElement(doc, ELEM_TEST);
elementProvider = provider.serialize(rootElement); elementProvider = provider.serialize(rootElement);
String xmlString = XmlUtil.toString(doc); String xmlString = XmlUtil.toString(doc);
assertTrue(xmlString.contains(CUSTOM_PARAMETER)); assertTrue(xmlString.contains(VALUE_PARAMETER));
} }
{ {
// re-load and check custom parameter of the newly loaded provider // re-load and check custom parameter of the newly loaded provider
LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider); LanguageSettingsSerializableProvider provider = new LanguageSettingsSerializableProvider(elementProvider);
assertEquals(CUSTOM_PARAMETER, provider.getCustomParameter()); assertEquals(VALUE_PARAMETER, provider.getProperty(ATTR_PARAMETER));
} }
} }
@ -1175,7 +1183,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
// create a model provider // create a model provider
LanguageSettingsSerializableProvider provider1 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); LanguageSettingsSerializableProvider provider1 = new LanguageSettingsSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
provider1.setLanguageScope(sampleLanguages); provider1.setLanguageScope(sampleLanguages);
provider1.setCustomParameter(CUSTOM_PARAMETER); provider1.setProperty(ATTR_PARAMETER, VALUE_PARAMETER);
assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1)); assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1));
LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true);
provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1);
@ -1199,7 +1207,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
assertFalse(provider1.equals(provider2)); assertFalse(provider1.equals(provider2));
assertFalse(provider1.hashCode()==provider2.hashCode()); assertFalse(provider1.hashCode()==provider2.hashCode());
provider2.setCustomParameter(CUSTOM_PARAMETER); provider2.setProperty(ATTR_PARAMETER, VALUE_PARAMETER);
assertFalse(provider1.equals(provider2)); assertFalse(provider1.equals(provider2));
assertFalse(provider1.hashCode()==provider2.hashCode()); assertFalse(provider1.hashCode()==provider2.hashCode());
@ -1252,7 +1260,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
} }
MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
provider1.setLanguageScope(sampleLanguages); provider1.setLanguageScope(sampleLanguages);
provider1.setCustomParameter(CUSTOM_PARAMETER); provider1.setProperty(ATTR_PARAMETER, VALUE_PARAMETER);
assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1)); assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1));
LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true);
provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1); provider1.setSettingEntries(MOCK_CFG, MOCK_RC, LANG_ID, sampleEntries_1);
@ -1264,10 +1272,10 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
assertTrue(provider1.equals(providerClone)); assertTrue(provider1.equals(providerClone));
assertTrue(provider1.getClass()==providerClone.getClass()); assertTrue(provider1.getClass()==providerClone.getClass());
assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); assertEquals(provider1.getProperty(ATTR_PARAMETER), providerClone.getProperty(ATTR_PARAMETER));
// ensure we did not clone reference // ensure we did not clone reference
provider1.setCustomParameter(""); provider1.setProperty(ATTR_PARAMETER, "");
assertFalse(provider1.getCustomParameter().equals(providerClone.getCustomParameter())); assertFalse(provider1.getProperty(ATTR_PARAMETER).equals(providerClone.getProperty(ATTR_PARAMETER)));
assertEquals(LanguageSettingsManager.isStoringEntriesInProjectArea(provider1), LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone)); assertEquals(LanguageSettingsManager.isStoringEntriesInProjectArea(provider1), LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone));
// ensure we did not clone reference // ensure we did not clone reference
@ -1309,7 +1317,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
} }
MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1); MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
provider1.setLanguageScope(sampleLanguages); provider1.setLanguageScope(sampleLanguages);
provider1.setCustomParameter(CUSTOM_PARAMETER); provider1.setProperty(ATTR_PARAMETER, VALUE_PARAMETER);
assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1)); assertEquals(false, LanguageSettingsManager.isStoringEntriesInProjectArea(provider1));
LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true); LanguageSettingsManager.setStoringEntriesInProjectArea(provider1, true);
@ -1322,7 +1330,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
assertNotSame(provider1, providerClone); assertNotSame(provider1, providerClone);
assertFalse(provider1.equals(providerClone)); assertFalse(provider1.equals(providerClone));
assertTrue(provider1.getClass()==providerClone.getClass()); assertTrue(provider1.getClass()==providerClone.getClass());
assertEquals(provider1.getCustomParameter(), providerClone.getCustomParameter()); assertEquals(provider1.getProperty(ATTR_PARAMETER), providerClone.getProperty(ATTR_PARAMETER));
assertEquals(LanguageSettingsManager.isStoringEntriesInProjectArea(provider1), LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone)); assertEquals(LanguageSettingsManager.isStoringEntriesInProjectArea(provider1), LanguageSettingsManager.isStoringEntriesInProjectArea(providerClone));
assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0)); assertEquals(provider1.getLanguageScope().get(0), providerClone.getLanguageScope().get(0));

View file

@ -1,19 +1,23 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others. * Copyright (c) 2009, 2011 Andrew Gvozdev and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation * Andrew Gvozdev - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.language.settings.providers; package org.eclipse.cdt.core.language.settings.providers;
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider;
public class MockLanguageSettingsBaseProvider extends LanguageSettingsBaseProvider { public class MockLanguageSettingsBaseProvider extends LanguageSettingsBaseProvider {
private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
/**
* @return the custom parameter defined in the extension in {@code plugin.xml}.
*/
public String getCustomParameter() {
return getProperty(ATTR_PARAMETER);
}
} }

View file

@ -13,7 +13,9 @@ package org.eclipse.cdt.core.language.settings.providers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.AbstractExecutableExtensionBase; import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
@ -27,15 +29,13 @@ import org.eclipse.core.resources.IResource;
* *
* This implementation supports "static" list of entries for languages specified in * This implementation supports "static" list of entries for languages specified in
* the extension point. * the extension point.
*
* @since 6.0
*/ */
public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider { public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBase implements ILanguageSettingsProvider {
/** Language scope, i.e. list of languages the entries will be provided for. */ /** Language scope, i.e. list of languages the entries will be provided for. */
protected List<String> languageScope = null; protected List<String> languageScope = null;
/** Custom parameter. Intended for providers extending this class. */ /** Provider-specific properties */
protected String customParameter = null; protected Map<String, String> properties = new HashMap<String, String>();
/** List of entries defined by this provider. */ /** List of entries defined by this provider. */
private List<ICLanguageSettingEntry> entries = null; private List<ICLanguageSettingEntry> entries = null;
@ -85,15 +85,15 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
* are provided for any language. * are provided for any language.
* @param entries - the list of language settings entries this provider provides. * @param entries - the list of language settings entries this provider provides.
* If {@code null} is passed, the provider creates an empty list. * If {@code null} is passed, the provider creates an empty list.
* @param customParameter - a custom parameter as the means to customize * @param properties - custom properties as the means to customize providers.
* providers extending this class.
*/ */
public LanguageSettingsBaseProvider(String id, String name, List<String> languages, public LanguageSettingsBaseProvider(String id, String name, List<String> languages,
List<ICLanguageSettingEntry> entries, String customParameter) { List<ICLanguageSettingEntry> entries, Map<String, String> properties) {
super(id, name); super(id, name);
this.languageScope = languages!=null ? new ArrayList<String>(languages) : null; this.languageScope = languages!=null ? new ArrayList<String>(languages) : null;
this.entries = getPooledList(entries); this.entries = getPooledList(entries);
this.customParameter = customParameter; if (properties != null)
this.properties = new HashMap<String, String>(properties);
} }
/** /**
@ -111,21 +111,34 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
* are provided for any language. * are provided for any language.
* @param entries - the list of language settings entries this provider provides. * @param entries - the list of language settings entries this provider provides.
* If {@code null} is passed, the provider creates an empty list. * If {@code null} is passed, the provider creates an empty list.
* @param customParameter - a custom parameter as the means to customize * @param properties - custom properties as the means to customize providers.
* providers extending this class from extension definition in {@code plugin.xml}.
* *
* @throws UnsupportedOperationException if an attempt to reconfigure provider is made. * @throws UnsupportedOperationException if an attempt to reconfigure provider is made.
*/ */
public void configureProvider(String id, String name, List<String> languages, public void configureProvider(String id, String name, List<String> languages,
List<ICLanguageSettingEntry> entries, String customParameter) { List<ICLanguageSettingEntry> entries, Map<String, String> properties) {
if (this.entries!=null) if (this.entries!=null || !this.properties.isEmpty())
throw new UnsupportedOperationException(SettingsModelMessages.getString("LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce")); //$NON-NLS-1$ throw new UnsupportedOperationException(SettingsModelMessages.getString("LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce")); //$NON-NLS-1$
setId(id); setId(id);
setName(name); setName(name);
this.languageScope = languages!=null ? new ArrayList<String>(languages) : null; this.languageScope = languages!=null ? new ArrayList<String>(languages) : null;
this.entries = getPooledList(entries); this.entries = getPooledList(entries);
this.customParameter = customParameter; if (properties != null)
this.properties = new HashMap<String, String>(properties);
}
/**
* {@code LanguageSettingsBaseProvider} keeps the list of key-value pairs
* so extenders of this class can customize the provider. The properties
* of {@code LanguageSettingsBaseProvider} come from the extension in plugin.xml
* although the extenders can provide their own method.
*
* @param key - property to check the value.
* @return value of the property.
*/
public String getProperty(String key) {
return properties.get(key);
} }
private List<ICLanguageSettingEntry> getPooledList(List<ICLanguageSettingEntry> entries) { private List<ICLanguageSettingEntry> getPooledList(List<ICLanguageSettingEntry> entries) {
@ -168,11 +181,4 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
return null; return null;
return Collections.unmodifiableList(languageScope); return Collections.unmodifiableList(languageScope);
} }
/**
* @return the custom parameter defined in the extension in {@code plugin.xml}.
*/
public String getCustomParameter() {
return customParameter;
}
} }

View file

@ -44,9 +44,7 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
private static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$ private static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$
private static final String ATTR_NAME = "name"; //$NON-NLS-1$ private static final String ATTR_NAME = "name"; //$NON-NLS-1$
private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
private Map<String, String> properties = new HashMap<String, String>();
private LanguageSettingsSerializableStorage fStorage = new LanguageSettingsSerializableStorage(); private LanguageSettingsSerializableStorage fStorage = new LanguageSettingsSerializableStorage();
/** /**
@ -78,9 +76,9 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
} }
@Override @Override
public void configureProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries, String customParameter) { public void configureProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries, Map<String, String> properties) {
// do not pass entries to super, keep them in local storage // do not pass entries to super, keep them in local storage
super.configureProvider(id, name, languages, null, customParameter); super.configureProvider(id, name, languages, null, properties);
fStorage.clear(); fStorage.clear();
@ -113,16 +111,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
this.languageScope = new ArrayList<String>(languages); 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;
}
/** /**
* Clear all the entries for all configurations, all resources and all languages. * Clear all the entries for all configurations, all resources and all languages.
*/ */
@ -218,8 +206,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
attributes.add(getName()); attributes.add(getName());
attributes.add(ATTR_CLASS); attributes.add(ATTR_CLASS);
attributes.add(getClass().getCanonicalName()); attributes.add(getClass().getCanonicalName());
attributes.add(ATTR_PARAMETER);
attributes.add(getCustomParameter());
for (Entry<String, String> entry : properties.entrySet()) { for (Entry<String, String> entry : properties.entrySet()) {
attributes.add(entry.getKey()); attributes.add(entry.getKey());
attributes.add(entry.getValue()); attributes.add(entry.getValue());
@ -281,7 +267,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
public void loadAttributes(Element providerNode) { public void loadAttributes(Element providerNode) {
String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID); String providerId = XmlUtil.determineAttributeValue(providerNode, ATTR_ID);
String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME); String providerName = XmlUtil.determineAttributeValue(providerNode, ATTR_NAME);
String providerParameter = XmlUtil.determineAttributeValue(providerNode, ATTR_PARAMETER);
properties.clear(); properties.clear();
NamedNodeMap attrs = providerNode.getAttributes(); NamedNodeMap attrs = providerNode.getAttributes();
@ -298,7 +283,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
this.setId(providerId); this.setId(providerId);
this.setName(providerName); this.setName(providerName);
this.setCustomParameter(providerParameter);
NodeList nodes = providerNode.getChildNodes(); NodeList nodes = providerNode.getChildNodes();
for (int i=0;i<nodes.getLength();i++) { for (int i=0;i<nodes.getLength();i++) {
@ -322,17 +306,19 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
} }
/** /**
* TODO * Set a custom property of the provider.
*/ * @see LanguageSettingsBaseProvider#getProperty(String)
public String getProperty(String key) { *
return properties.get(key); * @param key - name of the property.
} * @param value - value of the property.
* If value is {@code null} the property is removed from the list.
/**
* TODO
*/ */
public void setProperty(String key, String value) { public void setProperty(String key, String value) {
properties.put(key, value); if (value != null) {
properties.put(key, value);
} else {
properties.remove(key);
}
} }
/** /**
@ -374,7 +360,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode()); result = prime * result + ((languageScope == null) ? 0 : languageScope.hashCode());
result = prime * result + ((customParameter == null) ? 0 : customParameter.hashCode());
result = prime * result + ((properties == null) ? 0 : properties.hashCode()); result = prime * result + ((properties == null) ? 0 : properties.hashCode());
result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode()); result = prime * result + ((fStorage == null) ? 0 : fStorage.hashCode());
result = prime * result + getClass().hashCode(); result = prime * result + getClass().hashCode();
@ -417,12 +402,6 @@ public class LanguageSettingsSerializableProvider extends LanguageSettingsBasePr
} else if (!languageScope.equals(other.languageScope)) } else if (!languageScope.equals(other.languageScope))
return false; return false;
if (customParameter == null) {
if (other.customParameter != null)
return false;
} else if (!customParameter.equals(other.customParameter))
return false;
if (properties == null) { if (properties == null) {
if (other.properties != null) if (other.properties != null)
return false; return false;

View file

@ -13,8 +13,10 @@ package org.eclipse.cdt.internal.core.language.settings.providers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -49,7 +51,6 @@ public class LanguageSettingsExtensionManager {
static final String ATTR_CLASS = "class"; //$NON-NLS-1$ static final String ATTR_CLASS = "class"; //$NON-NLS-1$
static final String ATTR_ID = "id"; //$NON-NLS-1$ static final String ATTR_ID = "id"; //$NON-NLS-1$
static final String ATTR_NAME = "name"; //$NON-NLS-1$ static final String ATTR_NAME = "name"; //$NON-NLS-1$
static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$ static final String ELEM_LANGUAGE_SCOPE = "language-scope"; //$NON-NLS-1$
@ -163,10 +164,14 @@ public class LanguageSettingsExtensionManager {
private static void configureExecutableProvider(ILanguageSettingsProvider provider, IConfigurationElement ce) { private static void configureExecutableProvider(ILanguageSettingsProvider provider, IConfigurationElement ce) {
String ceId = determineAttributeValue(ce, ATTR_ID); String ceId = determineAttributeValue(ce, ATTR_ID);
String ceName = determineAttributeValue(ce, ATTR_NAME); String ceName = determineAttributeValue(ce, ATTR_NAME);
String ceParameter = determineAttributeValue(ce, ATTR_PARAMETER); Map<String, String> ceAttributes = new HashMap<String, String>();
List<String> languages = null; List<String> languages = null;
List<ICLanguageSettingEntry> entries = null; List<ICLanguageSettingEntry> entries = null;
for (String attr : ce.getAttributeNames()) {
ceAttributes.put(attr, determineAttributeValue(ce, attr));
}
for (IConfigurationElement ceLang : ce.getChildren(ELEM_LANGUAGE_SCOPE)) { for (IConfigurationElement ceLang : ce.getChildren(ELEM_LANGUAGE_SCOPE)) {
String langId = determineAttributeValue(ceLang, ATTR_ID); String langId = determineAttributeValue(ceLang, ATTR_ID);
if (langId.length() > 0) { if (langId.length() > 0) {
@ -203,7 +208,7 @@ public class LanguageSettingsExtensionManager {
} }
if (provider instanceof LanguageSettingsBaseProvider) { if (provider instanceof LanguageSettingsBaseProvider) {
((LanguageSettingsBaseProvider) provider).configureProvider(ceId, ceName, languages, entries, ceParameter); ((LanguageSettingsBaseProvider) provider).configureProvider(ceId, ceName, languages, entries, ceAttributes);
} else if (provider instanceof AbstractExecutableExtensionBase) { } else if (provider instanceof AbstractExecutableExtensionBase) {
((AbstractExecutableExtensionBase) provider).setId(ceId); ((AbstractExecutableExtensionBase) provider).setId(ceId);
((AbstractExecutableExtensionBase) provider).setName(ceName); ((AbstractExecutableExtensionBase) provider).setName(ceName);