Skip to content

Package: Bootstrap$1

Bootstrap$1

nameinstructionbranchcomplexitylinemethod
accept(File, String)
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%
{...}
M: 3 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, 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;
12:
13: import java.io.File;
14: import java.io.FilenameFilter;
15: import java.io.IOException;
16: import java.lang.reflect.Method;
17: import java.net.URL;
18: import java.net.URLClassLoader;
19: import java.util.ArrayList;
20: import java.util.List;
21: import java.util.logging.Logger;
22:
23: /**
24: * Entry point for setting up the classworlds.
25: *
26: * <p>
27: * To maximize the isolation and avoid test interference, test harness
28: * could should not be put into the system classloader. The bootstrap module
29: * is the small code that's loaded into the system classloader.
30: *
31: * <p>
32: * It's only job is to find all the jars that consistute the harness,
33: * and create a {@link URLClassLoader}, then call into it.
34: *
35: * @author Kohsuke Kawaguchi
36: */
37: public class Bootstrap {
38: public static void main(String[] args) throws Exception {
39: File home = getHomeDirectory();
40: logger.fine("test harness home is "+home);
41:
42: // system properties are ugly but easy way to communicate values to the harness main code
43: // setting a value other than String makes Ant upset
44: System.getProperties().put("HARNESS_HOME",home.getPath());
45:
46: // create the harness realm and put everything in there
47: List<URL> harness = new ArrayList<URL>();
48: // extension hook to add more libraries
49: File extLib = new File(home,"lib");
50: if(extLib.exists()) {
51: for (File jar : extLib.listFiles(new FilenameFilter() {
52: public boolean accept(File dir, String name) {
53: return name.endsWith(".jar");
54: }
55: })) {
56: logger.info("Adding "+jar+" to the harness realm");
57: harness.add(jar.toURL());
58: }
59: }
60:
61: // add harness-lib.jar. Do this at the end so that overrides can take precedence.
62: File libJar = new File(home,"harness-lib.jar");
63: harness.add(libJar.toURL());
64:
65: // use the system classloader as the parent, so that the harness
66: // and the test code can share the same JUnit
67: ClassLoader cl = new URLClassLoader(harness.toArray(new URL[0]),
68: ClassLoader.getSystemClassLoader());
69:
70: // call into the main method
71: Class main = cl.loadClass("com.sun.xml.ws.test.Main");
72: Method mainMethod = main.getMethod("main", String[].class);
73: Thread.currentThread().setContextClassLoader(cl);
74: mainMethod.invoke(null,new Object[]{args});
75: }
76:
77: /**
78: * Determines the 'home' directory of the test harness.
79: * This is used to determine where to load other files.
80: */
81: private static File getHomeDirectory() throws IOException {
82: String res = Bootstrap.class.getClassLoader().getResource("com/sun/xml/ws/test/Bootstrap.class").toExternalForm();
83: if(res.startsWith("jar:")) {
84: res = res.substring(4,res.lastIndexOf('!'));
85: // different classloader behaves differently when it comes to space
86: return new File(new URL(res).getFile().replace("%20"," ")).getParentFile();
87: }
88: throw new IllegalStateException("I can't figure out where the harness is loaded from: "+res);
89: }
90:
91: private static final Logger logger = Logger.getLogger(Bootstrap.class.getName());
92: }