Skip to content

Package: Realm

Realm

nameinstructionbranchcomplexitylinemethod
Realm(String, Realm)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
addClassFolder(File)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
addJar(File)
M: 24 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
addJarFolder(File, String[])
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
dump(PrintStream)
M: 25 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getClassLoader()
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getPath()
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%
list()
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
loadClass(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
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%
toString()
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;
12:
13: import com.sun.istack.Nullable;
14: import org.apache.tools.ant.AntClassLoader;
15: import org.apache.tools.ant.types.Path;
16:
17: import java.io.File;
18: import java.io.FileFilter;
19: import java.io.IOException;
20: import java.io.PrintStream;
21:
22: /**
23: * Represents a classloader.
24: *
25: * {@link Realm}s form a tree structure where children delegates
26: * to the parent for classloading.
27: *
28: * @author Kohsuke Kawaguchi
29: */
30: public class Realm {
31: /**
32: * Human readable name that identifies this realm for the debugging purpose.
33: */
34: private final String name;
35:
36: /**
37: * Parent realm. Class loading delegates to this parent.
38: */
39: private final @Nullable Realm parent;
40:
41: /**
42: * Jar files and class folders that are added.
43: */
44: private final Path classPath = new Path(World.project);
45:
46: private AntClassLoader classLoader;
47:
48: public Realm(String name, Realm parent) {
49: this.name = name;
50: this.parent = parent;
51: }
52:
53: public synchronized ClassLoader getClassLoader() {
54:• if(classLoader==null) {
55: // delegates to the system classloader by default.
56: // when invoked for debugging harness (with a lot of jars in system classloader),
57: // this provides the easy debug path.
58: // when invoked through bootstrap, this still provides the maximum isolation.
59: ClassLoader pcl = ClassLoader.getSystemClassLoader();
60:• if(parent!=null)
61: pcl = parent.getClassLoader();
62: classLoader = new AntClassLoader();
63: classLoader.setParent(pcl);
64: classLoader.setProject(World.project);
65: classLoader.setClassPath(classPath);
66: classLoader.setDefaultAssertionStatus(true);
67: }
68:
69: return classLoader;
70: }
71:
72: /**
73: * Adds a single jar.
74: */
75: public void addJar(File jar) throws IOException {
76:• assert classLoader==null : "classLoader is already created";
77:• if(!jar.exists())
78: throw new IOException("No such file: "+jar);
79: classPath.createPathElement().setLocation(jar);
80: }
81:
82: /**
83: * Adds a single class folder.
84: */
85: public void addClassFolder(File classFolder) throws IOException {
86: addJar(classFolder);
87: }
88:
89: /**
90: * Adds all jars in the given folder.
91: *
92: * @param folder
93: * A directory that contains a bunch of jar files.
94: * @param excludes
95: * List of jars to be excluded
96: */
97: public void addJarFolder(File folder, final String... excludes) throws IOException {
98:• if(!folder.isDirectory())
99: throw new IOException("Not a directory "+folder);
100:
101: File[] children = folder.listFiles(new FileFilter() {
102: public boolean accept(File pathname) {
103: for (String name : excludes) {
104: if(pathname.getName().equals(name))
105: return false; // excluded
106: }
107: return pathname.getPath().endsWith(".jar");
108: }
109: });
110:
111:• for (File child : children) {
112: addJar(child);
113: }
114: }
115:
116: public void dump(PrintStream out) {
117:• for( String item : classPath.toString().split(File.pathSeparator)) {
118: out.println(" "+item);
119: }
120: }
121:
122: public String toString() {
123: return name+" realm";
124: }
125:
126: /**
127: * List all the components in this realm (excluding those defined in parent.)
128: */
129: public File[] list() {
130: String[] names = classPath.list();
131: File[] r = new File[names.length];
132:• for (int i = 0; i < r.length; i++) {
133: r[i] = new File(names[i]);
134: }
135: return r;
136: }
137:
138: public Path getPath() {
139: return classPath;
140: }
141:
142: public Class loadClass(String className) throws ClassNotFoundException {
143: return getClassLoader().loadClass(className);
144: }
145: }