Coverage Report - com.jcabi.github.FromProperties
 
Classes in this File Line Coverage Branch Coverage Complexity
FromProperties
80%
12/15
N/A
2
 
 1  
 /**
 2  
  * Copyright (c) 2013-2017, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.github;
 31  
 
 32  
 import java.io.IOException;
 33  
 import java.util.Properties;
 34  
 
 35  
 /**
 36  
  * User agent data read from the jcabigithub.properties file.
 37  
  * @author Mihai Andronache (amihaiemil@gmail.com)
 38  
  * @version $Id: dc697aa6421463c678b8d3236f9c016e60baa329 $
 39  
  * @since 0.37
 40  
  */
 41  
 public final class FromProperties implements UserAgent {
 42  
 
 43  
     /**
 44  
      * Build timestamp.
 45  
      */
 46  
     private static final String JCABI_DATE = "JCabi-Date";
 47  
 
 48  
     /**
 49  
      * Project version.
 50  
      */
 51  
     private static final String JCABI_VERSION = "JCabi-Version";
 52  
 
 53  
     /**
 54  
      * Build number.
 55  
      */
 56  
     private static final String JCABI_BUILD = "JCabi-Build";
 57  
 
 58  
     /**
 59  
      * Properties.
 60  
      */
 61  3
     private final transient Properties props = new Properties();
 62  
 
 63  
     /**
 64  
      * Name of the properties file to load.
 65  
      */
 66  
     private final transient String name;
 67  
 
 68  
     /**
 69  
      * Ctor.
 70  
      * @param filename Name of the properties file to look for
 71  
      */
 72  3
     public FromProperties(final String filename) {
 73  3
         this.name = filename;
 74  3
     }
 75  
 
 76  
     @Override
 77  
     public String format() {
 78  
         try {
 79  6
             this.props.load(
 80  3
                 Thread.currentThread().getContextClassLoader()
 81  3
                     .getResourceAsStream(this.name)
 82  
             );
 83  0
         } catch (final IOException ex) {
 84  0
             throw new IllegalStateException(
 85  0
                 String.format("IOException when loading %s", this.name),
 86  
                 ex
 87  
             );
 88  2
         }
 89  4
         return String.format(
 90  
             "jcabi-github %s %s %s",
 91  2
             this.props.getProperty(FromProperties.JCABI_VERSION),
 92  2
             this.props.getProperty(FromProperties.JCABI_BUILD),
 93  2
             this.props.getProperty(FromProperties.JCABI_DATE)
 94  
         );
 95  
     }
 96  
 }