Skip to content

Package: RemoteWsTool

RemoteWsTool

nameinstructionbranchcomplexitylinemethod
RemoteWsTool(File, boolean, String)
M: 22 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
invoke(String[])
M: 113 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 30 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package com.sun.xml.ws.test.tool;
12:
13: import java.io.File;
14: import java.io.InputStream;
15: import java.util.ArrayList;
16: import java.util.Arrays;
17: import java.util.List;
18:
19: /**
20: * Launches {@code wsimport} as a separate process.
21: *
22: * @author Kohsuke Kawaguchi
23: */
24: final class RemoteWsTool extends WsTool {
25:
26: /**
27: * The path to the executable tool.bat or wsimport.sh
28: */
29: private final File executable;
30:
31: private String toolsExtraArgs = null;
32:
33:
34: public RemoteWsTool(File executable, boolean dumpParameters, String toolsExtraArgs) {
35: super(dumpParameters);
36: this.executable = executable;
37: this.toolsExtraArgs = toolsExtraArgs;
38:• if(!executable.exists())
39: throw new IllegalArgumentException("Non-existent executable "+executable);
40: }
41:
42: public void invoke(String... args) throws Exception {
43: List<String> params = new ArrayList<String>();
44: params.add(executable.getPath());
45:
46: // add http proxy properties as CLI arguments
47: String proxyHost = System.getProperty("http.proxyHost");
48:• if (proxyHost != null) {
49: params.add("-J-Dhttp.proxyHost="+proxyHost);
50: }
51: String proxyPort = System.getProperty("http.proxyPort");
52:• if (proxyPort != null) {
53: params.add("-J-Dhttp.proxyPort="+proxyPort);
54: }
55: String nonProxyHosts = System.getProperty("http.nonProxyHosts");
56:• if (nonProxyHosts != null) {
57: // if running in bash, value must be quoted
58:• if (!nonProxyHosts.startsWith("\"")) {
59: nonProxyHosts = "\"" + nonProxyHosts + "\"";
60: }
61: params.add("-J-Dhttp.nonProxyHosts="+nonProxyHosts);
62: }
63:• if (toolsExtraArgs != null) {
64: System.err.println("adding extra tools args [" + toolsExtraArgs + "]");
65: params.add(toolsExtraArgs);
66: }
67:
68:
69: params.addAll(Arrays.asList(args));
70:
71:• if (dumpParams()) {
72: dumpWsParams(params);
73: }
74:
75: ProcessBuilder b = new ProcessBuilder(params);
76: b.redirectErrorStream(true);
77: Process proc = b.start();
78:
79: // copy the stream and wait for the process completion
80: proc.getOutputStream().close();
81: byte[] buf = new byte[8192];
82: InputStream in = proc.getInputStream();
83: int len;
84:• while((len=in.read(buf))>=0) {
85: System.out.write(buf,0,len);
86: }
87:
88: int exit = proc.waitFor();
89: assertEquals(
90: "wsimport reported exit code "+exit,
91: 0,exit);
92: }
93:
94: }