11
22package org .xbib .elasticsearch .plugin .knapsack ;
33
4+ import org .xbib .elasticsearch .plugin .support .SupportPlugin ;
5+
46import java .io .ByteArrayOutputStream ;
57import java .io .IOException ;
68import java .io .InputStream ;
79import java .io .OutputStream ;
810import java .io .StringReader ;
11+ import java .net .URL ;
12+ import java .util .Enumeration ;
913import java .util .Properties ;
1014
1115public class Build {
@@ -20,36 +24,37 @@ public class Build {
2024 String date = "NA" ;
2125
2226 try {
23- InputStream in = Build .class .getResourceAsStream ("/es-plugin.properties" );
24- if (in == null ) {
25- System .err .println ("no es-plugin.properties in class path" );
26- } else {
27+ String pluginName = SupportPlugin .class .getName ();
28+ Enumeration <URL > e = SupportPlugin .class .getClassLoader ().getResources ("/es-plugin.properties" );
29+ while (e .hasMoreElements ()) {
30+ URL url = e .nextElement ();
31+ InputStream in = url .openStream ();
2732 ByteArrayOutputStream out = new ByteArrayOutputStream ();
28- copy (in , out );
33+ byte [] buffer = new byte [1024 ];
34+ int len ;
35+ while ((len = in .read (buffer )) != -1 ) {
36+ out .write (buffer , 0 , len );
37+ }
38+ in .close ();
2939 Properties props = new Properties ();
3040 props .load (new StringReader (new String (out .toByteArray ())));
31- version = props .getProperty ("version" );
32- hash = props .getProperty ("hash" );
33- if (!"NA" .equals (hash )) {
34- hashShort = hash .substring (0 , 7 );
41+ String plugin = props .getProperty ("plugin" );
42+ if (pluginName .equals (plugin )) {
43+ version = props .getProperty ("version" );
44+ hash = props .getProperty ("hash" );
45+ if (!"NA" .equals (hash )) {
46+ hashShort = hash .substring (0 , 7 );
47+ }
48+ timestamp = props .getProperty ("timestamp" );
49+ date = props .getProperty ("date" );
3550 }
36- timestamp = props .getProperty ("timestamp" );
37- date = props .getProperty ("date" );
3851 }
3952 } catch (Throwable e ) {
4053 // just ignore...
4154 }
4255 INSTANCE = new Build (version , hash , hashShort , timestamp , date );
4356 }
4457
45- public static void copy (InputStream in , OutputStream out ) throws IOException {
46- byte [] buffer = new byte [1024 ];
47- int len ;
48- while ((len = in .read (buffer )) != -1 ) {
49- out .write (buffer , 0 , len );
50- }
51- }
52-
5358 private String version ;
5459
5560 private String hash ;
0 commit comments