mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
RESOLVED - bug 272986: changes to ICommandLauncher
https://bugs.eclipse.org/bugs/show_bug.cgi?id=272986
This commit is contained in:
parent
724860a02b
commit
68718b41f9
9 changed files with 113 additions and 18 deletions
|
@ -155,6 +155,7 @@ public class MakeBuilder extends ACBuilder {
|
||||||
|
|
||||||
String errMsg = null;
|
String errMsg = null;
|
||||||
ICommandLauncher launcher = new CommandLauncher();
|
ICommandLauncher launcher = new CommandLauncher();
|
||||||
|
launcher.setProject(currProject);
|
||||||
// Print the command for visual interaction.
|
// Print the command for visual interaction.
|
||||||
launcher.showCommand(true);
|
launcher.showCommand(true);
|
||||||
|
|
||||||
|
@ -208,7 +209,7 @@ public class MakeBuilder extends ACBuilder {
|
||||||
stdout, stderr, getProject(), workingDirectory, null, this, null);
|
stdout, stderr, getProject(), workingDirectory, null, this, null);
|
||||||
OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream());
|
OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream());
|
||||||
OutputStream consoleErr = (sniffer == null ? stderr : sniffer.getErrorStream());
|
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) {
|
if (p != null) {
|
||||||
try {
|
try {
|
||||||
// Close the input of the Process explicitly.
|
// Close the input of the Process explicitly.
|
||||||
|
|
|
@ -103,6 +103,7 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
||||||
|
|
||||||
String errMsg = null;
|
String errMsg = null;
|
||||||
ICommandLauncher launcher = new CommandLauncher();
|
ICommandLauncher launcher = new CommandLauncher();
|
||||||
|
launcher.setProject(currentProject);
|
||||||
// Print the command for visual interaction.
|
// Print the command for visual interaction.
|
||||||
launcher.showCommand(true);
|
launcher.showCommand(true);
|
||||||
|
|
||||||
|
@ -118,7 +119,7 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
||||||
OutputStream consoleOut = (sniffer == null ? cos : sniffer.getOutputStream());
|
OutputStream consoleOut = (sniffer == null ? cos : sniffer.getOutputStream());
|
||||||
OutputStream consoleErr = (sniffer == null ? cos : sniffer.getErrorStream());
|
OutputStream consoleErr = (sniffer == null ? cos : sniffer.getErrorStream());
|
||||||
TraceUtil.outputTrace("Default provider is executing command:", fCompileCommand.toString() + ca, ""); //$NON-NLS-1$ //$NON-NLS-2$
|
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) {
|
if (p != null) {
|
||||||
try {
|
try {
|
||||||
// Close the input of the Process explicitely.
|
// Close the input of the Process explicitely.
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.eclipse.cdt.core.CommandLauncher;
|
||||||
import org.eclipse.cdt.core.ICommandLauncher;
|
import org.eclipse.cdt.core.ICommandLauncher;
|
||||||
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand;
|
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand;
|
||||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
|
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.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
|
@ -160,7 +161,15 @@ public class CommandBuilder implements IBuildModelBuilder {
|
||||||
|
|
||||||
launcher.showCommand(true);
|
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) {
|
if (fProcess != null) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1935,6 +1935,7 @@ public class CommonBuilder extends ACBuilder {
|
||||||
|
|
||||||
String errMsg = null;
|
String errMsg = null;
|
||||||
ICommandLauncher launcher = builder.getCommandLauncher();
|
ICommandLauncher launcher = builder.getCommandLauncher();
|
||||||
|
launcher.setProject(currProject);
|
||||||
// Print the command for visual interaction.
|
// Print the command for visual interaction.
|
||||||
launcher.showCommand(true);
|
launcher.showCommand(true);
|
||||||
|
|
||||||
|
@ -1975,7 +1976,7 @@ public class CommonBuilder extends ACBuilder {
|
||||||
ConsoleOutputSniffer sniffer = createBuildOutputSniffer(stdout, stderr, currProject, cfg, workingDirectory, this, null);
|
ConsoleOutputSniffer sniffer = createBuildOutputSniffer(stdout, stderr, currProject, cfg, workingDirectory, this, null);
|
||||||
OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream());
|
OutputStream consoleOut = (sniffer == null ? stdout : sniffer.getOutputStream());
|
||||||
OutputStream consoleErr = (sniffer == null ? stderr : sniffer.getErrorStream());
|
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) {
|
if (p != null) {
|
||||||
try {
|
try {
|
||||||
// Close the input of the Process explicitly.
|
// Close the input of the Process explicitly.
|
||||||
|
|
|
@ -948,6 +948,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
|
||||||
String errMsg = null;
|
String errMsg = null;
|
||||||
IBuilder builder = info.getDefaultConfiguration().getBuilder();
|
IBuilder builder = info.getDefaultConfiguration().getBuilder();
|
||||||
ICommandLauncher launcher = builder.getCommandLauncher();
|
ICommandLauncher launcher = builder.getCommandLauncher();
|
||||||
|
launcher.setProject(currentProject);
|
||||||
launcher.showCommand(true);
|
launcher.showCommand(true);
|
||||||
|
|
||||||
// Set the environmennt
|
// Set the environmennt
|
||||||
|
@ -1009,7 +1010,7 @@ public class GeneratedMakefileBuilder extends ACBuilder {
|
||||||
premakeArgs.add("-q"); //$NON-NLS-1$
|
premakeArgs.add("-q"); //$NON-NLS-1$
|
||||||
premakeArgs.add("main-build"); //$NON-NLS-1$
|
premakeArgs.add("main-build"); //$NON-NLS-1$
|
||||||
premakeTargets = (String[]) premakeArgs.toArray(new String[premakeArgs.size()]);
|
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) {
|
if (proc != null) {
|
||||||
try {
|
try {
|
||||||
// Close the input of the process since we will never write to it
|
// 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
|
// Launch make - main invocation
|
||||||
if (!isuptodate) {
|
if (!isuptodate) {
|
||||||
proc = launcher.execute(makeCommand, makeTargets, env,
|
proc = launcher.execute(makeCommand, makeTargets, env, workingDirectory, monitor);
|
||||||
workingDirectory);
|
|
||||||
if (proc != null) {
|
if (proc != null) {
|
||||||
try {
|
try {
|
||||||
// Close the input of the process since we will never write to it
|
// Close the input of the process since we will never write to it
|
||||||
|
|
|
@ -18,6 +18,8 @@ import java.util.Properties;
|
||||||
import org.eclipse.cdt.internal.core.ProcessClosure;
|
import org.eclipse.cdt.internal.core.ProcessClosure;
|
||||||
import org.eclipse.cdt.utils.spawner.EnvironmentReader;
|
import org.eclipse.cdt.utils.spawner.EnvironmentReader;
|
||||||
import org.eclipse.cdt.utils.spawner.ProcessFactory;
|
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.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
|
@ -38,6 +40,7 @@ public class CommandLauncher implements ICommandLauncher {
|
||||||
protected String fErrorMessage = ""; //$NON-NLS-1$
|
protected String fErrorMessage = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
private String lineSeparator;
|
private String lineSeparator;
|
||||||
|
private IProject fProject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of milliseconds to pause between polling.
|
* The number of milliseconds to pause between polling.
|
||||||
|
@ -107,10 +110,40 @@ public class CommandLauncher implements ICommandLauncher {
|
||||||
return args;
|
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)
|
* @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 {
|
try {
|
||||||
// add platform specific arguments (shell invocation)
|
// add platform specific arguments (shell invocation)
|
||||||
fCommandArgs = constructCommandArray(commandPath.toOSString(), args);
|
fCommandArgs = constructCommandArray(commandPath.toOSString(), args);
|
||||||
|
@ -209,4 +242,21 @@ public class CommandLauncher implements ICommandLauncher {
|
||||||
return buf.toString();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,6 +3,8 @@ package org.eclipse.cdt.core;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Properties;
|
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.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
|
@ -17,6 +19,22 @@ public interface ICommandLauncher {
|
||||||
public final static int ILLEGAL_COMMAND = -1;
|
public final static int ILLEGAL_COMMAND = -1;
|
||||||
public final static int OK = 0;
|
public final static int OK = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the project that this launcher is associated with, or <code>null</code> if there is no such
|
||||||
|
* project.
|
||||||
|
*
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
public void setProject(IProject project);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the project this launcher is associated with.
|
||||||
|
*
|
||||||
|
* @return IProject, or <code>null</code> if there is no such project.
|
||||||
|
*/
|
||||||
|
public IProject getProject();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets if the command should be printed out first before executing.
|
* Sets if the command should be printed out first before executing.
|
||||||
*/
|
*/
|
||||||
|
@ -64,8 +82,10 @@ public interface ICommandLauncher {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a command
|
* 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.
|
* Reads output form the process to the streams.
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.eclipse.cdt.core.CommandLauncher;
|
import org.eclipse.cdt.core.CommandLauncher;
|
||||||
import org.eclipse.cdt.core.ICommandLauncher;
|
import org.eclipse.cdt.core.ICommandLauncher;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,9 +30,15 @@ public class CygwinMIEnvironmentCD extends WinMIEnvironmentCD {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ByteArrayOutputStream err = new ByteArrayOutputStream();
|
ByteArrayOutputStream err = new ByteArrayOutputStream();
|
||||||
String newPath = null;
|
String newPath = null;
|
||||||
|
try {
|
||||||
launcher.execute( new Path( "cygpath" ), //$NON-NLS-1$
|
launcher.execute( new Path( "cygpath" ), //$NON-NLS-1$
|
||||||
new String[]{ "-u", path }, //$NON-NLS-1$
|
new String[]{ "-u", path }, //$NON-NLS-1$
|
||||||
new String[0], new 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 ) {
|
if ( launcher.waitAndRead( out, err ) == ICommandLauncher.OK ) {
|
||||||
newPath = out.toString();
|
newPath = out.toString();
|
||||||
if ( newPath != null ) {
|
if ( newPath != null ) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.util.StringTokenizer;
|
||||||
import org.eclipse.cdt.core.CommandLauncher;
|
import org.eclipse.cdt.core.CommandLauncher;
|
||||||
import org.eclipse.cdt.core.ICommandLauncher;
|
import org.eclipse.cdt.core.ICommandLauncher;
|
||||||
import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory;
|
import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,11 +89,16 @@ public class CygwinMIEnvironmentDirectory extends MIEnvironmentDirectory {
|
||||||
String result = path;
|
String result = path;
|
||||||
ICommandLauncher launcher = new CommandLauncher();
|
ICommandLauncher launcher = new CommandLauncher();
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
launcher.execute(
|
launcher.execute(
|
||||||
new Path("cygpath"), //$NON-NLS-1$
|
new Path("cygpath"), //$NON-NLS-1$
|
||||||
new String[] { "-p", "-u", path }, //$NON-NLS-1$ //$NON-NLS-2$
|
new String[] { "-p", "-u", path }, //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
new String[0],
|
new String[0],
|
||||||
new Path(".")); //$NON-NLS-1$
|
new Path("."), null);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} //$NON-NLS-1$
|
||||||
if (launcher.waitAndRead(out, out) == ICommandLauncher.OK)
|
if (launcher.waitAndRead(out, out) == ICommandLauncher.OK)
|
||||||
result = out.toString().trim();
|
result = out.toString().trim();
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue