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/17 11:51:32 UTC
[solr] branch main 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 main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new a498003b827 SOLR-16842: Make "version" just another Tool. (#1784)
a498003b827 is described below
commit a498003b827d1d5ec495452f48f7cdad2b850c01
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 | 13 ++-----
.../core/src/java/org/apache/solr/cli/SolrCLI.java | 10 ++----
.../src/java/org/apache/solr/cli/VersionTool.java | 42 ++++++++++++++++++++++
5 files changed, 51 insertions(+), 23 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 3c3c1d1caa1..f42986cad3c 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -78,7 +78,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)
================== 9.3.0 ==================
diff --git a/solr/bin/solr b/solr/bin/solr
index 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
- ;;
+ ;;
esac
fi
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 662fc392615..e38f3645f17 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
@@ -1376,13 +1376,6 @@ SHIFT
SHIFT
goto 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_args
IF "%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.java
index 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 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);
+ }
+}