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