001: package org.pentaho.util;
002:
003: /**
004: * Bean that holds the results of the version information
005: * @author dkincade
006: */
007: public class VersionInfo {
008: /**
009: * The product id of the product
010: */
011: private String productID;
012:
013: /**
014: * The text title of the product
015: */
016: private String title;
017:
018: /**
019: * The major portion of the version number
020: */
021: private String versionMajor;
022:
023: /**
024: * The minor portion of the version number
025: */
026: private String versionMinor;
027:
028: /**
029: * The release portion of the version number
030: */
031: private String versionRelease;
032:
033: /**
034: * The milestone portion of the version number
035: */
036: private String versionMilestone;
037:
038: /**
039: * THe build number portion of the version number
040: */
041: private String versionBuild;
042:
043: /**
044: * Boolean indicating if this was retrieved from the manifest
045: * (indicating that it is running from a build) or from class files
046: * (indicating it is running from compiled class files).
047: */
048: private boolean fromManifest;
049:
050: public boolean isFromManifest() {
051: return fromManifest;
052: }
053:
054: public String getProductID() {
055: return productID;
056: }
057:
058: public String getTitle() {
059: return title;
060: }
061:
062: public String getVersionMajor() {
063: return versionMajor;
064: }
065:
066: public String getVersionMinor() {
067: return versionMinor;
068: }
069:
070: public String getVersionRelease() {
071: return versionRelease;
072: }
073:
074: public String getVersionMilestone() {
075: return versionMilestone;
076: }
077:
078: public String getVersionBuild() {
079: return versionBuild;
080: }
081:
082: public String getVersionNumber() {
083: StringBuffer sb = new StringBuffer();
084: if (versionMajor != null) {
085: sb.append(versionMajor);
086: if (versionMinor != null) {
087: sb.append('.').append(versionMinor);
088: if (versionRelease != null) {
089: sb.append('.').append(versionRelease);
090: if (versionMilestone != null) {
091: sb.append('.').append(versionMilestone);
092: if (versionBuild != null) {
093: sb.append('.').append(versionBuild);
094: }
095: }
096: }
097: }
098: }
099: return sb.toString();
100: }
101:
102: public String toString() {
103: StringBuffer sb = new StringBuffer();
104: sb
105: .append("fromManifest = [").append(fromManifest).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
106: sb
107: .append("productID = [").append(productID).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
108: sb.append("title = [").append(title).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
109: sb
110: .append("versionMajor = [").append(versionMajor).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
111: sb
112: .append("versionMinor = [").append(versionMinor).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
113: sb
114: .append("versionRelease = [").append(versionRelease).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
115: sb
116: .append("versionMilestone = [").append(versionMilestone).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
117: sb
118: .append("versionBuild = [").append(versionBuild).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
119: sb
120: .append("getVersionNumber() = [").append(getVersionNumber()).append("]\n"); //$NON-NLS-1$ //$NON-NLS-2$
121: return sb.toString();
122: }
123:
124: void setFromManifest(boolean fromManifest) {
125: this .fromManifest = fromManifest;
126: }
127:
128: void setProductID(String productID) {
129: this .productID = productID;
130: }
131:
132: void setTitle(String title) {
133: this .title = title;
134: }
135:
136: void setVersionMajor(String versionMajor) {
137: this .versionMajor = versionMajor;
138: }
139:
140: void setVersionMinor(String versionMinor) {
141: this .versionMinor = versionMinor;
142: }
143:
144: void setVersionRelease(String versionRelease) {
145: this .versionRelease = versionRelease;
146: }
147:
148: void setVersionMilestone(String versionMilestone) {
149: this .versionMilestone = versionMilestone;
150: }
151:
152: void setVersionBuild(String versionBuild) {
153: this .versionBuild = versionBuild;
154: }
155:
156: /**
157: * Sets the version fields by passing the whole string and parsing it.
158: * <br/>
159: * NOTE: spaces will be changed to dots before parsing
160: * @param version the version number (1.6.0.GA.500 or 1.6.0-RC2.400)
161: */
162: void setVersion(String version) {
163: // Parse the version
164: if (version != null) {
165: String[] pieces = version.replace('-', '.').split("\\."); //$NON-NLS-1$
166: switch (pieces.length) {
167: case 9: // just in case
168: case 8: // just in case
169: case 7: // just in case
170: case 6: // just in case
171: case 5:
172: setVersionBuild(pieces[4]); // intentional fall through
173: case 4:
174: setVersionMilestone(pieces[3]); // intentional fall through
175: case 3:
176: setVersionRelease(pieces[2]); // intentional fall through
177: case 2:
178: setVersionMinor(pieces[1]); // intentional fall through
179: case 1:
180: setVersionMajor(pieces[0]); // intentional fall through
181: default: // do nothing
182: }
183: }
184: }
185: }
|