01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.env;
05:
06: import java.io.PrintStream;
07: import java.lang.reflect.Method;
08:
09: public class EnvironmentDetector {
10:
11: private final PrintStream m_stream;
12:
13: public EnvironmentDetector(PrintStream s) {
14: m_stream = s;
15: }
16:
17: public void printTomcatInfo() {
18: String info;
19: try {
20: // TODO check if this class and method exists for all Tomcat versions - I have only looked at 5.x
21: Class serverInfo = Class.forName(
22: "org.apache.catalina.util.ServerInfo", true,
23: EnvironmentDetector.class.getClassLoader());
24: Method getServerInfo = serverInfo.getMethod(
25: "getServerInfo", new Class[] {});
26: info = (String) getServerInfo.invoke(null, new Object[] {});
27: } catch (Throwable e) {
28: // ignore - not Tomcat
29: return;
30: }
31: m_stream.println("Tomcat Version:\t" + info);
32: }
33:
34: public void printJavaInfo() {
35: m_stream.println("JVM Vendor:\t\t"
36: + System.getProperty("java.vendor").toUpperCase());
37: m_stream.println("JVM Version:\t\tto"
38: + System.getProperty("java.version").toUpperCase());
39: }
40:
41: public void printOSInfo() {
42: m_stream.println("OS Arch:\t\t"
43: + System.getProperty("os.arch").toUpperCase());
44: m_stream.println("OS Name:\t\t"
45: + System.getProperty("os.name").toUpperCase());
46: m_stream.println("OS Version:\t\t"
47: + System.getProperty("os.version").toUpperCase());
48: }
49:
50: public void printEnv() {
51: EnvironmentDetector detector = new EnvironmentDetector(m_stream);
52: m_stream.println("----------------------------------");
53: detector.printOSInfo();
54: detector.printJavaInfo();
55: detector.printTomcatInfo();
56: }
57:
58: public static void main(String[] args) {
59: new EnvironmentDetector(System.out).printEnv();
60: }
61: }
|