aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java47
1 files changed, 19 insertions, 28 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java
index 0aea491bd3..59d9792696 100644
--- a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java
+++ b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.windows;
import com.google.devtools.build.lib.shell.Subprocess;
+import com.google.devtools.build.lib.windows.jni.WindowsProcesses;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -57,7 +58,7 @@ public class WindowsSubprocess implements Subprocess {
*
* <p>This class is non-static for debugging purposes.
*/
- private class ProcessInputStream extends InputStream {
+ private static final class ProcessInputStream extends InputStream {
private long nativeStream;
ProcessInputStream(long nativeStream) {
@@ -75,18 +76,18 @@ public class WindowsSubprocess implements Subprocess {
}
@Override
- public synchronized int read(byte b[], int off, int len) throws IOException {
+ public synchronized int read(byte[] b, int off, int len) throws IOException {
if (nativeStream == WindowsProcesses.INVALID) {
throw new IllegalStateException();
}
- int result = WindowsProcesses.nativeReadStream(nativeStream, b, off, len);
+ int result = WindowsProcesses.readStream(nativeStream, b, off, len);
if (result == 0) {
return -1; // EOF
}
if (result == -1) {
- throw new IOException(WindowsProcesses.nativeStreamGetLastError(nativeStream));
+ throw new IOException(WindowsProcesses.streamGetLastError(nativeStream));
}
return result;
@@ -95,7 +96,7 @@ public class WindowsSubprocess implements Subprocess {
@Override
public synchronized void close() {
if (nativeStream != WindowsProcesses.INVALID) {
- WindowsProcesses.nativeCloseStream(nativeStream);
+ WindowsProcesses.closeStream(nativeStream);
nativeStream = WindowsProcesses.INVALID;
}
}
@@ -107,7 +108,7 @@ public class WindowsSubprocess implements Subprocess {
}
}
- private static AtomicInteger THREAD_SEQUENCE_NUMBER = new AtomicInteger(1);
+ private static final AtomicInteger THREAD_SEQUENCE_NUMBER = new AtomicInteger(1);
private static final ExecutorService WAITER_POOL = Executors.newCachedThreadPool(
new ThreadFactory() {
@Override
@@ -134,13 +135,9 @@ public class WindowsSubprocess implements Subprocess {
this.nativeProcess = nativeProcess;
this.timeoutMillis = timeoutMillis;
stdoutStream =
- stdoutRedirected
- ? null
- : new ProcessInputStream(WindowsProcesses.nativeGetStdout(nativeProcess));
+ stdoutRedirected ? null : new ProcessInputStream(WindowsProcesses.getStdout(nativeProcess));
stderrStream =
- stderrRedirected
- ? null
- : new ProcessInputStream(WindowsProcesses.nativeGetStderr(nativeProcess));
+ stderrRedirected ? null : new ProcessInputStream(WindowsProcesses.getStderr(nativeProcess));
stdinStream = new ProcessOutputStream();
waitLatch = new CountDownLatch(1);
// Every Windows process we start consumes a thread here. This is suboptimal, but seems to be
@@ -150,7 +147,7 @@ public class WindowsSubprocess implements Subprocess {
}
private void waiterThreadFunc() {
- switch (WindowsProcesses.nativeWaitFor(nativeProcess, timeoutMillis)) {
+ switch (WindowsProcesses.waitFor(nativeProcess, timeoutMillis)) {
case 0:
// Excellent, process finished in time.
break;
@@ -158,15 +155,15 @@ public class WindowsSubprocess implements Subprocess {
case 1:
// Timeout. Terminate the process if we can.
timedout.set(true);
- WindowsProcesses.nativeTerminate(nativeProcess);
+ WindowsProcesses.terminate(nativeProcess);
break;
case 2:
// Error. There isn't a lot we can do -- the process is still alive but
// WaitForMultipleObjects() failed for some odd reason. We'll pretend it terminated and
// log a message to jvm.out .
- System.err.println("Waiting for process "
- + WindowsProcesses.nativeGetProcessPid(nativeProcess) + " failed");
+ System.err.println(
+ "Waiting for process " + WindowsProcesses.getProcessPid(nativeProcess) + " failed");
break;
}
@@ -184,20 +181,15 @@ public class WindowsSubprocess implements Subprocess {
@Override
public synchronized boolean destroy() {
checkLiveness();
-
- if (!WindowsProcesses.nativeTerminate(nativeProcess)) {
- return false;
- }
-
- return true;
+ return WindowsProcesses.terminate(nativeProcess);
}
@Override
public synchronized int exitValue() {
checkLiveness();
- int result = WindowsProcesses.nativeGetExitCode(nativeProcess);
- String error = WindowsProcesses.nativeProcessGetLastError(nativeProcess);
+ int result = WindowsProcesses.getExitCode(nativeProcess);
+ String error = WindowsProcesses.processGetLastError(nativeProcess);
if (!error.isEmpty()) {
throw new IllegalStateException(error);
}
@@ -227,7 +219,7 @@ public class WindowsSubprocess implements Subprocess {
stderrStream.close();
long process = nativeProcess;
nativeProcess = WindowsProcesses.INVALID;
- WindowsProcesses.nativeDeleteProcess(process);
+ WindowsProcesses.deleteProcess(process);
}
}
@@ -252,12 +244,11 @@ public class WindowsSubprocess implements Subprocess {
int remaining = len;
int currentOffset = off;
while (remaining != 0) {
- int written = WindowsProcesses.nativeWriteStdin(
- nativeProcess, b, currentOffset, remaining);
+ int written = WindowsProcesses.writeStdin(nativeProcess, b, currentOffset, remaining);
// I think the Windows API never returns 0 in dwNumberOfBytesWritten
// Verify.verify(written != 0);
if (written == -1) {
- throw new IOException(WindowsProcesses.nativeProcessGetLastError(nativeProcess));
+ throw new IOException(WindowsProcesses.processGetLastError(nativeProcess));
}
remaining -= written;