Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gvozdev2012-03-16 18:23:55 -0400
committerAndrew Gvozdev2012-03-16 18:23:55 -0400
commit626c0cdaf397d7d94134ea7478d58ab139f17cce (patch)
tree572cb0fdb1280e0b9fd89d8b412dfbe420eea7c1 /build/org.eclipse.cdt.make.core
parentb36fe677457c4960c4f094a595228c136aa0feeb (diff)
downloadorg.eclipse.cdt-626c0cdaf397d7d94134ea7478d58ab139f17cce.tar.gz
org.eclipse.cdt-626c0cdaf397d7d94134ea7478d58ab139f17cce.tar.xz
org.eclipse.cdt-626c0cdaf397d7d94134ea7478d58ab139f17cce.zip
bug 261976: CommandLauncher to report about $PATH problems and related
clean-up
Diffstat (limited to 'build/org.eclipse.cdt.make.core')
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java14
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeMessages.properties5
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/DefaultRunSIProvider.java310
3 files changed, 144 insertions, 185 deletions
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java
index df6f7d2ee5..79a7880705 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java
@@ -256,24 +256,12 @@ public class MakeBuilder extends ACBuilder {
getProject().setSessionProperty(qName, !monitor.isCanceled() && !isClean ? new Integer(streamMon.getWorkDone()) : null);
if (errMsg != null) {
- StringBuffer buf = new StringBuffer(buildCommand.toString() + " "); //$NON-NLS-1$
- for (String buildArgument : buildArguments) {
- buf.append(buildArgument);
- buf.append(' ');
- }
-
- String errorDesc = MakeMessages.getFormattedString("MakeBuilder.buildError", buf.toString()); //$NON-NLS-1$
- buf = new StringBuffer(errorDesc);
- buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$
- buf.append("(").append(errMsg).append(")"); //$NON-NLS-1$ //$NON-NLS-2$
- cos.write(buf.toString().getBytes());
- cos.flush();
+ consoleErr.write((errMsg + '\n').getBytes());
}
stdout.close();
stderr.close();
- monitor.subTask(MakeMessages.getString("MakeBuilder.Creating_Markers")); //$NON-NLS-1$
consoleOut.close();
consoleErr.close();
cos.close();
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeMessages.properties b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeMessages.properties
index dbeb9de63d..7509f90aa4 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeMessages.properties
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeMessages.properties
@@ -13,7 +13,6 @@
AbstractGCCBOPConsoleParser_EnteringDirectory=Entering directory
AbstractGCCBOPConsoleParser_LeavingDirectory=Leaving directory
-MakeBuilder.buildError=Error launching builder ({0})
MakeBuilder.Invoking_Make_Builder=Invoking Make Builder...
MakeBuilder.Invoking_Command=Invoking Command:
MakeBuilder.Updating_project=Updating project...
@@ -41,9 +40,7 @@ ExternalScannerInfoProvider.Reading_Specs=Reading specs ...
ExternalScannerInfoProvider.Invoking_Command=Invoking Command:
ExternalScannerInfoProvider.Parsing_Output=Parsing output ...
ExternalScannerInfoProvider.Creating_Markers=Generating markers ...
-# Error_Prefix affects generation of markers in the Problems view
-ExternalScannerInfoProvider.Error_Prefix=Warning:
-ExternalScannerInfoProvider.Provider_Error=Error launching external scanner info generator ({0})
+ExternalScannerInfoProvider.Provider_Error=Warning: Error launching external scanner info generator ({0})
ExternalScannerInfoProvider.Working_Directory=Working directory: {0}
ExternalScannerInfoProvider.Program_Not_In_Path=Program ''{0}'' is not found in $PATH
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/DefaultRunSIProvider.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/DefaultRunSIProvider.java
index 5dd879706f..19123121aa 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/DefaultRunSIProvider.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/DefaultRunSIProvider.java
@@ -37,7 +37,6 @@ import org.eclipse.cdt.make.internal.core.StreamMonitor;
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigUtil;
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerInfoConsoleParserFactory;
import org.eclipse.cdt.utils.EFSExtensionManager;
-import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
@@ -55,55 +54,53 @@ import org.osgi.service.prefs.BackingStoreException;
* @author vhirsl
*/
public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
- private static final String EXTERNAL_SI_PROVIDER_ERROR = "ExternalScannerInfoProvider.Provider_Error"; //$NON-NLS-1$
private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$
private static final String PREF_CONSOLE_ENABLED = "org.eclipse.cdt.make.core.scanner.discovery.console.enabled"; //$NON-NLS-1$
private static final String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
- private static final String PATH_ENV = "PATH"; //$NON-NLS-1$
- protected IResource resource;
- protected String providerId;
- protected IScannerConfigBuilderInfo2 buildInfo;
- protected IScannerInfoCollector collector;
- // To be initialized by a subclass
- protected IPath fWorkingDirectory;
- protected IPath fCompileCommand;
- protected String[] fCompileArguments;
+ protected IResource resource;
+ protected String providerId;
+ protected IScannerConfigBuilderInfo2 buildInfo;
+ protected IScannerInfoCollector collector;
+ // To be initialized by a subclass
+ protected IPath fWorkingDirectory;
+ protected IPath fCompileCommand;
+ protected String[] fCompileArguments;
- private SCMarkerGenerator markerGenerator = new SCMarkerGenerator();
+ private SCMarkerGenerator markerGenerator = new SCMarkerGenerator();
- @Override
+ @Override
public boolean invokeProvider(IProgressMonitor monitor, IResource resource,
- String providerId, IScannerConfigBuilderInfo2 buildInfo,
- IScannerInfoCollector collector) {
- return invokeProvider(monitor, resource, new InfoContext(resource.getProject()), providerId, buildInfo, collector, null);
- }
+ String providerId, IScannerConfigBuilderInfo2 buildInfo,
+ IScannerInfoCollector collector) {
+ return invokeProvider(monitor, resource, new InfoContext(resource.getProject()), providerId, buildInfo, collector, null);
+ }
- @Override
+ @Override
public boolean invokeProvider(IProgressMonitor monitor,
- IResource resource,
- InfoContext context,
- String providerId,
- IScannerConfigBuilderInfo2 buildInfo,
- IScannerInfoCollector collector,
- Properties env) {
- // initialize fields
- this.resource = resource;
- this.providerId = providerId;
- this.buildInfo = buildInfo;
- this.collector = collector;
-
- IProject currentProject = resource.getProject();
- // call a subclass to initialize protected fields
- if (!initialize()) {
- return false;
- }
- if (monitor == null) {
- monitor = new NullProgressMonitor();
- }
- monitor.beginTask(MakeMessages.getString("ExternalScannerInfoProvider.Reading_Specs"), 100); //$NON-NLS-1$
-
- try {
+ IResource resource,
+ InfoContext context,
+ String providerId,
+ IScannerConfigBuilderInfo2 buildInfo,
+ IScannerInfoCollector collector,
+ Properties env) {
+ // initialize fields
+ this.resource = resource;
+ this.providerId = providerId;
+ this.buildInfo = buildInfo;
+ this.collector = collector;
+
+ IProject currentProject = resource.getProject();
+ // call a subclass to initialize protected fields
+ if (!initialize()) {
+ return false;
+ }
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ monitor.beginTask(MakeMessages.getString("ExternalScannerInfoProvider.Reading_Specs"), 100); //$NON-NLS-1$
+
+ try {
ILanguage language = context.getLanguage();
IConsole console;
if (language!=null && isConsoleEnabled()) {
@@ -114,23 +111,24 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
// that looks in extension points registry and won't find the id
console = CCorePlugin.getDefault().getConsole(MakeCorePlugin.PLUGIN_ID + ".console.hidden"); //$NON-NLS-1$
}
- console.start(currentProject);
- OutputStream cos = console.getOutputStream();
+ console.start(currentProject);
+ OutputStream cos = console.getOutputStream();
- // Before launching give visual cues via the monitor
- monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Reading_Specs")); //$NON-NLS-1$
+ // Before launching give visual cues via the monitor
+ monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Reading_Specs")); //$NON-NLS-1$
- String errMsg = null;
- ICommandLauncher launcher = new CommandLauncher();
- launcher.setProject(currentProject);
- // Print the command for visual interaction.
- launcher.showCommand(true);
+ String errMsg = null;
+ ICommandLauncher launcher = new CommandLauncher();
+ launcher.setProject(currentProject);
+ // Print the command for visual interaction.
+ launcher.showCommand(true);
- String[] comandLineOptions = getCommandLineOptions();
- String params = coligate(comandLineOptions);
+ String[] comandLineOptions = getCommandLineOptions();
+ IPath program = getCommandToLaunch();
+ String params = coligate(comandLineOptions);
- monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Invoking_Command") //$NON-NLS-1$
- + getCommandToLaunch() + params);
+ monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Invoking_Command") //$NON-NLS-1$
+ + program + params);
ErrorParserManager epm = new ErrorParserManager(currentProject, markerGenerator, new String[] {GMAKE_ERROR_PARSER_ID});
epm.setOutputStream(cos);
@@ -140,90 +138,66 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
ConsoleOutputSniffer sniffer = ScannerInfoConsoleParserFactory.getESIProviderOutputSniffer(
stdout, stderr, currentProject, context, providerId, buildInfo, collector, markerGenerator);
- OutputStream consoleOut = (sniffer == null ? cos : sniffer.getOutputStream());
- OutputStream consoleErr = (sniffer == null ? cos : sniffer.getErrorStream());
- Process p = launcher.execute(getCommandToLaunch(), comandLineOptions, setEnvironment(launcher, env), fWorkingDirectory, monitor);
- if (p != null) {
- try {
- // Close the input of the Process explicitely.
- // We will never write to it.
- p.getOutputStream().close();
- } catch (IOException e) {
- }
- if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0)) != ICommandLauncher.OK) {
- errMsg = launcher.getErrorMessage();
- }
- monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Parsing_Output")); //$NON-NLS-1$
- }
- else {
- errMsg = launcher.getErrorMessage();
- }
+ OutputStream consoleOut = (sniffer == null ? cos : sniffer.getOutputStream());
+ OutputStream consoleErr = (sniffer == null ? cos : sniffer.getErrorStream());
+ Process p = launcher.execute(program, comandLineOptions, setEnvironment(launcher, env), fWorkingDirectory, monitor);
+ if (p != null) {
+ try {
+ // Close the input of the Process explicitly.
+ // We will never write to it.
+ p.getOutputStream().close();
+ } catch (IOException e) {
+ }
+ if (launcher.waitAndRead(consoleOut, consoleErr, new SubProgressMonitor(monitor, 0)) != ICommandLauncher.OK) {
+ errMsg = launcher.getErrorMessage();
+ }
+ monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Parsing_Output")); //$NON-NLS-1$
+ } else {
+ errMsg = launcher.getErrorMessage();
+ }
if (errMsg != null) {
- String errorPrefix = MakeMessages.getString("ExternalScannerInfoProvider.Error_Prefix"); //$NON-NLS-1$
- String program = fCompileCommand.toString();
+ printLine(consoleErr, errMsg);
+ printLine(consoleErr, MakeMessages.getFormattedString("ExternalScannerInfoProvider.Provider_Error", program + params) + NEWLINE); //$NON-NLS-1$
+ }
- String msg = MakeMessages.getFormattedString(EXTERNAL_SI_PROVIDER_ERROR, program+params);
- printLine(consoleErr, errorPrefix + msg + NEWLINE);
+ consoleOut.close();
+ consoleErr.close();
+ cos.close();
+ }
+ catch (Exception e) {
+ MakeCorePlugin.log(e);
+ }
+ finally {
+ monitor.done();
+ }
+ return true;
+ }
- // Launching failed, trying to figure out possible cause
- Properties envMap = getEnvMap(launcher, env);
- String envPath = envMap.getProperty(PATH_ENV);
- if (envPath == null) {
- envPath = System.getenv(PATH_ENV);
- }
- if (!fCompileCommand.isAbsolute() && PathUtil.findProgramLocation(program, envPath) == null) {
- printLine(consoleErr, errMsg);
- msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Working_Directory", fWorkingDirectory); //$NON-NLS-1$
- msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Program_Not_In_Path", program); //$NON-NLS-1$
- printLine(consoleErr, errorPrefix + msg + NEWLINE);
- printLine(consoleErr, PATH_ENV + "=[" + envPath + "]" + NEWLINE); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- printLine(consoleErr, errorPrefix + errMsg);
- msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Working_Directory", fWorkingDirectory); //$NON-NLS-1$
- printLine(consoleErr, PATH_ENV + "=[" + envPath + "]" + NEWLINE); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ protected IPath getCommandToLaunch() {
+ return fCompileCommand;
+ }
- monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Creating_Markers")); //$NON-NLS-1$
- }
+ protected String[] getCommandLineOptions() {
+ // add additional arguments
+ // subclass can change default behavior
+ return prepareArguments(
+ buildInfo.isUseDefaultProviderCommand(providerId));
+ }
- consoleOut.close();
- consoleErr.close();
- cos.close();
- }
- catch (Exception e) {
- MakeCorePlugin.log(e);
- }
- finally {
- monitor.done();
- }
- return true;
- }
-
- protected IPath getCommandToLaunch() {
- return fCompileCommand;
- }
-
- protected String[] getCommandLineOptions() {
- // add additional arguments
- // subclass can change default behavior
- return prepareArguments(
- buildInfo.isUseDefaultProviderCommand(providerId));
- }
-
- private void printLine(OutputStream stream, String msg) throws IOException {
- stream.write((msg + NEWLINE).getBytes());
- stream.flush();
- }
-
- /**
- * Initialization of protected fields.
- * Subclasses are most likely to override default implementation.
- */
- protected boolean initialize() {
+ private void printLine(OutputStream stream, String msg) throws IOException {
+ stream.write((msg + NEWLINE).getBytes());
+ stream.flush();
+ }
+
+ /**
+ * Initialization of protected fields.
+ * Subclasses are most likely to override default implementation.
+ */
+ protected boolean initialize() {
IProject currProject = resource.getProject();
- //fWorkingDirectory = resource.getProject().getLocation();
+ //fWorkingDirectory = resource.getProject().getLocation();
URI workingDirURI = MakeBuilderUtil.getBuildDirectoryURI(currProject, MakeBuilder.BUILDER_ID);
String pathString = EFSExtensionManager.getDefault().getPathFromURI(workingDirURI);
if(pathString != null) {
@@ -235,34 +209,34 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
throw new IllegalStateException();
}
- fCompileCommand = new Path(buildInfo.getProviderRunCommand(providerId));
- fCompileArguments = ScannerConfigUtil.tokenizeStringWithQuotes(buildInfo.getProviderRunArguments(providerId), "\"");//$NON-NLS-1$
- return (fCompileCommand != null);
- }
-
- /**
- * Add additional arguments. For example: tso - target specific options
- * Base class implementation returns compileArguments.
- * Subclasses are most likely to override default implementation.
- */
- protected String[] prepareArguments(boolean isDefaultCommand) {
- return fCompileArguments;
- }
-
- private String coligate(String[] array) {
- StringBuffer sb = new StringBuffer(128);
- for (int i = 0; i < array.length; ++i) {
- sb.append(' ');
- sb.append(array[i]);
- }
- String ca = sb.toString();
- return ca;
- }
+ fCompileCommand = new Path(buildInfo.getProviderRunCommand(providerId));
+ fCompileArguments = ScannerConfigUtil.tokenizeStringWithQuotes(buildInfo.getProviderRunArguments(providerId), "\"");//$NON-NLS-1$
+ return (fCompileCommand != null);
+ }
+
+ /**
+ * Add additional arguments. For example: tso - target specific options
+ * Base class implementation returns compileArguments.
+ * Subclasses are most likely to override default implementation.
+ */
+ protected String[] prepareArguments(boolean isDefaultCommand) {
+ return fCompileArguments;
+ }
+
+ private String coligate(String[] array) {
+ StringBuffer sb = new StringBuffer(128);
+ for (int i = 0; i < array.length; ++i) {
+ sb.append(' ');
+ sb.append(array[i]);
+ }
+ String ca = sb.toString();
+ return ca;
+ }
private Properties getEnvMap(ICommandLauncher launcher, Properties initialEnv) {
// Set the environmennt, some scripts may need the CWD var to be set.
Properties props = initialEnv != null ? initialEnv : launcher.getEnvironment();
-
+
if (fWorkingDirectory != null) {
props.put("CWD", fWorkingDirectory.toOSString()); //$NON-NLS-1$
props.put("PWD", fWorkingDirectory.toOSString()); //$NON-NLS-1$
@@ -278,20 +252,20 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
return props;
}
- protected String[] setEnvironment(ICommandLauncher launcher, Properties initialEnv) {
- Properties props = getEnvMap(launcher, initialEnv);
- String[] env = null;
- ArrayList<String> envList = new ArrayList<String>();
- Enumeration<?> names = props.propertyNames();
- if (names != null) {
- while (names.hasMoreElements()) {
- String key = (String) names.nextElement();
- envList.add(key + "=" + props.getProperty(key)); //$NON-NLS-1$
- }
- env = envList.toArray(new String[envList.size()]);
- }
- return env;
- }
+ protected String[] setEnvironment(ICommandLauncher launcher, Properties initialEnv) {
+ Properties props = getEnvMap(launcher, initialEnv);
+ String[] env = null;
+ ArrayList<String> envList = new ArrayList<String>();
+ Enumeration<?> names = props.propertyNames();
+ if (names != null) {
+ while (names.hasMoreElements()) {
+ String key = (String) names.nextElement();
+ envList.add(key + "=" + props.getProperty(key)); //$NON-NLS-1$
+ }
+ env = envList.toArray(new String[envList.size()]);
+ }
+ return env;
+ }
/**

Back to the top