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