mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 01:05:38 +02:00
Bug 559707 - Promote ToolchainBuiltinSpecsDetector.getTool(String)
added protected Optional<ITool> languageTool(String languageId) instead of private ITool getTool(String languageId) Change-Id: Ic21d2a493acf4e547c7354c544c2cef34b53eab6 Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
parent
a0963136f8
commit
d4bcea1ec7
1 changed files with 71 additions and 61 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2009, 2013 Andrew Gvozdev and others.
|
* Copyright (c) 2009, 2020 Andrew Gvozdev and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -10,13 +10,16 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrew Gvozdev - initial API and implementation
|
* Andrew Gvozdev - initial API and implementation
|
||||||
|
* Alexander Fedorov <alexander.fedorov@arsysop.ru> - Bug 559707
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.managedbuilder.language.settings.providers;
|
package org.eclipse.cdt.managedbuilder.language.settings.providers;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
||||||
import org.eclipse.cdt.managedbuilder.core.BuildException;
|
import org.eclipse.cdt.managedbuilder.core.BuildException;
|
||||||
|
@ -28,6 +31,7 @@ import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
||||||
import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableManagerToolChain;
|
import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableManagerToolChain;
|
||||||
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract parser capable to execute compiler command printing built-in compiler
|
* Abstract parser capable to execute compiler command printing built-in compiler
|
||||||
|
@ -58,18 +62,18 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a tool handling given language in the tool-chain of the provider.
|
* Finds a tool handling given language in the tool-chain of the provider.
|
||||||
* This returns the first tool found.
|
* This returns the first tool found or empty {@link Optional}.
|
||||||
* @since 8.8
|
* @since 8.8
|
||||||
*/
|
*/
|
||||||
protected ITool getTool(String languageId) {
|
protected Optional<ITool> languageTool(String languageId) {
|
||||||
if (languageId == null) {
|
if (languageId == null) {
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentCfgDescription == null) {
|
if (currentCfgDescription == null) {
|
||||||
ITool tool = toolMap.get(languageId);
|
ITool tool = toolMap.get(languageId);
|
||||||
if (tool != null) {
|
if (tool != null) {
|
||||||
return tool;
|
return Optional.of(tool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +104,7 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
|
||||||
ManagedBuilderCorePlugin
|
ManagedBuilderCorePlugin
|
||||||
.error("Unable to find tool in toolchain=" + toolchainId + " for language=" + languageId); //$NON-NLS-1$ //$NON-NLS-2$
|
.error("Unable to find tool in toolchain=" + toolchainId + " for language=" + languageId); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
return tool;
|
return Optional.ofNullable(tool);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,34 +127,41 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getCompilerCommand(String languageId) {
|
protected String getCompilerCommand(String languageId) {
|
||||||
ITool tool = getTool(languageId);
|
Optional<String> found = languageTool(languageId)//
|
||||||
String compilerCommand = tool != null ? tool.getToolCommand() : ""; //$NON-NLS-1$
|
.flatMap(t -> Optional.of(t.getToolCommand()));
|
||||||
if (compilerCommand.isEmpty()) {
|
if (!found.isPresent()) {
|
||||||
ManagedBuilderCorePlugin.error("Unable to find compiler command in toolchain=" + getToolchainId()); //$NON-NLS-1$
|
ManagedBuilderCorePlugin
|
||||||
|
.error(NLS.bind("Unable to find compiler command in toolchain={0}", getToolchainId())); //$NON-NLS-1$
|
||||||
|
return ""; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
return compilerCommand;
|
return found.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getSpecFileExtension(String languageId) {
|
protected String getSpecFileExtension(String languageId) {
|
||||||
String ext = null;
|
Optional<String> found = languageTool(languageId)//
|
||||||
ITool tool = getTool(languageId);
|
.flatMap(t -> Optional.of(t.getAllInputExtensions()))//
|
||||||
String[] srcFileExtensions = tool != null ? tool.getAllInputExtensions() : null;
|
.flatMap(e -> Arrays.asList(e).stream().findFirst());
|
||||||
if (srcFileExtensions != null && srcFileExtensions.length > 0) {
|
if (!found.isPresent()) {
|
||||||
ext = srcFileExtensions[0];
|
ManagedBuilderCorePlugin.error(NLS.bind("Unable to find file extension for language {0}", languageId)); //$NON-NLS-1$
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
if (ext == null || ext.isEmpty()) {
|
String firstInput = found.get();
|
||||||
ManagedBuilderCorePlugin.error("Unable to find file extension for language " + languageId); //$NON-NLS-1$
|
if (firstInput == null || firstInput.isEmpty()) {
|
||||||
|
//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 ext;
|
return firstInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getToolOptions(String languageId) {
|
protected String getToolOptions(String languageId) {
|
||||||
String flags = ""; //$NON-NLS-1$
|
Optional<IOption[]> found = languageTool(languageId).flatMap(t -> Optional.of(t.getOptions()));
|
||||||
ITool tool = getTool(languageId);
|
if (!found.isPresent()) {
|
||||||
if (tool != null) {
|
return ""; //$NON-NLS-1$
|
||||||
IOption[] options = tool.getOptions();
|
}
|
||||||
|
StringBuilder flags = new StringBuilder();
|
||||||
|
IOption[] options = found.get();
|
||||||
for (IOption option : options) {
|
for (IOption option : options) {
|
||||||
if (option.isForScannerDiscovery()) {
|
if (option.isForScannerDiscovery()) {
|
||||||
try {
|
try {
|
||||||
|
@ -187,15 +198,14 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if (optionValue != null) {
|
if (optionValue != null) {
|
||||||
flags = flags + ' ' + optionValue.trim();
|
flags.append(' ').append(optionValue.trim());
|
||||||
}
|
}
|
||||||
} catch (BuildException e) {
|
} catch (BuildException e) {
|
||||||
ManagedBuilderCorePlugin.log(e);
|
ManagedBuilderCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return flags.toString().trim();
|
||||||
return flags.trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue