001package org.xbib.elasticsearch.plugin.websocket; 002 003import java.io.ByteArrayOutputStream; 004import java.io.InputStream; 005import java.io.StringReader; 006import java.net.URL; 007import java.util.Enumeration; 008import java.util.Properties; 009 010public class Build { 011 012 private static final Build INSTANCE; 013 014 static { 015 String version = "NA"; 016 String hash = "NA"; 017 String hashShort = "NA"; 018 String timestamp = "NA"; 019 String date = "NA"; 020 021 try { 022 String pluginName = WebSocketPlugin.class.getName(); 023 Enumeration<URL> e = WebSocketPlugin.class.getClassLoader().getResources("es-plugin.properties"); 024 while (e.hasMoreElements()) { 025 URL url = e.nextElement(); 026 InputStream in = url.openStream(); 027 ByteArrayOutputStream out = new ByteArrayOutputStream(); 028 byte[] buffer = new byte[1024]; 029 int len; 030 while ((len = in.read(buffer)) != -1) { 031 out.write(buffer, 0, len); 032 } 033 in.close(); 034 Properties props = new Properties(); 035 props.load(new StringReader(new String(out.toByteArray()))); 036 String plugin = props.getProperty("plugin"); 037 if (pluginName.equals(plugin)) { 038 version = props.getProperty("version"); 039 hash = props.getProperty("hash"); 040 if (!"NA".equals(hash)) { 041 hashShort = hash.substring(0, 7); 042 } 043 timestamp = props.getProperty("timestamp"); 044 date = props.getProperty("date"); 045 } 046 } 047 } catch (Throwable e) { 048 // just ignore... 049 } 050 INSTANCE = new Build(version, hash, hashShort, timestamp, date); 051 } 052 053 private String version; 054 055 private String hash; 056 057 private String hashShort; 058 059 private String timestamp; 060 061 private String date; 062 063 Build(String version, String hash, String hashShort, String timestamp, String date) { 064 this.version = version; 065 this.hash = hash; 066 this.hashShort = hashShort; 067 this.timestamp = timestamp; 068 this.date = date; 069 } 070 071 public static Build getInstance() { 072 return INSTANCE; 073 } 074 075 public String getVersion() { 076 return version; 077 } 078 079 public String getHash() { 080 return hash; 081 } 082 083 public String getShortHash() { 084 return hashShort; 085 } 086 087 public String getTimestamp() { 088 return timestamp; 089 } 090 091 public String getDate() { 092 return date; 093 } 094}