Apache Solr open-source search software
SOLR-16842: Make "version" just another Tool. (#1784)
Eric Pugha498003b827d
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 3c3c1d1caa1..f42986cad3c 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -78,7 +78,8 @@ Dependency UpgradesOther Changes----------------------(No changes)++* SOLR-16842: Eliminate special case code in Solr CLI by introducing explicit VersionTool.java. (Eric Pugh, Will White)================== 9.3.0 ==================diff --git a/solr/bin/solr b/solr/bin/solrindex d69a974b28b..45aa5a108b5 100644--- a/solr/bin/solr+++ b/solr/bin/solr@@ -816,11 +816,7 @@ if [ $# -eq 1 ]; then-help|-h)run_tool ""exit- ;;- -version|-v|version)- run_tool version- exit- ;;+ ;;esacfidiff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmdindex 662fc392615..e38f3645f17 100755--- a/solr/bin/solr.cmd+++ b/solr/bin/solr.cmd@@ -229,9 +229,9 @@ IF "%1"=="-h" goto usageIF "%1"=="--help" goto usageIF "%1"=="/?" goto usageIF "%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_solrcliIF "%1"=="assert" goto run_solrcliIF "%1"=="export" goto run_solrcliIF "%1"=="package" goto run_solrcli@@ -1376,13 +1376,6 @@ SHIFTSHIFTgoto parse_config_args-:get_version-"%JAVA%" %SOLR_SSL_OPTS% %AUTHC_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -Dsolr.install.dir="%SOLR_TIP%" ^- -Dlog4j.configurationFile="file:///%DEFAULT_SERVER_DIR%\resources\log4j2-console.xml" ^- -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^- org.apache.solr.cli.SolrCLI version-goto done-REM Clumsy to do the state machine thing for -d and -n, but that's required for back-compat:parse_zk_argsIF "%1"=="-V" (diff --git a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java b/solr/core/src/java/org/apache/solr/cli/SolrCLI.javaindex 571d781f228..28de99ce25b 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;@@ -127,12 +126,8 @@ public class SolrCLI implements CLIO {}if (Arrays.asList("-v", "-version", "version").contains(args[0])) {- // Simple version tool, no need for its own class- if (args.length != 1) {- CLIO.err("Version tool does not accept any parameters!");- }- CLIO.out("Solr version is: " + SolrVersion.LATEST);- exit(0);+ // select the version tool to be run+ args[0] = "version";}SSLConfigurationsFactory.current().init();@@ -235,6 +230,7 @@ public class SolrCLI implements CLIO {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 scanningdiff --git a/solr/core/src/java/org/apache/solr/cli/VersionTool.java b/solr/core/src/java/org/apache/solr/cli/VersionTool.javanew file mode 100644index 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);+ }+}