Restrict build info loading to ES jar, not any jar (#24049)

This change makes the build info initialization only try to load a jar
manifest if it is the elasticsearch jar. Anything else (eg a repackaged
ES for use of transport client in an uber jar) will contain "Unknown"
for the build info as it does for tests currently.

fixes #21955
This commit is contained in:
Ryan Ernst 2017-04-12 23:22:43 -07:00 committed by GitHub
parent 12b46bdbc4
commit c19044ddf6
1 changed files with 4 additions and 2 deletions

View File

@ -43,8 +43,10 @@ public class Build {
final String date;
final boolean isSnapshot;
final String esPrefix = "elasticsearch-" + Version.CURRENT;
final URL url = getElasticsearchCodebase();
if (url.toString().endsWith(".jar")) {
final String urlStr = url.toString();
if (urlStr.startsWith("file:/") && (urlStr.endsWith(esPrefix + ".jar") || urlStr.endsWith(esPrefix + "-SNAPSHOT.jar"))) {
try (JarInputStream jar = new JarInputStream(FileSystemUtils.openFileURLStream(url))) {
Manifest manifest = jar.getManifest();
shortHash = manifest.getMainAttributes().getValue("Change");
@ -54,7 +56,7 @@ public class Build {
throw new RuntimeException(e);
}
} else {
// not running from a jar (unit tests, IDE)
// not running from the official elasticsearch jar file (unit tests, IDE, uber client jar, shadiness)
shortHash = "Unknown";
date = "Unknown";
isSnapshot = true;