1 21 22 package org.armedbear.j; 23 24 import java.io.BufferedReader ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.InputStreamReader ; 28 29 public final class Version 30 { 31 private static String version; 32 private static String build; 33 private static String hostName; 34 private static String snapshot; 35 36 private static boolean initialized; 37 38 public static String getVersion() 40 { 41 initialize(); 42 return version; 43 } 44 45 public static String getShortVersionString() 47 { 48 initialize(); 49 FastStringBuffer sb = new FastStringBuffer("J"); 50 if (version != null && version.length() > 0) { 51 sb.append(' '); 52 sb.append(version); 53 } 54 return sb.toString(); 55 } 56 57 public static String getLongVersionString() 59 { 60 FastStringBuffer sb = new FastStringBuffer(getShortVersionString()); 61 if (build != null && build.length() > 0) { 62 sb.append(" (built "); 63 sb.append(build); 64 if (hostName != null && hostName.length() > 0) { 65 sb.append(" on "); 66 sb.append(hostName); 67 } 68 sb.append(")"); 69 } 70 return sb.toString(); 71 } 72 73 81 public static String getSnapshotInformation() 82 { 83 if (version != null && version.endsWith("+") && snapshot != null) { 84 if (!snapshot.equals(build)) { 85 FastStringBuffer sb = 86 new FastStringBuffer("(built from development snapshot created "); 87 sb.append(snapshot); 88 sb.append(')'); 89 return sb.toString(); 90 } 91 } 92 return null; 93 } 94 95 private static void initialize() 96 { 97 if (!initialized) { 98 InputStream inputStream = 99 Editor.class.getResourceAsStream("version"); 100 if (inputStream != null) { 101 try { 102 BufferedReader reader = 103 new BufferedReader (new InputStreamReader (inputStream)); 104 version = reader.readLine(); 105 reader.close(); 106 } 107 catch (IOException e) { 108 Log.error(e); 109 } 110 } 111 inputStream = Editor.class.getResourceAsStream("build"); 112 if (inputStream != null) { 113 try { 114 BufferedReader reader = 115 new BufferedReader (new InputStreamReader (inputStream)); 116 build = reader.readLine(); 117 hostName = reader.readLine(); 118 reader.close(); 119 } 120 catch (IOException e) { 121 Log.error(e); 122 } 123 } 124 inputStream = Editor.class.getResourceAsStream("snapshot"); 125 if (inputStream != null) { 126 try { 127 BufferedReader reader = 128 new BufferedReader (new InputStreamReader (inputStream)); 129 snapshot = reader.readLine(); 130 reader.close(); 131 } 132 catch (IOException e) { 133 Log.error(e); 134 } 135 } 136 initialized = true; 137 } 138 } 139 } 140 | Popular Tags |