Coverage Report - com.jeantessier.dependencyfinder.Version
 
Classes in this File Line Coverage Branch Coverage Complexity
Version
41%
25/60
29%
7/24
1.929
 
 1  
 /*
 2  
  *  Copyright (c) 2001-2009, Jean Tessier
 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:
 8  
  *  
 9  
  *      * Redistributions of source code must retain the above copyright
 10  
  *        notice, this list of conditions and the following disclaimer.
 11  
  *  
 12  
  *      * Redistributions in binary form must reproduce the above copyright
 13  
  *        notice, this list of conditions and the following disclaimer in the
 14  
  *        documentation and/or other materials provided with the distribution.
 15  
  *  
 16  
  *      * Neither the name of Jean Tessier nor the names of his contributors
 17  
  *        may be used to endorse or promote products derived from this software
 18  
  *        without specific prior written permission.
 19  
  *  
 20  
  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  
  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  
  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  
  *  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 24  
  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25  
  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26  
  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27  
  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28  
  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29  
  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30  
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 
 33  
 package com.jeantessier.dependencyfinder;
 34  
 
 35  
 import java.io.*;
 36  
 import java.util.jar.*;
 37  
 
 38  
 import org.apache.log4j.*;
 39  
 
 40  
 public class Version {
 41  
     public static final String DEFAULT_URL              = "http://depfind.sourceforge.net/";
 42  
     public static final String DEFAULT_TITLE            = "Dependency Finder";
 43  
     public static final String DEFAULT_VERSION          = "<i>unknown</i>";
 44  
     public static final String DEFAULT_VENDOR           = "Jean Tessier";
 45  
     public static final String DEFAULT_DATE             = "<i>unknown</i>";
 46  
     public static final String DEFAULT_COPYRIGHT_HOLDER = "Jean Tessier";
 47  
     public static final String DEFAULT_COPYRIGHT_DATE   = "2001-2009";
 48  
 
 49  88
     private String resourceURL = null;
 50  88
     private String jarName     = null;
 51  
 
 52  88
     private Attributes attributes = null;
 53  
     
 54  88
     public Version() {
 55  88
         resourceURL = getClass().getResource("Version.class").toString();
 56  
         
 57  88
         if (resourceURL.startsWith("jar:file:")) {
 58  0
             jarName = resourceURL.substring(9, resourceURL.indexOf(".jar!") + 4);
 59  
 
 60  
             try {
 61  0
                 JarFile  jar      = new JarFile(jarName);
 62  0
                 Manifest manifest = jar.getManifest();
 63  
                 
 64  0
                 attributes = manifest.getMainAttributes();
 65  0
             } catch (IOException ex) {
 66  0
                 Logger.getLogger(getClass()).error("Could not get version information, using defaults", ex);
 67  0
             }
 68  
         }
 69  88
     }
 70  
     
 71  
     public String getResourceURL() {
 72  0
         return resourceURL;
 73  
     }
 74  
 
 75  
     public String getJarName() {
 76  0
         return jarName;
 77  
     }
 78  
 
 79  
     public String getImplementationURL() {
 80  344
         String result = DEFAULT_URL;
 81  
 
 82  344
         if (attributes != null) {
 83  0
             result = attributes.getValue("Implementation-URL");
 84  
         }
 85  
 
 86  344
         return result;
 87  
     }
 88  
 
 89  
     public String getImplementationTitle() {
 90  192
         String result = DEFAULT_TITLE;
 91  
 
 92  192
         if (attributes != null) {
 93  0
             result = attributes.getValue("Implementation-Title");
 94  
         }
 95  
 
 96  192
         return result;
 97  
     }
 98  
 
 99  
     public String getImplementationVersion() {
 100  192
         String result = DEFAULT_VERSION;
 101  
 
 102  192
         if (attributes != null) {
 103  0
             result = attributes.getValue("Implementation-Version");
 104  
         }
 105  
 
 106  192
         return result;
 107  
     }
 108  
 
 109  
     public String getImplementationVendor() {
 110  0
         String result = DEFAULT_VENDOR;
 111  
 
 112  0
         if (attributes != null) {
 113  0
             result = attributes.getValue("Implementation-Vendor");
 114  
         }
 115  
 
 116  0
         return result;
 117  
     }
 118  
 
 119  
     public String getImplementationDate() {
 120  192
         String result = DEFAULT_DATE;
 121  
 
 122  192
         if (attributes != null) {
 123  0
             result = attributes.getValue("Implementation-Date");
 124  
         }
 125  
 
 126  192
         return result;
 127  
     }
 128  
 
 129  
     public String getSpecificationTitle() {
 130  0
         String result = DEFAULT_TITLE;
 131  
 
 132  0
         if (attributes != null) {
 133  0
             result = attributes.getValue("Specification-Title");
 134  
         }
 135  
 
 136  0
         return result;
 137  
     }
 138  
 
 139  
     public String getSpecificationVersion() {
 140  0
         String result = DEFAULT_VERSION;
 141  
 
 142  0
         if (attributes != null) {
 143  0
             result = attributes.getValue("Specification-Version");
 144  
         }
 145  
 
 146  0
         return result;
 147  
     }
 148  
 
 149  
     public String getSpecificationVendor() {
 150  0
         String result = DEFAULT_VENDOR;
 151  
 
 152  0
         if (attributes != null) {
 153  0
             result = attributes.getValue("Specification-Vendor");
 154  
         }
 155  
 
 156  0
         return result;
 157  
     }
 158  
 
 159  
     public String getSpecificationDate() {
 160  0
         String result = DEFAULT_DATE;
 161  
 
 162  0
         if (attributes != null) {
 163  0
             result = attributes.getValue("Specification-Date");
 164  
         }
 165  
 
 166  0
         return result;
 167  
     }
 168  
 
 169  
     public String getCopyrightHolder() {
 170  192
         String result = DEFAULT_COPYRIGHT_HOLDER;
 171  
 
 172  192
         if (attributes != null) {
 173  0
             result = attributes.getValue("Copyright-Holder");
 174  
         }
 175  
 
 176  192
         return result;
 177  
     }
 178  
 
 179  
     public String getCopyrightDate() {
 180  192
         String result = DEFAULT_COPYRIGHT_DATE;
 181  
 
 182  192
         if (attributes != null) {
 183  0
             result = attributes.getValue("Copyright-Date");
 184  
         }
 185  
 
 186  192
         return result;
 187  
     }
 188  
 }