View Javadoc

1   package org.andromda.core.common;
2   
3   import java.io.InputStream;
4   
5   import java.net.URL;
6   
7   import java.util.Properties;
8   
9   
10  /***
11   * This class provides statistics on how the build was performed.
12   *
13   * @author Martin West
14   * @author Chad Brandon
15   */
16  public class BuildInformation
17  {
18      /***
19       * The shared instance.
20       */
21      private static final BuildInformation instance = new BuildInformation();
22  
23      /***
24       * Gets the shared instance of the BuildInformation.
25       *
26       * @return the shared BuildInformation instance.
27       */
28      public static BuildInformation instance()
29      {
30          return instance;
31      }
32  
33      /***
34       * Private default constructor of BuildInformation. This class is not intended to be instantiated.
35       */
36      private BuildInformation()
37      {
38          this.initialize();
39      }
40  
41      /***
42       * The build timestamp.
43       */
44      private String buildDate;
45  
46      /***
47       * The build operating system and version.
48       */
49      private String buildSystem;
50  
51      /***
52       * The JDK details used to build the system.
53       */
54      private String buildJdk;
55  
56      /***
57       * The name of the user that built the system.
58       */
59      private String buildBuilder;
60  
61      /***
62       * The version of the AndroMDA build.
63       */
64      private String buildVersion;
65  
66      private void initialize()
67      {
68          final String buildPropertiesUri = "META-INF/andromda-build.properties";
69          final String versionPropertyName = "andromda.build.version";
70          final String datePropertyName = "andromda.build.date";
71          final String systemPropertyName = "andromda.build.system";
72          final String jdkPropertyName = "andromda.build.jdk";
73          final String builderPropertyName = "andromda.build.builder";
74          final URL versionUri = ResourceUtils.getResource(buildPropertiesUri);
75          try
76          {
77              if (versionUri == null)
78              {
79                  throw new IllegalStateException(
80                      "BuildInformation: could not load file --> '" + buildPropertiesUri + "'");
81              }
82              final Properties properties = new Properties();
83              InputStream stream = versionUri.openStream();
84              properties.load(stream);
85              stream.close();
86              stream = null;
87              this.buildDate = properties.getProperty(datePropertyName);
88              this.buildSystem = properties.getProperty(systemPropertyName);
89              this.buildJdk = properties.getProperty(jdkPropertyName);
90              this.buildBuilder = properties.getProperty(builderPropertyName);
91              this.buildVersion = properties.getProperty(versionPropertyName);
92          }
93          catch (final Throwable throwable)
94          {
95              ExceptionRecorder.instance().record(throwable);
96              throw new IllegalStateException(throwable.getMessage());
97          }
98      }
99  
100     /***
101      * Return the name of the operating system and version.
102      *
103      * @return Returns the build version.
104      */
105     public String getBuildVersion()
106     {
107         return this.buildVersion;
108     }
109 
110     /***
111      * Return the user name of the id which built the system.
112      *
113      * @return Returns the build builder.
114      */
115     public String getBuildBuilder()
116     {
117         return this.buildBuilder;
118     }
119 
120     /***
121      * Return the timestamp of the build.
122      *
123      * @return Returns the build date.
124      */
125     public String getBuildDate()
126     {
127         return this.buildDate;
128     }
129 
130     /***
131      * Return the vendor and jdk version.
132      *
133      * @return Returns the build jdk.
134      */
135     public String getBuildJdk()
136     {
137         return this.buildJdk;
138     }
139 
140     /***
141      * Return the name of the operating system and version.
142      *
143      * @return Returns the build system.
144      */
145     public String getBuildSystem()
146     {
147         return this.buildSystem;
148     }
149 }