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