1919
2020package org .elasticsearch ;
2121
22- import org .elasticsearch .common .SuppressForbidden ;
23- import org .elasticsearch .common .io .PathUtils ;
2422import org .elasticsearch .common .io .stream .StreamInput ;
2523import org .elasticsearch .common .io .stream .StreamOutput ;
2624
2725import java .io .IOException ;
28- import java .net .URISyntaxException ;
2926import java .net .URL ;
30- import java .nio .file .Files ;
31- import java .nio .file .Path ;
3227import java .util .jar .JarInputStream ;
3328import java .util .jar .Manifest ;
3429
@@ -47,9 +42,9 @@ public class Build {
4742 final String date ;
4843 final boolean isSnapshot ;
4944
50- Path path = getElasticsearchCodebase ();
51- if (path .toString ().endsWith (".jar" )) {
52- try (JarInputStream jar = new JarInputStream (Files . newInputStream ( path ))) {
45+ final URL url = getElasticsearchCodebase ();
46+ if (url .toString ().endsWith (".jar" )) {
47+ try (JarInputStream jar = new JarInputStream (url . openStream ( ))) {
5348 Manifest manifest = jar .getManifest ();
5449 shortHash = manifest .getMainAttributes ().getValue ("Change" );
5550 date = manifest .getMainAttributes ().getValue ("Build-Date" );
@@ -80,14 +75,8 @@ public class Build {
8075 /**
8176 * Returns path to elasticsearch codebase path
8277 */
83- @ SuppressForbidden (reason = "looks up path of elasticsearch.jar directly" )
84- static Path getElasticsearchCodebase () {
85- URL url = Build .class .getProtectionDomain ().getCodeSource ().getLocation ();
86- try {
87- return PathUtils .get (url .toURI ());
88- } catch (URISyntaxException bogus ) {
89- throw new RuntimeException (bogus );
90- }
78+ static URL getElasticsearchCodebase () {
79+ return Build .class .getProtectionDomain ().getCodeSource ().getLocation ();
9180 }
9281
9382 private String shortHash ;
0 commit comments