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 javax.annotation.Nonnull;
23
24 import static org.apache.maven.surefire.booter.Classpath.join;
25
26
27
28
29
30 public abstract class AbstractPathConfiguration
31 {
32 public static final String CHILD_DELEGATION = "childDelegation";
33
34 public static final String ENABLE_ASSERTIONS = "enableAssertions";
35
36 public static final String CLASSPATH = "classPathUrl.";
37
38 public static final String SUREFIRE_CLASSPATH = "surefireClassPathUrl.";
39
40 private final Classpath surefireClasspathUrls;
41
42
43
44
45
46 private final boolean enableAssertions;
47
48
49 private final boolean childDelegation;
50
51 protected AbstractPathConfiguration( @Nonnull Classpath surefireClasspathUrls,
52 boolean enableAssertions, boolean childDelegation )
53 {
54 if ( isClassPathConfig() == isModularPathConfig() )
55 {
56 throw new IllegalStateException( "modular path and class path should be exclusive" );
57 }
58 this.surefireClasspathUrls = surefireClasspathUrls;
59 this.enableAssertions = enableAssertions;
60 this.childDelegation = childDelegation;
61 }
62
63 public abstract Classpath getTestClasspath();
64
65
66
67
68
69
70 public abstract boolean isModularPathConfig();
71
72
73
74
75
76
77 public abstract boolean isClassPathConfig();
78
79 protected abstract Classpath getInprocClasspath();
80
81 public <T extends AbstractPathConfiguration> T toRealPath( Class<T> type )
82 {
83 if ( isClassPathConfig() && type == ClasspathConfiguration.class
84 || isModularPathConfig() && type == ModularClasspathConfiguration.class )
85 {
86 return type.cast( this );
87 }
88 throw new IllegalStateException( "no target matched " + type );
89 }
90
91 public ClassLoader createMergedClassLoader()
92 throws SurefireExecutionException
93 {
94 return createMergedClassLoader( getInprocTestClasspath() );
95 }
96
97 public Classpath getProviderClasspath()
98 {
99 return surefireClasspathUrls;
100 }
101
102 public boolean isEnableAssertions()
103 {
104 return enableAssertions;
105 }
106
107 @Deprecated
108 public boolean isChildDelegation()
109 {
110 return childDelegation;
111 }
112
113 final Classpath getInprocTestClasspath()
114 {
115 return join( getInprocClasspath(), getTestClasspath() );
116 }
117
118 final ClassLoader createMergedClassLoader( Classpath cp )
119 throws SurefireExecutionException
120 {
121 return cp.createClassLoader( isChildDelegation(), isEnableAssertions(), "test" );
122 }
123 }