Apache Solr open-source search software
SOLR-17429, SOLR-17338: Use stderr for SolrCLI deprecation logs (#2679)
Houston Putman26d00c38b23e
diff --git a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java b/solr/core/src/java/org/apache/solr/cli/SolrCLI.javaindex 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();