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