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