1 | /* |
2 | * Created on Jul 9, 2004 |
3 | * |
4 | * To change the template for this generated file go to |
5 | * Window - Preferences - Java - Code Generation - Code and Comments |
6 | */ |
7 | package biz.xsoftware.buildtemplate; |
8 | |
9 | /** |
10 | * Miscellaneous class that just prints the version of the mock object jar |
11 | * getting it from the manifest file. |
12 | * |
13 | * @author Dean Hiller |
14 | */ |
15 | public class VersionImpl implements Version { |
16 | |
17 | private Package thePackage; |
18 | |
19 | /** |
20 | * Constructor that takes a class to get the version information |
21 | * from out of the manifest. Uses the class's package to retrieve |
22 | * the manifest version info. |
23 | * @param c The Class on whose package to use to get version info. |
24 | */ |
25 | public VersionImpl() { |
26 | String name = VersionImpl.class.getName(); |
27 | int index = name.lastIndexOf("."); |
28 | |
29 | if(index < 0) |
30 | throw new RuntimeException("This class is the default package and can't be to use this feature"); |
31 | |
32 | String packageName = name.substring(0, index); |
33 | thePackage = Package.getPackage(packageName); |
34 | } |
35 | |
36 | public String getVersion() { |
37 | String version = thePackage.getImplementationVersion(); |
38 | int index = version.indexOf(" "); |
39 | version = version.substring(0, index); |
40 | return version; |
41 | } |
42 | } |