From commits-return-7825-apmail-zookeeper-commits-archive=zookeeper.apache.org@zookeeper.apache.org Fri May 31 20:16:39 2019 Return-Path: X-Original-To: apmail-zookeeper-commits-archive@www.apache.org Delivered-To: apmail-zookeeper-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 86FE51940D for ; Fri, 31 May 2019 20:16:39 +0000 (UTC) Received: (qmail 41513 invoked by uid 500); 31 May 2019 20:16:39 -0000 Delivered-To: apmail-zookeeper-commits-archive@zookeeper.apache.org Received: (qmail 41493 invoked by uid 500); 31 May 2019 20:16:39 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 41482 invoked by uid 99); 31 May 2019 20:16:38 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 May 2019 20:16:38 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id AA7808A567; Fri, 31 May 2019 20:16:38 +0000 (UTC) Date: Fri, 31 May 2019 20:16:38 +0000 To: "commits@zookeeper.apache.org" Subject: [zookeeper] branch master updated: ZOOKEEPER-1426: add version command to the zookeeper server MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <155933379856.5282.10626320551808376618@gitbox.apache.org> From: andor@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: zookeeper X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: ca4b12430ef579f67785146a195ebfed5ca73f39 X-Git-Newrev: d3dbe787f37eb9e17402e4a3d55a441ca43b2160 X-Git-Rev: d3dbe787f37eb9e17402e4a3d55a441ca43b2160 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. andor pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zookeeper.git The following commit(s) were added to refs/heads/master by this push: new d3dbe78 ZOOKEEPER-1426: add version command to the zookeeper server d3dbe78 is described below commit d3dbe787f37eb9e17402e4a3d55a441ca43b2160 Author: szepet AuthorDate: Fri May 31 22:16:29 2019 +0200 ZOOKEEPER-1426: add version command to the zookeeper server Adding a version command to the zkServer.sh. This is an open/unresolved issue, however, a really nice feature to have. The implementation is already provided by Eli Reisman on the issue page and got several +1 back then, but has not been committed. I just rebased the patch. Author: szepet Reviewers: eolivelli@apache.org, andor@apache.org Closes #923 from szepet/ZOOKEEPER-1426 and squashes the following commits: d9108bda1 [szepet] test-scripts.sh improved to work with ant build as well cd6a0bf7d [szepet] ZOOKEEPER-1426: add version command to the zookeeper server --- bin/zkServer-initialize.sh | 25 +++++------- bin/zkServer.sh | 6 ++- .../org/apache/zookeeper/version/util/VerGen.java | 46 ++++++++++++++++++++-- .../src/test/resources/findbugsExcludeFile.xml | 7 ++++ .../src/test/resources/test-scripts.sh | 8 ++-- 5 files changed, 67 insertions(+), 25 deletions(-) diff --git a/bin/zkServer-initialize.sh b/bin/zkServer-initialize.sh index 12bd419..062e265 100755 --- a/bin/zkServer-initialize.sh +++ b/bin/zkServer-initialize.sh @@ -47,15 +47,6 @@ usage() { exit 1 } -OPTS=$(getopt \ - -n $0 \ - -o 'h' \ - -l 'help' \ - -l 'configfile:' \ - -l 'myid:' \ - -l 'force' \ - -- "$@") - if [ $? != 0 ] ; then usage exit 1 @@ -117,15 +108,20 @@ initialize() { touch "$ZOO_DATADIR/initialize" } -eval set -- "${OPTS}" -while true; do +while [ ! -z "$1" ]; do case "$1" in --configfile) ZOOCFG=$2; shift 2 ;; + --configfile=?*) + ZOOCFG=${1#*=}; shift 1 + ;; --myid) MYID=$2; shift 2 ;; + --myid=?*) + MYID=${1#*=}; shift 1 + ;; --force) FORCE=1; shift 1 ;; @@ -135,14 +131,11 @@ while true; do --help) usage ;; - --) - initialize - break - ;; *) echo "Unknown option: $1" usage exit 1 ;; esac -done +done +initialize diff --git a/bin/zkServer.sh b/bin/zkServer.sh index e4e01e8..b83848a 100755 --- a/bin/zkServer.sh +++ b/bin/zkServer.sh @@ -216,6 +216,10 @@ stop) fi exit 0 ;; +version) + ZOOMAIN=org.apache.zookeeper.version.VersionInfoMain + $JAVA -cp "$CLASSPATH" $ZOOMAIN 2> /dev/null + ;; restart) shift "$0" stop ${@} @@ -272,6 +276,6 @@ status) fi ;; *) - echo "Usage: $0 [--config ] {start|start-foreground|stop|restart|status|print-cmd}" >&2 + echo "Usage: $0 [--config ] {start|start-foreground|stop|version|restart|status|print-cmd}" >&2 esac diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/version/util/VerGen.java b/zookeeper-server/src/main/java/org/apache/zookeeper/version/util/VerGen.java index 737c401..b84dacd 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/version/util/VerGen.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/version/util/VerGen.java @@ -28,7 +28,8 @@ import java.util.regex.Pattern; public class VerGen { private static final String PACKAGE_NAME = "org.apache.zookeeper.version"; - private static final String TYPE_NAME = "Info"; + private static final String VERSION_CLASS_NAME = "VersionInfoMain"; + private static final String VERSION_INTERFACE_NAME = "Info"; static void printUsage() { System.out.print("Usage:\tjava -cp org.apache.zookeeper." @@ -53,7 +54,7 @@ public class VerGen { System.exit(ExitCode.UNEXPECTED_ERROR.getValue()); } - try (FileWriter w = new FileWriter(new File(pkgdir, TYPE_NAME + ".java"))) { + try (FileWriter w = new FileWriter(new File(pkgdir, VERSION_INTERFACE_NAME + ".java"))) { w.write("// Do not edit!\n// File generated by org.apache.zookeeper" + ".version.util.VerGen.\n"); w.write("/**\n"); @@ -75,7 +76,7 @@ public class VerGen { w.write("*/\n"); w.write("\n"); w.write("package " + PACKAGE_NAME + ";\n\n"); - w.write("public interface " + TYPE_NAME + " {\n"); + w.write("public interface " + VERSION_INTERFACE_NAME + " {\n"); w.write(" int MAJOR=" + version.maj + ";\n"); w.write(" int MINOR=" + version.min + ";\n"); w.write(" int MICRO=" + version.micro + ";\n"); @@ -96,6 +97,45 @@ public class VerGen { + e.getMessage()); System.exit(ExitCode.UNEXPECTED_ERROR.getValue()); } + + // Generate a main class to display version data + // that can be exec'd in zkServer.sh + try (FileWriter w = new FileWriter(new File(pkgdir, VERSION_CLASS_NAME + ".java"))) { + w.write("// Do not edit!\n// File generated by org.apache.zookeeper" + + ".version.util.VerGen.\n"); + w.write("/**\n"); + w.write("* Licensed to the Apache Software Foundation (ASF) under one\n"); + w.write("* or more contributor license agreements. See the NOTICE file\n"); + w.write("* distributed with this work for additional information\n"); + w.write("* regarding copyright ownership. The ASF licenses this file\n"); + w.write("* to you under the Apache License, Version 2.0 (the\n"); + w.write("* \"License\"); you may not use this file except in compliance\n"); + w.write("* with the License. You may obtain a copy of the License at\n"); + w.write("*\n"); + w.write("* http://www.apache.org/licenses/LICENSE-2.0\n"); + w.write("*\n"); + w.write("* Unless required by applicable law or agreed to in writing, software\n"); + w.write("* distributed under the License is distributed on an \"AS IS\" BASIS,\n"); + w.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); + w.write("* See the License for the specific language governing permissions and\n"); + w.write("* limitations under the License.\n"); + w.write("*/\n"); + w.write("\n"); + w.write("package " + PACKAGE_NAME + ";\n\n"); + w.write("public class " + VERSION_CLASS_NAME + " implements " + + PACKAGE_NAME + ".Info {\n"); + w.write(" public static void main(String[] args) {\n"); + w.write(" final String VER_STRING = MAJOR + \".\" + MINOR + \".\" + MICRO +"); + w.write(" (QUALIFIER == null ? \"\" : \"-\" + QUALIFIER) + \" \" +"); + w.write(" BUILD_DATE;" + "\n"); + w.write(" System.out.println(\"Apache ZooKeeper, version \" + VER_STRING);\n"); + w.write(" }\n"); + w.write("}\n"); + } catch (IOException e) { + System.out.println("Unable to generate version.VersionInfoMain file: " + + e.getMessage()); + System.exit(1); + } } public static class Version { diff --git a/zookeeper-server/src/test/resources/findbugsExcludeFile.xml b/zookeeper-server/src/test/resources/findbugsExcludeFile.xml index fac9030..bc69be1 100644 --- a/zookeeper-server/src/test/resources/findbugsExcludeFile.xml +++ b/zookeeper-server/src/test/resources/findbugsExcludeFile.xml @@ -207,4 +207,11 @@ + + + + + + + diff --git a/zookeeper-server/src/test/resources/test-scripts.sh b/zookeeper-server/src/test/resources/test-scripts.sh index ad175ba..25854b8 100755 --- a/zookeeper-server/src/test/resources/test-scripts.sh +++ b/zookeeper-server/src/test/resources/test-scripts.sh @@ -23,11 +23,6 @@ if [ ! -d "conf" ]; then exit 1 fi -if [ ! `ls build/zookeeper*.jar` ]; then - echo "first compile the zk jar file" - exit 1 -fi - DATADIR=test-scripts_datadir DATALOGDIR=test-scripts_datalogdir @@ -217,6 +212,9 @@ stop $ZKSI --force --myid=1 --configfile "$ZOOCFGDIR/$ZOOCFG" || fail $LINENO +#test version script +TEST_PRINT_VERSION=`$ZKS version 2>/dev/null` +[ "$TEST_PRINT_VERSION" != "" ] || fail $LINENO #done, cleanup and exit clear_tmp