Lukacs Berki | 8b074c0 | 2016-07-01 13:36:38 +0000 | [diff] [blame] | 1 | // Copyright 2016 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package com.google.devtools.build.lib.shell; |
| 16 | |
Lukacs Berki | 5a2655a | 2016-07-05 12:23:48 +0000 | [diff] [blame] | 17 | import java.io.Closeable; |
Lukacs Berki | 8b074c0 | 2016-07-01 13:36:38 +0000 | [diff] [blame] | 18 | import java.io.IOException; |
| 19 | import java.io.InputStream; |
| 20 | import java.io.OutputStream; |
| 21 | |
| 22 | /** |
| 23 | * A process started by Bazel. |
| 24 | */ |
Lukacs Berki | 5a2655a | 2016-07-05 12:23:48 +0000 | [diff] [blame] | 25 | public interface Subprocess extends Closeable { |
Lukacs Berki | 8b074c0 | 2016-07-01 13:36:38 +0000 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Something that can create subprocesses. |
| 29 | */ |
| 30 | interface Factory { |
ulfjack | f2d4595 | 2017-08-09 15:27:49 +0200 | [diff] [blame] | 31 | /** |
Lukacs Berki | 8b074c0 | 2016-07-01 13:36:38 +0000 | [diff] [blame] | 32 | * Create a subprocess according to the specified parameters. |
| 33 | */ |
| 34 | Subprocess create(SubprocessBuilder params) throws IOException; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Kill the process. |
| 39 | */ |
| 40 | boolean destroy(); |
| 41 | |
| 42 | /** |
| 43 | * Returns the exit value of the process. |
| 44 | * |
Lukacs Berki | 0451cf0 | 2016-07-01 14:32:53 +0000 | [diff] [blame] | 45 | * <p>Throws {@code IOException} if the process has not terminated yet. |
Lukacs Berki | 8b074c0 | 2016-07-01 13:36:38 +0000 | [diff] [blame] | 46 | */ |
| 47 | int exitValue(); |
| 48 | |
| 49 | /** |
Lukacs Berki | 0451cf0 | 2016-07-01 14:32:53 +0000 | [diff] [blame] | 50 | * Returns the if the process has finished. |
| 51 | */ |
| 52 | boolean finished(); |
| 53 | |
| 54 | /** |
Lukacs Berki | 3d97e22 | 2016-08-19 14:40:20 +0000 | [diff] [blame] | 55 | * Returns if the process timed out. |
| 56 | */ |
| 57 | boolean timedout(); |
| 58 | |
| 59 | /** |
Lukacs Berki | 8b074c0 | 2016-07-01 13:36:38 +0000 | [diff] [blame] | 60 | * Waits for the process to finish. |
| 61 | */ |
Lukacs Berki | 0451cf0 | 2016-07-01 14:32:53 +0000 | [diff] [blame] | 62 | void waitFor() throws InterruptedException; |
Lukacs Berki | 8b074c0 | 2016-07-01 13:36:38 +0000 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Returns a stream into which data can be written that the process will get on its stdin. |
| 66 | */ |
| 67 | OutputStream getOutputStream(); |
| 68 | |
| 69 | /** |
| 70 | * Returns a stream from which the stdout of the process can be read. |
| 71 | */ |
| 72 | InputStream getInputStream(); |
| 73 | |
| 74 | /** |
| 75 | * Returns a stream from which the stderr of the process can be read. |
| 76 | */ |
| 77 | InputStream getErrorStream(); |
Lukacs Berki | 5a2655a | 2016-07-05 12:23:48 +0000 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Terminates the process as thoroughly as the underlying implementation allows and releases |
| 81 | * native data structures associated with the process. |
| 82 | */ |
| 83 | @Override |
| 84 | void close(); |
Lukacs Berki | 8b074c0 | 2016-07-01 13:36:38 +0000 | [diff] [blame] | 85 | } |