Coverage Report - org.apache.maven.surefire.booter.StartupConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
StartupConfiguration
0%
0/30
0%
0/20
1,917
 
 1  
 package org.apache.maven.surefire.booter;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *     http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 /**
 23  
  * Configuration that is used by the SurefireStarter but does not make it into the provider itself.
 24  
  *
 25  
  * @author Kristian Rosenvold
 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 final static 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  0
     {
 46  0
         this.classpathConfiguration = classpathConfiguration;
 47  0
         this.classLoaderConfiguration = classLoaderConfiguration;
 48  0
         this.isForkRequested = isForkRequested;
 49  0
         this.providerClassName = providerClassName;
 50  0
         isInForkedVm = inForkedVm;
 51  0
     }
 52  
 
 53  
     public boolean isProviderMainClass()
 54  
     {
 55  0
         return providerClassName.endsWith( "#main" );
 56  
     }
 57  
 
 58  
     public static StartupConfiguration inForkedVm( String providerClassName,
 59  
                                                    ClasspathConfiguration classpathConfiguration,
 60  
                                                    ClassLoaderConfiguration classLoaderConfiguration )
 61  
     {
 62  0
         return new StartupConfiguration( providerClassName, classpathConfiguration, classLoaderConfiguration, true,
 63  
                                          true );
 64  
     }
 65  
 
 66  
     public ClasspathConfiguration getClasspathConfiguration()
 67  
     {
 68  0
         return classpathConfiguration;
 69  
     }
 70  
 
 71  
     public boolean useSystemClassLoader()
 72  
     {
 73  
         // todo; I am not totally convinced this logic is as simple as it could be
 74  0
         return classLoaderConfiguration.isUseSystemClassLoader() && ( isInForkedVm || isForkRequested );
 75  
     }
 76  
 
 77  
     public boolean isManifestOnlyJarRequestedAndUsable()
 78  
     {
 79  0
         return classLoaderConfiguration.isManifestOnlyJarRequestedAndUsable();
 80  
     }
 81  
 
 82  
     public String getProviderClassName()
 83  
     {
 84  0
         return providerClassName;
 85  
     }
 86  
 
 87  
     public String getActualClassName()
 88  
     {
 89  0
         if ( isProviderMainClass() )
 90  
         {
 91  0
             return stripEnd( providerClassName, "#main" );
 92  
         }
 93  0
         return providerClassName;
 94  
     }
 95  
 
 96  
     /**
 97  
      * <p>Strip any of a supplied String from the end of a String.</p>
 98  
      * <p/>
 99  
      * <p>If the strip String is <code>null</code>, whitespace is
 100  
      * stripped.</p>
 101  
      *
 102  
      * @param str   the String to remove characters from
 103  
      * @param strip the String to remove
 104  
      * @return the stripped String
 105  
      */
 106  
     public static String stripEnd( String str, String strip )
 107  
     {
 108  0
         if ( str == null )
 109  
         {
 110  0
             return null;
 111  
         }
 112  0
         int end = str.length();
 113  
 
 114  0
         if ( strip == null )
 115  
         {
 116  0
             while ( ( end != 0 ) && Character.isWhitespace( str.charAt( end - 1 ) ) )
 117  
             {
 118  0
                 end--;
 119  
             }
 120  
         }
 121  
         else
 122  
         {
 123  0
             while ( ( end != 0 ) && ( strip.indexOf( str.charAt( end - 1 ) ) != -1 ) )
 124  
             {
 125  0
                 end--;
 126  
             }
 127  
         }
 128  0
         return str.substring( 0, end );
 129  
     }
 130  
 
 131  
     public ClassLoaderConfiguration getClassLoaderConfiguration()
 132  
     {
 133  0
         return classLoaderConfiguration;
 134  
     }
 135  
 
 136  
     public boolean isShadefire()
 137  
     {
 138  0
         return providerClassName.startsWith( "org.apache.maven.surefire.shadefire" );
 139  
     }
 140  
 
 141  
     public void writeSurefireTestClasspathProperty()
 142  
     {
 143  0
         ClasspathConfiguration classpathConfiguration = getClasspathConfiguration();
 144  0
         classpathConfiguration.getTestClasspath().writeToSystemProperty( SUREFIRE_TEST_CLASSPATH );
 145  0
     }
 146  
 
 147  
 }