001: package org.andromda.core.common;
002:
003: import java.io.InputStream;
004:
005: import java.net.URL;
006:
007: import java.util.Properties;
008:
009: /**
010: * This class provides statistics on how the build was performed.
011: *
012: * @author Martin West
013: * @author Chad Brandon
014: */
015: public class BuildInformation {
016: /**
017: * The shared instance.
018: */
019: private static final BuildInformation instance = new BuildInformation();
020:
021: /**
022: * Gets the shared instance of the BuildInformation.
023: *
024: * @return the shared BuildInformation instance.
025: */
026: public static BuildInformation instance() {
027: return instance;
028: }
029:
030: /**
031: * Private default constructor of BuildInformation. This class is not intended to be instantiated.
032: */
033: private BuildInformation() {
034: this .initialize();
035: }
036:
037: /**
038: * The build timestamp.
039: */
040: private String buildDate;
041:
042: /**
043: * The build operating system and version.
044: */
045: private String buildSystem;
046:
047: /**
048: * The JDK details used to build the system.
049: */
050: private String buildJdk;
051:
052: /**
053: * The name of the user that built the system.
054: */
055: private String buildBuilder;
056:
057: /**
058: * The version of the AndroMDA build.
059: */
060: private String buildVersion;
061:
062: private void initialize() {
063: final String buildPropertiesUri = "META-INF/andromda-build.properties";
064: final String versionPropertyName = "andromda.build.version";
065: final String datePropertyName = "andromda.build.date";
066: final String systemPropertyName = "andromda.build.system";
067: final String jdkPropertyName = "andromda.build.jdk";
068: final String builderPropertyName = "andromda.build.builder";
069: final URL versionUri = ResourceUtils
070: .getResource(buildPropertiesUri);
071: try {
072: if (versionUri == null) {
073: throw new IllegalStateException(
074: "BuildInformation: could not load file --> '"
075: + buildPropertiesUri + "'");
076: }
077: final Properties properties = new Properties();
078: InputStream stream = versionUri.openStream();
079: properties.load(stream);
080: stream.close();
081: stream = null;
082: this .buildDate = properties.getProperty(datePropertyName);
083: this .buildSystem = properties
084: .getProperty(systemPropertyName);
085: this .buildJdk = properties.getProperty(jdkPropertyName);
086: this .buildBuilder = properties
087: .getProperty(builderPropertyName);
088: this .buildVersion = properties
089: .getProperty(versionPropertyName);
090: } catch (final Throwable throwable) {
091: ExceptionRecorder.instance().record(throwable);
092: throw new IllegalStateException(throwable.getMessage());
093: }
094: }
095:
096: /**
097: * Return the name of the operating system and version.
098: *
099: * @return Returns the build version.
100: */
101: public String getBuildVersion() {
102: return this .buildVersion;
103: }
104:
105: /**
106: * Return the user name of the id which built the system.
107: *
108: * @return Returns the build builder.
109: */
110: public String getBuildBuilder() {
111: return this .buildBuilder;
112: }
113:
114: /**
115: * Return the timestamp of the build.
116: *
117: * @return Returns the build date.
118: */
119: public String getBuildDate() {
120: return this .buildDate;
121: }
122:
123: /**
124: * Return the vendor and jdk version.
125: *
126: * @return Returns the build jdk.
127: */
128: public String getBuildJdk() {
129: return this .buildJdk;
130: }
131:
132: /**
133: * Return the name of the operating system and version.
134: *
135: * @return Returns the build system.
136: */
137: public String getBuildSystem() {
138: return this.buildSystem;
139: }
140: }
|