From c8e462e5dca9be0c1a03fec1f3972788b1464daf Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sat, 20 Feb 2016 17:12:48 -0800 Subject: [PATCH] Apply feedback from @rjernst --- buildSrc/build.gradle | 2 +- .../main/java/org/elasticsearch/Version.java | 23 ++++++------------- .../rest/action/cat/RestNodesAction.java | 2 +- .../rest/action/main/RestMainAction.java | 2 +- .../java/org/elasticsearch/VersionTests.java | 12 +++++----- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 43ef0bf8625..f8d80679504 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -47,7 +47,7 @@ if (snapshot) { // we update the version property to reflect if we are building a snapshot or a release build // we write this back out below to load it in the Build.java which will be shown in rest main action // to indicate this being a snapshot build or a release build. - version = version+"-SNAPSHOT" + version += "-SNAPSHOT" props.put("elasticsearch", version); } diff --git a/core/src/main/java/org/elasticsearch/Version.java b/core/src/main/java/org/elasticsearch/Version.java index a202b300c0b..07fb07a2dfa 100644 --- a/core/src/main/java/org/elasticsearch/Version.java +++ b/core/src/main/java/org/elasticsearch/Version.java @@ -605,10 +605,13 @@ public class Version { return Version.smallest(this, fromId(major * 1000000 + 99)); } - /** - * The version number - */ - public String number() { + @SuppressForbidden(reason = "System.out.*") + public static void main(String[] args) { + System.out.println("Version: " + Version.CURRENT + ", Build: " + Build.CURRENT.shortHash() + "/" + Build.CURRENT.date() + ", JVM: " + JvmInfo.jvmInfo().version()); + } + + @Override + public String toString() { StringBuilder sb = new StringBuilder(); sb.append(major).append('.').append(minor).append('.').append(revision); if (isBeta()) { @@ -629,18 +632,6 @@ public class Version { return sb.toString(); } - @SuppressForbidden(reason = "System.out.*") - public static void main(String[] args) { - System.out.println("Version: " + Version.CURRENT + ", Build: " + Build.CURRENT.shortHash() + "/" + Build.CURRENT.date() + ", JVM: " + JvmInfo.jvmInfo().version()); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(number()); - return sb.toString(); - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java b/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java index f044ae7b023..104d9295299 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java @@ -248,7 +248,7 @@ public class RestNodesAction extends AbstractCatAction { table.addCell("-"); } - table.addCell(node.getVersion().number()); + table.addCell(node.getVersion().toString()); table.addCell(info == null ? null : info.getBuild().shortHash()); table.addCell(jvmInfo == null ? null : jvmInfo.version()); table.addCell(fsInfo == null ? null : fsInfo.getTotal().getAvailable()); diff --git a/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java b/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java index 2d215ee7d0a..bf3f0a3e5df 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java @@ -81,7 +81,7 @@ public class RestMainAction extends BaseRestHandler { builder.field("name", Node.NODE_NAME_SETTING.get(settings)); builder.field("cluster_name", clusterName.value()); builder.startObject("version") - .field("number", version.number()) + .field("number", version.toString()) .field("build_hash", Build.CURRENT.shortHash()) .field("build_date", Build.CURRENT.date()) .field("build_snapshot", Build.CURRENT.isSnapshot()) diff --git a/core/src/test/java/org/elasticsearch/VersionTests.java b/core/src/test/java/org/elasticsearch/VersionTests.java index 7499c8d8cd8..4669f5bc718 100644 --- a/core/src/test/java/org/elasticsearch/VersionTests.java +++ b/core/src/test/java/org/elasticsearch/VersionTests.java @@ -84,7 +84,7 @@ public class VersionTests extends ESTestCase { final int iters = scaledRandomIntBetween(100, 1000); for (int i = 0; i < iters; i++) { Version version = randomVersion(random()); - assertThat(Version.fromString(version.number()), sameInstance(version)); + assertThat(Version.fromString(version.toString()), sameInstance(version)); } } @@ -141,9 +141,9 @@ public class VersionTests extends ESTestCase { public void testToString() { // with 2.0.beta we lowercase - assertEquals("2.0.0-beta1", Version.V_2_0_0_beta1.number()); - assertEquals("1.4.0.Beta1", Version.V_1_4_0_Beta1.number()); - assertEquals("1.4.0", Version.V_1_4_0.number()); + assertEquals("2.0.0-beta1", Version.V_2_0_0_beta1.toString()); + assertEquals("1.4.0.Beta1", Version.V_1_4_0_Beta1.toString()); + assertEquals("1.4.0", Version.V_1_4_0.toString()); } public void testIsBeta() { @@ -192,7 +192,7 @@ public class VersionTests extends ESTestCase { assertEquals("Version id " + field.getName() + " does not point to " + constantName, v, Version.fromId(versionId)); assertEquals("Version " + constantName + " does not have correct id", versionId, v.id); if (v.major >= 2) { - String number = v.number(); + String number = v.toString(); if (v.isBeta()) { number = number.replace("-beta", "_beta"); } else if (v.isRC()) { @@ -200,7 +200,7 @@ public class VersionTests extends ESTestCase { } assertEquals("V_" + number.replace('.', '_'), constantName); } else { - assertEquals("V_" + v.number().replace('.', '_'), constantName); + assertEquals("V_" + v.toString().replace('.', '_'), constantName); } // only the latest version for a branch should be a snapshot (ie unreleased)