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

More cleanup

This commit is contained in:
Andrew Gvozdev 2012-03-27 14:20:13 -04:00
parent c97867bc23
commit 04bdc42203
4 changed files with 138 additions and 108 deletions

View file

@ -57,14 +57,6 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$
private class MockBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector {
@Override
protected void startupForLanguage(String languageId) throws CoreException {
super.startupForLanguage(languageId);
}
@Override
protected void shutdownForLanguage() {
super.shutdownForLanguage();
}
@Override
protected List<String> parseForOptions(String line) {
return null;
@ -73,6 +65,19 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
protected AbstractOptionParser[] getOptionParsers() {
return null;
}
@Override
protected String getCompilerCommand(String languageId) {
return null;
}
@Override
protected void startupForLanguage(String languageId) throws CoreException {
super.startupForLanguage(languageId);
}
@Override
protected void shutdownForLanguage() {
super.shutdownForLanguage();
}
}
private class MockBuiltinSpecsDetectorExecutedFlag extends AbstractBuiltinSpecsDetector {
@ -84,6 +89,11 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
protected AbstractOptionParser[] getOptionParsers() {
return null;
}
@Override
protected String getCompilerCommand(String languageId) {
return null;
}
@Override
protected void execute() {
super.execute();
@ -100,13 +110,14 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
};
@Override
protected int runProgramForLanguage(String languageId, String command, String[] envp, URI workingDirectoryURI, OutputStream consoleOut, OutputStream consoleErr, IProgressMonitor monitor) throws CoreException, IOException {
printLine(consoleOut, "#define MACRO VALUE");
String line = "#define MACRO VALUE";
consoleOut.write((line + '\n').getBytes());
consoleOut.flush();
return ICommandLauncher.OK;
}
@Override
protected IStatus runForEachLanguage(ICConfigurationDescription cfgDescription, URI workingDirectoryURI,
String[] env, IProgressMonitor monitor) {
return super.runForEachLanguage(cfgDescription, workingDirectoryURI, env, monitor);
protected IStatus runForEachLanguage(IProgressMonitor monitor) {
return super.runForEachLanguage(monitor);
}
@Override
protected List<String> parseForOptions(final String line) {
@ -116,6 +127,10 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
protected AbstractOptionParser[] getOptionParsers() {
return optionParsers;
}
@Override
protected String getCompilerCommand(String languageId) {
return null;
}
}
@Override
@ -338,7 +353,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
{
// test AbstractBuiltinSpecsDetector.processLine(...) flow
MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector();
provider.runForEachLanguage(null, null, null, null);
provider.startup(null, null);
provider.runForEachLanguage(null);
provider.shutdown();
}
}
@ -352,7 +369,10 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector();
provider.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID);}});
provider.runForEachLanguage(cfgDescription, null, null, null);
provider.startup(cfgDescription, null);
provider.runForEachLanguage(null);
provider.shutdown();
assertFalse(provider.isEmpty());
List<ICLanguageSettingEntry> noentries = provider.getSettingEntries(null, null, null);
@ -367,7 +387,10 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
MockConsoleBuiltinSpecsDetector provider = new MockConsoleBuiltinSpecsDetector();
provider.setLanguageScope(new ArrayList<String>() {{add(LANGUAGE_ID);}});
provider.runForEachLanguage(null, null, null, null);
provider.startup(null, null);
provider.runForEachLanguage(null);
provider.shutdown();
assertFalse(provider.isEmpty());
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, null, LANGUAGE_ID);

View file

@ -68,45 +68,44 @@ import org.w3c.dom.Element;
* @since 7.2
*/
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.make.core.scannerconfig.AbstractBuiltinSpecsDetector";
private static final int MONITOR_SCALE = 100;
private static final int TICKS_CLEAN_MARKERS = 1 * MONITOR_SCALE;
private static final int TICKS_RUN_FOR_ONE_LANGUAGE = 10 * MONITOR_SCALE;
private static final int TICKS_SERIALIZATION = 1 * MONITOR_SCALE;
private static final int TICKS_OUTPUT_PARSING = 1 * MONITOR_SCALE;
private static final int TICKS_REMOVE_MARKERS = 1 * MONITOR_SCALE;
private static final int TICKS_EXECUTE_COMMAND = 1 * MONITOR_SCALE;
private static final String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
private static final String PLUGIN_CDT_MAKE_UI_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$
private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$
private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$
protected static final String COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$
protected static final String SPEC_FILE_MACRO = "${INPUTS}"; //$NON-NLS-1$
protected static final String SPEC_EXT_MACRO = "${EXT}"; //$NON-NLS-1$
protected static final String SPEC_FILE_BASE = "spec"; //$NON-NLS-1$
private SDMarkerGenerator markerGenerator = new SDMarkerGenerator();
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;
private static final int TICKS_SERIALIZATION = 1 * MONITOR_SCALE;
private static final int TICKS_OUTPUT_PARSING = 1 * MONITOR_SCALE;
private static final int TICKS_EXECUTE_COMMAND = 1 * MONITOR_SCALE;
private String currentCommandResolved = null;
protected List<ICLanguageSettingEntry> detectedSettingEntries = null;
private static final String CDT_MAKE_UI_PLUGIN_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$
private static final String DEFAULT_CONSOLE_ICON = "icons/obj16/inspect_system.gif"; //$NON-NLS-1$
protected boolean isExecuted = false;
protected int collected = 0;
private boolean isConsoleEnabled = false;
protected java.io.File specFile = null;
protected boolean preserveSpecFile = false;
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 String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
protected URI mappedRootURI = null;
protected URI buildDirURI = null;
protected java.io.File specFile = null;
protected boolean preserveSpecFile = false;
protected List<ICLanguageSettingEntry> detectedSettingEntries = null;
protected int collected = 0;
protected boolean isExecuted = false;
private BuildRunnerHelper buildRunnerHelper;
private SDMarkerGenerator markerGenerator = new SDMarkerGenerator();
private boolean isConsoleEnabled = false;
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";
protected static final String ATTR_PROVIDER = "provider"; //$NON-NLS-1$
@ -127,20 +126,20 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
Job markerJob = new Job("Adding Scanner Discovery markers") {
@Override
protected IStatus run(IProgressMonitor monitor) {
// Try to find matching markers and don't put in duplicates
// Avoid duplicates as different languages can generate identical errors
try {
IMarker[] cur = problemMarkerInfo.file.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
if ((cur != null) && (cur.length > 0)) {
for (int i = 0; i < cur.length; i++) {
int sev = ((Integer) cur[i].getAttribute(IMarker.SEVERITY)).intValue();
String mesg = (String) cur[i].getAttribute(IMarker.MESSAGE);
if (sev == problemMarkerInfo.severity && mesg.equals(problemMarkerInfo.description)) {
IMarker[] markers = problemMarkerInfo.file.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
for (IMarker marker : markers) {
int sev = ((Integer) marker.getAttribute(IMarker.SEVERITY)).intValue();
if (sev == problemMarkerInfo.severity) {
String msg = (String) marker.getAttribute(IMarker.MESSAGE);
if (msg != null && msg.equals(problemMarkerInfo.description)) {
return Status.OK_STATUS;
}
}
}
} catch (CoreException e) {
return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error removing markers.", e);
return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error checking markers.", e); //$NON-NLS-1$
}
try {
@ -155,7 +154,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
marker.setAttribute(IMarker.LOCATION, "Project Properties, C++ Preprocessor Include.../Providers, [" + providerName + "] options");
}
} catch (CoreException e) {
return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error adding markers.", e);
return new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error adding markers.", e); //$NON-NLS-1$
}
return Status.OK_STATUS;
@ -176,7 +175,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
}
}
} catch (CoreException e) {
MakeCorePlugin.log(e);
MakeCorePlugin.log(new Status(Status.ERROR, MakeCorePlugin.getUniqueIdentifier(), "Error deleting markers.", e)); //$NON-NLS-1$
}
}
@ -200,6 +199,13 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
}
}
/**
* TODO
* @param languageId
* @return
*/
protected abstract String getCompilerCommand(String languageId);
/**
* The command to run. Some macros could be specified in there:
* <ul>
@ -210,7 +216,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
* The parameter could be taken from the extension
* in {@code plugin.xml} or from property file.
*
* @return the command to run.
* @return the command to run or empty string if command is not defined.
*/
public String getCommand() {
return getProperty(ATTR_PARAMETER);
@ -234,7 +240,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
protected String resolveCommand(String languageId) throws CoreException {
String cmd = getCommand();
if (cmd != null && (cmd.contains(COMPILER_MACRO) || cmd.contains(SPEC_FILE_MACRO) || cmd.contains(SPEC_EXT_MACRO))) {
if (cmd != null) {
if (cmd.contains(COMPILER_MACRO)) {
String compiler = getCompilerCommand(languageId);
if (compiler != null)
@ -259,7 +265,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
*/
@Override
protected String parseForResourceName(String line) {
// This works as if workspace-wide
// Returning null works as if workspace-wide
return null;
}
@ -271,7 +277,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
@Override
protected URI getMappedRootURI(IResource sourceFile, String parsedResourceName) {
if (mappedRootURI==null) {
if (mappedRootURI == null) {
mappedRootURI = super.getMappedRootURI(sourceFile, parsedResourceName);
}
return mappedRootURI;
@ -305,7 +311,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
super.startup(cfgDescription, cwdTracker);
mappedRootURI = null;
buildDirURI = null;
buildDirURI = super.getBuildDirURI(mappedRootURI);
}
@Override
@ -333,7 +339,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
IStatus status;
try {
startup(currentCfgDescription, null);
status = runForEachLanguage(currentCfgDescription, null, null, monitor);
status = runForEachLanguage(monitor);
} catch (CoreException e) {
MakeCorePlugin.log(e);
status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e);
@ -373,7 +379,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
/**
* TODO
*/
protected IStatus runForEachLanguage(ICConfigurationDescription cfgDescription, URI workingDirectoryURI, String[] env, IProgressMonitor monitor) {
protected IStatus runForEachLanguage(IProgressMonitor monitor) {
MultiStatus status = new MultiStatus(MakeCorePlugin.PLUGIN_ID, IStatus.OK, "Problem running CDT Scanner Discovery provider " + getId(), null);
if (monitor == null) {
@ -385,7 +391,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
List<String> languageIds = getLanguageScope();
if (languageIds != null) {
monitor.beginTask("CDT Scanner Discovery", TICKS_CLEAN_MARKERS + languageIds.size()*TICKS_RUN_FOR_ONE_LANGUAGE + TICKS_SERIALIZATION);
monitor.beginTask("CDT Scanner Discovery", TICKS_REMOVE_MARKERS + languageIds.size()*TICKS_RUN_FOR_ONE_LANGUAGE + TICKS_SERIALIZATION);
IResource markersResource = currentProject != null ? currentProject : ResourcesPlugin.getWorkspace().getRoot();
@ -394,22 +400,22 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
if (monitor.isCanceled())
throw new OperationCanceledException();
monitor.worked(TICKS_CLEAN_MARKERS);
monitor.worked(TICKS_REMOVE_MARKERS);
for (String languageId : languageIds) {
List<ICLanguageSettingEntry> oldEntries = getSettingEntries(cfgDescription, null, languageId);
List<ICLanguageSettingEntry> oldEntries = getSettingEntries(currentCfgDescription, null, languageId);
try {
startupForLanguage(languageId);
runForLanguage(languageId, currentCommandResolved, env, workingDirectoryURI, new SubProgressMonitor(monitor, TICKS_RUN_FOR_ONE_LANGUAGE));
runForLanguage(new SubProgressMonitor(monitor, TICKS_RUN_FOR_ONE_LANGUAGE));
} catch (Exception e) {
IStatus s = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e);
IStatus s = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e); //$NON-NLS-1$
MakeCorePlugin.log(s);
status.merge(s);
} finally {
shutdownForLanguage();
}
if (!isChanged) {
List<ICLanguageSettingEntry> newEntries = getSettingEntries(cfgDescription, null, languageId);
List<ICLanguageSettingEntry> newEntries = getSettingEntries(currentCfgDescription, null, languageId);
isChanged = newEntries != oldEntries;
}
@ -426,16 +432,12 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
monitor.worked(TICKS_SERIALIZATION);
} catch (OperationCanceledException e) {
// user chose to cancel operation, do not threaten them with error reporting
// user chose to cancel operation, do not threaten them with red error signs
} catch (Exception e) {
status.merge(new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e));
MakeCorePlugin.log(status);
} finally {
monitor.done();
// release resources
shutdown();
currentCfgDescription = cfgDescription; // current description gets cleared in super.shutdown(), keep it
}
return status;
@ -444,7 +446,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
protected void startupForLanguage(String languageId) throws CoreException {
currentLanguageId = languageId;
specFile = null; // init before calling resolveCommand(), can be set there
specFile = null; // init *before* calling resolveCommand(), can be set there
currentCommandResolved = resolveCommand(currentLanguageId);
detectedSettingEntries = new ArrayList<ICLanguageSettingEntry>();
@ -472,14 +474,14 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
currentLanguageId = null;
}
private void runForLanguage(String languageId, String command, String[] envp, URI workingDirectoryURI, IProgressMonitor monitor) throws CoreException {
private void runForLanguage(IProgressMonitor monitor) throws CoreException {
buildRunnerHelper = new BuildRunnerHelper(currentProject);
if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
monitor.beginTask("Running scanner discovery: " + getName(), TICKS_REMOVE_MARKERS + TICKS_EXECUTE_COMMAND + TICKS_OUTPUT_PARSING);
monitor.beginTask("Running scanner discovery: " + getName(), TICKS_EXECUTE_COMMAND + TICKS_OUTPUT_PARSING);
IConsole console;
if (isConsoleEnabled) {
@ -490,42 +492,43 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
}
console.start(currentProject);
IPath program = new Path("");
ICommandLauncher launcher = new CommandLauncher();
launcher.setProject(currentProject);
IPath program = new Path(""); //$NON-NLS-1$
String[] args = new String[0];
String[] cmdArray = CommandLineUtil.argumentsToArray(command);
String[] cmdArray = CommandLineUtil.argumentsToArray(currentCommandResolved);
if (cmdArray != null && cmdArray.length > 0) {
program = new Path(cmdArray[0]);
if (cmdArray.length>1) {
if (cmdArray.length > 1) {
args = new String[cmdArray.length-1];
System.arraycopy(cmdArray, 1, args, 0, args.length);
}
}
ICommandLauncher launcher = new CommandLauncher();
launcher.setProject(currentProject);
String[] envp = BuildRunnerHelper.getEnvp(currentCfgDescription);
// Using GMAKE_ERROR_PARSER_ID as it can handle generated error messages
ErrorParserManager epm = new ErrorParserManager(currentProject, markerGenerator, new String[] {GMAKE_ERROR_PARSER_ID});
ErrorParserManager epm = new ErrorParserManager(currentProject, buildDirURI, markerGenerator, new String[] {GMAKE_ERROR_PARSER_ID});
ConsoleParserAdapter consoleParser = new ConsoleParserAdapter();
consoleParser.startup(currentCfgDescription, epm);
List<IConsoleParser> parsers = new ArrayList<IConsoleParser>();
parsers.add(consoleParser);
buildRunnerHelper.setLaunchParameters(launcher, program, args, workingDirectoryURI, envp);
buildRunnerHelper.setLaunchParameters(launcher, program, args, buildDirURI, envp);
buildRunnerHelper.prepareStreams(epm, parsers, console, new SubProgressMonitor(monitor, TICKS_OUTPUT_PARSING));
buildRunnerHelper.removeOldMarkers(currentProject, new SubProgressMonitor(monitor, TICKS_REMOVE_MARKERS, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
buildRunnerHelper.greeting("Running scanner discovery: " + getName());
OutputStream outStream = buildRunnerHelper.getOutputStream();
OutputStream errStream = buildRunnerHelper.getErrorStream();
runProgramForLanguage(languageId, command, envp, workingDirectoryURI, outStream, errStream, new SubProgressMonitor(monitor, TICKS_EXECUTE_COMMAND, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
runProgramForLanguage(currentLanguageId, currentCommandResolved, envp, buildDirURI, outStream, errStream,
new SubProgressMonitor(monitor, TICKS_EXECUTE_COMMAND, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
buildRunnerHelper.close();
buildRunnerHelper.goodbye();
} catch (Exception e) {
// AG TODO - better message
Status status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Internal error running scanner discovery", e);
MakeCorePlugin.log(new CoreException(status));
} finally {
@ -548,7 +551,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
@Override
protected void setSettingEntries(List<ICLanguageSettingEntry> entries) {
// Builtin specs detectors collect entries not per line but for the whole output
if (entries!=null)
if (entries != null)
detectedSettingEntries.addAll(entries);
}
@ -563,19 +566,12 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
ILanguage ld = LanguageManager.getInstance().getLanguage(currentLanguageId);
String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId;
String consoleName = getName() + ", " + ld.getName();
URL defaultIcon = Platform.getBundle(PLUGIN_CDT_MAKE_UI_ID).getEntry("icons/obj16/inspect_system.gif");
URL defaultIcon = Platform.getBundle(CDT_MAKE_UI_PLUGIN_ID).getEntry(DEFAULT_CONSOLE_ICON);
IConsole console = CCorePlugin.getDefault().getConsole(extConsoleId, consoleId, consoleName, defaultIcon);
return console;
}
protected String getCompilerCommand(String languageId) {
IStatus status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Provider "+getId()
+" unable to find the compiler tool for language " + languageId);
MakeCorePlugin.log(new CoreException(status));
return null;
}
protected String getSpecFile(String languageId) {
String specExt = getSpecFileExtension(languageId);
String ext = ""; //$NON-NLS-1$
@ -622,20 +618,11 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
}
if (ext == null) {
MakeCorePlugin.log(new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Unable to find file extension for language "+languageId));
MakeCorePlugin.log(new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Unable to find file extension for language " + languageId)); //$NON-NLS-1$
}
return ext;
}
protected void printLine(OutputStream stream, String msg) {
try {
stream.write((msg + NEWLINE).getBytes());
stream.flush();
} catch (IOException e) {
MakeCorePlugin.log(e);
}
}
@Override
public Element serializeAttributes(Element parentElement) {
Element elementProvider = super.serializeAttributes(parentElement);

View file

@ -420,7 +420,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
}
private IResource findResource(String parsedResourceName) {
if (parsedResourceName==null)
if (parsedResourceName == null)
return null;
IResource sourceFile = null;

View file

@ -27,9 +27,12 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.ICommandLauncher;
import org.eclipse.cdt.core.IConsoleParser;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.resources.RefreshScopeManager;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.utils.EFSExtensionManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -471,19 +474,36 @@ public class BuildRunnerHelper implements Closeable {
}
/**
* Convert map of environment variables to array of "var=value"
* Get environment variables from configuration as array of "var=value" suitable
* for using as "envp" with Runtime.exec(String[] cmdarray, String[] envp, File dir)
*
* @param envMap - map of environment variables
* @return String array of environment variables in format "var=value" suitable for using
* as "envp" with Runtime.exec(String[] cmdarray, String[] envp, File dir)
* @return String array of environment variables in format "var=value"
*/
public static String[] envMapToEnvp(Map<String, String> envMap) {
// Convert into env strings
List<String> strings= new ArrayList<String>(envMap.size());
// Convert into envp strings
List<String> strings = new ArrayList<String>(envMap.size());
for (Entry<String, String> entry : envMap.entrySet()) {
StringBuffer buffer= new StringBuffer(entry.getKey());
buffer.append('=').append(entry.getValue());
strings.add(buffer.toString());
strings.add(entry.getKey() + '=' + entry.getValue());
}
return strings.toArray(new String[strings.size()]);
}
/**
* Get environment variables from configuration as array of "var=value" suitable
* for using as "envp" with Runtime.exec(String[] cmdarray, String[] envp, File dir)
*
* @param cfgDescription - configuration description
* @return String array of environment variables in format "var=value"
*/
public static String[] getEnvp(ICConfigurationDescription cfgDescription) {
IEnvironmentVariableManager mngr = CCorePlugin.getDefault().getBuildEnvironmentManager();
IEnvironmentVariable[] vars = mngr.getVariables(cfgDescription, true);
// Convert into envp strings
List<String> strings = new ArrayList<String>(vars.length);
for (IEnvironmentVariable var : vars) {
strings.add(var.getName() + '=' + var.getValue());
}
return strings.toArray(new String[strings.size()]);