/[schmitzm]/trunk/src/skrueger/versionnumber/ReleaseUtil.java
ViewVC logotype

Diff of /trunk/src/skrueger/versionnumber/ReleaseUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 801 by alfonx, Wed Apr 14 19:30:11 2010 UTC revision 1019 by alfonx, Mon Sep 20 17:41:04 2010 UTC
# Line 3  package skrueger.versionnumber; Line 3  package skrueger.versionnumber;
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    
# Line 93  public class ReleaseUtil { Line 95  public class ReleaseUtil {
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");
# Line 110  public class ReleaseUtil { Line 112  public class ReleaseUtil {
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          }          }
# Line 188  public class ReleaseUtil { Line 190  public class ReleaseUtil {
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 "
# Line 198  public class ReleaseUtil { Line 200  public class ReleaseUtil {
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

Legend:
Removed from v.801  
changed lines
  Added in v.1019

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26