Skip to content

Comments

Update org.apache.solr.cli classes to not use deprecated methods.#4142

Open
epugh wants to merge 7 commits intoapache:mainfrom
epugh:fix_commons_cli_deprecated_calls
Open

Update org.apache.solr.cli classes to not use deprecated methods.#4142
epugh wants to merge 7 commits intoapache:mainfrom
epugh:fix_commons_cli_deprecated_calls

Conversation

@epugh
Copy link
Contributor

@epugh epugh commented Feb 17, 2026

Description

The org.apache.solr.cli.* classes are using various deprecated methods from Commons CLI and Commons Exec libraries.

This PR updates them. In the process I also took what I've learned in Java coding, and went through and cleaned up various lint warnings.

I also got a NICE clean up in ZkSubcommandsTest, there was a bunch of cruft in it.

Nothing here is user facing.

One thing I did not tackle, is we need to flip our assertsEquals... We do assertEquals(actual,expected) but we should be doing assertEquals(expected,actuals).

Solution

Make edits, rerun the tests.

Tests

Just existing tests.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the org.apache.solr.cli classes to eliminate the use of deprecated methods from Commons CLI and Commons Exec libraries. As part of this modernization effort, the PR also addresses various lint warnings and performs code cleanup including:

  • Updating Option.builder().build() to Option.builder().get() across all CLI tool classes
  • Replacing DefaultExecutor constructor with DefaultExecutor.Builder<>().get()
  • Removing deprecated cloudSolrClient.connect() calls
  • Converting a class to a record (SolrProcessManager.SolrProcess)
  • Modernizing string operations (length() > 0isEmpty())
  • Improving thread interruption handling (Thread.interrupted()Thread.currentThread().interrupt())
  • Converting string concatenation to text blocks
  • Various test cleanup and simplifications

Changes:

  • Commons CLI deprecated method replacements (.build().get() for Option builders)
  • Commons Exec deprecated method replacements (DefaultExecutor constructor → builder pattern)
  • Code modernization (records, text blocks, improved interrupt handling)
  • Test cleanup (removed unused variables, simplified code, fixed typos)

Reviewed changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ZkSubcommandsTest.java Test cleanup: removed unused variables and imports, updated ACL provider setup
TestSolrCLIRunExample.java Updated to use RandomizingCloudHttp2SolrClientBuilder, modernized thread handling, fixed variable initialization
TestExportTool.java Removed unnecessary string concatenation in assertions
StreamToolTest.java Added IOException to method signature
SolrProcessManagerTest.java Updated method calls to use record accessors (getPort() → port()), improved comment grammar
PostToolTest.java Added try-with-resources for BufferedWriter, converted to text block
CLITestHelper.java Added assert statements for null checks
ApiToolTest.java Removed unused Exception from method signature
Multiple Tool classes Updated Option.builder().build() to .get() throughout
SolrCLI.java Updated HelpFormatter API usage, modernized DefaultParser usage
RunExampleTool.java Converted JSON strings to text blocks, improved interrupt handling, fixed executor instantiation
SolrProcessManager.java Converted SolrProcess class to record, modernized stream operations
StatusTool.java Updated Option builders, simplified return statement
AuthTool.java Added block scope to switch cases, converted strings to text blocks
AssertTool.java Renamed and inverted logic of isSolrRunningOn → isSolrStoppedOn for clarity
Various tools Removed deprecated cloudSolrClient.connect() calls, improved thread sleep patterns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@epugh
Copy link
Contributor Author

epugh commented Feb 17, 2026

Here is what the formatting of the --help looks like now, it's almost exact same as previously:

➜  dev git:(fix_commons_cli_deprecated_calls) ✗ bin/solr create -h
usage:  bin/solr create -c <NAME> [-d <DIR>] [-h] [-n <NAME>] [-rf <#>] [-s <HOST>] [-sh <#>] [-u <credentials>] [-v] [-z <HOST>]

Creates a core or collection depending on whether Solr is running in standalone (core) or SolrCloud mode (collection).
If you are using standalone mode you must run this command on the Solr server itself.

List of options:
                                                                                                                        
-h, --help                          Print this message.                                                                 
-v, --verbose                       Enable verbose command output.                                                      
-c, --name <NAME>                   Name of collection or core to create.                                               
-sh, --shards <#>                   Number of shards; default is 1.                                                     
-rf, --replication-factor <#>       Number of copies of each document across the collection (replicas per shard);       
                                     default is 1.                                                                      
-d, --conf-dir <DIR>                Configuration directory to copy when creating the new collection; default is        
                                     _default.                                                                          
-n, --conf-name <NAME>              Configuration name; default is the collection name.                                 
-u, --credentials <credentials>     Credentials in the format username:password. Example: --credentials solr:SolrRocks  
-s, --solr-url <HOST>               Base Solr URL, which can be used to determine the zk-host if that's not known;      
                                     defaults to: http://localhost:8983.                                                
-z, --zk-host <HOST>                Zookeeper connection string; unnecessary if ZK_HOST is defined in solr.in.sh;       
                                     otherwise, defaults to localhost:9983.                                             


Please see the Reference Guide for more tools documentation: https://solr.apache.org/guide/solr/latest/deployment-guide/solr-control-script-reference.html
➜  dev git:(fix_commons_cli_deprecated_calls) ✗ 

@epugh epugh requested a review from dsmiley February 19, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant