From 0119caa4a61141c2ab8ec5e008d33c0066512f7f Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 13 Nov 2015 16:57:20 -0500 Subject: [PATCH] Make Build work without git If you build elasticsearch without a git repository it was creating a null shortHash which was causing Elasticsearch not to be able to form transport connections. Closes #14748 --- .../org/elasticsearch/gradle/BuildPlugin.groovy | 4 ++++ core/src/main/java/org/elasticsearch/Build.java | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 8e1dce66f41..78c1d68303e 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -240,6 +240,10 @@ class BuildPlugin implements Plugin { 'X-Compile-Elasticsearch-Version': VersionProperties.elasticsearch, 'X-Compile-Lucene-Version': VersionProperties.lucene, 'Build-Date': ZonedDateTime.now(ZoneOffset.UTC)) + if (jarTask.manifest.attributes.containsKey('Change') == false) { + logger.warn('Building without git revision id.') + jarTask.manifest.attributes('Change': 'N/A') + } } } } diff --git a/core/src/main/java/org/elasticsearch/Build.java b/core/src/main/java/org/elasticsearch/Build.java index 2bb08a292ff..248040de0a8 100644 --- a/core/src/main/java/org/elasticsearch/Build.java +++ b/core/src/main/java/org/elasticsearch/Build.java @@ -33,9 +33,13 @@ import java.util.jar.JarInputStream; import java.util.jar.Manifest; /** + * Information about a build of Elasticsearch. */ public class Build { - + /** + * The current build of Elasticsearch. Filled with information scanned at + * startup from the jar. + */ public static final Build CURRENT; static { @@ -56,6 +60,14 @@ public class Build { shortHash = "Unknown"; date = "Unknown"; } + if (shortHash == null) { + throw new IllegalStateException("Error finding the build shortHash. " + + "Stopping Elasticsearch now so it doesn't run in subtly broken ways. This is likely a build bug."); + } + if (date == null) { + throw new IllegalStateException("Error finding the build date. " + + "Stopping Elasticsearch now so it doesn't run in subtly broken ways. This is likely a build bug."); + } CURRENT = new Build(shortHash, date); }