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 committed Apr 13, 2017
1 parent 6412806 commit d90b1e2
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 @@ -42,8 +42,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(url.openStream())) {
Manifest manifest = jar.getManifest();
shortHash = manifest.getMainAttributes().getValue("Change");
Expand All @@ -53,7 +55,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 d90b1e2

Please sign in to comment.