Coverage Report - org.mule.config.MuleManifest
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleManifest
0%
0/28
0%
0/8
0
MuleManifest$1
0%
0/11
0%
0/8
0
 
 1  
 /*
 2  
  * $Id: MuleManifest.java 20088 2010-11-05 16:51:41Z aperepel $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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  
 // TODO EE-572
 30  0
 public class MuleManifest
 31  
 {
 32  
     /**
 33  
      * logger used by this class
 34  
      */
 35  0
     protected static final Log logger = LogFactory.getLog(MuleManifest.class);
 36  
 
 37  
     private static Manifest manifest;
 38  
 
 39  
     public static String getProductVersion()
 40  
     {
 41  0
         final String version = getManifestProperty("Implementation-Version");
 42  0
         return version == null ? "Unknown" : version;
 43  
     }
 44  
 
 45  
     public static String getVendorName()
 46  
     {
 47  0
         return getManifestProperty("Specification-Vendor");
 48  
     }
 49  
 
 50  
     public static String getVendorUrl()
 51  
     {
 52  0
         return getManifestProperty("Vendor-Url");
 53  
     }
 54  
 
 55  
     public static String getProductUrl()
 56  
     {
 57  0
         return getManifestProperty("Product-Url");
 58  
     }
 59  
 
 60  
     public static String getProductName()
 61  
     {
 62  0
         return getManifestProperty("Implementation-Title");
 63  
     }
 64  
 
 65  
     public static String getProductMoreInfo()
 66  
     {
 67  0
         return getManifestProperty("More-Info");
 68  
     }
 69  
 
 70  
     public static String getProductSupport()
 71  
     {
 72  0
         return getManifestProperty("Support");
 73  
     }
 74  
 
 75  
     public static String getProductLicenseInfo()
 76  
     {
 77  0
         return getManifestProperty("License");
 78  
     }
 79  
 
 80  
     public static String getProductDescription()
 81  
     {
 82  0
         return getManifestProperty("Description");
 83  
     }
 84  
 
 85  
     public static String getBuildNumber()
 86  
     {
 87  0
         return getManifestProperty("Build-Revision");
 88  
     }
 89  
     
 90  
     public static String getBuildDate()
 91  
     {
 92  0
         return getManifestProperty("Build-Date");
 93  
     }
 94  
 
 95  
     public static String getDevListEmail()
 96  
     {
 97  0
         return getManifestProperty("Dev-List-Email");
 98  
     }
 99  
 
 100  
     public static Manifest getManifest()
 101  
     {
 102  0
         if (manifest == null)
 103  
         {
 104  0
             manifest = new Manifest();
 105  
 
 106  0
             InputStream is = null;
 107  
             try
 108  
             {
 109  
                 // We want to load the MANIFEST.MF from the mule-core jar. Sine we
 110  
                 // don't know the version we're using we have to search for the jar on the classpath
 111  0
                 URL url = AccessController.doPrivileged(new PrivilegedAction<URL>()
 112  0
                 {
 113  
                     public URL run()
 114  
                     {
 115  
                         try
 116  
                         {
 117  0
                             Enumeration e = MuleConfiguration.class.getClassLoader().getResources(
 118  
                                     ("META-INF/MANIFEST.MF"));
 119  0
                             while (e.hasMoreElements())
 120  
                             {
 121  0
                                 URL url = (URL) e.nextElement();
 122  0
                                 if ((url.toExternalForm().indexOf("mule-core") > -1 && url.toExternalForm()
 123  
                                     .indexOf("tests.jar") < 0)
 124  
                                     || url.toExternalForm().matches(".*mule.*-.*-embedded.*\\.jar.*"))
 125  
                                 {
 126  0
                                     return url;
 127  
                                 }
 128  0
                             }
 129  
                         }
 130  0
                         catch (IOException e1)
 131  
                         {
 132  0
                             logger.warn("Failure reading manifest: " + e1.getMessage(), e1);
 133  0
                         }
 134  0
                         return null;
 135  
                     }
 136  
                 });
 137  
 
 138  0
                 if (url != null)
 139  
                 {
 140  0
                     is = url.openStream();
 141  
                 }
 142  
 
 143  0
                 if (is != null)
 144  
                 {
 145  0
                     manifest.read(is);
 146  
                 }
 147  
             }
 148  0
             catch (IOException e)
 149  
             {
 150  0
                 logger.warn("Failed to read manifest Info, Manifest information will not display correctly: "
 151  
                         + e.getMessage());
 152  0
             }
 153  
         }
 154  0
         return manifest;
 155  
     }
 156  
 
 157  
     protected static String getManifestProperty(String name)
 158  
     {
 159  0
         return getManifest().getMainAttributes().getValue(new Attributes.Name(name));
 160  
     }
 161  
 }