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