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

View file

@ -68,45 +68,44 @@ import org.w3c.dom.Element;
* @since 7.2 * @since 7.2
*/ */
public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSettingsOutputScanner implements ICListenerAgent { 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"; 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 COMPILER_MACRO = "${COMMAND}"; //$NON-NLS-1$
protected static final String SPEC_FILE_MACRO = "${INPUTS}"; //$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_EXT_MACRO = "${EXT}"; //$NON-NLS-1$
protected static final String SPEC_FILE_BASE = "spec"; //$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; private static final String CDT_MAKE_UI_PLUGIN_ID = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$
protected List<ICLanguageSettingEntry> detectedSettingEntries = null; private static final String DEFAULT_CONSOLE_ICON = "icons/obj16/inspect_system.gif"; //$NON-NLS-1$
protected boolean isExecuted = false; private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$
protected int collected = 0; private static final String ATTR_PARAMETER = "parameter"; //$NON-NLS-1$
private static final String ATTR_CONSOLE = "console"; //$NON-NLS-1$
private boolean isConsoleEnabled = false; private static final String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
protected java.io.File specFile = null;
protected boolean preserveSpecFile = false;
protected URI mappedRootURI = null; protected URI mappedRootURI = null;
protected URI buildDirURI = 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 BuildRunnerHelper buildRunnerHelper;
private SDMarkerGenerator markerGenerator = new SDMarkerGenerator();
private boolean isConsoleEnabled = false;
private String currentCommandResolved = null;
private class SDMarkerGenerator implements IMarkerGenerator { 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 // 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 SCANNER_DISCOVERY_PROBLEM_MARKER = "org.eclipse.cdt.managedbuilder.core.scanner.discovery.problem";
protected static final String ATTR_PROVIDER = "provider"; //$NON-NLS-1$ 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") { Job markerJob = new Job("Adding Scanner Discovery markers") {
@Override @Override
protected IStatus run(IProgressMonitor monitor) { 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 { try {
IMarker[] cur = problemMarkerInfo.file.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); IMarker[] markers = problemMarkerInfo.file.findMarkers(SDMarkerGenerator.SCANNER_DISCOVERY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
if ((cur != null) && (cur.length > 0)) { for (IMarker marker : markers) {
for (int i = 0; i < cur.length; i++) { int sev = ((Integer) marker.getAttribute(IMarker.SEVERITY)).intValue();
int sev = ((Integer) cur[i].getAttribute(IMarker.SEVERITY)).intValue(); if (sev == problemMarkerInfo.severity) {
String mesg = (String) cur[i].getAttribute(IMarker.MESSAGE); String msg = (String) marker.getAttribute(IMarker.MESSAGE);
if (sev == problemMarkerInfo.severity && mesg.equals(problemMarkerInfo.description)) { if (msg != null && msg.equals(problemMarkerInfo.description)) {
return Status.OK_STATUS; return Status.OK_STATUS;
} }
} }
} }
} catch (CoreException e) { } 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 { try {
@ -155,7 +154,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
marker.setAttribute(IMarker.LOCATION, "Project Properties, C++ Preprocessor Include.../Providers, [" + providerName + "] options"); marker.setAttribute(IMarker.LOCATION, "Project Properties, C++ Preprocessor Include.../Providers, [" + providerName + "] options");
} }
} catch (CoreException e) { } 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; return Status.OK_STATUS;
@ -176,7 +175,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
} }
} }
} catch (CoreException e) { } 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: * The command to run. Some macros could be specified in there:
* <ul> * <ul>
@ -210,7 +216,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
* The parameter could be taken from the extension * The parameter could be taken from the extension
* in {@code plugin.xml} or from property file. * 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() { public String getCommand() {
return getProperty(ATTR_PARAMETER); return getProperty(ATTR_PARAMETER);
@ -234,7 +240,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
protected String resolveCommand(String languageId) throws CoreException { protected String resolveCommand(String languageId) throws CoreException {
String cmd = getCommand(); 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)) { if (cmd.contains(COMPILER_MACRO)) {
String compiler = getCompilerCommand(languageId); String compiler = getCompilerCommand(languageId);
if (compiler != null) if (compiler != null)
@ -259,7 +265,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
*/ */
@Override @Override
protected String parseForResourceName(String line) { protected String parseForResourceName(String line) {
// This works as if workspace-wide // Returning null works as if workspace-wide
return null; return null;
} }
@ -305,7 +311,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
super.startup(cfgDescription, cwdTracker); super.startup(cfgDescription, cwdTracker);
mappedRootURI = null; mappedRootURI = null;
buildDirURI = null; buildDirURI = super.getBuildDirURI(mappedRootURI);
} }
@Override @Override
@ -333,7 +339,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
IStatus status; IStatus status;
try { try {
startup(currentCfgDescription, null); startup(currentCfgDescription, null);
status = runForEachLanguage(currentCfgDescription, null, null, monitor); status = runForEachLanguage(monitor);
} catch (CoreException e) { } catch (CoreException e) {
MakeCorePlugin.log(e); MakeCorePlugin.log(e);
status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", 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 * 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); MultiStatus status = new MultiStatus(MakeCorePlugin.PLUGIN_ID, IStatus.OK, "Problem running CDT Scanner Discovery provider " + getId(), null);
if (monitor == null) { if (monitor == null) {
@ -385,7 +391,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
List<String> languageIds = getLanguageScope(); List<String> languageIds = getLanguageScope();
if (languageIds != null) { 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(); IResource markersResource = currentProject != null ? currentProject : ResourcesPlugin.getWorkspace().getRoot();
@ -394,22 +400,22 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
if (monitor.isCanceled()) if (monitor.isCanceled())
throw new OperationCanceledException(); throw new OperationCanceledException();
monitor.worked(TICKS_CLEAN_MARKERS); monitor.worked(TICKS_REMOVE_MARKERS);
for (String languageId : languageIds) { for (String languageId : languageIds) {
List<ICLanguageSettingEntry> oldEntries = getSettingEntries(cfgDescription, null, languageId); List<ICLanguageSettingEntry> oldEntries = getSettingEntries(currentCfgDescription, null, languageId);
try { try {
startupForLanguage(languageId); 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) { } 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); MakeCorePlugin.log(s);
status.merge(s); status.merge(s);
} finally { } finally {
shutdownForLanguage(); shutdownForLanguage();
} }
if (!isChanged) { if (!isChanged) {
List<ICLanguageSettingEntry> newEntries = getSettingEntries(cfgDescription, null, languageId); List<ICLanguageSettingEntry> newEntries = getSettingEntries(currentCfgDescription, null, languageId);
isChanged = newEntries != oldEntries; isChanged = newEntries != oldEntries;
} }
@ -426,16 +432,12 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
monitor.worked(TICKS_SERIALIZATION); monitor.worked(TICKS_SERIALIZATION);
} catch (OperationCanceledException e) { } 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) { } catch (Exception e) {
status.merge(new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e)); status.merge(new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error running Builtin Specs Detector", e));
MakeCorePlugin.log(status); MakeCorePlugin.log(status);
} finally { } finally {
monitor.done(); monitor.done();
// release resources
shutdown();
currentCfgDescription = cfgDescription; // current description gets cleared in super.shutdown(), keep it
} }
return status; return status;
@ -444,7 +446,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
protected void startupForLanguage(String languageId) throws CoreException { protected void startupForLanguage(String languageId) throws CoreException {
currentLanguageId = languageId; 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); currentCommandResolved = resolveCommand(currentLanguageId);
detectedSettingEntries = new ArrayList<ICLanguageSettingEntry>(); detectedSettingEntries = new ArrayList<ICLanguageSettingEntry>();
@ -472,14 +474,14 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
currentLanguageId = null; 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); buildRunnerHelper = new BuildRunnerHelper(currentProject);
if (monitor == null) { if (monitor == null) {
monitor = new NullProgressMonitor(); monitor = new NullProgressMonitor();
} }
try { 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; IConsole console;
if (isConsoleEnabled) { if (isConsoleEnabled) {
@ -490,9 +492,12 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
} }
console.start(currentProject); 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[] args = new String[0];
String[] cmdArray = CommandLineUtil.argumentsToArray(command); String[] cmdArray = CommandLineUtil.argumentsToArray(currentCommandResolved);
if (cmdArray != null && cmdArray.length > 0) { if (cmdArray != null && cmdArray.length > 0) {
program = new Path(cmdArray[0]); program = new Path(cmdArray[0]);
if (cmdArray.length > 1) { if (cmdArray.length > 1) {
@ -501,31 +506,29 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
} }
} }
ICommandLauncher launcher = new CommandLauncher(); String[] envp = BuildRunnerHelper.getEnvp(currentCfgDescription);
launcher.setProject(currentProject);
// Using GMAKE_ERROR_PARSER_ID as it can handle generated error messages // 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(); ConsoleParserAdapter consoleParser = new ConsoleParserAdapter();
consoleParser.startup(currentCfgDescription, epm); consoleParser.startup(currentCfgDescription, epm);
List<IConsoleParser> parsers = new ArrayList<IConsoleParser>(); List<IConsoleParser> parsers = new ArrayList<IConsoleParser>();
parsers.add(consoleParser); 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.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()); buildRunnerHelper.greeting("Running scanner discovery: " + getName());
OutputStream outStream = buildRunnerHelper.getOutputStream(); OutputStream outStream = buildRunnerHelper.getOutputStream();
OutputStream errStream = buildRunnerHelper.getErrorStream(); 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.close();
buildRunnerHelper.goodbye(); buildRunnerHelper.goodbye();
} catch (Exception e) { } catch (Exception e) {
// AG TODO - better message
Status status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Internal error running scanner discovery", e); Status status = new Status(IStatus.ERROR, MakeCorePlugin.PLUGIN_ID, "Internal error running scanner discovery", e);
MakeCorePlugin.log(new CoreException(status)); MakeCorePlugin.log(new CoreException(status));
} finally { } finally {
@ -563,19 +566,12 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
ILanguage ld = LanguageManager.getInstance().getLanguage(currentLanguageId); ILanguage ld = LanguageManager.getInstance().getLanguage(currentLanguageId);
String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId; String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + getId() + '.' + currentLanguageId;
String consoleName = getName() + ", " + ld.getName(); 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); IConsole console = CCorePlugin.getDefault().getConsole(extConsoleId, consoleId, consoleName, defaultIcon);
return console; 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) { protected String getSpecFile(String languageId) {
String specExt = getSpecFileExtension(languageId); String specExt = getSpecFileExtension(languageId);
String ext = ""; //$NON-NLS-1$ String ext = ""; //$NON-NLS-1$
@ -622,20 +618,11 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
} }
if (ext == null) { 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; return ext;
} }
protected void printLine(OutputStream stream, String msg) {
try {
stream.write((msg + NEWLINE).getBytes());
stream.flush();
} catch (IOException e) {
MakeCorePlugin.log(e);
}
}
@Override @Override
public Element serializeAttributes(Element parentElement) { public Element serializeAttributes(Element parentElement) {
Element elementProvider = super.serializeAttributes(parentElement); Element elementProvider = super.serializeAttributes(parentElement);

View file

@ -27,9 +27,12 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ErrorParserManager; import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.ICommandLauncher; import org.eclipse.cdt.core.ICommandLauncher;
import org.eclipse.cdt.core.IConsoleParser; 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.model.ICModelMarker;
import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.resources.RefreshScopeManager; import org.eclipse.cdt.core.resources.RefreshScopeManager;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.utils.EFSExtensionManager; import org.eclipse.cdt.utils.EFSExtensionManager;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; 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 * @param envMap - map of environment variables
* @return String array of environment variables in format "var=value" suitable for using * @return String array of environment variables in format "var=value"
* as "envp" with Runtime.exec(String[] cmdarray, String[] envp, File dir)
*/ */
public static String[] envMapToEnvp(Map<String, String> envMap) { public static String[] envMapToEnvp(Map<String, String> envMap) {
// Convert into env strings // Convert into envp strings
List<String> strings = new ArrayList<String>(envMap.size()); List<String> strings = new ArrayList<String>(envMap.size());
for (Entry<String, String> entry : envMap.entrySet()) { for (Entry<String, String> entry : envMap.entrySet()) {
StringBuffer buffer= new StringBuffer(entry.getKey()); strings.add(entry.getKey() + '=' + entry.getValue());
buffer.append('=').append(entry.getValue()); }
strings.add(buffer.toString());
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()]); return strings.toArray(new String[strings.size()]);