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 java.util.Collections;
24 import java.util.List;
25
26
27
28
29
30
31 public class StartupConfiguration {
32 private static final String SUREFIRE_TEST_CLASSPATH = "surefire.test.class.path";
33
34 private final String providerClassName;
35 private final AbstractPathConfiguration classpathConfiguration;
36 private final ClassLoaderConfiguration classLoaderConfiguration;
37 private final ProcessCheckerType processChecker;
38 private final List<String[]> jpmsArguments;
39
40 public StartupConfiguration(
41 @Nonnull String providerClassName,
42 @Nonnull AbstractPathConfiguration classpathConfiguration,
43 @Nonnull ClassLoaderConfiguration classLoaderConfiguration,
44 ProcessCheckerType processChecker,
45 @Nonnull List<String[]> jpmsArguments) {
46 this.classpathConfiguration = classpathConfiguration;
47 this.classLoaderConfiguration = classLoaderConfiguration;
48 this.providerClassName = providerClassName;
49 this.processChecker = processChecker;
50 this.jpmsArguments = jpmsArguments;
51 }
52
53 public boolean isProviderMainClass() {
54 return providerClassName.endsWith("#main");
55 }
56
57 public static StartupConfiguration inForkedVm(
58 String providerClassName,
59 ClasspathConfiguration classpathConfig,
60 ClassLoaderConfiguration classLoaderConfig,
61 ProcessCheckerType processChecker) {
62 return new StartupConfiguration(
63 providerClassName,
64 classpathConfig,
65 classLoaderConfig,
66 processChecker,
67 Collections.<String[]>emptyList());
68 }
69
70 public AbstractPathConfiguration getClasspathConfiguration() {
71 return classpathConfiguration;
72 }
73
74 public boolean isManifestOnlyJarRequestedAndUsable() {
75 return classLoaderConfiguration.isManifestOnlyJarRequestedAndUsable();
76 }
77
78 public String getProviderClassName() {
79 return providerClassName;
80 }
81
82 public String getActualClassName() {
83 return isProviderMainClass() ? stripEnd(providerClassName, "#main") : providerClassName;
84 }
85
86
87
88
89
90
91
92
93
94
95
96 private static String stripEnd(String str, String strip) {
97 if (str == null) {
98 return null;
99 }
100 int end = str.length();
101
102 if (strip == null) {
103 while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) {
104 end--;
105 }
106 } else {
107 while (end != 0 && strip.indexOf(str.charAt(end - 1)) != -1) {
108 end--;
109 }
110 }
111 return str.substring(0, end);
112 }
113
114 public ClassLoaderConfiguration getClassLoaderConfiguration() {
115 return classLoaderConfiguration;
116 }
117
118 public boolean isShadefire() {
119 return providerClassName.startsWith("org.apache.maven.shadefire.surefire");
120 }
121
122 public void writeSurefireTestClasspathProperty() {
123 getClasspathConfiguration().getTestClasspath().writeToSystemProperty(SUREFIRE_TEST_CLASSPATH);
124 }
125
126 public ProcessCheckerType getProcessChecker() {
127 return processChecker;
128 }
129
130 public List<String[]> getJpmsArguments() {
131 return jpmsArguments;
132 }
133 }