|
35 | 35 | import java.util.List; |
36 | 36 | import java.util.concurrent.TimeUnit; |
37 | 37 | import java.util.concurrent.locks.ReentrantLock; |
| 38 | +import javax.annotation.Nullable; |
38 | 39 |
|
39 | 40 | public final class AppiumDriverLocalService extends DriverService { |
40 | 41 |
|
41 | 42 | private static final String URL_MASK = "http://%s:%d/wd/hub"; |
42 | 43 | private final File nodeJSExec; |
43 | | - private final int nodeJSPort; |
44 | 44 | private final ImmutableList<String> nodeJSArgs; |
45 | 45 | private final ImmutableMap<String, String> nodeJSEnvironment; |
46 | | - private final String ipAddress; |
47 | 46 | private final long startupTimeout; |
48 | 47 | private final TimeUnit timeUnit; |
49 | 48 | private final ReentrantLock lock = new ReentrantLock(true); //uses "fair" thread ordering policy |
50 | 49 | private final ListOutputStream stream = new ListOutputStream().add(System.out); |
51 | 50 | private final URL url; |
52 | 51 |
|
53 | | - |
54 | | - |
55 | 52 | private CommandLine process = null; |
56 | 53 |
|
57 | 54 | AppiumDriverLocalService(String ipAddress, File nodeJSExec, int nodeJSPort, |
58 | 55 | ImmutableList<String> nodeJSArgs, ImmutableMap<String, String> nodeJSEnvironment, |
59 | 56 | long startupTimeout, TimeUnit timeUnit) throws IOException { |
60 | 57 | super(nodeJSExec, nodeJSPort, nodeJSArgs, nodeJSEnvironment); |
61 | | - this.ipAddress = ipAddress; |
62 | 58 | this.nodeJSExec = nodeJSExec; |
63 | | - this.nodeJSPort = nodeJSPort; |
64 | 59 | this.nodeJSArgs = nodeJSArgs; |
65 | 60 | this.nodeJSEnvironment = nodeJSEnvironment; |
66 | 61 | this.startupTimeout = startupTimeout; |
67 | 62 | this.timeUnit = timeUnit; |
68 | | - this.url = new URL(String.format(URL_MASK, this.ipAddress, this.nodeJSPort)); |
| 63 | + this.url = new URL(String.format(URL_MASK, ipAddress, nodeJSPort)); |
69 | 64 | } |
70 | 65 |
|
71 | 66 | public static AppiumDriverLocalService buildDefaultService() { |
@@ -185,6 +180,7 @@ private void destroyProcess() { |
185 | 180 | * @return String logs if the server has been run. |
186 | 181 | * null is returned otherwise. |
187 | 182 | */ |
| 183 | + @Nullable |
188 | 184 | public String getStdOut() { |
189 | 185 | if (process != null) { |
190 | 186 | return process.getStdOut(); |
@@ -215,4 +211,12 @@ public void addOutPutStreams(List<OutputStream> outputStreams) { |
215 | 211 | } |
216 | 212 | } |
217 | 213 |
|
| 214 | + /** |
| 215 | + * Remove all existing server output streams. |
| 216 | + * |
| 217 | + * @return true if at least one output stream has been cleared |
| 218 | + */ |
| 219 | + public boolean clearOutPutStreams() { |
| 220 | + return stream.clear(); |
| 221 | + } |
218 | 222 | } |
0 commit comments