1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
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 | |
|
25 | |
|
26 | |
|
27 | 0 | public class MuleManifest |
28 | |
{ |
29 | |
|
30 | |
|
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 | |
|
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 | |
|
108 | |
|
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 | |
} |