You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2023/07/18 13:07:21 UTC

[solr] branch branch_9x updated: SOLR-16842: Make "version" just another Tool. (#1784)

This is an automated email from the ASF dual-hosted git repository.

epugh pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new b37bf8f65a9 SOLR-16842: Make "version" just another Tool. (#1784)
b37bf8f65a9 is described below

commit b37bf8f65a9969a5326f2523adefc794df6f714e
Author: Eric Pugh <ep...@opensourceconnections.com>
AuthorDate: Mon Jul 17 07:51:26 2023 -0400

    SOLR-16842: Make "version" just another Tool. (#1784)
    
    Simplify the Solr CLI by handling the version output as an explicit VersionTool.java, like the other Solr CLI tools.
---
 solr/CHANGES.txt                                   |  3 +-
 solr/bin/solr                                      |  6 +---
 solr/bin/solr.cmd                                  |  6 ++--
 .../core/src/java/org/apache/solr/cli/SolrCLI.java | 10 +++---
 .../src/java/org/apache/solr/cli/VersionTool.java  | 42 ++++++++++++++++++++++
 5 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index c1975ae1330..b5e05a20dc9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -30,7 +30,8 @@ Dependency Upgrades
 
 Other Changes
 ---------------------
-(No changes)
+
+* SOLR-16842: Eliminate special case code in Solr CLI by introducing explicit VersionTool.java.  (Eric Pugh, Will White)
 
 * SOLR-16856: The default auto-soft-commit time has been set to 3 seconds. Previously, auto-soft-commit was disabled by default. (Houston Putman)
 
diff --git a/solr/bin/solr b/solr/bin/solr
index 2bd6e14e98b..9183d840db0 100644
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -940,11 +940,7 @@ if [ $# -eq 1 ]; then
     -help|-h)
         print_usage ""
         exit
-    ;;
-    -version|-v|version)
-        run_tool version
-        exit
-    ;;
+    ;;    
   esac
 fi
 
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 6eeeef11e21..a75f882f407 100755
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -229,9 +229,9 @@ IF "%1"=="-h" goto usage
 IF "%1"=="--help" goto usage
 IF "%1"=="/?" goto usage
 IF "%1"=="status" goto get_status
-IF "%1"=="version" goto get_version
-IF "%1"=="-v" goto get_version
-IF "%1"=="-version" goto get_version
+IF "%1"=="version" goto run_solrcli
+IF "%1"=="-v" goto run_solrcli
+IF "%1"=="-version" goto run_solrcli
 IF "%1"=="assert" goto run_solrcli
 IF "%1"=="export" goto run_solrcli
 IF "%1"=="package" goto run_solrcli
diff --git a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
index cde8dbc865f..a2b52dcd8f3 100755
--- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
@@ -62,7 +62,6 @@ import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.util.ContentStreamBase;
 import org.apache.solr.common.util.NamedList;
-import org.apache.solr.util.SolrVersion;
 import org.apache.solr.util.StartupLoggingUtils;
 import org.apache.solr.util.configuration.SSLConfigurationsFactory;
 import org.slf4j.Logger;
@@ -137,10 +136,9 @@ public class SolrCLI implements CLIO {
       exit(1);
     }
 
-    if (args.length == 1 && Arrays.asList("-v", "-version", "version").contains(args[0])) {
-      // Simple version tool, no need for its own class
-      CLIO.out(SolrVersion.LATEST.toString());
-      exit(0);
+    if (Arrays.asList("-v", "-version", "version").contains(args[0])) {
+      // select the version tool to be run
+      args[0] = "version";
     }
 
     SSLConfigurationsFactory.current().init();
@@ -242,6 +240,8 @@ public class SolrCLI implements CLIO {
     else if ("auth".equals(toolType)) return new AuthTool();
     else if ("export".equals(toolType)) return new ExportTool();
     else if ("package".equals(toolType)) return new PackageTool();
+    else if ("post".equals(toolType)) return new PostTool();
+    else if ("version".equals(toolType)) return new VersionTool();
 
     // If you add a built-in tool to this class, add it here to avoid
     // classpath scanning
diff --git a/solr/core/src/java/org/apache/solr/cli/VersionTool.java b/solr/core/src/java/org/apache/solr/cli/VersionTool.java
new file mode 100644
index 00000000000..1b0e1fa4644
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cli/VersionTool.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.cli;
+
+import java.util.Collections;
+import java.util.List;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.solr.util.SolrVersion;
+
+public class VersionTool extends ToolBase {
+
+  @Override
+  public String getName() {
+    return "version";
+  }
+
+  @Override
+  public List<Option> getOptions() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public void runImpl(CommandLine cli) throws Exception {
+    CLIO.out("Solr version is: " + SolrVersion.LATEST);
+  }
+}