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
9
10
11
12
13 public final class BuildInformation
14 {
15
16
17
18 private static final BuildInformation INSTANCE = new BuildInformation();
19
20
21
22
23
24
25 public static BuildInformation instance()
26 {
27 return INSTANCE;
28 }
29
30
31
32
33 private BuildInformation()
34 {
35 this.initialize();
36 }
37
38
39
40
41 private String buildDate;
42
43
44
45
46 private String buildSystem;
47
48
49
50
51 private String buildJdk;
52
53
54
55
56 private String buildBuilder;
57
58
59
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
99
100
101
102 public String getBuildVersion()
103 {
104 return this.buildVersion;
105 }
106
107
108
109
110
111
112 public String getBuildBuilder()
113 {
114 return this.buildBuilder;
115 }
116
117
118
119
120
121
122 public String getBuildDate()
123 {
124 return this.buildDate;
125 }
126
127
128
129
130
131
132 public String getBuildJdk()
133 {
134 return this.buildJdk;
135 }
136
137
138
139
140
141
142 public String getBuildSystem()
143 {
144 return this.buildSystem;
145 }
146 }