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

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


The following commit(s) were added to refs/heads/branch_9_7 by this push:
     new 71b816be00e SOLR-17429, SOLR-17338: Use stderr for SolrCLI deprecation 
logs (#2679)
71b816be00e is described below

commit 71b816be00ee9f10afe2208bbf85faf4d864b9f0
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)
    
    (cherry picked from commit 26d00c38b23e53f4859c0fc454e496706f568504)
---
 .../core/src/java/org/apache/solr/cli/SolrCLI.java | 44 +++++++++++++++-------
 1 file changed, 31 insertions(+), 13 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 c585e4f55d2..2dc25b03556 100755
--- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
@@ -363,6 +363,20 @@ public class SolrCLI implements CLIO {
     return val == null ? def : val;
   }
 
+  // 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();
@@ -379,7 +393,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;
@@ -614,12 +632,14 @@ public class SolrCLI implements CLIO {
       if (urlPath.contains(hostContext)) {
         String newSolrUrl =
             uri.resolve(urlPath.substring(0, urlPath.indexOf(hostContext)) + 
"/").toString();
-        CLIO.out(
-            "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 ["
-                + newSolrUrl
-                + "].");
+        if (logUrlFormatWarning) {
+          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 ["
+                  + newSolrUrl
+                  + "].");
+        }
         solrUrl = newSolrUrl;
       }
       if (solrUrl.endsWith("/")) {
@@ -641,13 +661,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();

Reply via email to