Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorJonah Graham2020-04-25 16:16:25 +0000
committerJonah Graham2020-04-25 20:43:23 +0000
commiteeebe5234c8b9bb73b98bc55fa1024b137fa4fd9 (patch)
tree9fcd9172bb0cddc758855deca6afbd6a262ab942 /build
parent5947786365990ad6431696f4f9a23f96864459f8 (diff)
downloadorg.eclipse.cdt-eeebe5234c8b9bb73b98bc55fa1024b137fa4fd9.tar.gz
org.eclipse.cdt-eeebe5234c8b9bb73b98bc55fa1024b137fa4fd9.tar.xz
org.eclipse.cdt-eeebe5234c8b9bb73b98bc55fa1024b137fa4fd9.zip
Bug 562452: Avoid using .C for C++ files when calculating specs
Diffstat (limited to 'build')
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF2
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java29
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/ToolchainBuiltinSpecsDetector.java19
3 files changed, 34 insertions, 16 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF
index ee0249ddded..fb26e2a50dd 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF
+++ b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.core; singleton:=true
-Bundle-Version: 8.8.0.qualifier
+Bundle-Version: 8.9.0.qualifier
Bundle-Activator: org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
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 c06d5a17c0c..a372a3a74af 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
@@ -26,6 +26,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
@@ -894,23 +895,41 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
* @return file extension associated with the language or {@code null} if not found.
*/
protected String getSpecFileExtension(String languageId) {
- String ext = null;
+ Optional<String> extension = Optional.empty();
ILanguageDescriptor langDescriptor = LanguageManager.getInstance().getLanguageDescriptor(languageId);
if (langDescriptor != null) {
IContentType[] contentTypes = langDescriptor.getContentTypes();
if (contentTypes != null && contentTypes.length > 0) {
String[] fileExtensions = contentTypes[0].getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
- if (fileExtensions != null && fileExtensions.length > 0) {
- ext = fileExtensions[0];
+ if (fileExtensions != null) {
+ List<String> extensions = Arrays.asList(fileExtensions);
+ extension = selectBestSpecFileExtension(extensions);
}
}
}
- if (ext == null) {
+ if (!extension.isPresent()) {
ManagedBuilderCorePlugin.log(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID,
"Unable to find file extension for language " + languageId)); //$NON-NLS-1$
+ return null;
}
- return ext;
+ return extension.get();
+ }
+
+ /**
+ * Return the best extension to use for calculating spec file from a list of extensions.
+ * @param extensions list of possible extensions to choose from
+ * @return one of the extensions deemed the best one to use from the list
+ * @since 8.9
+ */
+ protected Optional<String> selectBestSpecFileExtension(List<String> extensions) {
+ return extensions.stream().filter(s -> s != null && !s.isEmpty()).findFirst().map(ext -> {
+ // Bug 562452: Special case where we prefer not to use .C for c++ files.
+ if ("C".equals(ext) && extensions.contains("cpp")) { //$NON-NLS-1$//$NON-NLS-2$
+ return "cpp"; //$NON-NLS-1$
+ }
+ return ext;
+ });
}
/**
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 98219a57c92..59312318f0a 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
@@ -16,6 +16,7 @@
package org.eclipse.cdt.managedbuilder.language.settings.providers;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -139,19 +140,17 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
@Override
protected String getSpecFileExtension(String languageId) {
- Optional<String> found = languageTool(languageId)//
- .flatMap(t -> Optional.of(t.getAllInputExtensions()))//
- .flatMap(e -> Arrays.asList(e).stream().findFirst());
- if (!found.isPresent()) {
- ManagedBuilderCorePlugin.error(NLS.bind("Unable to find file extension for language {0}", languageId)); //$NON-NLS-1$
- return null;
- }
- String firstInput = found.get();
- if (firstInput == null || firstInput.isEmpty()) {
+ Optional<String[]> optionalExtensions = languageTool(languageId)
+ .flatMap(t -> Optional.of(t.getAllInputExtensions()));
+ List<String> extensions = optionalExtensions.map(Arrays::asList).orElseGet(() -> Collections.emptyList());
+ Optional<String> extension = selectBestSpecFileExtension(extensions);
+
+ if (!extension.isPresent()) {
//this looks like either invalid configuration settings or API issue
ManagedBuilderCorePlugin.error(NLS.bind("Unable to find file extension for language {0}", languageId)); //$NON-NLS-1$
+ return null;
}
- return firstInput;
+ return extension.get();
}
@Override

Back to the top