| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * |
|---|
| 4 | * Copyright 2006, The jCoderZ.org Project. All rights reserved. |
|---|
| 5 | * |
|---|
| 6 | * Redistribution and use in source and binary forms, with or without |
|---|
| 7 | * modification, are permitted provided that the following conditions are |
|---|
| 8 | * met: |
|---|
| 9 | * |
|---|
| 10 | * * Redistributions of source code must retain the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer. |
|---|
| 12 | * * Redistributions in binary form must reproduce the above |
|---|
| 13 | * copyright notice, this list of conditions and the following |
|---|
| 14 | * disclaimer in the documentation and/or other materials |
|---|
| 15 | * provided with the distribution. |
|---|
| 16 | * * Neither the name of the jCoderZ.org Project nor the names of |
|---|
| 17 | * its contributors may be used to endorse or promote products |
|---|
| 18 | * derived from this software without specific prior written |
|---|
| 19 | * permission. |
|---|
| 20 | * |
|---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND |
|---|
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS |
|---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|---|
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|---|
| 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|---|
| 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | */ |
|---|
| 33 | package ${project.package}; |
|---|
| 34 | |
|---|
| 35 | import java.util.Collections; |
|---|
| 36 | import java.util.Map; |
|---|
| 37 | import java.util.TreeMap; |
|---|
| 38 | |
|---|
| 39 | /** |
|---|
| 40 | * This class holds version information at compile time. |
|---|
| 41 | * |
|---|
| 42 | * Compiled at ${build.time} on ${env.HOSTNAME} by ${user.name}. |
|---|
| 43 | * |
|---|
| 44 | * @author generated |
|---|
| 45 | * |
|---|
| 46 | * TODO: provide getter and constants for remaining properties. |
|---|
| 47 | */ |
|---|
| 48 | public final class Version |
|---|
| 49 | { |
|---|
| 50 | /** Release version number from VERSION file. */ |
|---|
| 51 | public static final String RELEASE_VERSION = "version"; |
|---|
| 52 | /** Name of the property holding the project name. */ |
|---|
| 53 | public static final String PROJECT_NAME = "project.Name"; |
|---|
| 54 | /** Name of the property holding the project name (lowercase). */ |
|---|
| 55 | public static final String PROJECT_NAME_LOWERCASE = "project.name"; |
|---|
| 56 | /** Name of the property holding the project base Java package. */ |
|---|
| 57 | public static final String PROJECT_PACKAGE = "project.package"; |
|---|
| 58 | /** Name of the property holding the project's copyright year. */ |
|---|
| 59 | public static final String COPYRIGHT_YEAR = "project.copyright.year"; |
|---|
| 60 | /** Name of the property holding the compile date (w/o time). */ |
|---|
| 61 | public static final String COMPILE_DATE = "compile.date"; |
|---|
| 62 | /** Name of the property holding the compile time (w/o date). */ |
|---|
| 63 | public static final String COMPILE_TIME = "compile.time"; |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | private static final Map /* <String, String> */ PROPERTIES; |
|---|
| 67 | static |
|---|
| 68 | { |
|---|
| 69 | final Map m = new TreeMap(); |
|---|
| 70 | // Project specific |
|---|
| 71 | m.put(RELEASE_VERSION, "${version}"); |
|---|
| 72 | m.put(PROJECT_NAME, "${Name}"); |
|---|
| 73 | m.put(PROJECT_NAME_LOWERCASE, "${name}"); |
|---|
| 74 | m.put(PROJECT_PACKAGE, "${project.package}"); |
|---|
| 75 | m.put(COPYRIGHT_YEAR, "${copyright.year}"); |
|---|
| 76 | |
|---|
| 77 | // Compile time |
|---|
| 78 | m.put(COMPILE_DATE, "${DSTAMP}"); |
|---|
| 79 | m.put(COMPILE_TIME, "${TSTAMP}"); |
|---|
| 80 | m.put("compile.user.name", "${user.name}"); |
|---|
| 81 | |
|---|
| 82 | m.put("cclabel", "${label}"); |
|---|
| 83 | // Compile environment |
|---|
| 84 | m.put("ant.version", "${ant.version}"); |
|---|
| 85 | m.put("java.vm.info", "${java.vm.info}"); |
|---|
| 86 | m.put("java.vm.name", "${java.vm.name}"); |
|---|
| 87 | m.put("java.vendor", "${java.vendor}"); |
|---|
| 88 | m.put("java.version", "${java.version}"); |
|---|
| 89 | m.put("os.arch", "${os.arch}"); |
|---|
| 90 | m.put("os.name", "${os.name}"); |
|---|
| 91 | m.put("os.version", "${os.version}"); |
|---|
| 92 | m.put("file.encoding", "${file.encoding}"); |
|---|
| 93 | |
|---|
| 94 | PROPERTIES = Collections.unmodifiableMap(m); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | /** |
|---|
| 98 | * Returns a unmodifiable {@link java.util.Map} <String, String> |
|---|
| 99 | * of all compile time properties. |
|---|
| 100 | * @return a unmodifiable {@link java.util.Map} <String, String> |
|---|
| 101 | * of all compile time properties. |
|---|
| 102 | */ |
|---|
| 103 | public static Map getProperties () |
|---|
| 104 | { |
|---|
| 105 | return PROPERTIES; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | * Returns the release version number as {@link String}. |
|---|
| 110 | * @return the release version number as {@link String}. |
|---|
| 111 | */ |
|---|
| 112 | public static String getReleaseVersion () |
|---|
| 113 | { |
|---|
| 114 | return getProperty(RELEASE_VERSION); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | /** |
|---|
| 118 | * Returns the project name as {@link String}. |
|---|
| 119 | * @return the project name as {@link String}. |
|---|
| 120 | */ |
|---|
| 121 | public static String getProjectName () |
|---|
| 122 | { |
|---|
| 123 | return getProperty(PROJECT_NAME); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | * Returns the project name in lowercase as {@link String}. |
|---|
| 128 | * @return the project name in lowercase as {@link String}. |
|---|
| 129 | */ |
|---|
| 130 | public static String getProjectNameLowerCase () |
|---|
| 131 | { |
|---|
| 132 | return getProperty(PROJECT_NAME_LOWERCASE); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | /** |
|---|
| 136 | * Returns the project's copyright year as {@link String}. |
|---|
| 137 | * @return the project's copyright year as {@link String}. |
|---|
| 138 | */ |
|---|
| 139 | public static String getCopyrightYear () |
|---|
| 140 | { |
|---|
| 141 | return getProperty(COPYRIGHT_YEAR); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | /** |
|---|
| 145 | * Returns the compile date (w/o time) as {@link String}. |
|---|
| 146 | * @return the compile date (w/o time) as {@link String}. |
|---|
| 147 | */ |
|---|
| 148 | public static String getCompileDateString () |
|---|
| 149 | { |
|---|
| 150 | return getProperty(COMPILE_DATE); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | /** |
|---|
| 154 | * Returns the compile time (w/o date) as {@link String}. |
|---|
| 155 | * @return the compile time (w/o date) as {@link String}. |
|---|
| 156 | */ |
|---|
| 157 | public static String getCompileTimeString () |
|---|
| 158 | { |
|---|
| 159 | return getProperty(COMPILE_TIME); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | /** |
|---|
| 163 | * Returns the value of the named property. |
|---|
| 164 | * @param key the property name. |
|---|
| 165 | * @return the value of the named property or <tt>null</tt> if the given |
|---|
| 166 | * property is not available. |
|---|
| 167 | */ |
|---|
| 168 | public static String getProperty (String key) |
|---|
| 169 | { |
|---|
| 170 | return (String) PROPERTIES.get(key); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | public static String getDescription () |
|---|
| 174 | { |
|---|
| 175 | final StringBuffer sb = new StringBuffer(); |
|---|
| 176 | sb.append("Project "); |
|---|
| 177 | sb.append(getProjectName()); |
|---|
| 178 | sb.append("/"); |
|---|
| 179 | sb.append(getReleaseVersion()); |
|---|
| 180 | sb.append("/"); |
|---|
| 181 | final String ccLabel = getProperty("cclabel"); |
|---|
| 182 | if (ccLabel != null && ccLabel.indexOf("_") != -1) |
|---|
| 183 | { |
|---|
| 184 | sb.append(ccLabel); |
|---|
| 185 | } |
|---|
| 186 | else |
|---|
| 187 | { |
|---|
| 188 | sb.append(getCompileDateString()); |
|---|
| 189 | sb.append('-'); |
|---|
| 190 | sb.append(getCompileTimeString()); |
|---|
| 191 | sb.append('-'); |
|---|
| 192 | sb.append(getProperty("compile.user.name")); |
|---|
| 193 | } |
|---|
| 194 | sb.append("/"); |
|---|
| 195 | sb.append(Version.class.getPackage().getName()); |
|---|
| 196 | return sb.toString(); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | /** |
|---|
| 200 | * Dump the build version to System.out |
|---|
| 201 | */ |
|---|
| 202 | public static void main (String[] args) |
|---|
| 203 | { |
|---|
| 204 | if (args.length == 0) |
|---|
| 205 | { |
|---|
| 206 | System.out.println(getDescription()); |
|---|
| 207 | } |
|---|
| 208 | else |
|---|
| 209 | { |
|---|
| 210 | System.out.println(getProperty(args[0])); |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | } |
|---|