diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyCalculatorTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyCalculatorTests.java index 9b840d527a8..3ee59d21068 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyCalculatorTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyCalculatorTests.java @@ -239,4 +239,4 @@ public class ManagedBuildDependencyCalculatorTests extends TestCase { buildProjects(projects, makefiles); } -} +} \ No newline at end of file diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/AllLanguageSettingsProvidersMBSTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/AllLanguageSettingsProvidersMBSTests.java index 9659fbe9a6f..6937c34379a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/AllLanguageSettingsProvidersMBSTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/AllLanguageSettingsProvidersMBSTests.java @@ -13,6 +13,9 @@ package org.eclipse.cdt.managedbuilder.language.settings.providers.tests; import junit.framework.TestSuite; +/** + * Test suite to test language settings providers defined in cdt.managedbuilder.core. + */ public class AllLanguageSettingsProvidersMBSTests extends TestSuite { public static TestSuite suite() { diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java index fab13c3a8e8..6fe2262c2f1 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java @@ -44,6 +44,9 @@ import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Document; import org.w3c.dom.Element; +/** + * Test cases to test built-in specs detectors. + */ public class BuiltinSpecsDetectorTest extends BaseTestCase { private static final String PROVIDER_ID = "provider.id"; private static final String PROVIDER_NAME = "provider name"; @@ -56,6 +59,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ + /** + * Mock built-in specs detector to test basic functionality of {@link AbstractBuiltinSpecsDetector}. + */ private class MockBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { @Override protected List parseOptions(String line) { @@ -80,6 +86,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { } } + /** + * Mock built-in specs detector to test execute() functionality. + */ private class MockBuiltinSpecsDetectorExecutedFlag extends AbstractBuiltinSpecsDetector { @Override protected List parseOptions(String line) { @@ -103,6 +112,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { } } + /** + * Mock built-in specs detector to test parsing functionality. + */ private class MockConsoleBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector { @SuppressWarnings("nls") private final AbstractOptionParser[] optionParsers = { @@ -148,6 +160,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { super.tearDown(); } + /** + * Helper method to fetch configuration descriptions. + */ private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { CoreModel coreModel = CoreModel.getDefault(); ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); @@ -160,6 +175,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { return cfgDescriptions; } + /** + * Test configure, getters and setters. + */ public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception { { // provider configured with null parameters @@ -206,6 +224,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { } } + /** + * Test clone() and equals(). + */ public void testAbstractBuiltinSpecsDetector_CloneAndEquals() throws Exception { // define mock detector class MockDetectorCloneable extends MockBuiltinSpecsDetectorExecutedFlag implements Cloneable { @@ -302,8 +323,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { } /** + * Test basic serialization functionality. */ - public void testAbstractBuiltinSpecsDetector_Serialize() throws Exception { + public void testAbstractBuiltinSpecsDetector_SerializeDOM() throws Exception { { // create empty XML Document doc = XmlUtil.newDocument(); @@ -344,6 +366,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { } } + /** + * Smoke test exercising passing {@code null} to the functions. + */ public void testAbstractBuiltinSpecsDetector_Nulls() throws Exception { { // test AbstractBuiltinSpecsDetector.processLine(...) flow @@ -363,6 +388,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { } } + /** + * Test basic parsing functionality. + */ public void testAbstractBuiltinSpecsDetector_RunConfiguration() throws Exception { // Create model project and accompanied descriptions String projectName = getName(); @@ -373,6 +401,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector(); provider.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + // Run provider provider.startup(cfgDescription, null); provider.runForEachLanguage(null); provider.shutdown(); @@ -382,26 +411,36 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { List noentries = provider.getSettingEntries(null, null, null); assertNull(noentries); + // Check parsed entries List entries = provider.getSettingEntries(cfgDescription, null, LANGUAGE_ID); ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); assertEquals(expected, entries.get(0)); } + /** + * Smoke test running as global provider on workspace level. + */ public void testAbstractBuiltinSpecsDetector_RunGlobal() throws Exception { + // Create provider MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector(); provider.setLanguageScope(new ArrayList() {{add(LANGUAGE_ID);}}); + // Run provider provider.startup(null, null); provider.runForEachLanguage(null); provider.shutdown(); assertFalse(provider.isEmpty()); + // Check parsed entries List entries = provider.getSettingEntries(null, null, LANGUAGE_ID); ICLanguageSettingEntry expected = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); assertEquals(expected, entries.get(0)); } + /** + * Check that entries get grouped by kinds by stock built-in specs detector. + */ public void testAbstractBuiltinSpecsDetector_GroupSettings() throws Exception { // define benchmarks final CIncludePathEntry includePath_1 = new CIncludePathEntry("/include/path_1", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); @@ -448,7 +487,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { // compare benchmarks, expected well-sorted List entries = provider.getSettingEntries(null, null, null); - int i=0; + int i = 0; assertEquals(includePath_1, entries.get(i++)); assertEquals(includePath_2, entries.get(i++)); assertEquals(includeFile_1, entries.get(i++)); diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuildCommandParserTest.java index d5cae2d8543..f18c4eb9b0d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuildCommandParserTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Andrew Gvozdev and others. + * Copyright (c) 2009, 2012 Andrew Gvozdev and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -54,6 +54,9 @@ import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Document; import org.w3c.dom.Element; +/** + * Test cases to test build command parsers. + */ public class GCCBuildCommandParserTest extends BaseTestCase { // ID of the parser taken from the extension point private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"; //$NON-NLS-1$ @@ -70,6 +73,9 @@ public class GCCBuildCommandParserTest extends BaseTestCase { private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ private static final String ATTR_KEEP_RELATIVE_PATHS = "keep-relative-paths"; //$NON-NLS-1$ + /** + * Mock build command parser. + */ private class MockBuildCommandParser extends AbstractBuildCommandParser implements Cloneable { @Override protected AbstractOptionParser[] getOptionParsers() { @@ -100,6 +106,9 @@ public class GCCBuildCommandParserTest extends BaseTestCase { super.tearDown(); } + /** + * Helper method to fetch configuration descriptions. + */ private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { CoreModel coreModel = CoreModel.getDefault(); ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); @@ -139,6 +148,9 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } } + /** + * Helper method to set reference project. + */ private void setReference(IProject project, final IProject projectReferenced) throws CoreException { { CoreModel coreModel = CoreModel.getDefault(); @@ -169,6 +181,9 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } + /** + * Test getters and setters. + */ public void testAbstractBuildCommandParser_GettersSetters() throws Exception { { // provider configured with null parameters @@ -206,6 +221,9 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } } + /** + * Test clone() and equals(). + */ public void testAbstractBuildCommandParser_CloneAndEquals() throws Exception { // create instance to compare to MockBuildCommandParser parser = new MockBuildCommandParser(); @@ -242,7 +260,10 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } - public void testAbstractBuildCommandParser_Serialize() throws Exception { + /** + * Test basic serialization functionality. + */ + public void testAbstractBuildCommandParser_SerializeDOM() throws Exception { { // create empty XML Document doc = XmlUtil.newDocument(); @@ -283,6 +304,9 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } } + /** + * Smoke test exercising passing {@code null} to the functions. + */ public void testAbstractBuildCommandParser_Nulls() throws Exception { MockBuildCommandParser parser = new MockBuildCommandParser(); parser.startup(null, null); @@ -293,6 +317,9 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertNull(entries); } + /** + * Test basic parsing functionality. + */ public void testAbstractBuildCommandParser_Basic() throws Exception { // Create model project and accompanied descriptions String projectName = getName(); @@ -333,17 +360,8 @@ public class GCCBuildCommandParserTest extends BaseTestCase { assertEquals(expected, entries.get(0)); } -// public void testGCCBuildCommandParser_Nulls() throws Exception { -// GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT); -// parser.startup(null); -// parser.processLine(null); -// parser.shutdown(); -// -// List entries = parser.getSettingEntries(null, null, null); -// assertNull(entries); -// } - /** + * Test parsing of one typical entry. */ public void testOneEntry() throws Exception { // Create model project and accompanied descriptions @@ -379,6 +397,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test possible variations of compiler command. */ public void testGccFlavors() throws Exception { // Create model project and accompanied descriptions @@ -450,6 +469,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parse variations of -I options. */ public void testCIncludePathEntry() throws Exception { // Create model project and accompanied descriptions @@ -522,6 +542,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parse variations of -D options. */ public void testCMacroEntry() throws Exception { // Create model project and accompanied descriptions @@ -600,6 +621,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parse -U option. */ public void testCMacroEntry_undef() throws Exception { // Create model project and accompanied descriptions @@ -630,6 +652,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parse variations of -include options. */ public void testCIncludeFileEntry() throws Exception { // Create model project and accompanied descriptions @@ -681,6 +704,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parse variations of -macros options. */ public void testCMacroFileEntry() throws Exception { // Create model project and accompanied descriptions @@ -726,6 +750,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parse variations of -L options. */ public void testCLibraryPathEntry() throws Exception { // Create model project and accompanied descriptions @@ -770,6 +795,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parse variations of -l options. */ public void testCLibraryFileEntry() throws Exception { // Create model project and accompanied descriptions @@ -802,6 +828,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parse mixed options in the same command. */ public void testMixedSettingEntries() throws Exception { // Create model project and accompanied descriptions @@ -856,6 +883,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parse command where resource is missing. */ public void testFileMissing() throws Exception { // Create model project and accompanied descriptions @@ -877,6 +905,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parsing of absolute path to the file being compiled. */ public void testFileAbsolutePath() throws Exception { // Create model project and accompanied descriptions @@ -910,6 +939,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parsing of absolute path to the file being compiled where provider is global. */ public void testFileAbsolutePath_NoProject() throws Exception { // Create model project and accompanied descriptions @@ -943,6 +973,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Parsing where the name of the file being compiled contains spaces. */ public void testFileWithSpaces() throws Exception { // Create model project and accompanied descriptions @@ -998,6 +1029,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Resolve disagreement between working directory and path to the file being compiled. */ public void testFileIgnoreWrongBuildDir() throws Exception { // Create model project and accompanied descriptions @@ -1015,6 +1047,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); // Shift build directory, that could happen if Make Target from folder1 was run + // Build directory points to /project/Folder1/ IFolder buildDir = folder1; epm.pushDirectoryURI(buildDir.getLocationURI()); @@ -1023,6 +1056,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { parser.processLine("gcc " + "-I/path0 " + "-I. " + // This implies the build working directory is /project/ + "Folder1/Folder2/file.cpp"); parser.shutdown(); @@ -1037,6 +1071,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test various ends of lines for the lines being parsed. */ public void testEndOfLine() throws Exception { // Create model project and accompanied descriptions @@ -1084,6 +1119,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test parsing of paths located on a different drive on Windows. */ public void testPathEntry_DriveLetter() throws Exception { // do not test on non-windows systems where drive letters are not supported @@ -1117,6 +1153,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test various relative paths provided in options with resolving. */ public void testPathEntry_ExpandRelativePath() throws Exception { // Create model project and accompanied descriptions @@ -1157,6 +1194,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test various relative paths provided in options without resolving. */ public void testPathEntry_DoNotExpandRelativePath() throws Exception { // Create model project and accompanied descriptions @@ -1194,6 +1232,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Ensure that duplicate paths are ignored. */ public void testPathEntry_DuplicatePath() throws Exception { // Create model project and accompanied descriptions @@ -1228,6 +1267,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test that working directory supplied by ErrorParserManager is considered. */ public void testPathEntry_FollowCWD() throws Exception { // Create model project and accompanied descriptions @@ -1247,6 +1287,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { // create GCCBuildCommandParser GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); + // Set different working directory epm.pushDirectoryURI(buildDir.getLocationURI()); // parse line @@ -1272,6 +1313,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Determine working directory basing on file being compiled. */ public void testPathEntry_GuessCWD() throws Exception { // Create model project and accompanied descriptions @@ -1303,6 +1345,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test case when build command indicates impossible working directory. */ public void testPathEntry_NonExistentCWD_Workspace() throws Exception { // Create model project and accompanied descriptions @@ -1320,6 +1363,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); + // define working directory epm.pushDirectoryURI(buildDir.getLocationURI()); // parse line @@ -1328,6 +1372,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + " -I." + " -I.." + " -IFolder" + // indicates non-existing working directory + " ../file.cpp"); parser.shutdown(); @@ -1341,6 +1386,8 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test case when build command indicates impossible working directory and + * ErrorParserManager indicates non-existing working directory. */ public void testPathEntry_NonExistentCWD_Filesystem() throws Exception { // Create model project and accompanied descriptions @@ -1358,6 +1405,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { ErrorParserManager epm = new ErrorParserManager(project, null); URI uriBuildDir = new URI("file:/non-existing/path"); + // define non-existing working directory epm.pushDirectoryURI(uriBuildDir); // parse line @@ -1366,6 +1414,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { + " -I." + " -I.." + " -IFolder" + // indicates non-existing working directory + " ../file.cpp"); parser.shutdown(); @@ -1380,6 +1429,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Simulate mapping of a sub-folder in the project to remote URI. */ public void testPathEntry_MappedRemoteFolder() throws Exception { // Create model project and accompanied descriptions @@ -1399,6 +1449,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true); ErrorParserManager epm = new ErrorParserManager(project, null); + // define working directory as URI pointing outside workspace URI uriBuildDir = new URI("file:/BuildDir"); epm.pushDirectoryURI(uriBuildDir); @@ -1425,6 +1476,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test mapping folders heuristics - inside a project. */ public void testPathEntry_MappedFolderInProject() throws Exception { // Create model project and accompanied descriptions @@ -1475,6 +1527,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test mapping folders heuristics - mapping to another project. */ public void testPathEntry_MappedFolderInAnotherProject() throws Exception { // Create model project and accompanied descriptions @@ -1526,6 +1579,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test mapping folders heuristics - mapping to a referenced project. */ public void testPathEntry_MappedFolderInReferencedProject() throws Exception { // Create model project and accompanied descriptions @@ -1579,6 +1633,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test ".." in symbolic links where the symbolic link is present as absolute path. */ public void testPathEntry_NavigateSymbolicLinkUpAbsolute() throws Exception { // do not test on systems where symbolic links are not supported @@ -1619,6 +1674,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test ".." in symbolic links where the symbolic link is present as relative path. */ public void testPathEntry_NavigateSymbolicLinkUpRelative() throws Exception { // do not test on systems where symbolic links are not supported @@ -1659,6 +1715,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Determine working directory from configuration builder settings. */ public void testPathEntry_BuildDirDefinedByConfiguration_RelativePath() throws Exception { // Create model project and accompanied descriptions @@ -1702,6 +1759,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test where working directory from command line disagrees with configuration builder settings. */ public void testPathEntry_BuildDirDefinedByConfiguration_AbsolutePath() throws Exception { // Create model project and accompanied descriptions @@ -1746,6 +1804,9 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } + /** + * Smoke test when non-C files appear in output, should not choke. + */ public void testContentType_None() throws Exception { MockBuildCommandParser parser = new MockBuildCommandParser() { @Override @@ -1762,6 +1823,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test that unsupported language is ignored. */ public void testContentType_Mismatch() throws Exception { // Create model project and accompanied descriptions @@ -1785,6 +1847,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test custom file extensions defined in content type. */ public void testContentType_FileExtensions() throws Exception { // Create model project and accompanied descriptions @@ -1824,6 +1887,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test filenames appearing in upper-case. */ public void testUpperCase() throws Exception { // Create model project and accompanied descriptions @@ -1855,6 +1919,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test sample output of boost builder utility bjam. */ public void testBoostBjam() throws Exception { // Create model project and accompanied descriptions @@ -1897,6 +1962,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test resource file residing on EFS file-system. */ public void testPathEntry_Efs() throws Exception { // Create model project and accompanied descriptions @@ -1935,6 +2001,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { } /** + * Test mapping entries to EFS. */ public void testPathEntry_EfsMappedFolder() throws Exception { // Create model project and accompanied descriptions diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuiltinSpecsDetectorTest.java index d6d47f398f2..45fc75c5d72 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuiltinSpecsDetectorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Andrew Gvozdev and others. + * Copyright (c) 2010, 2012 Andrew Gvozdev and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.internal.core.Cygwin; import org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorCygwin; import org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector; import org.eclipse.core.resources.IProject; @@ -31,9 +32,15 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +/** + * Test cases to test GCC built-in specs detector. + */ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { private static final String LANGUAGE_ID_C = GCCLanguage.ID; + /** + * Mock GCCBuiltinSpecsDetector to gain access to protected methods. + */ class MockGCCBuiltinSpecsDetector extends GCCBuiltinSpecsDetector { @Override public void startupForLanguage(String languageId) throws CoreException { @@ -45,6 +52,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { } } + /** + * Mock GCCBuiltinSpecsDetectorCygwin to gain access to protected methods. + */ class MockGCCBuiltinSpecsDetectorCygwin extends GCCBuiltinSpecsDetectorCygwin { @Override public void startupForLanguage(String languageId) throws CoreException { @@ -66,6 +76,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { super.tearDown(); } + /** + * Helper method to fetch configuration descriptions. + */ private ICConfigurationDescription[] getConfigurationDescriptions(IProject project) { CoreModel coreModel = CoreModel.getDefault(); ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager(); @@ -78,6 +91,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { return cfgDescriptions; } + /** + * Test expansion of variables in build command. + */ public void testGCCBuiltinSpecsDetector_ResolvedCommand() throws Exception { class MockGCCBuiltinSpecsDetectorLocal extends GCCBuiltinSpecsDetector { @Override @@ -105,6 +121,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { } } + /** + * Test parsing of macro without value. + */ public void testGCCBuiltinSpecsDetector_Macro_NoValue() throws Exception { MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); @@ -119,6 +138,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, entries.size()); } + /** + * Test parsing of macro with ordinary value. + */ public void testGCCBuiltinSpecsDetector_Macro_Simple() throws Exception { MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); @@ -133,6 +155,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, entries.size()); } + /** + * Test parsing of macro with value in round brackets. + */ public void testGCCBuiltinSpecsDetector_Macro_Const() throws Exception { MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); @@ -147,6 +172,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, entries.size()); } + /** + * Test parsing of macro definition with tabs. + */ public void testGCCBuiltinSpecsDetector_Macro_WhiteSpaces() throws Exception { MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); @@ -166,6 +194,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(index, entries.size()); } + /** + * Test parsing of macro definition with empty argument list. + */ public void testGCCBuiltinSpecsDetector_Macro_EmptyArgList() throws Exception { MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); @@ -180,6 +211,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, entries.size()); } + /** + * Test parsing of macro definition with unused parameter. + */ public void testGCCBuiltinSpecsDetector_Macro_ParamUnused() throws Exception { MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); @@ -194,6 +228,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, entries.size()); } + /** + * Test parsing of macro definition with multiple parameters. + */ public void testGCCBuiltinSpecsDetector_Macro_ParamSpace() throws Exception { MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); @@ -208,6 +245,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, entries.size()); } + /** + * Test parsing of macro definition with multiple parameters and no value. + */ public void testGCCBuiltinSpecsDetector_Macro_ArgsNoValue() throws Exception { MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); @@ -222,6 +262,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, entries.size()); } + /** + * Test parsing of macro definition having white spaces in various places. + */ public void testGCCBuiltinSpecsDetector_Macro_Args_WhiteSpaces() throws Exception { MockGCCBuiltinSpecsDetector detector = new MockGCCBuiltinSpecsDetector(); @@ -241,6 +284,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(index, entries.size()); } + /** + * Test parsing of include directives. + */ public void testGCCBuiltinSpecsDetector_Includes() throws Exception { // Create model project and folders to test String projectName = getName(); @@ -288,6 +334,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(index, entries.size()); } + /** + * Test parsing of macro definition of include directives having white spaces. + */ public void testGCCBuiltinSpecsDetector_Includes_WhiteSpaces() throws Exception { String loc = ResourceHelper.createTemporaryFolder().toString(); @@ -316,6 +365,9 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(index, entries.size()); } + /** + * Test parsing of include directives incorporating symbolic links. + */ public void testGCCBuiltinSpecsDetector_Includes_SymbolicLinkUp() throws Exception { // do not test on systems where symbolic links are not supported if (!ResourceHelper.isSymbolicLinkSupported()) @@ -347,15 +399,17 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, entries.size()); } + /** + * Test parsing of include directives for Cygwin for global provider. + */ public void testGCCBuiltinSpecsDetector_Cygwin_NoProject() throws Exception { - String windowsLocation; - String cygwinLocation = "/usr/include"; - try { - windowsLocation = ResourceHelper.cygwinToWindowsPath(cygwinLocation); - } catch (UnsupportedOperationException e) { + if (!Cygwin.isAvailable()) { // Skip the test if Cygwin is not available. return; } + + String cygwinLocation = "/usr/include"; + String windowsLocation = ResourceHelper.cygwinToWindowsPath(cygwinLocation); assertTrue("windowsLocation=["+windowsLocation+"]", new Path(windowsLocation).getDevice()!=null); MockGCCBuiltinSpecsDetectorCygwin detector = new MockGCCBuiltinSpecsDetectorCygwin(); @@ -374,15 +428,17 @@ public class GCCBuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, entries.size()); } + /** + * Test parsing of include directives for Cygwin for provider running for a configuration. + */ public void testGCCBuiltinSpecsDetector_Cygwin_Configuration() throws Exception { - String windowsLocation; - String cygwinLocation = "/usr/include"; - try { - windowsLocation = ResourceHelper.cygwinToWindowsPath(cygwinLocation); - } catch (UnsupportedOperationException e) { + if (!Cygwin.isAvailable()) { // Skip the test if Cygwin is not available. return; } + + String cygwinLocation = "/usr/include"; + String windowsLocation = ResourceHelper.cygwinToWindowsPath(cygwinLocation); assertTrue("windowsLocation=["+windowsLocation+"]", new Path(windowsLocation).getDevice()!=null); // Create model project and folders to test diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/LanguageSettingsProvidersMBSTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/LanguageSettingsProvidersMBSTest.java index 9847248dda9..2f63c1c041c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/LanguageSettingsProvidersMBSTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/LanguageSettingsProvidersMBSTest.java @@ -30,6 +30,9 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; +/** + * Test creation of a new project in respect with language settings providers. + */ public class LanguageSettingsProvidersMBSTest extends BaseTestCase { private static final String MBS_LANGUAGE_SETTINGS_PROVIDER_ID = ScannerDiscoveryLegacySupport.MBS_LANGUAGE_SETTINGS_PROVIDER_ID; private static final String USER_LANGUAGE_SETTINGS_PROVIDER_ID = ScannerDiscoveryLegacySupport.USER_LANGUAGE_SETTINGS_PROVIDER_ID; @@ -50,7 +53,7 @@ public class LanguageSettingsProvidersMBSTest extends BaseTestCase { } /** - * New Project Wizards do all these things + * Imitate a new Project Wizard. New Project Wizards really do these things in CDT. */ private static IProject imitateNewProjectWizard(String name, String projectTypeId) throws CoreException { IProject project = ManagedBuildTestHelper.createProject(name, projectTypeId); @@ -76,10 +79,13 @@ public class LanguageSettingsProvidersMBSTest extends BaseTestCase { } /** + * Test new GNU Executable project. */ public void testGnuToolchainProviders() throws Exception { + // create a new project imitating wizard IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); + // check that the language settings providers are in place. ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); assertNotNull(prjDescription); ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); @@ -114,37 +120,14 @@ public class LanguageSettingsProvidersMBSTest extends BaseTestCase { } /** - */ - public void testProjectPersistence_NoProviders() throws Exception { - IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); - - ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, true); - assertNotNull(prjDescription); - ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); - for (ICConfigurationDescription cfgDescription : cfgDescriptions) { - assertNotNull(cfgDescription); - assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); - - ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(new ArrayList()); - assertTrue(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders().size() == 0); - } - - CoreModel.getDefault().setProjectDescription(project, prjDescription); - - IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); - assertEquals(true, xmlStorageFile.exists()); - - String xmlPrjWspStorageFileLocation = LanguageSettingsPersistenceProjectTests.getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML); - java.io.File xmlStorageFilePrjWsp = new java.io.File(xmlPrjWspStorageFileLocation); - assertEquals(false, xmlStorageFilePrjWsp.exists()); - - } - - /** + * Test that no unnecessary storage file is created for language settings for default set + * of language settings providers. */ public void testProjectPersistence_Defaults() throws Exception { + // create a new project imitating wizard IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); + // double-check that the project contains language settings providers ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, false); assertNotNull(prjDescription); ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); @@ -161,13 +144,47 @@ public class LanguageSettingsProvidersMBSTest extends BaseTestCase { assertTrue(defaultIds.length > 0); } + // no settings file in project area IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); assertEquals(false, xmlStorageFile.exists()); assertEquals(false, xmlStorageFile.getParent().exists()); // .settings folder + // no settings file in workspace area String xmlPrjWspStorageFileLocation = LanguageSettingsPersistenceProjectTests.getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML); java.io.File xmlStorageFilePrjWsp = new java.io.File(xmlPrjWspStorageFileLocation); assertEquals(false, xmlStorageFilePrjWsp.exists()); } + /** + * Test that storage file is created for language settings for empty set of language settings providers. + */ + public void testProjectPersistence_NoProviders() throws Exception { + // create a new project imitating wizard + IProject project = imitateNewProjectWizard(this.getName(), PROJECT_TYPE_EXECUTABLE_GNU); + + // remove language settings providers from the project + ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project, true); + assertNotNull(prjDescription); + ICConfigurationDescription[] cfgDescriptions = prjDescription.getConfigurations(); + for (ICConfigurationDescription cfgDescription : cfgDescriptions) { + assertNotNull(cfgDescription); + assertTrue(cfgDescription instanceof ILanguageSettingsProvidersKeeper); + + ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(new ArrayList()); + assertTrue(((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders().size() == 0); + } + + CoreModel.getDefault().setProjectDescription(project, prjDescription); + + // settings file appears in project area + IFile xmlStorageFile = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML); + assertEquals(true, xmlStorageFile.exists()); + + // no settings file in workspace area + String xmlPrjWspStorageFileLocation = LanguageSettingsPersistenceProjectTests.getStoreLocationInWorkspaceArea(project.getName()+'.'+LANGUAGE_SETTINGS_WORKSPACE_XML); + java.io.File xmlStorageFilePrjWsp = new java.io.File(xmlPrjWspStorageFileLocation); + assertEquals(false, xmlStorageFilePrjWsp.exists()); + + } + } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java index 755a208fafb..44b60c34dd9 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ExternalBuildRunner.java @@ -289,5 +289,4 @@ public class ExternalBuildRunner extends AbstractBuildRunner { CfgInfoContext context, IPath workingDirectory, IMarkerGenerator markerGenerator) { return ScannerInfoConsoleParserFactory.getScannerInfoConsoleParser(project, context.toInfoContext(), workingDirectory, map.get(context), markerGenerator, null); } - } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuilderCorePlugin.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuilderCorePlugin.java index 353811565db..03b68fa445d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuilderCorePlugin.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuilderCorePlugin.java @@ -15,7 +15,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.Map; import org.eclipse.cdt.build.internal.core.scannerconfig.CfgDiscoveredPathManager; -import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.managedbuilder.internal.buildmodel.BuildStateManager; import org.eclipse.cdt.managedbuilder.internal.buildmodel.DbgUtil; import org.eclipse.cdt.managedbuilder.internal.core.BuilderFactory; @@ -27,7 +26,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; @@ -285,10 +283,4 @@ public class ManagedBuilderCorePlugin extends Plugin { ProjectConverter.convertOldStdMakeToNewStyle(project, monitor); } - /** - * @since 8.1 - */ - public static IPath getWorkingDirectory() { - return MakeCorePlugin.getDefault().getStateLocation(); - } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java index 129f2002d74..5dda8ac90d4 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java @@ -152,7 +152,6 @@ public class CommonBuilder extends ACBuilder { private final IConfiguration fCfg; private final IBuilder fBuilder; private IConsole fConsole; - CfgBuildInfo(IBuilder builder, boolean isForegound){ this.fBuilder = builder; this.fCfg = builder.getParent().getParent(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties index 83ee8b40fa1..2c339a4f22e 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties @@ -169,3 +169,15 @@ MultiResourceInfo.MultiResourceInfo.UnhandledIHoldsOptionsType=Unhandled parent ResourceChangeHandler2.0=project build settings update job ToolInfo.0=conversion failure ToolInfo.1=the tool is removed + +#Language settings providers messages +AbstractBuildCommandParser.SerializeJobName=Serialize CDT language settings entries +AbstractBuiltinSpecsDetector.AddScannerDiscoveryMarkers=Adding Scanner Discovery markers +AbstractBuiltinSpecsDetector.ClearingMarkers=Clearing markers for {0} +AbstractBuiltinSpecsDetector.DiscoverBuiltInSettingsJobName=Discover compiler built-in language settings +AbstractBuiltinSpecsDetector.RunningScannerDiscovery=Running scanner discovery: {0} +AbstractBuiltinSpecsDetector.ScannerDiscoveryMarkerLocationPreferences=Preferences, C++/Build/Settings/Discovery, [{0}] options +AbstractBuiltinSpecsDetector.ScannerDiscoveryMarkerLocationProperties=Project Properties, C++ Preprocessor Include.../Providers, [{0}] options +AbstractBuiltinSpecsDetector.ScannerDiscoveryTaskTitle=CDT Scanner Discovery +AbstractBuiltinSpecsDetector.SerializingResults=Serializing results + diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/MBSLanguageSettingsProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/MBSLanguageSettingsProvider.java index 618dbf80ada..1026f2e5f56 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/MBSLanguageSettingsProvider.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/MBSLanguageSettingsProvider.java @@ -41,7 +41,7 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase if (rc instanceof IFile) { ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(projectPath, true); if (ls != null) { - languageSettings = new ICLanguageSetting[] {ls}; + languageSettings = new ICLanguageSetting[] { ls }; } else { return getSettingEntries(cfgDescription, rc.getParent(), languageId); } @@ -54,26 +54,25 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase if (languageSettings != null) { for (ICLanguageSetting langSetting : languageSettings) { - if (langSetting!=null) { + if (langSetting != null) { String id = langSetting.getLanguageId(); - if (id!=null && id.equals(languageId)) { + if (id != null && id.equals(languageId)) { int kindsBits = langSetting.getSupportedEntryKinds(); - for (int kind=1;kind<=kindsBits;kind<<=1) { + for (int kind=1; kind <= kindsBits; kind <<= 1) { if ((kindsBits & kind) != 0) { list.addAll(langSetting.getSettingEntriesList(kind)); } } - } else { - // System.err.println("languageSetting id=null: name=" + languageSetting.getName()); } - } else { - System.err.println("languageSetting=null: rc=" + rc); } } } return LanguageSettingsStorage.getPooledList(list); } + /** + * Get language settings for resource description. + */ private ICLanguageSetting[] getLanguageSettings(ICResourceDescription rcDescription) { ICLanguageSetting[] array = null; switch (rcDescription.getType()) { @@ -86,48 +85,16 @@ public class MBSLanguageSettingsProvider extends AbstractExecutableExtensionBase case ICSettingBase.SETTING_FILE: ICFileDescription fiDes = (ICFileDescription)rcDescription; ICLanguageSetting ls = fiDes.getLanguageSetting(); - if (ls!=null) { + if (ls != null) { array = new ICLanguageSetting[] { ls }; } } - if (array==null) { + if (array == null) { array = new ICLanguageSetting[0]; } return array; } - public void setSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId, - List entries) { - -// lang.setSettingEntries(kind, entries); - IPath projectPath = rc.getProjectRelativePath(); - ICResourceDescription rcDescription = cfgDescription.getResourceDescription(projectPath, false); - - for (ICLanguageSetting languageSetting : getLanguageSettings(rcDescription)) { - if (languageSetting!=null) { - String id = languageSetting.getLanguageId(); - if (id!=null && id.equals(languageId)) { - int kindsBits = languageSetting.getSupportedEntryKinds(); - for (int kind=1;kind<=kindsBits;kind<<=1) { - if ((kindsBits & kind) != 0) { - List list = new ArrayList(entries.size()); - for (ICLanguageSettingEntry entry : entries) { - if (entry.getKind()==kind) { - list.add(entry); - } - } - languageSetting.setSettingEntries(kind, list); - } - } - } else { -// System.err.println("languageSetting id=null: name=" + languageSetting.getName()); - } - } else { - System.err.println("languageSetting=null: rcDescription=" + rcDescription.getName()); - } - } - } - @Override public LanguageSettingsStorage copyStorage() { class PretendStorage extends LanguageSettingsStorage { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuildCommandParser.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuildCommandParser.java index e030f4b582b..0d9499e54c5 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuildCommandParser.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuildCommandParser.java @@ -12,14 +12,10 @@ package org.eclipse.cdt.managedbuilder.language.settings.providers; import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IErrorParser2; import org.eclipse.cdt.core.IMarkerGenerator; import org.eclipse.cdt.core.errorparsers.RegexErrorParser; @@ -27,20 +23,17 @@ import org.eclipse.cdt.core.errorparsers.RegexErrorPattern; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; +import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; /** - * Abstract class for providers parsing compiler option from build command when it - * is present in build output. + * Abstract class for providers parsing compiler option from build command when present in build output. * * @since 8.1 */ @@ -56,7 +49,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting * Note: design patterns to keep file group the same and matching {@link #FILE_GROUP} */ @SuppressWarnings("nls") - private static final String[] PATTERN_TEMPLATES = { + private static final String[] COMPILER_COMMAND_PATTERN_TEMPLATES = { "${COMPILER_PATTERN}.*\\s" + "()([^'\"\\s]*\\.${EXTENSIONS_PATTERN})(\\s.*)?[\r\n]*", // compiling unquoted file "${COMPILER_PATTERN}.*\\s" + "(['\"])(.*\\.${EXTENSIONS_PATTERN})\\${COMPILER_GROUPS+1}(\\s.*)?[\r\n]*" // compiling quoted file }; @@ -84,16 +77,25 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting setProperty(ATTR_PARAMETER, commandPattern); } + /** + * Sub-expression for compiler command pattern accounting for spaces, quotes etc. + */ @SuppressWarnings("nls") private String getCompilerPatternExtended() { String compilerPattern = getCompilerPattern(); return "\\s*\"?("+LEADING_PATH_PATTERN+")?(" + compilerPattern + ")\"?"; } + /** + * Adjust count for file group taking into consideration extra groups added by {@link #getCompilerPatternExtended()}. + */ private int adjustFileGroup() { return countGroups(getCompilerPatternExtended()) + FILE_GROUP; } + /** + * Make search pattern for compiler command based on template. + */ private String makePattern(String template) { @SuppressWarnings("nls") String pattern = template @@ -103,46 +105,13 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting return pattern; } - @SuppressWarnings("nls") - private static String expressionLogicalOr(Set fileExts) { - String pattern = "("; - for (String ext : fileExts) { - if (pattern.length() != 1) - pattern += "|"; - pattern += "(" + Pattern.quote(ext) + ")"; - ext = ext.toUpperCase(); - if (!fileExts.contains(ext)) { - pattern += "|(" + Pattern.quote(ext) + ")"; - } - } - pattern += ")"; - return pattern; - } - - protected String getPatternFileExtensions() { - IContentTypeManager manager = Platform.getContentTypeManager(); - - Set fileExts = new HashSet(); - - IContentType contentTypeCpp = manager.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE); - fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); - - IContentType contentTypeC = manager.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE); - fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); - - String pattern = expressionLogicalOr(fileExts); - - return pattern; - } - - @Override protected String parseResourceName(String line) { if (line == null) { return null; } - for (String template : PATTERN_TEMPLATES) { + for (String template : COMPILER_COMMAND_PATTERN_TEMPLATES) { String pattern = makePattern(template); Matcher fileMatcher = Pattern.compile(pattern).matcher(line); if (fileMatcher.matches()) { @@ -171,12 +140,6 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting return options; } - // This is redundant but let us keep it here to navigate in java code easier - @Override - public boolean processLine(String line) { - return super.processLine(line); - } - @Override public void shutdown() { scheduleSerializingJob(currentCfgDescription); @@ -185,7 +148,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting private void scheduleSerializingJob(final ICConfigurationDescription cfgDescription) { - Job job = new Job("Serialize CDT language settings entries") { + Job job = new Job(ManagedMakeMessages.getResourceString("AbstractBuildCommandParser.SerializeJobName")) { //$NON-NLS-1$ @Override protected IStatus run(IProgressMonitor monitor) { return serializeLanguageSettings(cfgDescription); @@ -219,18 +182,25 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting /** * Trivial Error Parser which allows highlighting of output lines matching the patterns * of this parser. Intended for better troubleshooting experience. - * Implementers are supposed to add the error parser as an extension. Initialize with - * build command parser extension ID. + * Implementers are supposed to add the error parser via extension point {@code org.eclipse.cdt.core.ErrorParser}. */ protected static abstract class AbstractBuildCommandPatternHighlighter extends RegexErrorParser implements IErrorParser2 { - public AbstractBuildCommandPatternHighlighter(String buildCommandParserPluginExtension) { - init(buildCommandParserPluginExtension); + /** + * Constructor. + * @param parserId - build command parser ID specified in the extension {@code org.eclipse.cdt.core.LanguageSettingsProvider}. + */ + public AbstractBuildCommandPatternHighlighter(String parserId) { + init(parserId); } - protected void init(String buildCommandParserId) { - AbstractBuildCommandParser buildCommandParser = (AbstractBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(buildCommandParserId, false); + /** + * Initialize the error parser. + * @param parserId - language settings provider (the build command parser) ID. + */ + protected void init(String parserId) { + AbstractBuildCommandParser buildCommandParser = (AbstractBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(parserId, false); if (buildCommandParser != null) { - for (String template : PATTERN_TEMPLATES) { + for (String template : COMPILER_COMMAND_PATTERN_TEMPLATES) { String pattern = buildCommandParser.makePattern(template); String fileExpr = "$"+buildCommandParser.adjustFileGroup(); //$NON-NLS-1$ String descExpr = "$0"; //$NON-NLS-1$ diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java index 1a33a97b6de..66cbbde2e7b 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java @@ -38,6 +38,7 @@ import org.eclipse.cdt.internal.core.BuildRunnerHelper; import org.eclipse.cdt.internal.core.XmlUtil; import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsLogger; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; +import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages; import org.eclipse.cdt.utils.CommandLineUtil; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; @@ -67,7 +68,6 @@ import org.w3c.dom.Element; * @since 8.1 */ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ICListenerAgent { - // TODO - refine id after settling with the plugin public static final String JOB_FAMILY_BUILTIN_SPECS_DETECTOR = "org.eclipse.cdt.managedbuilder.AbstractBuiltinSpecsDetector"; //$NON-NLS-1$ protected static final String COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$ @@ -75,6 +75,15 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti protected static final String SPEC_EXT_MACRO = "${EXT}"; //$NON-NLS-1$ protected static final String SPEC_FILE_BASE = "spec"; //$NON-NLS-1$ + private static final String CDT_MANAGEDBUILDER_UI_PLUGIN_ID = "org.eclipse.cdt.managedbuilder.ui"; //$NON-NLS-1$ + private static final String SCANNER_DISCOVERY_CONSOLE = "org.eclipse.cdt.managedbuilder.ScannerDiscoveryConsole"; //$NON-NLS-1$ + private static final String SCANNER_DISCOVERY_GLOBAL_CONSOLE = "org.eclipse.cdt.managedbuilder.ScannerDiscoveryGlobalConsole"; //$NON-NLS-1$ + private static final String DEFAULT_CONSOLE_ICON = "icons/obj16/inspect_system.gif"; //$NON-NLS-1$ + private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$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 int MONITOR_SCALE = 100; private static final int TICKS_REMOVE_MARKERS = 1 * MONITOR_SCALE; private static final int TICKS_RUN_FOR_ONE_LANGUAGE = 10 * MONITOR_SCALE; @@ -82,13 +91,6 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti private static final int TICKS_OUTPUT_PARSING = 1 * MONITOR_SCALE; private static final int TICKS_EXECUTE_COMMAND = 1 * MONITOR_SCALE; - private static final String CDT_MANAGEDBUILDER_UI_PLUGIN_ID = "org.eclipse.cdt.managedbuilder.ui"; //$NON-NLS-1$ - private static final String DEFAULT_CONSOLE_ICON = "icons/obj16/inspect_system.gif"; //$NON-NLS-1$ - - private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$ - private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$ - private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$ - protected URI mappedRootURI = null; protected URI buildDirURI = null; protected java.io.File specFile = null; @@ -103,9 +105,8 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti private String currentCommandResolved = null; private class SDMarkerGenerator implements IMarkerGenerator { - // TODO - define own markers types after settling with the plugin - // Scanner discovery markers are defined in org.eclipse.cdt.managedbuilder.core plugin.xml - protected static final String SCANNER_DISCOVERY_PROBLEM_MARKER = "org.eclipse.cdt.managedbuilder.core.scanner.discovery.problem"; + // Reuse scanner discovery markers defined in org.eclipse.cdt.managedbuilder.core plugin.xml + protected static final String SCANNER_DISCOVERY_PROBLEM_MARKER = "org.eclipse.cdt.managedbuilder.core.scanner.discovery.problem"; //$NON-NLS-1$ protected static final String ATTR_PROVIDER = "provider"; //$NON-NLS-1$ @Override @@ -118,10 +119,8 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti public void addMarker(final ProblemMarkerInfo problemMarkerInfo) { final String providerName = getName(); final String providerId = getId(); - // we have to add the marker in the job or we can deadlock other - // threads that are responding to a resource delta by doing something - // that accesses the project description - Job markerJob = new Job("Adding Scanner Discovery markers") { + // Add markers in a job to avoid deadlocks + Job markerJob = new Job(ManagedMakeMessages.getResourceString("AbstractBuiltinSpecsDetector.AddScannerDiscoveryMarkers")) { //$NON-NLS-1$ @Override protected IStatus run(IProgressMonitor monitor) { // Avoid duplicates as different languages can generate identical errors @@ -147,9 +146,11 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti marker.setAttribute(SDMarkerGenerator.ATTR_PROVIDER, providerId); if (problemMarkerInfo.file instanceof IWorkspaceRoot) { - marker.setAttribute(IMarker.LOCATION, "Preferences, C++/Build/Settings/Discovery, [" + providerName + "] options"); + String msgPreferences = ManagedMakeMessages.getFormattedString("AbstractBuiltinSpecsDetector.ScannerDiscoveryMarkerLocationPreferences", providerName); //$NON-NLS-1$ + marker.setAttribute(IMarker.LOCATION, msgPreferences); } else { - marker.setAttribute(IMarker.LOCATION, "Project Properties, C++ Preprocessor Include.../Providers, [" + providerName + "] options"); + String msgProperties = ManagedMakeMessages.getFormattedString("AbstractBuiltinSpecsDetector.ScannerDiscoveryMarkerLocationProperties", providerName); //$NON-NLS-1$ + marker.setAttribute(IMarker.LOCATION, msgProperties); } } catch (CoreException e) { return new Status(Status.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, "Error adding markers.", e); //$NON-NLS-1$ @@ -163,6 +164,11 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti markerJob.schedule(); } + /** + * Delete markers previously set by this provider for the resource. + * + * @param rc - resource to check markers. + */ public void deleteMarkers(IResource rc) { String providerId = getId(); try { @@ -180,7 +186,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } /** - * This ICConsoleParser handles each individual run for one language TODO + * Internal ICConsoleParser to handle individual run for one language. */ private class ConsoleParserAdapter implements ICBuildOutputParser { @Override @@ -198,16 +204,20 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } /** - * TODO - * @param languageId - * @return + * Compiler command without arguments. This value is used to replace macro ${COMMAND}. + * In particular, this method is implemented in {@link ToolchainBuiltinSpecsDetector} + * which retrieves the command from tool-chain. + * + * @param languageId - language ID. + * @return compiler command without arguments, i.e. compiler program. */ protected abstract String getCompilerCommand(String languageId); /** * The command to run. Some macros could be specified in there: *
    - * ${COMMAND} - compiler command taken from the toolchain.
    + * ${COMMAND} - compiler command without arguments (compiler program). + * Normally would come from the tool-chain.
    * ${INPUTS} - path to spec file which will be placed in workspace area.
    * ${EXT} - file extension calculated from language ID. *
@@ -228,14 +238,30 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti setProperty(ATTR_PARAMETER, command); } - public void setConsoleEnabled(boolean enable) { - isConsoleEnabled = enable; - } - + /** + * @return {@code true} if console output is enabled for this provider, {@code false} otherwise. + */ public boolean isConsoleEnabled() { return isConsoleEnabled; } + /** + * Enable or disable console output for this provider. + * + * @param enable - {@code true} to enable console output or {@code false} to disable. + */ + public void setConsoleEnabled(boolean enable) { + isConsoleEnabled = enable; + } + + /** + * Expand macros specified in the compiler command. See {@link #getCommand()} for + * the recognized list of macros. + * + * @param languageId - language ID. + * @return - resolved command to run. + * @throws CoreException if something goes wrong. + */ protected String resolveCommand(String languageId) throws CoreException { String cmd = getCommand(); if (cmd != null) { @@ -258,12 +284,10 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return cmd; } - /** - * TODO - */ @Override protected String parseResourceName(String line) { - // Returning null works as if workspace-wide + // Normally built-in specs detectors are per-language and the result applies for the whole workspace. + // Returning null works workspace-wide here. return null; } @@ -275,6 +299,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti @Override protected URI getMappedRootURI(IResource sourceFile, String parsedResourceName) { + // Do not calculate mappedRootURI for each line if (mappedRootURI == null) { mappedRootURI = super.getMappedRootURI(sourceFile, parsedResourceName); } @@ -283,7 +308,8 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti @Override protected URI getBuildDirURI(URI mappedRootURI) { - if (buildDirURI==null) { + // Do not calculate buildDirURI for each line + if (buildDirURI == null) { buildDirURI = super.getBuildDirURI(mappedRootURI); } return buildDirURI; @@ -320,6 +346,10 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti super.shutdown(); } + /** + * Execute provider's command which is expected to print built-in compiler options (specs) to build output. + * The parser will parse output and generate language settings for corresponding resources. + */ protected void execute() { if (isExecuted) { // AG FIXME - temporary log to remove before CDT Juno release @@ -328,7 +358,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } isExecuted = true; - Job job = new Job("Discover compiler's built-in language settings") { + Job job = new Job(ManagedMakeMessages.getResourceString("AbstractBuiltinSpecsDetector.DiscoverBuiltInSettingsJobNam")) { //$NON-NLS-1$ @Override protected IStatus run(IProgressMonitor monitor) { IStatus status; @@ -337,7 +367,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti status = runForEachLanguage(monitor); } catch (CoreException e) { ManagedBuilderCorePlugin.log(e); - status = new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e); + status = new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e); //$NON-NLS-1$ } finally { shutdown(); } @@ -372,10 +402,14 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } /** - * TODO + * Run built-in specs command for each language. + * + * @param monitor - progress monitor in the initial state where {@link IProgressMonitor#beginTask(String, int)} + * has not been called yet. + * @return status of operation. */ protected IStatus runForEachLanguage(IProgressMonitor monitor) { - MultiStatus status = new MultiStatus(ManagedBuilderCorePlugin.PLUGIN_ID, IStatus.OK, "Problem running CDT Scanner Discovery provider " + getId(), null); + MultiStatus status = new MultiStatus(ManagedBuilderCorePlugin.PLUGIN_ID, IStatus.OK, "Problem running CDT Scanner Discovery provider " + getId(), null); //$NON-NLS-1$ if (monitor == null) { monitor = new NullProgressMonitor(); @@ -386,11 +420,12 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti List languageIds = getLanguageScope(); if (languageIds != null) { - monitor.beginTask("CDT Scanner Discovery", TICKS_REMOVE_MARKERS + languageIds.size()*TICKS_RUN_FOR_ONE_LANGUAGE + TICKS_SERIALIZATION); + monitor.beginTask(ManagedMakeMessages.getResourceString("AbstractBuiltinSpecsDetector.ScannerDiscoveryTaskTitle"), //$NON-NLS-1$ + TICKS_REMOVE_MARKERS + languageIds.size()*TICKS_RUN_FOR_ONE_LANGUAGE + TICKS_SERIALIZATION); IResource markersResource = currentProject != null ? currentProject : ResourcesPlugin.getWorkspace().getRoot(); - monitor.subTask("Clearing markers for " + markersResource.getFullPath()); + monitor.subTask(ManagedMakeMessages.getFormattedString("AbstractBuiltinSpecsDetector.ClearingMarkers", markersResource.getFullPath().toString())); //$NON-NLS-1$ markerGenerator.deleteMarkers(markersResource); if (monitor.isCanceled()) throw new OperationCanceledException(); @@ -419,7 +454,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } } - monitor.subTask("Serializing results"); + monitor.subTask(ManagedMakeMessages.getResourceString("AbstractBuiltinSpecsDetector.SerializingResults")); //$NON-NLS-1$ if (isChanged) { // avoids resource and settings change notifications IStatus s = serializeLanguageSettings(currentCfgDescription); status.merge(s); @@ -429,7 +464,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } catch (OperationCanceledException e) { // user chose to cancel operation, do not threaten them with red error signs } catch (Exception e) { - status.merge(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e)); + status.merge(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e)); //$NON-NLS-1$ ManagedBuilderCorePlugin.log(status); } finally { monitor.done(); @@ -438,16 +473,25 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return status; } + /** + * Initialize provider before running for a language. + * + * @param languageId - language ID. + * @throws CoreException if something goes wrong. + */ protected void startupForLanguage(String languageId) throws CoreException { currentLanguageId = languageId; - specFile = null; // init *before* calling resolveCommand(), can be set there + specFile = null; // init specFile *before* calling resolveCommand(), can be changed in there currentCommandResolved = resolveCommand(currentLanguageId); detectedSettingEntries = new ArrayList(); collected = 0; } + /** + * Save collected entries and dispose temporary data used during run for the language. + */ protected void shutdownForLanguage() { if (detectedSettingEntries != null && detectedSettingEntries.size() > 0) { collected = detectedSettingEntries.size(); @@ -469,6 +513,12 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti currentLanguageId = null; } + /** + * Run built-in specs command for one language. + * + * @param monitor - progress monitor in the initial state where {@link IProgressMonitor#beginTask(String, int)} + * has not been called yet. + */ private void runForLanguage(IProgressMonitor monitor) throws CoreException { buildRunnerHelper = new BuildRunnerHelper(currentProject); @@ -476,7 +526,8 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti monitor = new NullProgressMonitor(); } try { - monitor.beginTask("Running scanner discovery: " + getName(), TICKS_EXECUTE_COMMAND + TICKS_OUTPUT_PARSING); + monitor.beginTask(ManagedMakeMessages.getFormattedString("AbstractBuiltinSpecsDetector.RunningScannerDiscovery", getName()), //$NON-NLS-1$ + TICKS_EXECUTE_COMMAND + TICKS_OUTPUT_PARSING); IConsole console; if (isConsoleEnabled) { @@ -513,7 +564,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti buildRunnerHelper.setLaunchParameters(launcher, program, args, buildDirURI, envp); buildRunnerHelper.prepareStreams(epm, parsers, console, new SubProgressMonitor(monitor, TICKS_OUTPUT_PARSING)); - buildRunnerHelper.greeting("Running scanner discovery: " + getName()); + buildRunnerHelper.greeting(ManagedMakeMessages.getFormattedString("AbstractBuiltinSpecsDetector.RunningScannerDiscovery", getName())); //$NON-NLS-1$ OutputStream outStream = buildRunnerHelper.getOutputStream(); OutputStream errStream = buildRunnerHelper.getErrorStream(); @@ -524,8 +575,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti buildRunnerHelper.goodbye(); } catch (Exception e) { - Status status = new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, "Internal error running scanner discovery", e); - ManagedBuilderCorePlugin.log(new CoreException(status)); + ManagedBuilderCorePlugin.log(new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, "Error running Builtin Specs Detector" , e))); //$NON-NLS-1$ } finally { try { buildRunnerHelper.close(); @@ -540,31 +590,33 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti return buildRunnerHelper.build(monitor); } - /** - * TODO - */ @Override protected void setSettingEntries(List entries) { - // Builtin specs detectors collect entries not per line but for the whole output - if (entries != null) + // Built-in specs detectors collect entries not per line but for the whole output + // so collect them to save later when output finishes + if (entries != null) { detectedSettingEntries.addAll(entries); + } } + /** + * Create and start the provider console. + * @return CDT console. + */ private IConsole startProviderConsole() { IConsole console = null; if (isConsoleEnabled && currentLanguageId != null) { String extConsoleId; if (currentProject != null) { - extConsoleId = "org.eclipse.cdt.managedbuilder.ScannerDiscoveryConsole"; + extConsoleId = SCANNER_DISCOVERY_CONSOLE; } else { - // TODO This console is not colored! - extConsoleId = "org.eclipse.cdt.managedbuilder.ScannerDiscoveryGlobalConsole"; + extConsoleId = SCANNER_DISCOVERY_GLOBAL_CONSOLE; } ILanguage ld = LanguageManager.getInstance().getLanguage(currentLanguageId); if (ld != null) { String consoleId = ManagedBuilderCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId; - String consoleName = getName() + ", " + ld.getName(); + String consoleName = getName() + ", " + ld.getName(); //$NON-NLS-1$ URL defaultIcon = Platform.getBundle(CDT_MANAGEDBUILDER_UI_PLUGIN_ID).getEntry(DEFAULT_CONSOLE_ICON); if (defaultIcon == null) { @SuppressWarnings("nls") @@ -581,11 +633,16 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti console = CCorePlugin.getDefault().getConsole(ManagedBuilderCorePlugin.PLUGIN_ID + ".console.hidden"); //$NON-NLS-1$ } - - return console; } + /** + * Get path to spec file which normally would be placed in workspace area. + * This value is used to replace macro ${INPUTS}. + * + * @param languageId - language ID. + * @return full path to the specs file. + */ protected String getSpecFile(String languageId) { String specExt = getSpecFileExtension(languageId); String ext = ""; //$NON-NLS-1$ @@ -594,7 +651,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } String specFileName = SPEC_FILE_BASE + ext; - IPath workingLocation = ManagedBuilderCorePlugin.getWorkingDirectory(); + IPath workingLocation = ManagedBuilderCorePlugin.getDefault().getStateLocation(); IPath fileLocation = workingLocation.append(specFileName); specFile = new java.io.File(fileLocation.toOSString()); @@ -602,6 +659,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti preserveSpecFile = specFile.exists(); if (!preserveSpecFile) { try { + // In the typical case it is sufficient to have an empty file. specFile.createNewFile(); } catch (IOException e) { ManagedBuilderCorePlugin.log(e); @@ -614,6 +672,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti /** * Determine file extension by language id. This implementation retrieves first extension * from the list as there could be multiple extensions associated with the given language. + * This value is used to replace macro ${EXT}. * * @param languageId - given language ID. * @return file extension associated with the language or {@code null} if not found. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractLanguageSettingsOutputScanner.java index 9d85ded9a2b..3e3ba681abb 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractLanguageSettingsOutputScanner.java @@ -16,6 +16,8 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -47,11 +49,16 @@ import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; import org.w3c.dom.Element; /** - * Abstract class for providers capable to parse build output. + * Abstract class for language settings providers capable to parse build output. * * @since 8.1 */ @@ -67,16 +74,33 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett protected String parsedResourceName = null; protected boolean isResolvingPaths = true; + /** + * Abstract class defining common functionality for option parsers. + * The purpose of this parser is to parse a portion of string representing + * a single option and create a language settings entry out of it. + * + * See {@link GCCBuildCommandParser} for an example how to define the parsers. + */ protected static abstract class AbstractOptionParser { - protected final Pattern pattern; - protected final String patternStr; - protected String nameExpression; - protected String valueExpression; - protected int extraFlag = 0; - protected int kind = 0; + private final int kind; + private final String patternStr; + private final Pattern pattern; + private final String nameExpression; + private final String valueExpression; + private final int extraFlag; + private String parsedName; private String parsedValue; + /** + * Constructor. + * + * @param kind - kind of language settings entries being parsed by the parser. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + * @param valueExpression - capturing group expression defining value of an entry. + * @param extraFlag - extra-flag to add while creating language settings entry. + */ public AbstractOptionParser(int kind, String pattern, String nameExpression, String valueExpression, int extraFlag) { this.kind = kind; this.patternStr = pattern; @@ -87,33 +111,59 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett this.pattern = Pattern.compile(pattern); } + /** + * Create language settings entry of appropriate kind and considering extra-flag passed in constructor. + * + * @param name - name of language settings entry. + * @param value - value of language settings entry. + * @param flag - flag to set. Note that the flag will be amended with the extra-flag defined in constructor. + * @return new language settings entry. + */ public ICLanguageSettingEntry createEntry(String name, String value, int flag) { return (ICLanguageSettingEntry) CDataUtil.createEntry(kind, name, value, null, flag | extraFlag); } /** - * TODO: explain + * Check if the king of option parsed by parser is "file". + * + * @return {@code true} if the kind is file, {@code false} otherwise. */ - protected String extractOption(String input) { - @SuppressWarnings("nls") - String option = input.replaceFirst("(" + patternStr + ").*", "$1"); - return option; + public boolean isForFile() { + return kind == ICSettingEntry.INCLUDE_FILE || kind == ICSettingEntry.MACRO_FILE; } - protected String parseStr(Matcher matcher, String str) { + /** + * Check if the king of option parsed by parser is "folder". + * + * @return {@code true} if the kind is folder, {@code false} otherwise. + */ + public boolean isForFolder() { + return kind == ICSettingEntry.INCLUDE_PATH || kind == ICSettingEntry.LIBRARY_PATH; + } + + /** + * Return value represented by the capturing group expression. + */ + private String parseStr(Matcher matcher, String str) { if (str != null) return matcher.replaceAll(str); return null; } - protected boolean isPathKind() { - return kind == ICSettingEntry.INCLUDE_PATH || kind == ICSettingEntry.INCLUDE_FILE - || kind == ICSettingEntry.MACRO_FILE || kind == ICSettingEntry.LIBRARY_PATH; - } + /** + * Test for a match and parse a portion of input string representing a single option + * to retrieve name and value. + * + * @param optionString - an option to test and parse, possibly with an argument. + * @return {@code true} if the option is a match to parser's regular expression + * or {@code false} otherwise. + */ + public boolean parseOption(String optionString) { + // get rid of extra text at the end (for example file name could be confused for an argument) + @SuppressWarnings("nls") + String option = optionString.replaceFirst("(" + patternStr + ").*", "$1"); - public boolean parseOption(String option) { - String opt = extractOption(option); - Matcher matcher = pattern.matcher(opt); + Matcher matcher = pattern.matcher(option); boolean isMatch = matcher.matches(); if (isMatch) { parsedName = parseStr(matcher, nameExpression); @@ -121,9 +171,11 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } return isMatch; } - } + /** + * Implementation of {@link AbstractOptionParser} for include path options parsing. + */ protected static class IncludePathOptionParser extends AbstractOptionParser { public IncludePathOptionParser(String pattern, String nameExpression) { super(ICLanguageSettingEntry.INCLUDE_PATH, pattern, nameExpression, nameExpression, 0); @@ -133,49 +185,127 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } } + /** + * Implementation of {@link AbstractOptionParser} for include file options parsing. + */ protected static class IncludeFileOptionParser extends AbstractOptionParser { + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + */ public IncludeFileOptionParser(String pattern, String nameExpression) { super(ICLanguageSettingEntry.INCLUDE_FILE, pattern, nameExpression, nameExpression, 0); } + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + * @param extraFlag - extra-flag to add while creating language settings entry. + */ public IncludeFileOptionParser(String pattern, String nameExpression, int extraFlag) { super(ICLanguageSettingEntry.INCLUDE_FILE, pattern, nameExpression, nameExpression, extraFlag); } } + /** + * Implementation of {@link AbstractOptionParser} for macro options parsing. + */ protected static class MacroOptionParser extends AbstractOptionParser { + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + * @param valueExpression - capturing group expression defining value of an entry. + */ public MacroOptionParser(String pattern, String nameExpression, String valueExpression) { super(ICLanguageSettingEntry.MACRO, pattern, nameExpression, valueExpression, 0); } + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + * @param valueExpression - capturing group expression defining value of an entry. + * @param extraFlag - extra-flag to add while creating language settings entry. + */ public MacroOptionParser(String pattern, String nameExpression, String valueExpression, int extraFlag) { super(ICLanguageSettingEntry.MACRO, pattern, nameExpression, valueExpression, extraFlag); } + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + * @param extraFlag - extra-flag to add while creating language settings entry. + */ public MacroOptionParser(String pattern, String nameExpression, int extraFlag) { super(ICLanguageSettingEntry.MACRO, pattern, nameExpression, null, extraFlag); } } + /** + * Implementation of {@link AbstractOptionParser} for macro file options parsing. + */ protected static class MacroFileOptionParser extends AbstractOptionParser { + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + */ public MacroFileOptionParser(String pattern, String nameExpression) { super(ICLanguageSettingEntry.MACRO_FILE, pattern, nameExpression, nameExpression, 0); } + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + * @param extraFlag - extra-flag to add while creating language settings entry. + */ public MacroFileOptionParser(String pattern, String nameExpression, int extraFlag) { super(ICLanguageSettingEntry.MACRO_FILE, pattern, nameExpression, nameExpression, extraFlag); } } + /** + * Implementation of {@link AbstractOptionParser} for library path options parsing. + */ protected static class LibraryPathOptionParser extends AbstractOptionParser { + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + */ public LibraryPathOptionParser(String pattern, String nameExpression) { super(ICLanguageSettingEntry.LIBRARY_PATH, pattern, nameExpression, nameExpression, 0); } + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + * @param extraFlag - extra-flag to add while creating language settings entry. + */ public LibraryPathOptionParser(String pattern, String nameExpression, int extraFlag) { super(ICLanguageSettingEntry.LIBRARY_PATH, pattern, nameExpression, nameExpression, extraFlag); } } + /** + * Implementation of {@link AbstractOptionParser} for library file options parsing. + */ protected static class LibraryFileOptionParser extends AbstractOptionParser { + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + */ public LibraryFileOptionParser(String pattern, String nameExpression) { super(ICLanguageSettingEntry.LIBRARY_FILE, pattern, nameExpression, nameExpression, 0); } + /** + * Constructor. + * @param pattern - regular expression pattern being parsed by the parser. + * @param nameExpression - capturing group expression defining name of an entry. + * @param extraFlag - extra-flag to add while creating language settings entry. + */ public LibraryFileOptionParser(String pattern, String nameExpression, int extraFlag) { super(ICLanguageSettingEntry.LIBRARY_FILE, pattern, nameExpression, nameExpression, extraFlag); } @@ -211,10 +341,22 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett */ protected abstract AbstractOptionParser[] getOptionParsers(); + /** + * @return {@code true} when the provider tries to resolve relative or remote paths + * to the existing paths in the workspace or local file-system using certain heuristics. + */ public boolean isResolvingPaths() { return isResolvingPaths; } + /** + * Enable or disable resolving relative or remote paths to the existing paths + * in the workspace or local file-system. + * + * @param resolvePaths - set {@code true} to enable or {@code false} to disable + * resolving paths. When this parameter is set to {@code false} the paths will + * be kept as they appear in the build output. + */ public void setResolvingPaths(boolean resolvePaths) { this.isResolvingPaths = resolvePaths; } @@ -272,14 +414,15 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett List options = parseOptions(line); if (options != null) { + AbstractOptionParser[] optionParsers = getOptionParsers(); for (String option : options) { - for (AbstractOptionParser optionParser : getOptionParsers()) { + for (AbstractOptionParser optionParser : optionParsers) { try { if (optionParser.parseOption(option)) { ICLanguageSettingEntry entry = null; - if (isResolvingPaths && optionParser.isPathKind()) { + if (isResolvingPaths && (optionParser.isForFile() || optionParser.isForFolder())) { URI baseURI = mappedRootURI; - if (!new Path(optionParser.parsedName).isAbsolute() && buildDirURI != null) { + if (buildDirURI != null && !new Path(optionParser.parsedName).isAbsolute()) { baseURI = EFSExtensionManager.getDefault().append(mappedRootURI, buildDirURI.getPath()); } entry = createResolvedPathEntry(optionParser, optionParser.parsedName, 0, baseURI); @@ -293,8 +436,9 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } } } catch (Throwable e) { - // protect from rogue parsers extending this class - ManagedBuilderCorePlugin.log(e); + @SuppressWarnings("nls") + String msg = "Exception trying to parse option [" + option + "], class " + getClass().getSimpleName(); + ManagedBuilderCorePlugin.log(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID, msg, e)); } } } @@ -307,7 +451,112 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return false; } - // TODO - temporary, remove me + /** + * In case when absolute path is mapped to the source tree in a project + * 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 + * used to prepend to other "absolute" paths where appropriate. + * + * @param resource - a resource referred by parsed path + * @param parsedResourceName - path as appears in the output + * @return mapped path as URI + */ + protected URI getMappedRootURI(IResource resource, String parsedResourceName) { + if (resource == null) { + return null; + } + + URI resourceURI = resource.getLocationURI(); + String mappedRoot = "/"; //$NON-NLS-1$ + + if (parsedResourceName != null) { + IPath parsedSrcPath = new Path(parsedResourceName); + if (parsedSrcPath.isAbsolute()) { + IPath absResourcePath = resource.getLocation(); + int absSegmentsCount = absResourcePath.segmentCount(); + int relSegmentsCount = parsedSrcPath.segmentCount(); + if (absSegmentsCount >= relSegmentsCount) { + IPath ending = absResourcePath.removeFirstSegments(absSegmentsCount - relSegmentsCount); + ending = ending.setDevice(parsedSrcPath.getDevice()).makeAbsolute(); + if (ending.equals(parsedSrcPath.makeAbsolute())) { + // mappedRoot here is parsedSrcPath with removed parsedResourceName trailing segments, + // i.e. if absResourcePath="/path/workspace/project/file.c" and parsedResourceName="project/file.c" + // then mappedRoot="/path/workspace/" + mappedRoot = absResourcePath.removeLastSegments(relSegmentsCount).toString(); + } + } + } + } + // this creates URI with schema and other components from resourceURI but path as mappedRoot + URI uri = EFSExtensionManager.getDefault().createNewURIFromPath(resourceURI, mappedRoot); + return uri; + } + + /** + * Determine current build directory considering currentResource (resource being compiled), + * parsedResourceName and mappedRootURI. + * + * @param mappedRootURI - root of the source tree when mapped to remote file-system. + * @return {@link URI} of current build directory + */ + protected URI getBuildDirURI(URI mappedRootURI) { + URI buildDirURI = null; + + // try to deduce build directory from full path of currentResource and partial path of parsedResourceName + URI cwdURI = null; + if (currentResource != null && parsedResourceName != null && !new Path(parsedResourceName).isAbsolute()) { + cwdURI = findBaseLocationURI(currentResource.getLocationURI(), parsedResourceName); + } + String cwdPath = cwdURI != null ? EFSExtensionManager.getDefault().getPathFromURI(cwdURI) : null; + if (cwdPath != null && mappedRootURI != null) { + buildDirURI = EFSExtensionManager.getDefault().append(mappedRootURI, cwdPath); + } else { + buildDirURI = cwdURI; + } + + // try IWorkingDirectoryTracker + if (buildDirURI == null && cwdTracker != null) { + buildDirURI = cwdTracker.getWorkingDirectoryURI(); + } + + // try builder working directory + if (buildDirURI == null && currentCfgDescription != null) { + IPath pathBuilderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD(); + if (pathBuilderCWD != null) { + String builderCWD = pathBuilderCWD.toString(); + try { + // here is a hack to overcome ${workspace_loc:/prj-name} returned by builder + // where "/" is treated as path separator by pathBuilderCWD + ICdtVariableManager vmanager = CCorePlugin.getDefault().getCdtVariableManager(); + builderCWD = vmanager.resolveValue(builderCWD, "", null, currentCfgDescription); //$NON-NLS-1$ + } catch (CdtVariableException e) { + ManagedBuilderCorePlugin.log(e); + } + if (builderCWD != null && !builderCWD.isEmpty()) { + buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD); + } + } + } + + // try directory of the current project + if (buildDirURI == null && currentProject != null) { + buildDirURI = currentProject.getLocationURI(); + } + + // try parent folder of the resource + if (buildDirURI == null && currentResource != null) { + IContainer container; + if (currentResource instanceof IContainer) { + container = (IContainer) currentResource; + } else { + container = currentResource.getParent(); + } + buildDirURI = container.getLocationURI(); + } + return buildDirURI; + } + + // AG FIXME - temporary, remove me @Deprecated protected String getPrefixForLog() { String str; @@ -320,6 +569,12 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return str + ": "; } + /** + * Sets language settings entries for current configuration description, current resource + * and current language ID. + * + * @param entries - language settings entries to set. + */ protected void setSettingEntries(List entries) { setSettingEntries(currentCfgDescription, currentResource, currentLanguageId, entries); @@ -363,50 +618,46 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } /** - * Resolve and create language settings path entry. + * Find resource in the workspace for a given URI with a preference for the resource + * to reside in the given project. */ - private ICLanguageSettingEntry createResolvedPathEntry(AbstractOptionParser optionParser, - String parsedPath, int flag, URI baseURI) { - - String resolvedPath = null; - - URI uri = determineMappedURI(parsedPath, baseURI); - IResource rc = null; - if (uri != null && uri.isAbsolute()) { - rc = findResourceForLocationURI(uri, optionParser.kind, currentProject); - } - if (rc != null) { - IPath path = rc.getFullPath(); - resolvedPath = path.toString(); - flag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED; - } else { - IPath path = getFilesystemLocation(uri); - if (path != null && new File(path.toString()).exists()) { - resolvedPath = path.toString(); - } - if (resolvedPath == null) { - Set referencedProjectsNames = new LinkedHashSet(); - if (currentCfgDescription!=null) { - Map refs = currentCfgDescription.getReferenceInfo(); - referencedProjectsNames.addAll(refs.keySet()); - } - IResource resource = resolveResourceInWorkspace(parsedPath, currentProject, referencedProjectsNames); - if (resource != null) { - path = resource.getFullPath(); - resolvedPath = path.toString(); - flag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED; + private static IResource findFileForLocationURI(URI uri, IProject preferredProject) { + IResource sourceFile = null; + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource[] resources = root.findFilesForLocationURI(uri); + if (resources.length > 0) { + sourceFile = resources[0]; + if (preferredProject != null) { + for (IResource rc : resources) { + if (rc.getProject().equals(preferredProject)) { + sourceFile = rc; + break; + } } } - if (resolvedPath==null && path!=null) { - resolvedPath = path.toString(); + } + return sourceFile; + } + + /** + * Return a resource in workspace corresponding the given folder {@link URI} preferable residing in + * the provided project. + */ + private static IResource findContainerForLocationURI(URI uri, IProject preferredProject) { + IResource resource = null; + IResource[] resources = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(uri); + for (IResource rc : resources) { + if ((rc instanceof IProject || rc instanceof IFolder)) { // treat IWorkspaceRoot as non-workspace path + if (rc.getProject().equals(preferredProject)) { + resource = rc; + break; + } + if (resource == null) { + resource = rc; // to be deterministic the first qualified resource has preference + } } } - - if (resolvedPath==null) { - resolvedPath = parsedPath; - } - - return optionParser.createEntry(resolvedPath, resolvedPath, flag); + return resource; } /** @@ -458,67 +709,80 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } /** - * Determine current build directory considering currentResource (resource being compiled), - * parsedResourceName and mappedRootURI. - * - * @param mappedRootURI - root of the source tree when mapped to remote file-system. - * @return {@link URI} of current build directory + * Find base location of the file, i.e. location of the directory which + * results from removing trailing relativeFileName from fileURI or + * {@code null} if fileURI doesn't represent relativeFileName. */ - protected URI getBuildDirURI(URI mappedRootURI) { - URI buildDirURI = null; - - // try to deduce build directory from full path of currentResource and partial path of parsedResourceName + private static URI findBaseLocationURI(URI fileURI, String relativeFileName) { URI cwdURI = null; - if (currentResource != null && parsedResourceName != null && !new Path(parsedResourceName).isAbsolute()) { - cwdURI = findBaseLocationURI(currentResource.getLocationURI(), parsedResourceName); - } - String cwdPath = cwdURI != null ? EFSExtensionManager.getDefault().getPathFromURI(cwdURI) : null; - if (cwdPath != null && mappedRootURI != null) { - buildDirURI = EFSExtensionManager.getDefault().append(mappedRootURI, cwdPath); - } else { - buildDirURI = cwdURI; - } + String path = fileURI.getPath(); - // if not found - try IWorkingDirectoryTracker - if (buildDirURI == null && cwdTracker != null) { - buildDirURI = cwdTracker.getWorkingDirectoryURI(); - } + String[] segments = relativeFileName.split("[/\\\\]"); //$NON-NLS-1$ - // if not found - try builder working directory - if (buildDirURI == null && currentCfgDescription != null) { - IPath pathBuilderCWD = currentCfgDescription.getBuildSetting().getBuilderCWD(); - if (pathBuilderCWD != null) { - String builderCWD = pathBuilderCWD.toString(); - try { - // here is a hack to overcome ${workspace_loc:/prj-name} returned by builder - // where "/" is treated as path separator by pathBuilderCWD - ICdtVariableManager vmanager = CCorePlugin.getDefault().getCdtVariableManager(); - builderCWD = vmanager.resolveValue(builderCWD, "", null, currentCfgDescription); //$NON-NLS-1$ - } catch (CdtVariableException e) { - ManagedBuilderCorePlugin.log(e); - } - if (builderCWD != null && !builderCWD.isEmpty()) { - buildDirURI = org.eclipse.core.filesystem.URIUtil.toURI(builderCWD); + // start removing segments from the end of the path + for (int i = segments.length - 1; i >= 0; i--) { + String lastSegment = segments[i]; + if (lastSegment.length() > 0 && !lastSegment.equals(".")) { //$NON-NLS-1$ + if (lastSegment.equals("..")) { //$NON-NLS-1$ + // navigating ".." in the other direction is ambiguous, bailing out + return null; + } else { + if (path.endsWith("/" + lastSegment)) { //$NON-NLS-1$ + int pos = path.lastIndexOf("/" + lastSegment); //$NON-NLS-1$ + path = path.substring(0, pos); + continue; + } else { + // ouch, relativeFileName does not match fileURI, bailing out + return null; + } } } } - // if not found - try directory of the current project - if (buildDirURI == null && currentProject != null) { - buildDirURI = currentProject.getLocationURI(); + try { + cwdURI = new URI(fileURI.getScheme(), fileURI.getUserInfo(), fileURI.getHost(), + fileURI.getPort(), path + '/', fileURI.getQuery(), fileURI.getFragment()); + } catch (URISyntaxException e) { + // It should be valid URI here or something is really wrong + ManagedBuilderCorePlugin.log(e); } - // if not found - try parent folder of the resource - if (buildDirURI == null && currentResource != null) { - IContainer container; - if (currentResource instanceof IContainer) { - container = (IContainer) currentResource; - } else { - container = currentResource.getParent(); + return cwdURI; + } + + /** + * The manipulations here are done to resolve "../" navigation for symbolic links where "link/.." cannot + * be collapsed as it must follow the real file-system path. {@link java.io.File#getCanonicalPath()} deals + * with that correctly but {@link Path} or {@link URI} try to normalize the path which would be incorrect + * here. + */ + private static URI resolvePathFromBaseLocation(String name, IPath baseLocation) { + String pathName = name; + if (baseLocation != null && !baseLocation.isEmpty()) { + pathName = pathName.replace(File.separatorChar, '/'); + String device = new Path(pathName).getDevice(); + if (device==null || device.equals(baseLocation.getDevice())) { + if (device != null && device.length() > 0) { + pathName = pathName.substring(device.length()); + } + + baseLocation = baseLocation.addTrailingSeparator(); + if (pathName.startsWith("/")) { //$NON-NLS-1$ + pathName = pathName.substring(1); + } + pathName = baseLocation.toString() + pathName; } - buildDirURI = container.getLocationURI(); } - return buildDirURI; + + try { + File file = new File(pathName); + file = file.getCanonicalFile(); + return file.toURI(); + } catch (IOException e) { + // if error just leave it as is + } + + return org.eclipse.core.filesystem.URIUtil.toURI(pathName); } /** @@ -559,6 +823,29 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return uri; } + /** + * Find all resources in the folder which might be represented by relative path passed. + */ + private static List findPathInFolder(IPath path, IContainer folder) { + List paths = new ArrayList(); + IResource resource = folder.findMember(path); + if (resource != null) { + paths.add(resource); + } + + try { + for (IResource res : folder.members()) { + if (res instanceof IContainer) { + paths.addAll(findPathInFolder(path, (IContainer) res)); + } + } + } catch (CoreException e) { + // ignore + } + + return paths; + } + /** * Determine which resource in workspace is the best fit to parsedName passed. */ @@ -598,7 +885,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } } } - if (rc!=null) { + if (rc != null) { return rc; } } @@ -629,214 +916,6 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return null; } - /** - * Find all resources in the folder which might be represented by relative path passed. - */ - private static List findPathInFolder(IPath path, IContainer folder) { - List paths = new ArrayList(); - IResource resource = folder.findMember(path); - if (resource != null) { - paths.add(resource); - } - - try { - for (IResource res : folder.members()) { - if (res instanceof IContainer) { - paths.addAll(findPathInFolder(path, (IContainer) res)); - } - } - } catch (CoreException e) { - // ignore - } - - return paths; - } - - /** - * Find resource in the workspace for a given URI with a preference for the resource - * to reside in the given project. - */ - private static IResource findFileForLocationURI(URI uri, IProject preferredProject) { - IResource sourceFile = null; - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IResource[] resources = root.findFilesForLocationURI(uri); - if (resources.length > 0) { - sourceFile = resources[0]; - if (preferredProject != null) { - for (IResource rc : resources) { - if (rc.getProject().equals(preferredProject)) { - sourceFile = rc; - break; - } - } - } - } - return sourceFile; - } - - /** - * Find base location of the file, i.e. location of the directory which - * results from removing trailing relativeFileName from fileURI or - * {@code null} if fileURI doesn't represent relativeFileName. - */ - private static URI findBaseLocationURI(URI fileURI, String relativeFileName) { - URI cwdURI = null; - String path = fileURI.getPath(); - - String[] segments = relativeFileName.split("[/\\\\]"); //$NON-NLS-1$ - - // start removing segments from the end of the path - for (int i = segments.length - 1; i >= 0; i--) { - String lastSegment = segments[i]; - if (lastSegment.length() > 0 && !lastSegment.equals(".")) { //$NON-NLS-1$ - if (lastSegment.equals("..")) { //$NON-NLS-1$ - // navigating ".." in the other direction is ambiguous, bailing out - return null; - } else { - if (path.endsWith("/" + lastSegment)) { //$NON-NLS-1$ - int pos = path.lastIndexOf("/" + lastSegment); //$NON-NLS-1$ - path = path.substring(0, pos); - continue; - } else { - // ouch, relativeFileName does not match fileURI, bailing out - return null; - } - } - } - } - - try { - cwdURI = new URI(fileURI.getScheme(), fileURI.getUserInfo(), fileURI.getHost(), - fileURI.getPort(), path + '/', fileURI.getQuery(), fileURI.getFragment()); - } catch (URISyntaxException e) { - // It should be valid URI here or something is wrong - ManagedBuilderCorePlugin.log(e); - } - - return cwdURI; - } - - /** - * In case when absolute path is mapped to the source tree in a project - * 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 - * used to prepend to other "absolute" paths where appropriate. - * - * @param resource - a resource referred by parsed path - * @param parsedResourceName - path as appears in the output - * @return mapped path as URI - */ - protected URI getMappedRootURI(IResource resource, String parsedResourceName) { - if (resource == null) { - return null; - } - - URI resourceURI = resource.getLocationURI(); - String mappedRoot = "/"; //$NON-NLS-1$ - - if (parsedResourceName != null) { - IPath parsedSrcPath = new Path(parsedResourceName); - if (parsedSrcPath.isAbsolute()) { - IPath absResourcePath = resource.getLocation(); - int absSegmentsCount = absResourcePath.segmentCount(); - int relSegmentsCount = parsedSrcPath.segmentCount(); - if (absSegmentsCount >= relSegmentsCount) { - IPath ending = absResourcePath.removeFirstSegments(absSegmentsCount - relSegmentsCount); - ending = ending.setDevice(parsedSrcPath.getDevice()).makeAbsolute(); - if (ending.equals(parsedSrcPath.makeAbsolute())) { - // mappedRoot here is parsedSrcPath with removed parsedResourceName trailing segments, - // i.e. if absResourcePath="/path/workspace/project/file.c" and parsedResourceName="project/file.c" - // then mappedRoot="/path/workspace/" - mappedRoot = absResourcePath.removeLastSegments(relSegmentsCount).toString(); - } - } - } - } - // this creates URI with schema and other components from resourceURI but path as mappedRoot - URI uri = EFSExtensionManager.getDefault().createNewURIFromPath(resourceURI, mappedRoot); - return uri; - } - - /** - * The manipulations here are done to resolve "../" navigation for symbolic links where "link/.." cannot - * be collapsed as it must follow the real file-system path. {@link java.io.File#getCanonicalPath()} deals - * with that correctly but {@link Path} or {@link URI} try to normalize the path which would be incorrect - * here. - */ - private static URI resolvePathFromBaseLocation(String name, IPath baseLocation) { - String pathName = name; - if (baseLocation != null && !baseLocation.isEmpty()) { - pathName = pathName.replace(File.separatorChar, '/'); - String device = new Path(pathName).getDevice(); - if (device==null || device.equals(baseLocation.getDevice())) { - if (device != null && device.length() > 0) { - pathName = pathName.substring(device.length()); - } - - baseLocation = baseLocation.addTrailingSeparator(); - if (pathName.startsWith("/")) { //$NON-NLS-1$ - pathName = pathName.substring(1); - } - pathName = baseLocation.toString() + pathName; - } - } - - try { - File file = new File(pathName); - file = file.getCanonicalFile(); - return file.toURI(); - } catch (IOException e) { - // if error just leave it as is - } - - return org.eclipse.core.filesystem.URIUtil.toURI(pathName); - } - - /** - * Return a resource in workspace corresponding the given {@link URI} preferable residing in - * the provided project. - */ - private static IResource findResourceForLocationURI(URI uri, int kind, IProject preferredProject) { - if (uri == null) - return null; - - IResource resource = null; - - switch (kind) { - case ICSettingEntry.INCLUDE_PATH: - case ICSettingEntry.LIBRARY_PATH: - resource = findContainerForLocationURI(uri, preferredProject); - break; - case ICSettingEntry.INCLUDE_FILE: - case ICSettingEntry.MACRO_FILE: - resource = findFileForLocationURI(uri, preferredProject); - break; - } - - return resource; - } - - /** - * Return a resource in workspace corresponding the given folder {@link URI} preferable residing in - * the provided project. - */ - private static IResource findContainerForLocationURI(URI uri, IProject preferredProject) { - IResource resource = null; - IResource[] resources = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(uri); - for (IResource rc : resources) { - if ((rc instanceof IProject || rc instanceof IFolder)) { // treat IWorkspaceRoot as non-workspace path - if (rc.getProject().equals(preferredProject)) { - resource = rc; - break; - } - if (resource == null) { - resource = rc; // to be deterministic the first qualified resource has preference - } - } - } - return resource; - } - /** * Get location on the local file-system considering possible mapping by {@link EFSExtensionManager}. */ @@ -857,12 +936,119 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett return null; } + /** + * Resolve and create language settings path entry. + */ + private ICLanguageSettingEntry createResolvedPathEntry(AbstractOptionParser optionParser, + String parsedPath, int flag, URI baseURI) { + + String resolvedPath = null; + int resolvedFlag = 0; + + URI uri = determineMappedURI(parsedPath, baseURI); + IResource rc = null; + + // Try to resolve in the workspace + if (uri != null && uri.isAbsolute()) { + if (optionParser.isForFolder()) { + rc = findContainerForLocationURI(uri, currentProject); + } else if (optionParser.isForFile()) { + rc = findFileForLocationURI(uri, currentProject); + } + if (rc != null) { + resolvedPath = rc.getFullPath().toString(); + resolvedFlag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED; + } + } + + // Try to resolve on the file-system + if (resolvedPath == null) { + IPath path = getFilesystemLocation(uri); + if (path != null && new File(path.toString()).exists()) { + resolvedPath = path.toString(); + resolvedFlag = flag; + } + if (resolvedPath == null) { + Set referencedProjectsNames = new LinkedHashSet(); + if (currentCfgDescription!=null) { + Map refs = currentCfgDescription.getReferenceInfo(); + referencedProjectsNames.addAll(refs.keySet()); + } + IResource resource = resolveResourceInWorkspace(parsedPath, currentProject, referencedProjectsNames); + if (resource != null) { + resolvedPath = resource.getFullPath().toString(); + resolvedFlag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED; + } + } + if (resolvedPath == null && path != null) { + resolvedPath = path.toString(); + resolvedFlag = flag; + } + } + + // if cannot resolve keep parsed path + if (resolvedPath == null) { + resolvedPath = parsedPath; + resolvedFlag = flag; + } + + return optionParser.createEntry(resolvedPath, resolvedPath, resolvedFlag); + } + + /** + * Count how many groups are present in regular expression. + * The implementation is simplistic but should be sufficient for the cause. + * + * @param str - regular expression to count the groups. + * @return number of the groups (groups are enclosed in round brackets) present. + */ protected static int countGroups(String str) { @SuppressWarnings("nls") int count = str.replaceAll("[^\\(]", "").length(); return count; } + /** + * Helper method to construct logical "or" to be used inside regular expressions. + */ + @SuppressWarnings("nls") + private static String expressionLogicalOr(Set fileExts) { + String pattern = "("; + for (String ext : fileExts) { + if (pattern.length() != 1) + pattern += "|"; + pattern += "(" + Pattern.quote(ext) + ")"; + ext = ext.toUpperCase(); + if (!fileExts.contains(ext)) { + pattern += "|(" + Pattern.quote(ext) + ")"; + } + } + pattern += ")"; + return pattern; + } + + /** + * Construct regular expression to find any file extension for C or C++. + * Returns expression shaped in form of "((cpp)|(c++)|(c))". + * + * @return regular expression for searching C/C++ file extensions. + */ + protected String getPatternFileExtensions() { + IContentTypeManager manager = Platform.getContentTypeManager(); + + Set fileExts = new HashSet(); + + IContentType contentTypeCpp = manager.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE); + fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); + + IContentType contentTypeC = manager.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE); + fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); + + String pattern = expressionLogicalOr(fileExts); + + return pattern; + } + @Override public Element serializeAttributes(Element parentElement) { Element elementProvider = super.serializeAttributes(parentElement); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/GCCBuildCommandParser.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/GCCBuildCommandParser.java index 92ec9d2a1fd..93d0e20062c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/GCCBuildCommandParser.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/GCCBuildCommandParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Andrew Gvozdev and others. + * Copyright (c) 2009, 2012 Andrew Gvozdev and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,6 +16,9 @@ import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsEditabl import org.eclipse.cdt.core.settings.model.ICSettingEntry; /** + * Build command parser capable to parse gcc command in build output and generate + * language settings per file being compiled. + * * @since 8.1 */ public class GCCBuildCommandParser extends AbstractBuildCommandParser implements ILanguageSettingsEditableProvider { @@ -51,10 +54,17 @@ public class GCCBuildCommandParser extends AbstractBuildCommandParser implements return (GCCBuildCommandParser) super.clone(); } + /** + * Error Parser which allows highlighting of output lines matching the patterns of this parser. + * Intended for better troubleshooting experience. + */ public static class GCCBuildCommandPatternHighlighter extends AbstractBuildCommandParser.AbstractBuildCommandPatternHighlighter { // ID of the parser taken from the existing extension point private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"; //$NON-NLS-1$ + /** + * Default constructor. + */ public GCCBuildCommandPatternHighlighter() { super(GCC_BUILD_COMMAND_PARSER_EXT); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/GCCBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/GCCBuiltinSpecsDetector.java index f6a5a4899e4..865832c45ce 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/GCCBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/GCCBuiltinSpecsDetector.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Andrew Gvozdev and others. + * Copyright (c) 2009, 2012 Andrew Gvozdev and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -26,7 +26,7 @@ import org.eclipse.core.runtime.CoreException; * @since 8.1 */ public class GCCBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { - // ID must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point + // ID must match the tool-chain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$ private enum State {NONE, EXPECTING_LOCAL_INCLUDE, EXPECTING_SYSTEM_INCLUDE, EXPECTING_FRAMEWORKS} @@ -51,12 +51,16 @@ public class GCCBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector imple return optionParsers; } + /** + * Create a list from one item. + */ private List makeList(String line) { List list = new ArrayList(); list.add(line); return list; } + @SuppressWarnings("nls") @Override protected List parseOptions(String line) { line = line.trim(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/ToolchainBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/ToolchainBuiltinSpecsDetector.java index 3a5412d61fd..e919180d5d8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/ToolchainBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/ToolchainBuiltinSpecsDetector.java @@ -31,7 +31,7 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs private Map toolMap = new HashMap(); /** - * Concrete compiler specs detectors need to supply Toolchain ID. + * Concrete compiler specs detectors need to supply tool-chain ID. * * Tool-chain id must be supplied for global providers where we don't * have configuration description to figure that out programmatically. @@ -39,7 +39,7 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs protected abstract String getToolchainId(); /** - * Finds a tool handling given language in the tool-chain. + * Finds a tool handling given language in the tool-chain of the provider. * This returns the first tool found. */ private ITool getTool(String languageId) { @@ -55,10 +55,14 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs return tool; } } - ManagedBuilderCorePlugin.error("Unable to find tool in toolchain="+toolchainId+" for language="+languageId); + ManagedBuilderCorePlugin.error("Unable to find tool in toolchain=" + toolchainId + " for language=" + languageId); //$NON-NLS-1$ //$NON-NLS-2$ return null; } + /** + * Finds a tool handling given language in the tool-chain. + * This returns the first tool found. + */ private ITool getTool(String languageId, IToolChain toolchain) { ITool[] tools = toolchain.getTools(); for (ITool tool : tools) { @@ -79,8 +83,7 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs ITool tool = getTool(languageId); String compilerCommand = tool.getToolCommand(); if (compilerCommand.isEmpty()) { - String msg = "Unable to find compiler command in toolchain="+getToolchainId(); - ManagedBuilderCorePlugin.error(msg); + ManagedBuilderCorePlugin.error("Unable to find compiler command in toolchain=" + getToolchainId()); //$NON-NLS-1$ } return compilerCommand; } @@ -94,7 +97,7 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs ext = srcFileExtensions[0]; } if (ext == null || ext.isEmpty()) { - ManagedBuilderCorePlugin.error("Unable to find file extension for language "+languageId); + ManagedBuilderCorePlugin.error("Unable to find file extension for language " + languageId); //$NON-NLS-1$ } return ext; } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/ScannerDiscoveryGlobalConsole.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/ScannerDiscoveryGlobalConsole.java index 76122242a8f..e8ad5a4b935 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/ScannerDiscoveryGlobalConsole.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/ScannerDiscoveryGlobalConsole.java @@ -28,6 +28,12 @@ import org.eclipse.ui.console.IConsoleManager; import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.console.MessageConsoleStream; +/** + * TODO + * + * Note that this console is not colored. + * + */ public class ScannerDiscoveryGlobalConsole implements ICConsole { private MessageConsole console; private ConsoleOutputStreamAdapter stream; @@ -56,14 +62,7 @@ public class ScannerDiscoveryGlobalConsole implements ICConsole { @Override public void close() throws IOException { - // FIXME - clean way of closing the streams. Currently the stream could get being used after closing fConsoleStream.close(); -// if (!isOpen) { -// fConsoleStream.close(); -// IStatus s = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Attempt to close stream second time", new Exception()); -// MakeCorePlugin.log(s); -// flush(); -// } isOpen = false; } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java index ab217399b42..df806313cad 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java @@ -334,10 +334,8 @@ public class CDataUtil { } /** - * Convenience method to create {@link ICLanguageSettingEntry} depending on kind. + * Convenience method to create {@link ICSettingEntry} depending on kind. * Note that this method keeps the entries in the pool to avoid proliferation of duplicates. - * - * Note that the method always returns {@link ICLanguageSettingEntry}. */ public static ICSettingEntry createEntry(int kind, String name, String value, IPath[] exclusionPatterns, int flags) { return createEntry(kind, name, value, exclusionPatterns, flags, null, null, null); diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Cygwin.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Cygwin.java index 00c9abe7650..e0b770d87c9 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Cygwin.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Cygwin.java @@ -31,13 +31,23 @@ public class Cygwin { * Check if cygwin path conversion utilities are available in the path. * * @param envPath - list of directories to search for cygwin utilities separated - * by path separator (format of environment variable $PATH). + * by path separator (format of environment variable $PATH) + * or {@code null} to use current $PATH. * @return {@code true} if cygwin is available, {@code false} otherwise. */ public static boolean isAvailable(String envPath) { return Platform.getOS().equals(Platform.OS_WIN32) && findCygpathLocation(envPath) != null; } + /** + * Check if cygwin path conversion utilities are available in $PATH. + * + * @return {@code true} if cygwin is available, {@code false} otherwise. + */ + public static boolean isAvailable() { + return Platform.getOS().equals(Platform.OS_WIN32) && findCygpathLocation(null) != null; + } + /** * Conversion from Cygwin path to Windows path. * diff --git a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java index 2530eb4cb2c..630686325ae 100644 --- a/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java +++ b/xlc/org.eclipse.cdt.managedbuilder.xlc.core/src/org/eclipse/cdt/managedbuilder/xlc/core/XlcBuiltinSpecsDetector.java @@ -24,7 +24,6 @@ import org.eclipse.cdt.managedbuilder.language.settings.providers.ToolchainBuilt /** * Language settings provider to detect built-in compiler settings for IBM XLC compiler. - * Note that currently this class is hardwired to GCC toolchain {@code cdt.managedbuild.toolchain.gnu.base}. */ public class XlcBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector implements ILanguageSettingsEditableProvider { // must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point