blob: 3b85aafab59b7d4968d7f9ed8c0ac8751c2f2141 [file] [log] [blame]
Lukacs Berki8b074c02016-07-01 13:36:38 +00001// 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
15package com.google.devtools.build.lib.shell;
16
Lukacs Berki5a2655a2016-07-05 12:23:48 +000017import java.io.Closeable;
Lukacs Berki8b074c02016-07-01 13:36:38 +000018import java.io.IOException;
19import java.io.InputStream;
20import java.io.OutputStream;
21
22/**
23 * A process started by Bazel.
24 */
Lukacs Berki5a2655a2016-07-05 12:23:48 +000025public interface Subprocess extends Closeable {
Lukacs Berki8b074c02016-07-01 13:36:38 +000026
27 /**
28 * Something that can create subprocesses.
29 */
30 interface Factory {
ulfjackf2d45952017-08-09 15:27:49 +020031 /**
Lukacs Berki8b074c02016-07-01 13:36:38 +000032 * 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 Berki0451cf02016-07-01 14:32:53 +000045 * <p>Throws {@code IOException} if the process has not terminated yet.
Lukacs Berki8b074c02016-07-01 13:36:38 +000046 */
47 int exitValue();
48
49 /**
Lukacs Berki0451cf02016-07-01 14:32:53 +000050 * Returns the if the process has finished.
51 */
52 boolean finished();
53
54 /**
Lukacs Berki3d97e222016-08-19 14:40:20 +000055 * Returns if the process timed out.
56 */
57 boolean timedout();
58
59 /**
Lukacs Berki8b074c02016-07-01 13:36:38 +000060 * Waits for the process to finish.
61 */
Lukacs Berki0451cf02016-07-01 14:32:53 +000062 void waitFor() throws InterruptedException;
Lukacs Berki8b074c02016-07-01 13:36:38 +000063
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 Berki5a2655a2016-07-05 12:23:48 +000078
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 Berki8b074c02016-07-01 13:36:38 +000085}