1
2
3
4
5
6
7
8
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
28
29 public class MuleManifest
30 {
31
32
33
34 protected static final Log logger = LogFactory.getLog(MuleManifest.class);
35
36 private static Manifest manifest;
37
38 public static String getProductVersion()
39 {
40 return getManifestProperty("Implementation-Version");
41 }
42
43 public static String getVendorName()
44 {
45 return getManifestProperty("Specification-Vendor");
46 }
47
48 public static String getVendorUrl()
49 {
50 return getManifestProperty("Vendor-Url");
51 }
52
53 public static String getProductUrl()
54 {
55 return getManifestProperty("Product-Url");
56 }
57
58 public static String getProductName()
59 {
60 return getManifestProperty("Implementation-Title");
61 }
62
63 public static String getProductMoreInfo()
64 {
65 return getManifestProperty("More-Info");
66 }
67
68 public static String getProductSupport()
69 {
70 return getManifestProperty("Support");
71 }
72
73 public static String getProductLicenseInfo()
74 {
75 return getManifestProperty("License");
76 }
77
78 public static String getProductDescription()
79 {
80 return getManifestProperty("Description");
81 }
82
83 public static String getBuildNumber()
84 {
85 return getManifestProperty("Build-Revision");
86 }
87
88 public static String getBuildDate()
89 {
90 return getManifestProperty("Build-Date");
91 }
92
93 public static String getDevListEmail()
94 {
95 return getManifestProperty("Dev-List-Email");
96 }
97
98 public static String getDTDSystemId()
99 {
100 return getManifestProperty("Dtd-System-Id");
101 }
102
103 public static String getDTDPublicId()
104 {
105 return getManifestProperty("Dtd-Public-Id");
106 }
107
108 public static Manifest getManifest()
109 {
110 if (manifest == null)
111 {
112 manifest = new Manifest();
113
114 InputStream is = null;
115 try
116 {
117
118
119 URL url = (URL) AccessController.doPrivileged(new PrivilegedAction()
120 {
121 public Object run()
122 {
123 try
124 {
125 Enumeration e = MuleConfiguration.class.getClassLoader().getResources(
126 ("META-INF/MANIFEST.MF"));
127 while (e.hasMoreElements())
128 {
129 URL url = (URL) e.nextElement();
130 if (url.toExternalForm().indexOf("mule-core") > -1)
131 {
132 return url;
133 }
134 }
135 }
136 catch (IOException e1)
137 {
138 logger.warn("Failure reading manifest: " + e1.getMessage(), e1);
139 }
140 return null;
141 }
142 });
143
144 if (url != null)
145 {
146 is = url.openStream();
147 }
148
149 if (is != null)
150 {
151 manifest.read(is);
152 }
153 }
154 catch (IOException e)
155 {
156 logger.warn("Failed to read manifest Info, Manifest information will not display correctly: "
157 + e.getMessage());
158 }
159 }
160 return manifest;
161 }
162
163 protected static String getManifestProperty(String name)
164 {
165 return getManifest().getMainAttributes().getValue(new Attributes.Name(name));
166 }
167 }