Skip to content

Commit

Permalink
Restrict build info loading to ES jar, not any jar (#24049)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rjernst authored Apr 13, 2017
1 parent 12b46bd commit c19044d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/src/main/java/org/elasticsearch/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down

0 comments on commit c19044d

Please sign in to comment.