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