Source Code Cross Referenced for ProductInfo.java in  » Net » Terracotta » com » tc » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tc.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.util;
006:
007:        import org.apache.commons.cli.CommandLine;
008:        import org.apache.commons.cli.CommandLineParser;
009:        import org.apache.commons.cli.GnuParser;
010:        import org.apache.commons.cli.HelpFormatter;
011:        import org.apache.commons.cli.Options;
012:        import org.apache.commons.lang.StringUtils;
013:
014:        import java.io.IOException;
015:        import java.io.InputStream;
016:        import java.text.DateFormat;
017:        import java.text.ParseException;
018:        import java.text.SimpleDateFormat;
019:        import java.util.Date;
020:        import java.util.Properties;
021:
022:        /**
023:         * Utility class to retrieve the build information for the product.
024:         */
025:        public final class ProductInfo {
026:            private static final ResourceBundleHelper bundleHelper = new ResourceBundleHelper(
027:                    ProductInfo.class);
028:
029:            private static final DateFormat DATE_FORMAT = new SimpleDateFormat(
030:                    "yyyyMMdd-HHmmss");
031:
032:            private static final String BUILD_DATA_RESOURCE_NAME = "/build-data.txt";
033:
034:            private static final String BUILD_DATA_ROOT_KEY = "terracotta.build.";
035:            private static final String BUILD_DATA_VERSION_KEY = "version";
036:            private static final String BUILD_DATA_EDITION_KEY = "edition";
037:            private static final String BUILD_DATA_TIMESTAMP_KEY = "timestamp";
038:            private static final String BUILD_DATA_HOST_KEY = "host";
039:            private static final String BUILD_DATA_USER_KEY = "user";
040:            private static final String BUILD_DATA_REVISION_KEY = "revision";
041:            private static final String BUILD_DATA_BRANCH_KEY = "branch";
042:            private static final String UNKNOWN_VALUE = "[unknown]";
043:
044:            private final String moniker;
045:            private final String version;
046:            private final Date timestamp;
047:            private final String host;
048:            private final String user;
049:            private final String branch;
050:            private final String edition;
051:            private final String revision;
052:
053:            private ProductInfo(InputStream in, String fromWhere) {
054:                Properties properties = new Properties();
055:
056:                moniker = bundleHelper.getString("moniker");
057:
058:                if (in != null) {
059:                    try {
060:                        properties.load(in);
061:                    } catch (IOException ioe) {
062:                        ioe.printStackTrace();
063:                        System.exit(1);
064:                    }
065:                }
066:
067:                this .version = getProperty(properties, BUILD_DATA_VERSION_KEY,
068:                        UNKNOWN_VALUE);
069:                this .edition = getProperty(properties, BUILD_DATA_EDITION_KEY,
070:                        "opensource");
071:
072:                String timestampString = getProperty(properties,
073:                        BUILD_DATA_TIMESTAMP_KEY, null);
074:                this .host = getProperty(properties, BUILD_DATA_HOST_KEY,
075:                        UNKNOWN_VALUE);
076:                this .user = getProperty(properties, BUILD_DATA_USER_KEY,
077:                        UNKNOWN_VALUE);
078:                this .branch = getProperty(properties, BUILD_DATA_BRANCH_KEY,
079:                        UNKNOWN_VALUE);
080:                this .revision = getProperty(properties,
081:                        BUILD_DATA_REVISION_KEY, UNKNOWN_VALUE);
082:
083:                Date realTimestamp = null;
084:                if (timestampString != null) {
085:                    try {
086:                        realTimestamp = DATE_FORMAT.parse(timestampString);
087:                    } catch (ParseException pe) {
088:                        pe.printStackTrace();
089:                        System.exit(1);
090:                    }
091:                }
092:
093:                this .timestamp = realTimestamp;
094:            }
095:
096:            private String getProperty(Properties properties, String name,
097:                    String defaultValue) {
098:                String out = properties.getProperty(BUILD_DATA_ROOT_KEY + name);
099:                if (StringUtils.isBlank(out))
100:                    out = defaultValue;
101:                return out;
102:            }
103:
104:            private static ProductInfo PRODUCTINFO = null;
105:
106:            public static synchronized ProductInfo getInstance() {
107:                if (PRODUCTINFO == null) {
108:                    InputStream in = ProductInfo.class
109:                            .getResourceAsStream(BUILD_DATA_RESOURCE_NAME);
110:                    PRODUCTINFO = new ProductInfo(in, "resource '"
111:                            + BUILD_DATA_RESOURCE_NAME + "'");
112:                }
113:
114:                return PRODUCTINFO;
115:            }
116:
117:            public boolean isDevMode() {
118:                return this .version.endsWith(UNKNOWN_VALUE);
119:            }
120:
121:            public String moniker() {
122:                return this .moniker;
123:            }
124:
125:            public String edition() {
126:                return this .edition;
127:            }
128:
129:            public String rawVersion() {
130:                return this .version;
131:            }
132:
133:            public String buildVersion() {
134:                return this .version;
135:            }
136:
137:            public Date buildTimestamp() {
138:                return this .timestamp;
139:            }
140:
141:            public String buildTimestampAsString() {
142:                if (this .timestamp == null)
143:                    return UNKNOWN_VALUE;
144:                else
145:                    return DATE_FORMAT.format(this .timestamp);
146:            }
147:
148:            public String buildHost() {
149:                return this .host;
150:            }
151:
152:            public String buildUser() {
153:                return this .user;
154:            }
155:
156:            public String buildBranch() {
157:                return this .branch;
158:            }
159:
160:            public String copyright() {
161:                return bundleHelper.getString("copyright");
162:            }
163:
164:            public String buildRevision() {
165:                return this .revision;
166:            }
167:
168:            public String toShortString() {
169:                return this .moniker + " "
170:                        + ("opensource".equals(edition) ? "" : (edition + " "))
171:                        + buildVersion();
172:            }
173:
174:            public String toLongString() {
175:                return toShortString() + ", as of " + buildTimestampAsString()
176:                        + " (Revision " + buildRevision() + " by "
177:                        + buildUser() + "@" + buildHost() + " from "
178:                        + buildBranch() + ")";
179:            }
180:
181:            public String toString() {
182:                return toShortString();
183:            }
184:
185:            public static void main(String[] args) throws Exception {
186:                Options options = new Options();
187:                options.addOption("v", "verbose", false, bundleHelper
188:                        .getString("option.verbose"));
189:                options.addOption("h", "help", false, bundleHelper
190:                        .getString("option.help"));
191:
192:                CommandLineParser parser = new GnuParser();
193:                CommandLine cli = parser.parse(options, args);
194:
195:                if (cli.hasOption("h")) {
196:                    new HelpFormatter().printHelp("java "
197:                            + ProductInfo.class.getName(), options);
198:                }
199:
200:                if (cli.hasOption("v")) {
201:                    System.out.println(getInstance().toLongString());
202:                } else {
203:                    System.out.println(getInstance().toShortString());
204:                }
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.