11package org .codechecker .eclipse .plugin .runtime ;
22
3- import com .google .common .base .Optional ;
3+ import java .io .File ;
4+ import java .io .IOException ;
5+ import java .util .Map ;
6+ import java .util .Vector ;
47
5- import org .apache .commons .exec .*;
8+ import org .apache .commons .exec .CommandLine ;
9+ import org .apache .commons .exec .DefaultExecutor ;
10+ import org .apache .commons .exec .ExecuteWatchdog ;
11+ import org .apache .commons .exec .Executor ;
12+ import org .apache .commons .exec .LogOutputStream ;
13+ import org .apache .commons .exec .PumpStreamHandler ;
614import org .apache .commons .lang3 .reflect .FieldUtils ;
715import org .eclipse .core .runtime .IProgressMonitor ;
816import org .eclipse .core .runtime .SubMonitor ;
917import org .eclipse .jdt .annotation .Nullable ;
1018
11- import java .io .*;
12- import java .util .Map ;
13- import java .util .Vector ;
19+ import com .google .common .base .Optional ;
1420
1521public class ShellExecutorHelper {
1622
1723 private static final int DEFAULT_TIMEOUT = 1000 ; // in milliseconds
1824 private static final String WRAP_CHARACTER = "\" " ;
1925
26+ private Executor ec ;
2027 final Map <String , String > environment ;
2128
2229 public ShellExecutorHelper (Map <String , String > environment ) {
@@ -32,7 +39,7 @@ public ShellExecutorHelper(Map<String, String> environment) {
3239 * @return The first line of the script's output in an Optional wrapper.
3340 */
3441 public Optional <String > quickReturnFirstLine (String cmd , @ Nullable Map <String , File > substitutionMap ) {
35- Executor ec = build (DEFAULT_TIMEOUT );
42+ ec = build (DEFAULT_TIMEOUT );
3643 try {
3744 OneLineReader olr = new OneLineReader ();
3845 ec .setStreamHandler (new PumpStreamHandler (olr ));
@@ -63,7 +70,7 @@ public Optional<String> quickReturnOutput(String cmd, @Nullable Map<String, File
6370 * @return The script's output in an Optional wrapper.
6471 */
6572 public Optional <String > quickReturnOutput (String cmd , @ Nullable Map <String , File > substitutionMap , double timeOut ) {
66- Executor ec = build (new Double (timeOut ).longValue ());
73+ ec = build (new Double (timeOut ).longValue ());
6774 try {
6875 AllLineReader olr = new AllLineReader ();
6976 ec .setStreamHandler (new PumpStreamHandler (olr ));
@@ -83,7 +90,7 @@ public Optional<String> quickReturnOutput(String cmd, @Nullable Map<String, File
8390 * @return The script's output in an Optional wrapper.
8491 */
8592 public Optional <String > waitReturnOutput (String cmd , @ Nullable Map <String , File > substitutionMap , boolean logToConsole ) {
86- Executor ec = build ();
93+ ec = build ();
8794 try {
8895 AllLineReader olr = new AllLineReader (logToConsole );
8996 ec .setStreamHandler (new PumpStreamHandler (olr ));
@@ -107,7 +114,7 @@ public Optional<String> waitReturnOutput(String cmd, @Nullable Map<String, File>
107114 */
108115 public Optional <String > progressableWaitReturnOutput (String cmd , @ Nullable Map <String , File > substitutionMap ,
109116 boolean logToConsole , IProgressMonitor monitor , int taskCount ) {
110- Executor ec = build ();
117+ ec = build ();
111118 try {
112119 AllLineReader olr = new ProgressableAllLineReader (logToConsole , monitor , taskCount );
113120 ec .setStreamHandler (new PumpStreamHandler (olr ));
@@ -127,7 +134,7 @@ public Optional<String> progressableWaitReturnOutput(String cmd, @Nullable Map<S
127134 * @return true if successful
128135 */
129136 public boolean quickAndSuccessfull (String cmd , @ Nullable Map <String , File > substitutionMap ) {
130- Executor ec = build (DEFAULT_TIMEOUT );
137+ ec = build (DEFAULT_TIMEOUT );
131138 try {
132139 ec .execute (buildScriptCommandLine (cmd , substitutionMap ), environment );
133140 return true ;
@@ -173,6 +180,10 @@ private Executor build(Optional<String> workingDirectory, long timeoutInMilliSec
173180 return executor ;
174181 }
175182
183+ public void cancel () {
184+ ec .getWatchdog ().destroyProcess ();
185+ }
186+
176187 class PidObject {
177188 int pid ;
178189 }
0 commit comments