This is an automated email from the ASF dual-hosted git repository.
houston 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 26d00c38b23 SOLR-17429, SOLR-17338: Use stderr for SolrCLI deprecation
logs (#2679)
26d00c38b23 is described below
commit 26d00c38b23e53f4859c0fc454e496706f568504
Author: Houston Putman <[email protected]>
AuthorDate: Fri Aug 30 13:13:46 2024 -0500
SOLR-17429, SOLR-17338: Use stderr for SolrCLI deprecation logs (#2679)
---
.../core/src/java/org/apache/solr/cli/SolrCLI.java | 32 ++++++++++++++++------
1 file changed, 24 insertions(+), 8 deletions(-)
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 e02f81a0abc..a4f11a5815f 100755
--- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
@@ -371,6 +371,20 @@ public class SolrCLI implements CLIO {
return options;
}
+ // TODO: SOLR-17429 - remove the custom logic when CommonsCLI is upgraded and
+ // makes stderr the default, or makes Option.toDeprecatedString() public.
+ private static void deprecatedHandlerStdErr(Option o) {
+ if (o.isDeprecated()) {
+ final StringBuilder buf =
+ new StringBuilder().append("Option
'-").append(o.getOpt()).append('\'');
+ if (o.getLongOpt() != null) {
+ buf.append(",'--").append(o.getLongOpt()).append('\'');
+ }
+ buf.append(": ").append(o.getDeprecated());
+ CLIO.err(buf.toString());
+ }
+ }
+
/** Parses the command-line arguments passed by the user. */
public static CommandLine processCommandLineArgs(Tool tool, String[] args) {
List<Option> customOptions = tool.getOptions();
@@ -387,7 +401,11 @@ public class SolrCLI implements CLIO {
CommandLine cli = null;
try {
- cli = (new DefaultParser()).parse(options, args);
+ cli =
+ DefaultParser.builder()
+ .setDeprecatedHandler(SolrCLI::deprecatedHandlerStdErr)
+ .build()
+ .parse(options, args);
} catch (ParseException exp) {
// Check if we passed in a help argument with a non parsing set of
arguments.
boolean hasHelpArg = false;
@@ -642,7 +660,7 @@ public class SolrCLI implements CLIO {
String newSolrUrl =
uri.resolve(urlPath.substring(0, urlPath.lastIndexOf("/solr") +
1)).toString();
if (logUrlFormatWarning) {
- CLIO.out(
+ CLIO.err(
"WARNING: URLs provided to this tool needn't include Solr's
context-root (e.g. \"/solr\"). Such URLs are deprecated and support for them
will be removed in a future release. Correcting from ["
+ solrUrl
+ "] to ["
@@ -670,13 +688,11 @@ public class SolrCLI implements CLIO {
cli.hasOption("zk-host") ? cli.getOptionValue("zk-host") :
cli.getOptionValue("zkHost");
if (zkHost == null) {
solrUrl = SolrCLI.getDefaultSolrUrl();
- CLIO.getOutStream()
- .println(
- "Neither --zk-host or --solr-url parameters provided so
assuming solr url is "
- + solrUrl
- + ".");
+ CLIO.err(
+ "Neither --zk-host or --solr-url parameters provided so assuming
solr url is "
+ + solrUrl
+ + ".");
} else {
-
try (CloudSolrClient cloudSolrClient =
getCloudHttp2SolrClient(zkHost)) {
cloudSolrClient.connect();
Set<String> liveNodes =
cloudSolrClient.getClusterState().getLiveNodes();