Skip to content

Package: Main$1

Main$1

nameinstructionbranchcomplexitylinemethod
createTestResult()
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
doRun(Test)
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 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, 2022 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;
12:
13: import bsh.Interpreter;
14: import com.sun.istack.test.AntXmlFormatter;
15: import com.sun.istack.test.VersionNumber;
16: import com.sun.xml.ws.test.container.ApplicationContainer;
17: import com.sun.xml.ws.test.container.cargo.EmbeddedCargoApplicationContainer;
18: import com.sun.xml.ws.test.container.cargo.InstalledCargoApplicationContainer;
19: import com.sun.xml.ws.test.container.cargo.RemoteCargoApplicationContainer;
20: import com.sun.xml.ws.test.container.gf.GlassfishContainer;
21: import com.sun.xml.ws.test.container.invm.InVmContainer;
22: import com.sun.xml.ws.test.container.javase.JavaSeContainer;
23: import com.sun.xml.ws.test.container.local.LocalApplicationContainer;
24: import com.sun.xml.ws.test.model.TestDescriptor;
25: import com.sun.xml.ws.test.tool.WsTool;
26: import com.sun.xml.ws.test.util.FileUtil;
27: import junit.framework.Test;
28: import junit.framework.TestResult;
29: import junit.framework.TestSuite;
30: import junit.textui.TestRunner;
31: import org.apache.tools.ant.DefaultLogger;
32: import org.apache.tools.ant.Project;
33: import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter;
34: import org.kohsuke.args4j.Argument;
35: import org.kohsuke.args4j.CmdLineException;
36: import org.kohsuke.args4j.CmdLineParser;
37: import org.kohsuke.args4j.Option;
38: //import org.kohsuke.junit.ParallelTestSuite;
39: import org.xml.sax.SAXException;
40:
41: import javax.xml.parsers.ParserConfigurationException;
42: import java.io.File;
43: import java.io.IOException;
44: import java.net.MalformedURLException;
45: import java.net.URL;
46: import java.util.ArrayList;
47: import java.util.HashSet;
48: import java.util.List;
49: import java.util.Set;
50: import java.util.StringTokenizer;
51: import java.util.jar.Attributes;
52: import java.util.jar.JarFile;
53: import java.util.jar.Manifest;
54: import java.util.logging.Level;
55: import java.util.logging.Logger;
56: import java.util.regex.Matcher;
57: import java.util.regex.Pattern;
58:
59: /**
60: * Test harness driver.
61: *
62: * @author Kohsuke Kawaguchi
63: */
64: public class Main {
65: // private static final Logger logger = Logger.getLogger(Main.class.getName());
66:
67: /**
68: * Tests to be executed.
69: */
70: @Argument
71: List<String> tests = new ArrayList<String>();
72:
73: @Option(name = "-r", usage = "find test directories recursively")
74: boolean recursive = false;
75:
76: @Option(name = "-p", usage = "run multiple tests in parallel")
77: int parallel = 1;
78:
79: /*
80: Classpath builder variables
81: ---------------------------
82:
83: Test harness needs to load various JAX-WS/Tango classes to do its work,
84: yet where those classes are placed depends what the user is working on.
85:
86: Harness defines a few 'profiles' of the jar file layout, and allow users
87: to choose them.
88: */
89: @Option(name = "-cp:wsit-image", usage = "classpath option\npath to the WSIT dist image", metaVar = "WSIT_HOME")
90: File wsitImage = null;
91:
92: @Option(name = "-cp:wsit", usage = "classpath option\npath to WSIT workspace", metaVar = "WSIT_HOME")
93: File wsitWs = null;
94:
95: @Option(name = "-cp:jaxws-image", usage = "classpath option\npath to JAX-WS RI dist image", metaVar = "JAXWS_HOME")
96: File jaxwsImage = null;
97:
98: @Option(name = "-cp:jaxws", usage = "classpath option\npath to JAX-WS RI workspace", metaVar = "JAXWS_HOME")
99: File jaxwsWs = null;
100:
101: @Option(name = "-external-wsimport", usage = "use external tool.sh/.bat")
102: File externalWsImport = null;
103:
104: @Option(name = "-external-wsgen", usage = "use external wsgen.sh/.bat")
105: File externalWsGen = null;
106:
107: @Option(name = "-skip", usage = "skip all code generation and reuse the artifacts generated during the last run")
108: boolean skipCompilation;
109:
110: @Option(name = "-transport", usage = "specify the pluggable transport jar")
111: File transportJar;
112:
113: @Option(name = "-cp:override", usage = "these jars and folders are placed in front of other -cp:*** options. Useful for overriding some jars")
114: String classPathOverride;
115:
116: /**
117: * This is copied to {@link World#debug}.
118: */
119: @Option(name = "-debug", usage = "Generate output for debugging harness")
120: boolean debug;
121:
122: @Option(name = "-dump", usage = "Enable all transport dumps")
123: boolean dump;
124:
125: @Option(name = "-generateTestSources", usage = "Generates plain java sources + bash scripts to run the testcase (works just for JavaSE deployment)")
126: boolean generateTestSources;
127:
128: @Option(name = "-report", usage = "Generate JUnit test report XMLs", metaVar = "DIR")
129: File reportDir = null;
130:
131: @Option(name = "-concurrent-side-effect-free", usage = "Run all side-effect free tests as concurrent")
132: boolean concurrentSideEffectFree = false;
133:
134:
135: @Option(name = "-version", usage = "Specify the target JAX-WS version being tested. This determines test exclusions", handler = VersionNumberHandler.class)
136: VersionNumber version = null;
137:
138: @Option(name = "-targetVersion", usage = "Specify the target JAX-WS runtime version. This determines target option for the WS Tools to generate code compliant with the runtime version", handler = VersionNumberHandler.class)
139: VersionNumber targetVersion = null;
140:
141:
142: @Option(name = "-client", usage = "Just run a single client script, instead of all")
143: String clientScriptName = null;
144:
145: /*
146: Container variables
147: -------------------
148:
149: Options that choose the container to host services.
150: They are mutually exclusive, but we don't have means to enforce
151: exclusiveness right now.
152:
153: If none is given we test in the local mode.
154: */
155: @Option(name = "-tomcat-local", usage = "Launch Tomcat from the harness and test with it", metaVar = "TOMCAT_HOME")
156: File tomcat = null;
157:
158: @Option(name = "-tomcat-remote", metaVar = "CONFIG",
159: usage = "Test with remote Tomcat.\n" +
160: "CONFIG=[USER:PASS@]HOST[:PORT].\n" +
161: "Defaults: USER=admin, PASS=admin, PORT=8080")
162: String remoteTomcat = null;
163:
164: @Option(name = "-tomcat-embedded", metaVar = "TOMCAT_HOME",
165: usage = "loads Tomcat into the harness VM and test with it.")
166: File embeddedTomcat = null;
167:
168:
169: @Option(name = "-jetty-embedded", metaVar = "JETTY_HOME",
170: usage = "loads Jetty into the harness VM and test with it.")
171: File embeddedJetty;
172:
173: @Option(name = "-lwhs", usage = "tests using the Java lightweight HTTP server")
174: boolean lwhs = false;
175:
176: @Option(name = "-jaxwsInJDK", usage = "tests using JAX-WS impl in JDK")
177: boolean jaxwsInJDK = false;
178:
179: @Option(name = "-httpspi", usage = "use JAX-WS 2.2 httpspi API deployment for servlet containers")
180: boolean httpspi = false;
181:
182:
183: @Option(name = "-glassfish-remote", metaVar = "CONFIG",
184: usage =
185: "Test with remote Glassfish. Needs both JMX connection info and HTTP URL.\n" +
186: "CONFIG=[USER:PASS@]HOST[:PORT][-HTTPURL]\n" +
187: "e.g., admin:adminadmin@localhost:4848-http://localhost:8080/\n" +
188: "Defaults: USER=admin, PASS=adminadmin, PORT=4848, HTTPURL=http://HOST/")
189: String remoteGlassfish = null;
190:
191: @Option(name = "-glassfish-local", metaVar = "GLASSFISH_HOME",
192: usage =
193: "Launch Glassfish from the harness and test with it")
194: File localGlassfish = null;
195:
196: @Option(name = "-glassfishv3-local", metaVar = "GLASSFISH_HOME",
197: usage = "Launch Glassfish v3 from the harness and test with it")
198: File localGlassfishV3 = null;
199:
200: @Option(name = "-legacy-local", usage = "Emergency! I need to use the legacy local transport!")
201: boolean legacyLocalTransport = false;
202:
203: @Option(name = "-leave", usage = "leave the container running after all the tests are completed. Often useful for debugging problems.")
204: boolean leave = false;
205:
206: @Option(name = "-toolsDump", usage = "Dumps WsTools parameters. Useful for reproducing tools problems.")
207: boolean toolsDump = false;
208:
209: @Option(name = "-toolsExtraArgs", usage = "Adds extra argument(s) to all WsTools invocation. \n" +
210: "Useful when extra JVM param is necessary \n" +
211: "e.g. -toolsExtraArgs -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", metaVar = "TOOLS_ARGS")
212: String toolsExtraArgs = null;
213:
214: @Option(name = "-port", usage = "Choose the TCP port used for local/embedded container-based tests. Set to -1 to choose random port.")
215: int port = -1;
216:
217: @Option(name = "-wsgen", usage =
218: "Control the packaging of Wrapper and Exception beans.\n" +
219: "always - Beans are packaged.\n" +
220: "both - Test case is executed twice, with and without packaging beans.\n" +
221: "ignore - Beans are NOT packaged.", metaVar = "[always|both|ignore]"
222: )
223: WsGenMode wsGenMode = WsGenMode.ALWAYS;
224:
225: public static File[] containerClasspathPrefix = new File[0];
226:
227: public static void main(String[] args) throws Exception {
228: // enable all assertions
229: Main.class.getClassLoader().setDefaultAssertionStatus(true);
230:
231: // use the platform default proxy if available.
232: // see sun.net.spi.DefaultProxySelector for details.
233: try {
234: System.setProperty("java.net.useSystemProxies", "true");
235: } catch (SecurityException e) {
236: // failing to set this property isn't fatal
237: }
238:
239: System.exit(doMain(args));
240: }
241:
242: public static int doMain(String[] args) throws Exception {
243: Main main = new Main();
244: CmdLineParser parser = new CmdLineParser(main);
245: try {
246: parser.parseArgument(args);
247:
248: if (main.tests.isEmpty()) {
249: throw new CmdLineException("No test is given");
250: }
251:
252: CodeGenerator.setGenerateTestSources(main.generateTestSources);
253:
254: return main.run();
255: } catch (CmdLineException e) {
256: System.err.println(e.getMessage());
257: parser.printUsage(System.err);
258: return -1;
259: }
260: }
261:
262: /**
263: * Heart of the test.
264: */
265: public int run() throws Exception {
266: fillWorld();
267:
268: if (dump) {
269: // standalone version
270: System.setProperty("com.sun.xml.ws.transport.local.LocalTransportTube.dump", "true");
271: System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
272: System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
273:
274: // jdk version
275: System.setProperty("com.sun.xml.internal.ws.transport.local.LocalTransportTube.dump", "true");
276: System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");
277: System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");
278: }
279:
280: // set up objects that represent test environment.
281: WsTool wsimport, wsgen;
282: if (skipCompilation) {
283: System.err.println("Skipping compilation");
284: wsimport = wsgen = WsTool.NOOP;
285: } else {
286: wsimport = WsTool.createWsImport(externalWsImport, toolsDump, toolsExtraArgs);
287: wsgen = WsTool.createWsGen(externalWsGen, toolsDump, toolsExtraArgs);
288: }
289: ApplicationContainer container = createContainer(wsimport, wsgen);
290:
291: // build up test plan
292: TestSuite suite = createTestSuite();
293: for (String dir : tests) {
294: build(new File(dir), container, wsimport, suite);
295: }
296:
297: if (suite.countTestCases() == 0) {
298: System.err.println("No test to run");
299: return -1;
300: }
301:
302: container.start();
303:
304: try {// run the tests
305:
306: // custom TestRunner that can generate Ant format report
307: TestRunner testRunner = new TestRunner() {
308: private AntXmlFormatter formatter;
309:
310: @Override
311: protected TestResult createTestResult() {
312: TestResult result = super.createTestResult();
313:
314:• if (reportDir != null) {
315: reportDir.mkdirs();
316: formatter = new AntXmlFormatter(XMLJUnitResultFormatter.class, reportDir);
317: result.addListener(formatter);
318: }
319: return result;
320: }
321:
322: @Override
323: public TestResult doRun(Test test) {
324: try {
325: return super.doRun(test);
326: } finally {
327:• if (formatter != null) {
328: formatter.close();
329: }
330: }
331: }
332: };
333:
334: TestResult r = testRunner.doRun(suite);
335:
336: return r.errorCount() + r.failureCount();
337: } finally {
338: if (!leave) {
339: container.shutdown();
340: } else {
341: if (container instanceof JavaSeContainer) {
342: for(int i = 10; i > 0; i--) {
343: System.err.println("Keeping JavaSeContainer on for debugging. Shutting down in [" + (i * 30) + " secs] ...");
344: Thread.sleep(30000l);
345: }
346: System.err.println("Shutting JavaSeContainer down.");
347: }
348: }
349: CodeGenerator.testCaseDone();
350: CodeGenerator.allTestsDone(tests.get(0));
351: }
352: }
353:
354: /**
355: * Fills the world with classes.
356: */
357: private void fillWorld() throws Exception {
358: World.debug = this.debug;
359:
360: Realm runtime = World.runtime;
361: Realm tool = World.tool;
362:
363: if (classPathOverride != null) {
364: StringTokenizer tokens = new StringTokenizer(classPathOverride, File.pathSeparator);
365: while (tokens.hasMoreTokens()) {
366: runtime.addJar(new File(tokens.nextToken()));
367: }
368: }
369:
370: if (transportJar != null) {
371: if (transportJar.exists()) {
372: runtime.addJar(transportJar);
373: } else {
374: throw new IllegalArgumentException(transportJar + " does not exist.");
375: }
376: }
377:
378: // fill in container realm.
379: if (embeddedTomcat != null) {
380: runtime.addJarFolder(new File(embeddedTomcat, "bin"));
381: runtime.addJarFolder(new File(embeddedTomcat, "lib"));
382: }
383:
384: if (tomcat != null) {
385: runtime.addJarFolder(new File(tomcat, "bin"));
386: runtime.addJarFolder(new File(tomcat, "lib"));
387: }
388:
389: if (embeddedJetty != null) {
390: runtime.addJarFolder(embeddedJetty);
391: runtime.addJarFolder(new File(embeddedJetty, "lib"));
392: }
393:
394: if (wsitImage == null && wsitWs == null && jaxwsImage == null && jaxwsWs == null && !jaxwsInJDK) {
395: guessWorkspace();
396: }
397:
398: // fill in runtime and tool realms
399: if (wsitImage != null) {
400: runtime.addJarFolder(new File(wsitImage, "lib"), "webservices-tools.jar");
401: tool.addJar(new File(wsitImage, "lib/webservices-tools.jar"));
402:
403: containerClasspathPrefix = new File[4];
404: //TODO: FIX ME!?
405: // containerClasspathPrefix[0] = rtJar;
406: // containerClasspathPrefix[1] = toolJar;
407: // containerClasspathPrefix[2] = apiJar;
408: // containerClasspathPrefix[3] = extraJar;
409:
410: } else if (wsitWs != null) {
411: runtime.addClassFolder(new File(wsitWs, "rt/build/classes"));
412: runtime.addJarFolder(new File(wsitWs, "lib/runtime"));
413: /*runtime.addClassFolder( new File(wsitWs,"tools/build/classes"));
414: runtime.addJarFolder( new File(wsitWs,"lib/tooltime"));*/
415: tool.addClassFolder(new File(wsitWs, "tools/build/classes"));
416: tool.addJarFolder(new File(wsitWs, "lib/tooltime"));
417:
418: } else if (jaxwsImage != null) {
419: tool.addJar(new File(jaxwsImage, "lib/jaxws-tools.jar"));
420: if (new File(jaxwsImage, "lib/jaxb-jxc.jar").exists()) {
421: tool.addJar(new File(jaxwsImage, "lib/jaxb-jxc.jar"));
422: }
423: tool.addJar(new File(jaxwsImage, "lib/jaxb-xjc.jar"));
424: List<String> exclusionList = new ArrayList<>();
425: exclusionList.add("jaxws-tools.jar");
426: exclusionList.add("jaxb-jxc.jar");
427: exclusionList.add("jaxb-xjc.jar");
428: runtime.addJarFolder(new File(jaxwsImage, "lib"),
429: exclusionList.toArray(new String[exclusionList.size()]));
430:
431: } else if (jaxwsWs != null) {
432: //maven build
433: //runtime
434: File jaxwsRt = new File(jaxwsWs, "runtime");
435: //is the build instrumented by cobertura?
436: String classesFolder = new File(jaxwsRt, "rt/target/generated-classes/cobertura").exists()
437: ? "target/generated-classes/cobertura"
438: : "target/classes";
439:
440: if (new File(jaxwsRt, "policy/" + classesFolder).exists()) {
441: runtime.addClassFolder(new File(jaxwsRt, "policy/" + classesFolder));
442: }
443: if (new File(jaxwsRt, "rt/" + classesFolder + "/META-INF/versions/9").exists()) {
444: runtime.addClassFolder(new File(jaxwsRt, "rt/" + classesFolder + "/META-INF/versions/9"));
445: }
446: runtime.addClassFolder(new File(jaxwsRt, "rt/" + classesFolder));
447: if (new File(jaxwsRt, "rt-ha/" + classesFolder).exists()) {
448: runtime.addClassFolder(new File(jaxwsRt, "rt-ha/" + classesFolder));
449: }
450: runtime.addClassFolder(new File(jaxwsRt, "servlet/" + classesFolder));
451: runtime.addClassFolder(new File(jaxwsRt, "rt-fi/" + classesFolder));
452: runtime.addClassFolder(new File(jaxwsRt, "httpspi-servlet/" + classesFolder));
453:
454: runtime.addClassFolder(new File(jaxwsWs, "extras/transports/local/" + classesFolder));
455:
456: // this is needed for Localizer (which lives in jaxb-impl available to runtime) to find message resources of wsimport
457: runtime.addClassFolder(new File(jaxwsWs, "tools/wscompile/src/main/resources"));
458:
459: //databinding plugins
460: if ("com.sun.xml.ws.db.toplink.JAXBContextFactory".equals(System.getProperty("BindingContextFactory"))) {
461: runtime.addClassFolder(new File(jaxwsWs, "extras/eclipselink_jaxb/" + classesFolder));
462: } else if ("com.sun.xml.ws.db.sdo.SDOContextFactory".equals(System.getProperty("BindingContextFactory"))) {
463: runtime.addClassFolder(new File(jaxwsWs, "extras/eclipselink_sdo/" + classesFolder));
464: }
465:
466: if (new File(jaxwsWs, "tools/wscompile/" + classesFolder + "/META-INF/versions/9").exists()) {
467: tool.addClassFolder(new File(jaxwsWs, "tools/wscompile/" + classesFolder + "/META-INF/versions/9"));
468: }
469: tool.addClassFolder(new File(jaxwsWs, "tools/wscompile/" + classesFolder));
470:
471: //now find libraries
472: File libDir = System.getProperty("libraries.dir") != null
473: ? new File(System.getProperty("libraries.dir"))
474: : new File(jaxwsWs, "bundles/jaxws-ri/target/stage/jaxws-ri/lib");
475: for (File lib : libDir.listFiles()) {
476: String name = lib.getName();
477: if (name.contains("jaxws-rt") || name.contains("jaxws-tools")) {
478: continue;
479: }
480: if (name.contains("jaxb-jxc") || name.contains("jaxb-xjc")) {
481: tool.addJar(lib);
482: } else {
483: runtime.addJar(lib);
484: }
485: }
486:
487: } else if (jaxwsInJDK) {
488: System.out.println("Using JAX-WS in JDK");
489: File javaHome = new File(System.getProperty("java.home"));
490:
491: // first try: standard jre/jdk layout
492: findWsTools(javaHome.getParent());
493:
494: if (!externalWsGen.exists() || !externalWsImport.exists()) {
495: // second try: is it jigsaw modularized build?
496: findWsTools(javaHome.getAbsolutePath());
497: }
498:
499: if (!externalWsGen.exists() || !externalWsImport.exists()) {
500: // tools not found
501: throw new CmdLineException("wsgen or wsimport command line tools are not found in jdk");
502: }
503:
504: System.out.println("Using wsgen from " + externalWsGen);
505: System.out.println("Using wsimport from " + externalWsImport);
506: lwhs = true;
507: if (version == null) {
508: version = new VersionNumber("2.1.6");
509: }
510: System.out.println("Going to use SE lightweight http server");
511: } else {
512: throw new CmdLineException("No -cp option is specified, nor were we able to guess the -cp option");
513: }
514:
515: // pick up ${HARNESS_HOME}/ext jars or ${HARNESS_EXT} jars
516: File extDir = null;
517: if (System.getProperty("HARNESS_HOME") != null) {
518: extDir = new File(System.getProperty("HARNESS_HOME"), "ext");
519: } else if (System.getProperty("HARNESS_EXT") != null) {
520: extDir = new File(System.getProperty("HARNESS_EXT"));
521: }
522: if (extDir != null && extDir.isDirectory()) {
523: if (debug) {
524: System.err.println("Searching extensions in " + extDir);
525: }
526: if (extDir.exists()) {
527: for (File f : extDir.listFiles(FileUtil.JAR_FILE_FILTER)) {
528: System.err.println("Picking up extension: " + f);
529: runtime.addJar(f);
530: }
531: }
532: } else {
533: System.err.println("No extension jar");
534: }
535:
536:
537: // put tools.jar in the tools classpath
538: File jreHome = new File(System.getProperty("java.home"));
539: File toolsJar = new File(jreHome.getParent(), "lib/tools.jar");
540: if (toolsJar.exists()) {
541: tool.addJar(toolsJar);
542: }
543:
544:
545: if (debug) {
546: Interpreter.DEBUG = true;
547: System.err.println("runtime realm");
548: runtime.dump(System.err);
549: System.err.println("tool realm");
550: tool.dump(System.err);
551:
552: // install listener to Ant project so that we can get logging from there
553: DefaultLogger listener = new DefaultLogger();
554: World.project.addBuildListener(listener);
555: listener.setMessageOutputLevel(Project.MSG_INFO);
556: listener.setOutputPrintStream(System.out);
557: listener.setErrorPrintStream(System.err);
558: }
559:
560: }
561:
562: private void findWsTools(String path) {
563: externalWsGen = new File(path, "bin/wsgen");
564: if (!externalWsGen.exists()) {
565: externalWsGen = new File(path, "bin/wsgen.exe");
566: }
567: externalWsImport = new File(path, "bin/wsimport");
568: if (!externalWsImport.exists()) {
569: externalWsImport = new File(path, "bin/wsimport.exe");
570: }
571: }
572:
573: /**
574: * Guess which workspace we want to test against, in case no "-cp" is given.
575: */
576:
577: private void guessWorkspace() {
578: // JAX-WS RI teams often set this variable
579: String jaxwsHome = System.getenv("JAXWS_HOME");
580: if (jaxwsHome != null) {
581: File f = new File(jaxwsHome);
582: if (f.isDirectory()) {
583: if (f.getName().equals("build")) {
584: // probably being set to jaxws-ri/build. Let's verify.
585: File home = f.getParentFile();
586: if (new File(home, ".jaxws-ri").exists()) {
587: System.out.println("Found JAX-WS RI workspace at " + home);
588: jaxwsWs = home;
589: return;
590: }
591: }
592:
593: // is this really JAX-WS home?
594: if (new File(f, ".jaxws-ri").exists()) {
595: System.out.println("Found JAX-WS RI workspace at " + f);
596: jaxwsWs = f;
597: return;
598: }
599:
600: // the other possibility is it's pointing to the JAX-WS RI distribution image
601: if (new File(f, "lib/jaxws-rt.jar").exists() && new File(f, "bin/wsgen.bat").exists()) {
602: System.out.println("Found JAX-WS RI distribution image at " + f);
603: jaxwsImage = f;
604: return;
605: }
606: }
607: }
608:
609: // let's go up the directory hierarchy a bit to find a match
610: File harnessJar = getHarnessJarDirectory();
611: File jaxwsUnit = getParentWithName(harnessJar, "jaxws-unit");
612: if (jaxwsUnit != null) {
613: for (File other : jaxwsUnit.getParentFile().listFiles(FileUtil.DIRECTORY_FILTER)) {
614: if (new File(other, ".jaxws-ri").exists()) {
615: System.out.println("Found JAX-WS RI workspace at " + other);
616: jaxwsWs = other;
617: return;
618: }
619: }
620: }
621:
622: // are we in WSIT?
623: File wsitHome = getParentWithFile(harnessJar, ".wsit");
624: if (wsitHome != null) {
625: System.out.println("Found WSIT workspace at " + wsitHome);
626: this.wsitWs = wsitHome;
627: }
628:
629: // couldn't make any guess
630: }
631:
632: /**
633: * Determines the container to be used for tests.
634: *
635: * @param wsimport
636: */
637: private ApplicationContainer createContainer(WsTool wsimport, WsTool wsgen) throws Exception {
638: ApplicationContainer appContainer = null;
639: if (tomcat != null) {
640: TomcatVersion tv = getTomcatVersion(tomcat);
641: System.err.println("Using Tomcat from " + tomcat);
642: System.err.println("\tSpecification version " + tv.getSpecVersion());
643: System.err.println("\tImplementation version " + tv.getImplVersion());
644: appContainer = new InstalledCargoApplicationContainer(
645: wsimport, wsgen, tv.getId(), tomcat, port, httpspi);
646: appContainer.getUnsupportedUses().add("skip-tomcat");
647: }
648:
649: if (embeddedTomcat != null) {
650: TomcatVersion tv = getTomcatVersion(embeddedTomcat);
651: appContainer = new EmbeddedCargoApplicationContainer(
652: wsimport, wsgen, tv.getId(), port, httpspi);
653: appContainer.getUnsupportedUses().add("skip-embeddedTomcat");
654: }
655:
656: if (embeddedJetty != null) {
657: appContainer = new EmbeddedCargoApplicationContainer(
658: wsimport, wsgen, "jetty11x", port, httpspi);
659: appContainer.getUnsupportedUses().add("skip-jetty");
660: }
661:
662: if (remoteTomcat != null) {
663: System.err.println("Using remote Tomcat at " + remoteTomcat);
664: // group capture number : 12 3 4 5 6
665: Matcher matcher = Pattern.compile("((.+):(.*)@)?([^:]+)(:([0-9]+))?").matcher(remoteTomcat);
666: if (!matcher.matches()) {
667: throw new CmdLineException("Unable to parse " + remoteTomcat);
668: }
669:
670: appContainer = new RemoteCargoApplicationContainer(
671: wsimport, wsgen,
672: "tomcat10x",
673: new URL("http", matcher.group(4),
674: Integer.parseInt(defaultsTo(matcher.group(6), "8080")),
675: "/"),
676: defaultsTo(matcher.group(2), "admin"),
677: defaultsTo(matcher.group(3), "admin"),
678: httpspi
679: );
680: appContainer.getUnsupportedUses().add("skip-tomcat");
681: }
682:
683: if (localGlassfish != null) {
684: System.err.println("Using local Glassfish from " + localGlassfish);
685: appContainer = new InstalledCargoApplicationContainer(
686: wsimport, wsgen, "glassfish1x", localGlassfish, port, httpspi);
687: appContainer.getUnsupportedUses().add("servlet30");
688: }
689:
690: if (localGlassfishV3 != null) {
691: System.err.println("Using local Glassfish v3 from " + localGlassfishV3);
692: appContainer = new InstalledCargoApplicationContainer(
693: wsimport, wsgen, "glassfish3x", localGlassfishV3, port, httpspi);
694: }
695:
696: if (remoteGlassfish != null) {
697: // [USER:PASS@]HOST[:PORT][-HTTPURL]
698: System.err.println("Using remote Glassfish at " + remoteGlassfish);
699: // group capture number : 12 3 4 5 6 7 8
700: Matcher matcher = Pattern.compile("((.+):(.*)@)?([^:\\-]+)(:([0-9]+))?(\\-(.+))?").matcher(remoteGlassfish);
701: if (!matcher.matches()) {
702: throw new CmdLineException("Unable to parse " + remoteGlassfish);
703: }
704:
705: String userName = defaultsTo(matcher.group(2), "admin");
706: String password = defaultsTo(matcher.group(3), "adminadmin");
707: String remoteHost = matcher.group(4);
708: String remotePort = defaultsTo(matcher.group(6), "4848");
709: String httpUrl = matcher.group(8);
710:
711: if (httpUrl == null) {
712: // defaulted
713: httpUrl = "http://" + remoteHost + ":8080/";
714: }
715:
716: appContainer = new GlassfishContainer(
717: wsimport, wsgen, new URL(httpUrl), remoteHost, Integer.parseInt(remotePort), userName, password, httpspi
718: );
719: appContainer.getUnsupportedUses().add("servlet30");
720: }
721:
722: if (lwhs) {
723: System.err.println("Using the built-in Java SE lightweight HTTP server");
724: Set<String> unsupportedUses = new HashSet<String>();
725: unsupportedUses.add("servlet");
726: unsupportedUses.add("servlet30");
727: unsupportedUses.add("multi-endpoint");
728: unsupportedUses.add("skip-lwhs");
729: if (jaxwsInJDK) {
730: unsupportedUses.add("ri");
731: }
732: appContainer = new JavaSeContainer(wsimport, wsgen, port, unsupportedUses);
733: }
734:
735: if (legacyLocalTransport) {
736: System.err.println("Using the legacy local transport. This will be removed in a near future");
737: appContainer = new LocalApplicationContainer(wsimport, wsgen);
738: appContainer.getUnsupportedUses().add("servlet30");
739: }
740: if (appContainer == null) {
741: System.err.println("Testing with the in-vm transport");
742: appContainer = new InVmContainer(wsimport, wsgen);
743: appContainer.getUnsupportedUses().add("servlet30");
744: }
745: return appContainer;
746: }
747:
748: private static String defaultsTo(String value, String defaultValue) {
749: if (value == null) {
750: return defaultValue;
751: } else {
752: return value;
753: }
754: }
755:
756: /**
757: * Creates {@link TestSuite} that hides sequential/parallel execution
758: * of tests.
759: */
760: private TestSuite createTestSuite() {
761: if (parallel > 1) {
762: System.err.println("Running tests in " + parallel + " threads");
763: return new TestSuite();
764: } else {
765: return new TestSuite();
766: }
767: }
768:
769: /**
770: * Scans the given directory, builds {@link TestDescriptor}s,
771: * and schedule them to {@link TestSuite}.
772: */
773: private void build(File dir, ApplicationContainer container, WsTool wsimport, TestSuite suite) throws IOException, ParserConfigurationException,
774: SAXException {
775: File descriptor = new File(dir, "test-descriptor.xml");
776:
777: if (descriptor.exists()) {
778: try {
779: TestDescriptor td[] = new TestDescriptor[2];
780: if (wsGenMode == WsGenMode.ALWAYS) {
781: td[0] = new TestDescriptor(descriptor, false, jaxwsInJDK);
782: } else if (wsGenMode == WsGenMode.BOTH) {
783: td[0] = new TestDescriptor(descriptor, false, jaxwsInJDK);
784: td[1] = new TestDescriptor(descriptor, true, jaxwsInJDK);
785: } else if (wsGenMode == WsGenMode.IGNORE) {
786: td[0] = new TestDescriptor(descriptor, true, jaxwsInJDK);
787: } else {
788: throw new RuntimeException("Shouldn't happen. WsGenMode=" + wsGenMode);
789: }
790: if (version != null && !td[0].applicableVersions.isApplicable(version)) {
791: System.err.println("Skipping " + dir);
792: } else {
793: if (targetVersion != null) {
794: td[0].wsimportClientOptions.add("-target");
795: td[0].wsimportClientOptions.add(targetVersion.toString());
796: td[0].wsimportServerOptions.add("-target");
797: td[0].wsimportServerOptions.add(targetVersion.toString());
798:
799: if (td[1] != null) {
800: td[1].wsimportClientOptions.add("-target");
801: td[1].wsimportClientOptions.add(targetVersion.toString());
802: td[1].wsimportServerOptions.add("-target");
803: td[1].wsimportServerOptions.add(targetVersion.toString());
804:
805:
806: }
807: }
808: suite.addTest(td[0].build(container, wsimport, clientScriptName, concurrentSideEffectFree, version));
809: if (td[1] != null) {
810: suite.addTest(td[1].build(container, wsimport, clientScriptName, concurrentSideEffectFree, version));
811: }
812: }
813: } catch (IOException | ParserConfigurationException | SAXException e) {
814: // even if we fail to process this descriptor, don't let the whole thing fail.
815: // just report that failure as a test failure.
816: suite.addTest(new FailedTest("invalid descriptor", e));
817: }
818: return;
819: }
820:
821: if (recursive && dir.isDirectory()) {
822: // find test data recursively
823: File[] subdirs = dir.listFiles(FileUtil.DIRECTORY_FILTER);
824:
825: for (File subdir : subdirs) {
826: build(subdir, container, wsimport, suite);
827: }
828: }
829: }
830:
831: /**
832: * Determines the 'home' directory of the test harness.
833: * This is used to determine where to load other files.
834: */
835: private static File getHarnessJarDirectory() {
836: try {
837: String res = Main.class.getClassLoader().getResource("com/sun/xml/ws/test/Main.class").toExternalForm();
838: if (res.startsWith("jar:")) {
839: res = res.substring(4, res.lastIndexOf('!'));
840: return new File(new URL(res).getFile()).getParentFile();
841: }
842: return new File(".").getAbsoluteFile();
843: } catch (MalformedURLException e) {
844: throw new Error(e);
845: }
846: }
847:
848: /**
849: * Find the nearest ancestor directory that has the given name and returns it.
850: * Otherwise null.
851: */
852: private File getParentWithName(File file, String name) {
853: while (file != null) {
854: if (file.getName().equals(name)) {
855: return file;
856: }
857: file = file.getParentFile();
858: }
859: return null;
860: }
861:
862: /**
863: * Find the nearest ancestor directory that has the given file and returns it.
864: * Otherwise null.
865: */
866: private File getParentWithFile(File file, String markerFile) {
867: while (file != null) {
868: if (new File(file, markerFile).exists()) {
869: return file;
870: }
871: file = file.getParentFile();
872: }
873: return null;
874: }
875:
876: private static TomcatVersion getTomcatVersion(File tcHome) {
877: String implVersion = null;
878: String specVersion = null;
879: try {
880: File f = new File(tcHome, "lib/catalina.jar");
881: if (f.exists() && f.canRead()) {
882: JarFile jar = new JarFile(f);
883: Manifest mf = jar.getManifest();
884: if (mf != null) {
885: Attributes attrs = mf.getMainAttributes();
886: if (attrs != null) {
887: specVersion = attrs.getValue("Specification-Version");
888: implVersion = attrs.getValue("Implementation-Version");
889: }
890: }
891: } else {
892: System.err.println("Cannot read: " + f.getAbsolutePath());
893: }
894: } catch (IOException ex) {
895: Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
896: }
897: return TomcatVersion.create(specVersion, implVersion);
898: }
899:
900: private static class TomcatVersion {
901: private String implVersion;
902: private String specVersion;
903: private String id;
904: private final Set<String> features = new HashSet<String>();
905:
906: static TomcatVersion create(String specVersion, String implVersion) {
907: TomcatVersion tv = new TomcatVersion();
908: tv.setSpecVersion(specVersion);
909: tv.setImplVersion(implVersion);
910: char major = 0;
911: if (implVersion != null) {
912: major = implVersion.charAt(0);
913: } else if (specVersion != null) {
914: major = specVersion.charAt(0);
915: }
916: switch (major) {
917: case '5':
918: tv.setId("tomcat5x");
919: break;
920: case '6':
921: tv.setId("tomcat6x");
922: break;
923: case '7':
924: tv.setId("tomcat7x");
925: tv.addFeature("servlet30");
926: break;
927: case '8':
928: tv.setId("tomcat8x");
929: tv.addFeature("servlet30");
930: tv.addFeature("servlet31");
931: break;
932: case '9':
933: tv.setId("tomcat9x");
934: tv.addFeature("servlet30");
935: tv.addFeature("servlet31");
936: tv.addFeature("servlet40");
937: break;
938: default:
939: Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Unrecognized Tomcat version: spec {0}, impl {1}", new Object[]{specVersion, implVersion});
940: Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Using default tomcat10x...");
941: tv.setId("tomcat10x");
942: tv.addFeature("servlet30");
943: tv.addFeature("servlet31");
944: tv.addFeature("servlet40");
945: }
946: return tv;
947: }
948:
949: public String getImplVersion() {
950: return implVersion;
951: }
952:
953: public void setImplVersion(String implVersion) {
954: this.implVersion = implVersion;
955: }
956:
957: public String getSpecVersion() {
958: return specVersion;
959: }
960:
961: public void setSpecVersion(String specVersion) {
962: this.specVersion = specVersion;
963: }
964:
965: public String getId() {
966: return id;
967: }
968:
969: public void setId(String id) {
970: this.id = id;
971: }
972:
973: private void addFeature(String feature) {
974: features.add(feature);
975: }
976:
977: public boolean supports(String feature) {
978: return features.contains(feature);
979: }
980:
981: }
982: }