import org.sonar.runner.impl.JarExtractor;
import javax.annotation.Nullable;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class ForkedRunner extends Runner<ForkedRunner> {
private static final int ONE_DAY_IN_MILLISECONDS = 24 * 60 * 60 * 1000;
- private static final int TERMINATED_STATUS = 143;
private final Map<String, String> jvmEnvVariables = new HashMap<String, String>();
private final List<String> jvmArguments = new ArrayList<String>();
javaExecutable = new Os().thisJavaExe().getAbsolutePath();
}
Command command = Command.builder()
- .setExecutable(javaExecutable)
- .addEnvVariables(jvmEnvVariables)
- .addArguments(jvmArguments)
- .addArguments("-cp", jarFile.getAbsolutePath(), BatchLauncherMain.class.getName(), propertiesFile.getAbsolutePath())
- .build();
+ .setExecutable(javaExecutable)
+ .addEnvVariables(jvmEnvVariables)
+ .addArguments(jvmArguments)
+ .addArguments("-cp", jarFile.getAbsolutePath(), BatchLauncherMain.class.getName(), propertiesFile.getAbsolutePath())
+ .build();
return new ForkCommand(command, jarFile, propertiesFile);
}
stdErr = new PrintStreamConsumer(System.err);
}
int status = commandExecutor.execute(forkCommand.command, stdOut, stdErr, ONE_DAY_IN_MILLISECONDS, processMonitor);
-
- if (status == TERMINATED_STATUS) {
- stdOut.consumeLine(String.format("Sonar runner terminated with exit code %d", status));
- } else if (status != 0) {
- throw new IllegalStateException("Error status [command: " + forkCommand.command + "]: " + status);
+ if (status != 0) {
+ if (processMonitor.stop()) {
+ stdOut.consumeLine(String.format("SonarQube Runner was stopped [status=%s]", status));
+ }
+ else {
+ throw new IllegalStateException("Error status [command: " + forkCommand.command + "]: " + status);
+ }
}
}
*/
package org.sonar.runner.api;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- private ProcessMonitor processMonitor = mock(ProcessMonitor.class);
+ private ProcessMonitor processMonitor;
private final StreamConsumer out = mock(StreamConsumer.class);
private final StreamConsumer err = mock(StreamConsumer.class);
+ @Before
+ public void prepare() {
+ processMonitor = mock(ProcessMonitor.class);
+ }
+
@Test
public void should_create_forked_runner() {
ForkedRunner runner = ForkedRunner.create();
@Test
public void test_runner_was_requested_to_stop() throws Exception {
+ when(processMonitor.stop()).thenReturn(true);
ForkedRunner runner = new ForkedRunner(createMockExtractor(), createMockRunnerWithExecutionStatus(143), processMonitor);
runner.setStdOut(out);
runner.setStdErr(err);
runner.execute();
- verify(out).consumeLine("Sonar runner terminated with exit code 143");
+ verify(out).consumeLine("SonarQube Runner was stopped [status=143]");
}
}