1 /**
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Intalio, Inc. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Intalio, Inc. Exolab is a registered
23 * trademark of Intalio, Inc.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2002-2004 (C) Intalio, Inc. All Rights Reserved.
42 *
43 * $Id$
44 */
45
46 package org.exolab.castor.util;
47
48 import java.io.File;
49 import java.net.URL;
50 import java.util.Date;
51 import java.text.SimpleDateFormat;
52 import java.util.zip.ZipEntry;
53 import java.util.zip.ZipFile;
54
55 /**
56 * A class which contains the version information
57 *
58 * @author <a href="mailto:kvisco-at-intalio.com">Keith Visco</a>
59 * @version $Revision$ $Date: 2006-04-05 15:43:19 -0600 (Wed, 05 Apr 2006) $
60 */
61 public final class Version {
62
63 //-----------------------/
64 //- Public Class Fields -/
65 //-----------------------/
66
67 /**
68 * The version number
69 */
70 public static final String VERSION = "1.3.3";
71
72 /**
73 * The version date.
74 */
75 public static final String VERSION_DATE = "20131231";
76
77 /**
78 * The version number with build information
79 */
80 public static final String BUILD_VERSION = Version.getBuildVersion();
81
82
83 //------------------------/
84 //- Private Class Fields -/
85 //------------------------/
86
87 private static final String JAR_PROTOCOL = "jar:";
88 private static final String FILE_PROTOCOL = "file:";
89 private static final String DATE_FORMAT = "yyyyMMdd.HHmmss";
90
91 //------------------------/
92 //- Public Class Methods -/
93 //------------------------/
94
95 /**
96 *
97 */
98 public static String getBuildVersion() {
99
100 StringBuffer buffer = new StringBuffer(VERSION);
101 String classname = Version.class.getName();
102 String resource = "/" + classname.replace('.', '/') + ".class";
103
104 URL url = Version.class.getResource(resource);
105 // shouldn't be null, but you never know
106 if (url != null) {
107 buffer.append(" [");
108 String href = url.toString();
109 Date date = null;
110 if (href.startsWith(JAR_PROTOCOL)) {
111 href = href.substring(JAR_PROTOCOL.length());
112 if (href.startsWith(FILE_PROTOCOL))
113 href = href.substring(FILE_PROTOCOL.length());
114
115 int idx = href.indexOf('!');
116 //-- get entry name (remove '!/' from beginning)
117 String entryName = href.substring(idx+2);
118 href = href.substring(0, idx);
119 try {
120 ZipFile file = new ZipFile(href);
121 ZipEntry entry = file.getEntry(entryName);
122 if (entry != null) {
123 long t = entry.getTime();
124 if (t > 0) {
125 date = new Date(entry.getTime());
126 }
127 }
128 }
129 catch (java.io.IOException iox) {
130 //-- ignore...problem with finding or reading jar.
131 }
132 }
133 else if (href.startsWith(FILE_PROTOCOL)) {
134 File file = new File(href.substring(FILE_PROTOCOL.length()));
135 date = new Date(file.lastModified());
136 }
137 if (date != null) {
138 SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
139 buffer.append(format.format(date));
140 }
141 else buffer.append("0");
142 buffer.append(']');
143 }
144 return buffer.toString();
145
146 } //-- getBuildVersion
147
148 /**
149 * Command line
150 */
151 public static void main(String[] args) {
152 System.out.println(BUILD_VERSION);
153 }
154
155 } //-- Version