Skip to content

Commit 5723fe3

Browse files
committed
read build information from MANIFEST file
1 parent c43fd41 commit 5723fe3

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

src/main/java/com/tagtraum/perf/gcviewer/util/BuildInfoReader.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66

77
/**
88
* Small helper class to provide current version of GCViewer.
9-
*
9+
*
1010
* @author <a href="mailto:[email protected]">Joerg Wuethrich</a>
1111
* <p>created on: 14.07.2012</p>
1212
*
1313
*/
1414
public class BuildInfoReader {
1515

16-
private final static String FILE_NAME = "build.info.properties";
17-
16+
private final static String FILE_NAME = "META-INF/MANIFEST.MF";
17+
private final static String BUILD_VERSION = "Implementation-Version";
18+
private final static String BUILD_TIMESTAMP = "Implementation-Date";
19+
1820
/**
1921
* Reads the value of a property from FILE_NAME (must be in classpath).
20-
*
22+
*
2123
* @param propertyName name of the property to be read
2224
* @return "n/a" if it couldn't be found or the value
2325
*/
@@ -28,30 +30,33 @@ private static String readPropertyValue(String propertyName) {
2830
Properties props = new Properties();
2931
props.load(in);
3032
propertyValue = props.getProperty(propertyName);
33+
if (propertyValue == null || propertyValue.length() == 0) {
34+
propertyValue = "n/a";
35+
}
3136
}
32-
}
37+
}
3338
catch (IOException e) {
3439
e.printStackTrace();
3540
}
3641

3742
return propertyValue;
3843
}
39-
44+
4045
/**
4146
* Read version from properties file in classpath if it can be found.
42-
*
47+
*
4348
* @return version or "n/a" if not found.
4449
*/
4550
public static String getVersion() {
46-
return readPropertyValue("build.version");
51+
return readPropertyValue(BUILD_VERSION);
4752
}
4853

4954
/**
5055
* Read build date from properties file in classpath if it can be found.
51-
*
56+
*
5257
* @return date or "n/a" if not found.
5358
*/
5459
public static String getBuildDate() {
55-
return readPropertyValue("build.date");
60+
return readPropertyValue(BUILD_TIMESTAMP);
5661
}
5762
}
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.tagtraum.perf.gcviewer;
22

3-
import static org.junit.Assert.assertFalse;
4-
import static org.junit.Assert.assertNotNull;
3+
import static org.hamcrest.Matchers.isEmptyOrNullString;
4+
import static org.hamcrest.Matchers.not;
5+
import static org.hamcrest.Matchers.notNullValue;
6+
import static org.junit.Assert.assertThat;
57

68
import org.junit.Test;
79

@@ -10,7 +12,7 @@
1012
/**
1113
* Tests the class {@link BuildInfoReader} - makes sure that the properties from the file
1214
* can be read.
13-
*
15+
*
1416
* @author <a href="mailto:[email protected]">Joerg Wuethrich</a>
1517
* <p>created on: 05.12.2012</p>
1618
*/
@@ -19,14 +21,14 @@ public class TestBuildInfoReader {
1921
@Test
2022
public void readVersion() {
2123
String version = BuildInfoReader.getVersion();
22-
assertNotNull("version", version);
23-
assertFalse("must not be n/a", version.equals("n/a"));
24+
assertThat("version", version, notNullValue());
25+
assertThat("must not be empty", version, not(isEmptyOrNullString()));
2426
}
2527

2628
@Test
2729
public void readBuildDate() {
2830
String buildDate = BuildInfoReader.getBuildDate();
29-
assertNotNull("buildDate", buildDate);
30-
assertFalse("must not be n/a", buildDate.equals("n/a"));
31+
assertThat("buildDate", buildDate, notNullValue());
32+
assertThat("must not be empty", buildDate, not(isEmptyOrNullString()));
3133
}
3234
}

0 commit comments

Comments
 (0)