Skip to content

Commit 31f170c

Browse files
authored
Merge pull request #191 from Vodorok/jobcancel
Cancelable CodeChecker analyze
2 parents 97f0ed2 + 4cba523 commit 31f170c

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/CodeChecker.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,9 @@ private String getSubstituteAnalyzeString(CcConfigurationBase config) {
120120
+ config.get(ConfigTypes.ANAL_THREADS) + " -n javarunner" + " -o " + RESULTS_SUB + OPTION_SEPARATOR
121121
+ LOGFILE_SUB + OPTION_SEPARATOR + config.get(ConfigTypes.ANAL_OPTIONS);
122122
}
123+
124+
@Override
125+
public void cancelAnalyze() {
126+
she.cancel();
127+
}
123128
}

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/ICodeChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,6 @@ public interface ICodeChecker {
7070
*/
7171
public String analyze(Path logFile, boolean logToConsole, IProgressMonitor monitor, int taskCount,
7272
CcConfigurationBase config);
73+
74+
public void cancelAnalyze();
7375
}

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/job/AnalyzeJob.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public void accept(String t) {
8484
return Status.OK_STATUS;
8585
}
8686

87+
@Override
88+
protected void canceling() {
89+
config.getCodeChecker().cancelAnalyze();
90+
}
91+
8792
/**
8893
* Creates a copy of the log file created by ld logger, to avoid concurrency
8994
* issues.
@@ -107,4 +112,5 @@ public void deleteLogFile() {
107112
Logger.log(IStatus.ERROR, "Couldn't delete the temporary log file!");
108113
}
109114
}
115+
110116
}

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/runtime/ShellExecutorHelper.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
package 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;
614
import org.apache.commons.lang3.reflect.FieldUtils;
715
import org.eclipse.core.runtime.IProgressMonitor;
816
import org.eclipse.core.runtime.SubMonitor;
917
import 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

1521
public 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

Comments
 (0)