Coverage Report - org.apache.maven.shared.utils.PropertyUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertyUtils
66%
12/18
100%
2/2
3
 
 1  
 package org.apache.maven.shared.utils;
 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  
 import java.io.FileInputStream;
 24  
 import java.io.IOException;
 25  
 import java.util.Properties;
 26  
 import org.apache.maven.shared.utils.io.IOUtil;
 27  
 
 28  
 import javax.annotation.Nonnull;
 29  
 import javax.annotation.Nullable;
 30  
 
 31  
 public class PropertyUtils
 32  
 {
 33  
 
 34  
     public PropertyUtils()
 35  0
     {
 36  
         // should throw new IllegalAccessError( "Utility class" );
 37  0
     }
 38  
 
 39  
     public static java.util.Properties loadProperties( @Nonnull java.net.URL url )
 40  
     {
 41  
         try
 42  
         {
 43  3
             return loadProperties( url.openStream() );
 44  
         }
 45  1
         catch ( Exception e )
 46  
         {
 47  
             // ignore
 48  
         }
 49  1
         return null;
 50  
     }
 51  
 
 52  
     public static java.util.Properties loadProperties( @Nonnull java.io.File file )
 53  
     {
 54  
         try
 55  
         {
 56  3
             return loadProperties( new FileInputStream( file ) );
 57  
         }
 58  1
         catch ( Exception e )
 59  
         {
 60  
             // ignore
 61  
         }
 62  1
         return null;
 63  
     }
 64  
 
 65  
     public static java.util.Properties loadProperties( @Nullable java.io.InputStream is )
 66  
     {
 67  
         try
 68  
         {
 69  
             // to make this the same behaviour as the others we should really return null on any error
 70  7
             Properties result = new Properties();
 71  7
             if ( is != null )
 72  
             {
 73  
                 try
 74  
                 {
 75  6
                     result.load( is );
 76  
                 }
 77  0
                 catch ( IOException e )
 78  
                 {
 79  
                     // ignore
 80  6
                 }
 81  
             }
 82  7
             return result;
 83  
         }
 84  0
         catch ( Exception e )
 85  
         {
 86  
             // ignore
 87  
         }
 88  
         finally
 89  
         {
 90  7
             IOUtil.close( is );
 91  0
         }
 92  0
         return null;
 93  
     }
 94  
 
 95  
 }