Coverage Report - org.mule.config.MuleManifest
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleManifest
38%
11/29
67%
4/6
1.471
MuleManifest$1
73%
8/11
75%
3/4
1.471
 
 1  
 /*
 2  
  * $Id: MuleManifest.java 11371 2008-03-15 03:12:09Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.config;
 11  
 
 12  
 import org.mule.api.config.MuleConfiguration;
 13  
 
 14  
 import java.io.IOException;
 15  
 import java.io.InputStream;
 16  
 import java.net.URL;
 17  
 import java.security.AccessController;
 18  
 import java.security.PrivilegedAction;
 19  
 import java.util.Enumeration;
 20  
 import java.util.jar.Attributes;
 21  
 import java.util.jar.Manifest;
 22  
 
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 
 26  
 /**
 27  
  * This is a static class that provides access to the Mule core manifest file. 
 28  
  */
 29  0
 public class MuleManifest
 30  
 {
 31  
     /**
 32  
      * logger used by this class
 33  
      */
 34  2
     protected static final Log logger = LogFactory.getLog(MuleManifest.class);
 35  
 
 36  
     private static Manifest manifest;
 37  
 
 38  
     public static String getProductVersion()
 39  
     {
 40  0
         return getManifestProperty("Implementation-Version");
 41  
     }
 42  
 
 43  
     public static String getVendorName()
 44  
     {
 45  0
         return getManifestProperty("Specification-Vendor");
 46  
     }
 47  
 
 48  
     public static String getVendorUrl()
 49  
     {
 50  0
         return getManifestProperty("Vendor-Url");
 51  
     }
 52  
 
 53  
     public static String getProductUrl()
 54  
     {
 55  0
         return getManifestProperty("Product-Url");
 56  
     }
 57  
 
 58  
     public static String getProductName()
 59  
     {
 60  0
         return getManifestProperty("Implementation-Title");
 61  
     }
 62  
 
 63  
     public static String getProductMoreInfo()
 64  
     {
 65  0
         return getManifestProperty("More-Info");
 66  
     }
 67  
 
 68  
     public static String getProductSupport()
 69  
     {
 70  0
         return getManifestProperty("Support");
 71  
     }
 72  
 
 73  
     public static String getProductLicenseInfo()
 74  
     {
 75  0
         return getManifestProperty("License");
 76  
     }
 77  
 
 78  
     public static String getProductDescription()
 79  
     {
 80  0
         return getManifestProperty("Description");
 81  
     }
 82  
 
 83  
     public static String getBuildNumber()
 84  
     {
 85  0
         return getManifestProperty("Build-Revision");
 86  
     }
 87  
     
 88  
     public static String getBuildDate()
 89  
     {
 90  0
         return getManifestProperty("Build-Date");
 91  
     }
 92  
 
 93  
     public static String getDevListEmail()
 94  
     {
 95  4
         return getManifestProperty("Dev-List-Email");
 96  
     }
 97  
 
 98  
     public static String getDTDSystemId()
 99  
     {
 100  0
         return getManifestProperty("Dtd-System-Id");
 101  
     }
 102  
 
 103  
     public static String getDTDPublicId()
 104  
     {
 105  0
         return getManifestProperty("Dtd-Public-Id");
 106  
     }
 107  
 
 108  
     public static Manifest getManifest()
 109  
     {
 110  4
         if (manifest == null)
 111  
         {
 112  2
             manifest = new Manifest();
 113  
 
 114  2
             InputStream is = null;
 115  
             try
 116  
             {
 117  
                 // We want to load the MANIFEST.MF from the mule-core jar. Sine we
 118  
                 // don't know the version we're using we have to search for the jar on the classpath
 119  2
                 URL url = (URL) AccessController.doPrivileged(new PrivilegedAction()
 120  
                 {
 121  2
                     public Object run()
 122  
                     {
 123  
                         try
 124  
                         {
 125  2
                             Enumeration e = MuleConfiguration.class.getClassLoader().getResources(
 126  
                                     ("META-INF/MANIFEST.MF"));
 127  74
                             while (e.hasMoreElements())
 128  
                             {
 129  72
                                 URL url = (URL) e.nextElement();
 130  72
                                 if (url.toExternalForm().indexOf("mule-core") > -1)
 131  
                                 {
 132  0
                                     return url;
 133  
                                 }
 134  72
                             }
 135  
                         }
 136  0
                         catch (IOException e1)
 137  
                         {
 138  0
                             logger.warn("Failure reading manifest: " + e1.getMessage(), e1);
 139  2
                         }
 140  2
                         return null;
 141  
                     }
 142  
                 });
 143  
 
 144  2
                 if (url != null)
 145  
                 {
 146  0
                     is = url.openStream();
 147  
                 }
 148  
 
 149  2
                 if (is != null)
 150  
                 {
 151  0
                     manifest.read(is);
 152  
                 }
 153  
             }
 154  0
             catch (IOException e)
 155  
             {
 156  0
                 logger.warn("Failed to read manifest Info, Manifest information will not display correctly: "
 157  
                         + e.getMessage());
 158  2
             }
 159  
         }
 160  4
         return manifest;
 161  
     }
 162  
 
 163  
     protected static String getManifestProperty(String name)
 164  
     {
 165  4
         return getManifest().getMainAttributes().getValue(new Attributes.Name(name));
 166  
     }
 167  
 }