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 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class ClasspathConfiguration |
31 | |
{ |
32 | |
private static final String CHILD_DELEGATION = "childDelegation"; |
33 | |
|
34 | |
private static final String ENABLE_ASSERTIONS = "enableAssertions"; |
35 | |
|
36 | |
private static final String CLASSPATH = "classPathUrl."; |
37 | |
|
38 | |
private static final String SUREFIRE_CLASSPATH = "surefireClassPathUrl."; |
39 | |
|
40 | |
private final Classpath classpathUrls; |
41 | |
|
42 | |
private final Classpath surefireClasspathUrls; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
private final Classpath inprocClasspath; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
private final boolean enableAssertions; |
54 | |
|
55 | |
|
56 | |
private final boolean childDelegation; |
57 | |
|
58 | |
public ClasspathConfiguration( boolean enableAssertions, boolean childDelegation ) |
59 | |
{ |
60 | 0 | this( new Classpath(), new Classpath(), new Classpath(), enableAssertions, childDelegation ); |
61 | 0 | } |
62 | |
|
63 | |
ClasspathConfiguration( PropertiesWrapper properties ) |
64 | |
{ |
65 | 0 | this( properties.getClasspath( CLASSPATH ), properties.getClasspath( SUREFIRE_CLASSPATH ), new Classpath(), |
66 | |
properties.getBooleanProperty( ENABLE_ASSERTIONS ), properties.getBooleanProperty( CHILD_DELEGATION ) ); |
67 | 0 | } |
68 | |
|
69 | |
public ClasspathConfiguration( Classpath testClasspath, Classpath surefireClassPathUrls, Classpath inprocClasspath, |
70 | |
boolean enableAssertions, boolean childDelegation ) |
71 | 0 | { |
72 | 0 | this.enableAssertions = enableAssertions; |
73 | 0 | this.childDelegation = childDelegation; |
74 | 0 | this.inprocClasspath = inprocClasspath; |
75 | 0 | this.classpathUrls = testClasspath; |
76 | 0 | this.surefireClasspathUrls = surefireClassPathUrls; |
77 | 0 | } |
78 | |
|
79 | |
public void addForkProperties( PropertiesWrapper properties ) |
80 | |
{ |
81 | 0 | properties.setClasspath( CLASSPATH, classpathUrls ); |
82 | 0 | properties.setClasspath( SUREFIRE_CLASSPATH, surefireClasspathUrls ); |
83 | 0 | properties.setProperty( ENABLE_ASSERTIONS, String.valueOf( enableAssertions ) ); |
84 | 0 | properties.setProperty( CHILD_DELEGATION, String.valueOf( childDelegation ) ); |
85 | 0 | } |
86 | |
|
87 | |
public ClassLoader createTestClassLoader( boolean childDelegation ) |
88 | |
throws SurefireExecutionException |
89 | |
{ |
90 | 0 | return classpathUrls.createClassLoader( null, childDelegation, enableAssertions, "test" ); |
91 | |
} |
92 | |
|
93 | |
public ClassLoader createTestClassLoader() |
94 | |
throws SurefireExecutionException |
95 | |
{ |
96 | 0 | return classpathUrls.createClassLoader( null, this.childDelegation, enableAssertions, "test" ); |
97 | |
} |
98 | |
|
99 | |
public ClassLoader createSurefireClassLoader( ClassLoader parent ) |
100 | |
throws SurefireExecutionException |
101 | |
{ |
102 | 0 | return surefireClasspathUrls.createClassLoader( parent, false, enableAssertions, "provider" ); |
103 | |
} |
104 | |
|
105 | |
public ClassLoader createInprocSurefireClassLoader( ClassLoader parent ) |
106 | |
throws SurefireExecutionException |
107 | |
{ |
108 | 0 | return inprocClasspath.createClassLoader( parent, false, enableAssertions, "provider" ); |
109 | |
} |
110 | |
|
111 | |
public Classpath getTestClasspath() |
112 | |
{ |
113 | 0 | return classpathUrls; |
114 | |
} |
115 | |
|
116 | |
public ClassLoader createForkingTestClassLoader( boolean manifestOnlyJarRequestedAndUsable ) |
117 | |
throws SurefireExecutionException |
118 | |
{ |
119 | 0 | if ( manifestOnlyJarRequestedAndUsable ) |
120 | |
{ |
121 | 0 | System.setProperty( "surefire.real.class.path", System.getProperty( "java.class.path" ) ); |
122 | 0 | getTestClasspath().writeToSystemProperty( "java.class.path" ); |
123 | |
|
124 | |
|
125 | |
|
126 | 0 | return this.getClass().getClassLoader(); |
127 | |
} |
128 | |
else |
129 | |
{ |
130 | 0 | return createTestClassLoader(); |
131 | |
} |
132 | |
} |
133 | |
} |