3 |
import java.io.InputStream; |
import java.io.InputStream; |
4 |
import java.net.URL; |
import java.net.URL; |
5 |
import java.util.Properties; |
import java.util.Properties; |
6 |
|
import java.util.regex.Matcher; |
7 |
|
import java.util.regex.Pattern; |
8 |
|
|
9 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
10 |
|
|
95 |
* |
* |
96 |
* @Return the major part of the software version or 0 if a problem occurs. |
* @Return the major part of the software version or 0 if a problem occurs. |
97 |
*/ |
*/ |
98 |
public static int getVersionBuild(Class<?> clazz) { |
public static String getVersionBuild(Class<?> clazz) { |
99 |
try { |
try { |
100 |
final URL releasePropsURL = clazz |
final URL releasePropsURL = clazz |
101 |
.getResource("/release.properties"); |
.getResource("/release.properties"); |
112 |
if (str.equals("${buildNumber}")) { |
if (str.equals("${buildNumber}")) { |
113 |
// We are in development or Maven didn't filter the properties |
// We are in development or Maven didn't filter the properties |
114 |
// while building. |
// while building. |
115 |
return 0; |
return "0"; |
116 |
} |
} |
117 |
|
|
118 |
return Integer.parseInt(str); |
return str; |
119 |
} catch (final Exception e) { |
} catch (final Exception e) { |
120 |
log.error("/release.properties could not be read from " |
log.error("/release.properties could not be read from " |
121 |
+ clazz.getSimpleName(), e); |
+ clazz.getSimpleName(), e); |
122 |
return 0; |
return "0"; |
123 |
} |
} |
124 |
|
|
125 |
} |
} |
190 |
*/ |
*/ |
191 |
public static int getVersionMin(Class<?> clazz) { |
public static int getVersionMin(Class<?> clazz) { |
192 |
try { |
try { |
193 |
return Integer.parseInt(getVersion(clazz).split("\\.")[1]); |
return extractMinVersionFromString(getVersion(clazz)); |
194 |
} catch (final Exception e) { |
} catch (final Exception e) { |
195 |
log.error("Minor version number '" + getVersion(clazz) |
log.error("Minor version number '" + getVersion(clazz) |
196 |
+ "' part could not be parsed from could not parsed (from " |
+ "' part could not be parsed from could not parsed (from " |
200 |
|
|
201 |
} |
} |
202 |
|
|
203 |
|
public static int extractMinVersionFromString(String versionString) { |
204 |
|
Pattern minVersionPattern = Pattern.compile("\\d*\\.(\\d*).*"); |
205 |
|
Matcher matcher = minVersionPattern.matcher(versionString); |
206 |
|
matcher.find(); |
207 |
|
return Integer.parseInt(matcher.group(1)); |
208 |
|
} |
209 |
|
|
210 |
/** |
/** |
211 |
* @param clazz |
* @param clazz |
212 |
* Pass a class that resides in the same "project" or jar, where |
* Pass a class that resides in the same "project" or jar, where |