Coverage Report - org.apache.maven.surefire.booter.SystemPropertyManager
 
Classes in this File Line Coverage Branch Coverage Complexity
SystemPropertyManager
0%
0/26
0%
0/4
1,667
 
 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  
 import java.io.File;
 23  
 import java.io.FileInputStream;
 24  
 import java.io.FileOutputStream;
 25  
 import java.io.IOException;
 26  
 import java.io.InputStream;
 27  
 import java.util.Properties;
 28  
 
 29  
 /**
 30  
  * @author Kristian Rosenvold
 31  
  */
 32  0
 public class SystemPropertyManager
 33  
 {
 34  
 
 35  
     /**
 36  
      * Loads the properties, closes the stream
 37  
      *
 38  
      * @param inStream The stream to read from, will be closed
 39  
      * @return The properties
 40  
      * @throws java.io.IOException If something bad happens
 41  
      */
 42  
     public static PropertiesWrapper loadProperties( InputStream inStream )
 43  
         throws IOException
 44  
     {
 45  0
         Properties p = new Properties();
 46  
 
 47  
         try
 48  
         {
 49  0
             p.load( inStream );
 50  
         }
 51  
         finally
 52  
         {
 53  0
             close( inStream );
 54  0
         }
 55  
 
 56  0
         return new PropertiesWrapper( p );
 57  
     }
 58  
 
 59  
     private static PropertiesWrapper loadProperties( File file )
 60  
         throws IOException
 61  
     {
 62  0
         return loadProperties( new FileInputStream( file ) );
 63  
     }
 64  
 
 65  
 
 66  
     public static void setSystemProperties( File file )
 67  
         throws IOException
 68  
     {
 69  0
         PropertiesWrapper p = loadProperties( file );
 70  0
         p.setAsSystemProperties();
 71  0
     }
 72  
 
 73  
     public static File writePropertiesFile( Properties properties, File tempDirectory, String name,
 74  
                                             boolean keepForkFiles )
 75  
         throws IOException
 76  
     {
 77  0
         File file = File.createTempFile( name, "tmp", tempDirectory );
 78  0
         if ( !keepForkFiles )
 79  
         {
 80  0
             file.deleteOnExit();
 81  
         }
 82  
 
 83  0
         writePropertiesFile( file, name, properties );
 84  
 
 85  0
         return file;
 86  
     }
 87  
 
 88  
     public static void writePropertiesFile( File file, String name, Properties properties )
 89  
         throws IOException
 90  
     {
 91  0
         FileOutputStream out = new FileOutputStream( file );
 92  
 
 93  
         try
 94  
         {
 95  0
             properties.store( out, name );
 96  
         }
 97  
         finally
 98  
         {
 99  0
             out.close();
 100  0
         }
 101  0
     }
 102  
 
 103  
     public static void close( InputStream inputStream )
 104  
     {
 105  0
         if ( inputStream == null )
 106  
         {
 107  0
             return;
 108  
         }
 109  
 
 110  
         try
 111  
         {
 112  0
             inputStream.close();
 113  
         }
 114  0
         catch ( IOException ex )
 115  
         {
 116  
             // ignore
 117  0
         }
 118  0
     }
 119  
 
 120  
 
 121  
 }