
package org.xbib.elasticsearch.plugin.knapsack;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.Properties;

public class Build {

    private static final Build INSTANCE;

    static {
        String version = "NA";
        String hash = "NA";
        String hashShort = "NA";
        String timestamp = "NA";
        String date = "NA";

        try {
            InputStream in = Build.class.getResourceAsStream("/es-plugin.properties");
            if (in == null) {
                System.err.println("no es-plugin.properties in class path");
            } else {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                copy(in, out);
                Properties props = new Properties();
                props.load(new StringReader(new String(out.toByteArray())));
                version = props.getProperty("version");
                hash = props.getProperty("hash");
                if (!"NA".equals(hash)) {
                    hashShort = hash.substring(0, 7);
                }
                timestamp = props.getProperty("timestamp");
                date = props.getProperty("date");
            }
        } catch (Throwable e) {
            // just ignore...
        }
        INSTANCE = new Build(version, hash, hashShort, timestamp, date);
    }

    public static void copy(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[1024];
        int len;
        while ((len = in.read(buffer)) != -1) {
            out.write(buffer, 0, len);
        }
    }

    private String version;

    private String hash;

    private String hashShort;

    private String timestamp;

    private String date;

    Build(String version, String hash, String hashShort, String timestamp, String date) {
        this.version = version;
        this.hash = hash;
        this.hashShort = hashShort;
        this.timestamp = timestamp;
        this.date = date;
    }

    public static Build getInstance() {
        return INSTANCE;
    }

    public String getVersion() {
        return version;
    }

    public String getHash() {
        return hash;
    }

    public String getShortHash() {
        return hashShort;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public String getDate() {
        return date;
    }
}

@@ -43,16 +43,77 @@
 psack;%0A%0A
+import org.xbib.elasticsearch.plugin.support.SupportPlugin;%0A%0A
 import j
@@ -256,16 +256,67 @@
 Reader;%0A
+import java.net.URL;%0Aimport java.util.Enumeration;%0A
 import j
@@ -598,312 +598,596 @@
     
-InputStream in = Build.class.getResourceAsStream(%22/es-plugin.properties%22);%0A            if (in == null) %7B%0A                System.err.println(%22no es-plugin.properties in class path%22);%0A            %7D else %7B%0A                ByteArrayOutputStream out = new ByteArrayOutputStream();%0A                copy(in, out
+String pluginName = SupportPlugin.class.getName();%0A            Enumeration%3CURL%3E e = SupportPlugin.class.getClassLoader().getResources(%22/es-plugin.properties%22);%0A            while (e.hasMoreElements()) %7B%0A                URL url = e.nextElement();%0A                InputStream in = url.openStream();%0A                ByteArrayOutputStream out = new ByteArrayOutputStream();%0A                byte%5B%5D buffer = new byte%5B1024%5D;%0A                int len;%0A                while ((len = in.read(buffer)) != -1) %7B%0A                    out.write(buffer, 0, len);%0A                %7D%0A                in.close(
 );%0A 
@@ -1315,16 +1315,130 @@
 y())));%0A
+                String plugin = props.getProperty(%22plugin%22);%0A                if (pluginName.equals(plugin)) %7B%0A    
         
@@ -1497,24 +1497,28 @@
             
+    
 hash = props
@@ -1551,24 +1551,28 @@
             
+ 
+   
 if (!%22NA%22.eq
@@ -1601,24 +1601,28 @@
             
+   
+ 
 hashShort = 
@@ -1651,34 +1651,40 @@
                 
-%7D%0A
+    %7D%0A  
                 
@@ -1683,16 +1683,18 @@
         
+  
 timestam
@@ -1725,24 +1725,28 @@
 imestamp%22);%0A
+    
             
@@ -1779,24 +1779,42 @@
 ty(%22date%22);%0A
+                %7D%0A
             
@@ -1971,252 +1971,8 @@
  %7D%0A%0A
-    public static void copy(InputStream in, OutputStream out) throws IOException %7B%0A        byte%5B%5D buffer = new byte%5B1024%5D;%0A        int len;%0A        while ((len = in.read(buffer)) != -1) %7B%0A            out.write(buffer, 0, len);%0A        %7D%0A    %7D%0A%0A
     

build number fix