01: package org.continuent.sequoia.controller.core;
02:
03: import java.io.IOException;
04: import java.io.PrintStream;
05: import java.net.JarURLConnection;
06: import java.net.URL;
07: import java.util.HashMap;
08: import java.util.Map;
09: import java.util.jar.Attributes;
10: import java.util.jar.Manifest;
11:
12: import org.continuent.sequoia.common.util.Constants;
13:
14: /**
15: * This class can be used to display information on the Controller and its
16: * runtime environment
17: */
18: public class ControllerInfo {
19:
20: private static Map getManifestHeaders() {
21: // akward way to retrieve the manifest file of the
22: // jar containing the ControllerInfo class
23: String resource = "/"
24: + ControllerInfo.class.getName().replace('.', '/')
25: + ".class";
26: URL url = ControllerInfo.class.getResource(resource);
27: JarURLConnection conn;
28: try {
29: conn = (JarURLConnection) url.openConnection();
30: if (conn == null) {
31: return new HashMap();
32: }
33: Manifest manifest = conn.getManifest();
34: return manifest.getMainAttributes();
35: } catch (IOException e) {
36: return new HashMap();
37: }
38: }
39:
40: /**
41: * Print information on the controller and its runtime environment
42: * on the specified PrintStream.
43: *
44: * @param out the PrintStream which is used to print the information
45: */
46: public static void printOn(PrintStream out) {
47: out.println("Controller name: "
48: + ControllerConstants.PRODUCT_NAME);
49: out.println("Controller version: " + Constants.VERSION);
50: Map headers = getManifestHeaders();
51: if (headers.containsKey(new Attributes.Name("Build-Number"))) {
52: out.println("Build Number: "
53: + headers.get(new Attributes.Name("Build-Number")));
54: }
55: out.println("OS Name: "
56: + System.getProperty("os.name"));
57: out.println("OS Version: "
58: + System.getProperty("os.version"));
59: out.println("Architecture: "
60: + System.getProperty("os.arch"));
61: out.println("JVM Version: "
62: + System.getProperty("java.runtime.version"));
63: out.println("JVM Vendor: "
64: + System.getProperty("java.vm.vendor"));
65: }
66:
67: public static void main(String[] args) {
68: printOn(System.out);
69: }
70:
71: }
|