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