1 package org.apache.maven.surefire.booter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.net.URL;
23 import java.net.URLClassLoader;
24 import java.util.HashSet;
25 import java.util.Set;
26
27
28
29
30 public class IsolatedClassLoader
31 extends URLClassLoader
32 {
33 private final ClassLoader parent = ClassLoader.getSystemClassLoader();
34
35 private final Set urls = new HashSet();
36
37 private boolean childDelegation = true;
38
39 private static final URL[] EMPTY_URL_ARRAY = new URL[0];
40
41 public IsolatedClassLoader( ClassLoader parent, boolean childDelegation )
42 {
43 super( EMPTY_URL_ARRAY, parent );
44
45 this.childDelegation = childDelegation;
46 }
47
48 public void addURL( URL url )
49 {
50
51 if ( !urls.contains( url ) )
52 {
53 super.addURL( url );
54 urls.add( url );
55 }
56 }
57
58 public synchronized Class loadClass( String name )
59 throws ClassNotFoundException
60 {
61 Class c;
62
63 if ( childDelegation )
64 {
65 c = findLoadedClass( name );
66
67 ClassNotFoundException ex = null;
68
69 if ( c == null )
70 {
71 try
72 {
73 c = findClass( name );
74 }
75 catch ( ClassNotFoundException e )
76 {
77 ex = e;
78
79 if ( parent != null )
80 {
81 c = parent.loadClass( name );
82 }
83 }
84 }
85
86 if ( c == null )
87 {
88 throw ex;
89 }
90 }
91 else
92 {
93 c = super.loadClass( name );
94 }
95
96 return c;
97 }
98 }