001: /**
002: *
003: * Copyright (C) 2000-2005 Enterprise Distributed Technologies Ltd
004: *
005: * www.enterprisedt.com
006: *
007: * Change Log:
008: *
009: * $Log: VersionDetails.java,v $
010: * Revision 1.3 2007-05-29 03:10:09 bruceb
011: * add default unknown version string
012: *
013: * Revision 1.2 2005/11/15 21:01:53 bruceb
014: * fix javadoc
015: *
016: * Revision 1.1 2005/11/10 13:40:28 bruceb
017: * more elaborate versioning info to debug
018: *
019: *
020: */package com.enterprisedt.net.ftp;
021:
022: import java.io.PrintWriter;
023: import java.io.StringWriter;
024:
025: /**
026: * Aggregates the version information
027: *
028: * @author Bruce Blackshaw
029: * @version $Revision: 1.3 $
030: */
031: public class VersionDetails {
032:
033: /**
034: * Major version (substituted by ant)
035: */
036: final private static String majorVersion = "2";
037:
038: /**
039: * Middle version (substituted by ant)
040: */
041: final private static String middleVersion = "0";
042:
043: /**
044: * Middle version (substituted by ant)
045: */
046: final private static String minorVersion = "1";
047:
048: /**
049: * Full version
050: */
051: private static int[] version;
052:
053: /**
054: * Full version string
055: */
056: private static String versionString;
057:
058: /**
059: * Timestamp of build
060: */
061: final private static String buildTimestamp = "9-Jan-2008 14:00:06 EST";
062:
063: /**
064: * Work out the version array
065: */
066: static {
067: try {
068: version = new int[3];
069: version[0] = Integer.parseInt(majorVersion);
070: version[1] = Integer.parseInt(middleVersion);
071: version[2] = Integer.parseInt(minorVersion);
072: versionString = version[0] + "." + version[1] + "."
073: + version[2];
074: } catch (NumberFormatException ex) {
075: System.err.println("Failed to calculate version: "
076: + ex.getMessage());
077: versionString = "Unknown";
078: }
079: }
080:
081: /**
082: * Get the product version
083: *
084: * @return int array of {major,middle,minor} version numbers
085: */
086: final public static int[] getVersion() {
087: return version;
088: }
089:
090: /**
091: * Get the product version string
092: *
093: * @return version as string
094: */
095: final public static String getVersionString() {
096: return versionString;
097: }
098:
099: /**
100: * Get the build timestamp
101: *
102: * @return d-MMM-yyyy HH:mm:ss z build timestamp
103: */
104: final public static String getBuildTimestamp() {
105: return buildTimestamp;
106: }
107:
108: /**
109: * Report on useful things for debugging purposes
110: *
111: * @param obj instance to report on
112: * @return string
113: */
114: final public static String report(Object obj) {
115: StringWriter result = new StringWriter();
116: PrintWriter report = new PrintWriter(result, true);
117: report.print("Class: ");
118: report.println(obj.getClass().getName());
119: report.print("Version: ");
120: report.println(versionString);
121: report.print("Build timestamp: ");
122: report.println(buildTimestamp);
123: try {
124: report.print("Java version: ");
125: report.println(System.getProperty("java.version"));
126: report.print("CLASSPATH: ");
127: report.println(System.getProperty("java.class.path"));
128: report.print("OS name: ");
129: report.println(System.getProperty("os.name"));
130: report.print("OS arch: ");
131: report.println(System.getProperty("os.arch"));
132: report.print("OS version: ");
133: report.println(System.getProperty("os.version"));
134: } catch (SecurityException ex) {
135: report.println("Could not obtain system properties");
136: }
137: return result.toString();
138: }
139: }
|