From 68718b41f92d34f1ecf69c7b3123084e93e31592 Mon Sep 17 00:00:00 2001 From: Chris Recoskie Date: Wed, 22 Apr 2009 12:39:53 +0000 Subject: [PATCH] RESOLVED - bug 272986: changes to ICommandLauncher https://bugs.eclipse.org/bugs/show_bug.cgi?id=272986 --- .../eclipse/cdt/make/core/MakeBuilder.java | 3 +- .../scannerconfig2/DefaultRunSIProvider.java | 3 +- .../internal/buildmodel/CommandBuilder.java | 11 +++- .../internal/core/CommonBuilder.java | 3 +- .../core/GeneratedMakefileBuilder.java | 6 +-- .../org/eclipse/cdt/core/CommandLauncher.java | 54 ++++++++++++++++++- .../eclipse/cdt/core/ICommandLauncher.java | 22 +++++++- .../win32/CygwinMIEnvironmentCD.java | 13 +++-- .../win32/CygwinMIEnvironmentDirectory.java | 16 ++++-- 9 files changed, 113 insertions(+), 18 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 e93e0448109..c8b58181354 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 @@ -155,6 +155,7 @@ public class MakeBuilder extends ACBuilder { String errMsg = null; ICommandLauncher launcher = new CommandLauncher(); + launcher.setProject(currProject); // Print the command for visual interaction. launcher.showCommand(true); @@ -208,7 +209,7 @@ public class MakeBuilder extends ACBuilder { stdout, stderr, getProject(), workingDirectory, null, this, null); OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream()); OutputStream consoleErr = (sniffer == null ? stderr : sniffer.getErrorStream()); - Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory); + Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory, monitor); if (p != null) { try { // Close the input of the Process explicitly. 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 758911574c0..15590b67fe7 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 @@ -103,6 +103,7 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider { String errMsg = null; ICommandLauncher launcher = new CommandLauncher(); + launcher.setProject(currentProject); // Print the command for visual interaction. launcher.showCommand(true); @@ -118,7 +119,7 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider { OutputStream consoleOut = (sniffer == null ? cos : sniffer.getOutputStream()); OutputStream consoleErr = (sniffer == null ? cos : sniffer.getErrorStream()); TraceUtil.outputTrace("Default provider is executing command:", fCompileCommand.toString() + ca, ""); //$NON-NLS-1$ //$NON-NLS-2$ - Process p = launcher.execute(getCommandToLaunch(), comandLineOptions, setEnvironment(launcher, env), fWorkingDirectory); + Process p = launcher.execute(getCommandToLaunch(), comandLineOptions, setEnvironment(launcher, env), fWorkingDirectory, monitor); if (p != null) { try { // Close the input of the Process explicitely. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java index d3aafff10c9..d98b41a3f0d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/buildmodel/CommandBuilder.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.CommandLauncher; import org.eclipse.cdt.core.ICommandLauncher; import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand; import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubProgressMonitor; @@ -160,7 +161,15 @@ public class CommandBuilder implements IBuildModelBuilder { launcher.showCommand(true); - fProcess = launcher.execute(fCmd.getCommand(), fCmd.getArgs(), mapToStringArray(fCmd.getEnvironment()), fCmd.getCWD()); + try { + fProcess = launcher.execute(fCmd.getCommand(), fCmd.getArgs(), mapToStringArray(fCmd.getEnvironment()), fCmd.getCWD(), monitor); + } catch (CoreException e1) { + // TODO Auto-generated catch block + if(DbgUtil.DEBUG) + DbgUtil.trace("Error launching command: " + e1.getMessage()); //$NON-NLS-1$ + monitor.done(); + return STATUS_ERROR_LAUNCH; + } if (fProcess != null) { try { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java index 77d8ab3475b..6d5356386eb 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java @@ -1935,6 +1935,7 @@ public class CommonBuilder extends ACBuilder { String errMsg = null; ICommandLauncher launcher = builder.getCommandLauncher(); + launcher.setProject(currProject); // Print the command for visual interaction. launcher.showCommand(true); @@ -1975,7 +1976,7 @@ public class CommonBuilder extends ACBuilder { ConsoleOutputSniffer sniffer = createBuildOutputSniffer(stdout, stderr, currProject, cfg, workingDirectory, this, null); OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream()); OutputStream consoleErr = (sniffer == null ? stderr : sniffer.getErrorStream()); - Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory); + Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory, monitor); if (p != null) { try { // Close the input of the Process explicitly. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java index 661140ff0ef..c14c1fe0325 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java @@ -948,6 +948,7 @@ public class GeneratedMakefileBuilder extends ACBuilder { String errMsg = null; IBuilder builder = info.getDefaultConfiguration().getBuilder(); ICommandLauncher launcher = builder.getCommandLauncher(); + launcher.setProject(currentProject); launcher.showCommand(true); // Set the environmennt @@ -1009,7 +1010,7 @@ public class GeneratedMakefileBuilder extends ACBuilder { premakeArgs.add("-q"); //$NON-NLS-1$ premakeArgs.add("main-build"); //$NON-NLS-1$ premakeTargets = (String[]) premakeArgs.toArray(new String[premakeArgs.size()]); - proc = launcher.execute(makeCommand, premakeTargets, env, workingDirectory); + proc = launcher.execute(makeCommand, premakeTargets, env, workingDirectory, monitor); if (proc != null) { try { // Close the input of the process since we will never write to it @@ -1077,8 +1078,7 @@ public class GeneratedMakefileBuilder extends ACBuilder { // Launch make - main invocation if (!isuptodate) { - proc = launcher.execute(makeCommand, makeTargets, env, - workingDirectory); + proc = launcher.execute(makeCommand, makeTargets, env, workingDirectory, monitor); if (proc != null) { try { // Close the input of the process since we will never write to it diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java index 8a285644588..9e4e344fbfd 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java @@ -18,6 +18,8 @@ import java.util.Properties; import org.eclipse.cdt.internal.core.ProcessClosure; import org.eclipse.cdt.utils.spawner.EnvironmentReader; import org.eclipse.cdt.utils.spawner.ProcessFactory; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -38,6 +40,7 @@ public class CommandLauncher implements ICommandLauncher { protected String fErrorMessage = ""; //$NON-NLS-1$ private String lineSeparator; + private IProject fProject; /** * The number of milliseconds to pause between polling. @@ -107,10 +110,40 @@ public class CommandLauncher implements ICommandLauncher { return args; } - /* (non-Javadoc) + /** + * @deprecated + * @param commandPath + * @param args + * @param env + * @param changeToDirectory + * @return + * @throws CoreException + * @since 5.1 + */ + public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory) throws CoreException { + try { + // add platform specific arguments (shell invocation) + fCommandArgs = constructCommandArray(commandPath.toOSString(), args); + + File file = null; + + if(changeToDirectory != null) + file = changeToDirectory.toFile(); + + fProcess = ProcessFactory.getFactory().exec(fCommandArgs, env, file); + fErrorMessage = ""; //$NON-NLS-1$ + } catch (IOException e) { + setErrorMessage(e.getMessage()); + fProcess = null; + } + return fProcess; + } + + /** + * @since 5.1 * @see org.eclipse.cdt.core.ICommandLauncher#execute(org.eclipse.core.runtime.IPath, java.lang.String[], java.lang.String[], org.eclipse.core.runtime.IPath) */ - public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory) { + public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory, IProgressMonitor monitor) throws CoreException { try { // add platform specific arguments (shell invocation) fCommandArgs = constructCommandArray(commandPath.toOSString(), args); @@ -209,4 +242,21 @@ public class CommandLauncher implements ICommandLauncher { return buf.toString(); } + + /** + * @since 5.1 + * @see org.eclipse.cdt.core.ICommandLauncher#getProject() + */ + public IProject getProject() { + return fProject; + } + + /** + * @since 5.1 + * @see org.eclipse.cdt.core.ICommandLauncher#setProject(org.eclipse.core.resources.IProject) + */ + public void setProject(IProject project) { + fProject = project; + } + } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java index e0c74a48a25..1f9955a94cb 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncher.java @@ -3,6 +3,8 @@ package org.eclipse.cdt.core; import java.io.OutputStream; import java.util.Properties; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -16,6 +18,22 @@ public interface ICommandLauncher { public final static int COMMAND_CANCELED = 1; public final static int ILLEGAL_COMMAND = -1; public final static int OK = 0; + + + /** + * Sets the project that this launcher is associated with, or null if there is no such + * project. + * + * @param project + */ + public void setProject(IProject project); + + /** + * Gets the project this launcher is associated with. + * + * @return IProject, or null if there is no such project. + */ + public IProject getProject(); /** * Sets if the command should be printed out first before executing. @@ -64,8 +82,10 @@ public interface ICommandLauncher { /** * Execute a command + * @param env The list of environment variables in variable=value format. + * @throws CoreException if there is an error executing the command. */ - public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory); + public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory, IProgressMonitor monitor) throws CoreException; /** * Reads output form the process to the streams. diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinMIEnvironmentCD.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinMIEnvironmentCD.java index c7d0282b2cc..cdcef8cff69 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinMIEnvironmentCD.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinMIEnvironmentCD.java @@ -15,6 +15,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import org.eclipse.cdt.core.CommandLauncher; import org.eclipse.cdt.core.ICommandLauncher; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; /** @@ -29,9 +30,15 @@ public class CygwinMIEnvironmentCD extends WinMIEnvironmentCD { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); String newPath = null; - launcher.execute( new Path( "cygpath" ), //$NON-NLS-1$ - new String[]{ "-u", path }, //$NON-NLS-1$ - new String[0], new Path( "." ) ); //$NON-NLS-1$ + try { + launcher.execute( new Path( "cygpath" ), //$NON-NLS-1$ + new String[]{ "-u", path }, //$NON-NLS-1$ + new String[0], new Path( "." ), + null); + } catch (CoreException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } //$NON-NLS-1$ if ( launcher.waitAndRead( out, err ) == ICommandLauncher.OK ) { newPath = out.toString(); if ( newPath != null ) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinMIEnvironmentDirectory.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinMIEnvironmentDirectory.java index e06a9b7b354..1991542dd51 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinMIEnvironmentDirectory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinMIEnvironmentDirectory.java @@ -16,6 +16,7 @@ import java.util.StringTokenizer; import org.eclipse.cdt.core.CommandLauncher; import org.eclipse.cdt.core.ICommandLauncher; import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; /** @@ -88,11 +89,16 @@ public class CygwinMIEnvironmentDirectory extends MIEnvironmentDirectory { String result = path; ICommandLauncher launcher = new CommandLauncher(); ByteArrayOutputStream out = new ByteArrayOutputStream(); - launcher.execute( - new Path("cygpath"), //$NON-NLS-1$ - new String[] { "-p", "-u", path }, //$NON-NLS-1$ //$NON-NLS-2$ - new String[0], - new Path(".")); //$NON-NLS-1$ + try { + launcher.execute( + new Path("cygpath"), //$NON-NLS-1$ + new String[] { "-p", "-u", path }, //$NON-NLS-1$ //$NON-NLS-2$ + new String[0], + new Path("."), null); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } //$NON-NLS-1$ if (launcher.waitAndRead(out, out) == ICommandLauncher.OK) result = out.toString().trim(); return result;