Skip to content

Package: WsTool$1

WsTool$1

nameinstructionbranchcomplexitylinemethod
invoke(String[])
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
{...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2019 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 com.sun.xml.ws.test.CodeGenerator;
14: import junit.framework.Assert;
15:
16: import java.io.File;
17: import java.util.ArrayList;
18: import java.util.List;
19:
20: /**
21: * Interface to the <code>wsimport</code> or <code>wsgen</code> command-line tool.
22: *
23: * @author Kohsuke Kawaguchi
24: */
25: public abstract class WsTool extends Assert {
26:
27: private boolean dumpParameters;
28:
29: protected WsTool(boolean dumpParameters) {
30: this.dumpParameters = dumpParameters;
31: }
32:
33: /**
34: * Invokes wsimport with the given arguments.
35: *
36: * @throws Exception
37: * if the compilation fails.
38: * alternatively, JUnit {@link Assert}ions can be used
39: * to detect error conditions.
40: */
41: public abstract void invoke(String... args) throws Exception;
42:
43: /**
44: * Returns true if the '-skip' mode is on and
45: * the tool invocation is skipped.
46: */
47: public boolean isNoop() {
48: return this==NOOP;
49: }
50:
51: /**
52: * Determines which compiler to use.
53: *
54: * @param externalWsImport
55: * null to run {@link com.sun.xml.ws.test.tool.WsTool} from {@link com.sun.xml.ws.test.World#tool}.
56: * Otherwise this file will be the path to the script.
57: * @param extraWsToolsArgs
58: */
59: public static WsTool createWsImport(File externalWsImport, boolean dumpParameters, String extraWsToolsArgs) {
60: return createTool(externalWsImport, "com.sun.tools.ws.WsImport", dumpParameters, extraWsToolsArgs);
61: }
62:
63: /**
64: * Determines which wsgen to use.
65: *
66: * @param externalWsGen
67: * null to run {@link com.sun.xml.ws.test.tool.WsTool} from {@link com.sun.xml.ws.test.World#tool}.
68: * Otherwise this file will be the path to the script.
69: * @param extraWsToolsArgs
70: */
71: public static WsTool createWsGen(File externalWsGen, boolean dumpParameters, String extraWsToolsArgs) {
72: return createTool(externalWsGen,"com.sun.tools.ws.WsGen", dumpParameters, extraWsToolsArgs);
73: }
74:
75: private static WsTool createTool(File externalExecutable, String className, boolean dumpParameters, String extraWsToolsArgs) {
76: if(externalExecutable !=null) {
77: return new RemoteWsTool(externalExecutable, dumpParameters, extraWsToolsArgs);
78: } else {
79: return new LocalWsTool(className, dumpParameters);
80: }
81: }
82:
83: /**
84: * {@link WsTool} that does nothing.
85: *
86: * <p>
87: * This assumes that files that are supposed to be generated
88: * are already generated.
89: */
90: public static WsTool NOOP = new WsTool(false) {
91: public void invoke(String... args) {
92: }
93: };
94:
95: protected void dumpWsParams(List<String> params) {
96: System.err.println("\n\nINVOKING WS Tool:\n");
97: for(int i = 0; i < params.size(); i++) {
98: System.err.print(i == 0? " " : " ");
99: System.err.print(params.get(i));
100: System.err.println(i + 1 < params.size()? " \\" : "\n");
101: }
102:
103: // generate ws script
104: if (CodeGenerator.isGenerateTestSources()) {
105: List mkdirs = new ArrayList();
106: List params2 = new ArrayList();
107: for (int i = 0; i < params.size(); i++) {
108: String p = params.get(i);
109: if (i == 0) {
110: int index = p.lastIndexOf("/");
111: index++;
112: if (index > 0 && index < p.length()) {
113: // remove full path from tool
114: p = p.substring(index);
115: }
116: }
117: if ("-s".equals(p.trim()) || "-d".equals(p.trim()) || "-r".equals(p.trim())) {
118: String dir = params.get(i + 1);
119: mkdirs.add(dir);
120: }
121: p = CodeGenerator.fixedURLBASH(p);
122:
123: // change absolute path to relative
124: p = CodeGenerator.toRelativePath(p);
125:
126: // handle inner classes
127: if (!p.startsWith("http://")) {
128: p = p.replaceAll("\\$", "\\\\\\$");
129: }
130:
131: // ugly - "move" source wsdl to no-harness/ .. / .. /src dir
132: if (p.startsWith("../") && !p.startsWith("../src")) {
133: p = p.replaceAll("\\.\\./", "../src/");
134: }
135:
136: params2.add(p.replaceAll("localhost", "127.0.0.1"));
137: }
138: CodeGenerator.generateTool(mkdirs, params2);
139: }
140: }
141:
142: protected boolean dumpParams() {
143: return dumpParameters || CodeGenerator.isGenerateTestSources();
144: }
145:
146: }