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