001: /* Copyright 2004 2006 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010: import org.jasig.portal.security.IPermission;
011: import org.jasig.portal.tools.versioning.VersionsManager;
012:
013: /**
014: * Contains version information about the current release.
015: * This implementation uses static fields and static initializers to pre-compute
016: * once the return values for all String-returning methods so as to avoid
017: * String concatenation induced object churn at runtime. This adds a moderate
018: * amount of code complexity in exchange for non-impactful memory utilization
019: * behaviors in the case where this class is invoked in a tight loop, as when
020: * it is called on every portal render informing the theme transform.
021: *
022: * This class is deprecated so these heroics are likely misapplied. Use
023: * VersionManager instead.
024: *
025: * @author Ken Weiner, kweiner@unicon.net
026: * @author Bernie Durfee, bernard.durfee@suny.edu
027: * @version $Revision: 36790 $
028: * @deprecated use VersionManager with fname UP_FRAMEWORK instead.
029: */
030: public class Version {
031:
032: private static final Log LOG = LogFactory
033: .getLog(org.jasig.portal.Version.class);
034:
035: private static String product = "uPortal";
036:
037: private static org.jasig.portal.tools.versioning.Version uPVersion = null;
038:
039: private static String majorVersion = "unknown";
040:
041: private static String minorVersion = "unknown";
042:
043: private static String microVersion = "unknown";
044:
045: private static String releaseTag = "unknown";
046:
047: private static String dottedTriple = "unknown";
048:
049: private static String productAndVersion = "unknown";
050:
051: static {
052: // try blocks in static initializer to ensure that this class will statically
053: // initialize and report unknown versions rather than failing to initialize at all.
054:
055: try {
056: uPVersion = VersionsManager.getInstance().getVersion(
057: IPermission.PORTAL_FRAMEWORK);
058:
059: try {
060: majorVersion = Integer.toString(uPVersion.getMajor());
061: } catch (Exception e) {
062: LOG.error("Error computing major version of uPortal.",
063: e);
064: }
065:
066: try {
067: minorVersion = Integer.toString(uPVersion.getMinor());
068: } catch (Exception e) {
069: LOG.error("Error computing minor version of uPortal.",
070: e);
071: }
072:
073: try {
074: microVersion = Integer.toString(uPVersion.getMicro());
075: } catch (Exception e) {
076: LOG.error("Error computing micro version of uPortal.",
077: e);
078: }
079:
080: releaseTag = "rel-" + majorVersion + "-" + minorVersion
081: + "-" + microVersion;
082:
083: try {
084: dottedTriple = uPVersion.dottedTriple();
085: } catch (Exception e) {
086: LOG
087: .error(
088: "Error computing dotted triple representation of uPortal version.",
089: e);
090: }
091:
092: productAndVersion = product + " " + dottedTriple;
093:
094: } catch (Exception e) {
095: // if getting the version from VersionsManager fails,
096: // populating the dependent String static fields of this class will
097: // also fail, so this static initializer doesn't bother trying in that case
098: LOG.error("Error getting version of "
099: + IPermission.PORTAL_FRAMEWORK
100: + " from VersionsManager.", e);
101: }
102:
103: }
104:
105: /**
106: * Returns the product name.
107: * For example, this would return <code>uPortal</code> for uPortal 2.3.4.
108: * If the product name is unknown this method returns the String "unknown".
109: * @return the product name
110: */
111: public static String getProduct() {
112: return product;
113: }
114:
115: /**
116: * Returns the major version.
117: * For example, this would return <code>2</code> for uPortal 2.3.4.
118: * If the product major version is unknown this method returns the String "unknown".
119: * @return the major version
120: */
121: public static String getMajor() {
122: return majorVersion;
123: }
124:
125: /**
126: * Returns the minor version.
127: * For example, this would return <code>3</code> for uPortal 2.3.4.
128: * If the product minor version is unknown this method returns the String "unknown".
129: * @return the minor version
130: */
131: public static String getMinor() {
132: return minorVersion;
133: }
134:
135: /**
136: * Returns the patch version.
137: * For example, this would return <code>4</code> for uPortal 2.3.4.
138: * This method may return an empty String.
139: * If the product patch version is unknown this method returns the String "unknown".
140: * @return the patch version
141: */
142: public static String getPatch() {
143: return microVersion;
144: }
145:
146: /**
147: * Previously, returned the security version.
148: * For example, this would return <code>1</code> for uPortal 2.3.4.1.
149: * Now, this method always returns the String "unknown". Security
150: * version number is not supported by VersionsManager, upon which
151: * uPortal has standardized since the inception of this class. This class
152: * is deprecated and will be removed in a future uPortal release.
153: * @return "unknown"
154: */
155: public static String getSecurity() {
156: return "unknown";
157: }
158:
159: /**
160: * Previously, returned any extra string used to construct this version.
161: * For example, this would return <code>+</code> for uPortal 2.3.4+.
162: * A plus sign is used to denote that the code is between releases,
163: * the head of a branch in CVS.
164: * Now, this method always returns the String "unkown". Extra information
165: * beyond dotted triple version number is not supported by
166: * VersionsManager, upon which
167: * uPortal has standardized since the inception of this class. This class
168: * is deprecated and will be removed in a future uPortal release.
169: * @return "unknown"
170: */
171: public static String getExtra() {
172: return "unknown";
173: }
174:
175: /**
176: * Returns the release tag in the CVS repository
177: * corresponding to the current code.
178: * For example, <code>rel-2-3-4</code>.
179: * If the product release tag is unknown this method returns the String "unknown".
180: * @return the release tag matching the running code
181: */
182: public static String getReleaseTag() {
183: return releaseTag;
184: }
185:
186: /**
187: * Returns the version of the current code.
188: * For example, <code>2.3.4</code>.
189: * If the product version is unknown this method returns the String "unknown".
190: * @return the current version of the running code
191: */
192: public static String getVersion() {
193: return dottedTriple;
194: }
195:
196: /**
197: * Returns a display-friendly string representing the
198: * current product and version.
199: * For example, <code>uPortal 2.3.4</code>.
200: * If the version is unknown this method returns the String "unknown".
201: * @return a verison string suitable for display
202: */
203: public static String getProductAndVersion() {
204: return productAndVersion;
205: }
206:
207: }
|