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 | |
|
30 | 0 | public class MuleManifest |
31 | |
{ |
32 | |
|
33 | |
|
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 | |
|
110 | |
|
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 | |
} |