1 19 20 package com.sslexplorer.boot; 21 22 import java.io.FileInputStream ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.util.Properties ; 26 import java.util.StringTokenizer ; 27 28 39 public class VersionInfo { 40 41 private final static String VERSION = "0.2.15"; 42 43 private static Version version; 44 private static boolean developmentVersion; 45 46 static { 47 if (VERSION.startsWith("999.")) { 48 developmentVersion = true; 49 Properties p = new Properties (); 50 InputStream in = null; 51 try { 52 in = new FileInputStream ("build.properties"); 53 p.load(in); 54 version = new Version(p.getProperty("version.major", "999") + "." + p.getProperty("version.minor", "999") + "." 55 + p.getProperty("version.build", "999") + p.getProperty("version.tag")); 56 } catch (IOException ioe) { 57 version = new Version("0.2.15"); 58 } finally { 59 if (in != null) { 60 try { 61 in.close(); 62 } catch (IOException ioe) { 63 } 64 } 65 } 66 } else { 67 version = new Version(VERSION); 68 } 69 } 70 71 77 public static boolean isDevelopmentVersion() { 78 return developmentVersion; 79 } 80 81 86 public static Version getVersion() { 87 return version; 88 } 89 90 104 public static class Version implements Comparable { 105 int minor; 106 int major; 107 int build; 108 String tag; 109 int tagOffset; 110 111 116 public Version(String version) { 117 StringTokenizer t = new StringTokenizer (version, "."); 118 try { 119 major = Integer.parseInt(t.nextToken()); 120 minor = Integer.parseInt(t.nextToken()); 121 122 if (t.hasMoreTokens()) { 123 String s = t.nextToken(); 124 int pos = s.indexOf('_'); 125 if (pos > -1) { 126 build = Integer.parseInt(s.substring(0, pos)); 127 tag = s.substring(pos); 128 } else { 129 build = Integer.parseInt(s); 130 tag = ""; 131 } 132 } else { 133 build = 0; 134 tag = ""; 135 } 136 } catch (Throwable ex) { 137 major = 999; 138 minor = 999; 139 build = 999; 140 tag = ""; 141 } 142 143 tagOffset = 0; 145 tag = tag.toUpperCase(); 146 147 if(!tag.equals("")) { 149 if(tag.startsWith("_RC")) { 150 tagOffset = -100 + Integer.parseInt(tag.substring(3)); 151 } 152 else { 153 try { 155 tagOffset = Integer.parseInt(tag.substring(1)); 156 } 157 catch(NumberFormatException nfe) { 158 } 160 } 161 } 162 163 } 164 165 172 public Version(int major, int minor, int build) { 173 this.major = major; 174 this.minor = minor; 175 this.build = build; 176 } 177 178 186 public int compareTo(Object o) { 187 return new Integer (hashCode()).compareTo(new Integer (o.hashCode())); 188 } 189 190 193 public boolean equals(Object obj) { 194 return hashCode() == obj.hashCode(); 195 } 196 197 200 public int hashCode() { 201 return (int)(((long)major * 1000000000l) + ((long)minor * 1000000l) + ((long)build * 1000l) + tagOffset); 202 } 203 204 207 public String toString() { 208 return major + "." + minor + "." + build + tag; 209 } 210 211 216 public int getMajor() { 217 return major; 218 } 219 220 225 public int getMinor() { 226 return minor; 227 } 228 229 234 public int getBuild() { 235 return build; 236 } 237 238 243 public String getTag() { 244 return tag; 245 } 246 } 247 } 248 | Popular Tags |