Update org.apache.solr.cli classes to not use deprecated methods.#4142
Conversation
There was a problem hiding this comment.
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()toOption.builder().get()across all CLI tool classes - Replacing
DefaultExecutorconstructor withDefaultExecutor.Builder<>().get() - Removing deprecated
cloudSolrClient.connect()calls - Converting a class to a record (
SolrProcessManager.SolrProcess) - Modernizing string operations (
length() > 0→isEmpty()) - 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.
|
Here is what the formatting of the |
|
I've updated this merge conflicts and I'm looking for some plus 1's. I'm hoping to merge this on Thursday and then take another run at removing more code from our bin/solr scripts aroudn the "bin/solr start -h" command! |
|
Manual testing done. |
) Update calls that use deprecated methods, and general review of code quality. Use more modern java patterns where possible. (cherry picked from commit c1ac036)
malliaridis
left a comment
There was a problem hiding this comment.
In general this is fine. I didn't find the time to review it earlier, but better late than never.
I left a few notes / questions here, but overall this is a nice cleanup. This starts to look a lot like Kotlin syntax. 😁
| + " }\n" | ||
| + " }"); | ||
| """ | ||
| { |
There was a problem hiding this comment.
The indentation of these json objects could be reduced to line up with the opening bracket
| return; | ||
| } | ||
| // Create a new TableDefinition with empty headers to suppress the header row | ||
| java.util.List<String> emptyHeaders = |
There was a problem hiding this comment.
Is java.util.List not imported? Why is it written out here? Same applies to values below.
| @Override | ||
| public int compareTo(ReplicaHealth other) { | ||
| if (this == other) return 0; | ||
| if (other == null) return 1; |
There was a problem hiding this comment.
Is the removal of this line not making a difference in performance?
| } | ||
| try (var cloudSolrClient = CLIUtils.getCloudSolrClient(zkHost)) { | ||
| echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ..."); | ||
| cloudSolrClient.connect(); |
There was a problem hiding this comment.
Does the following command run the connect command already, which is why you removed this line?
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 doassertEquals(actual,expected)but we should be doingassertEquals(expected,actuals).Solution
Make edits, rerun the tests.
Tests
Just existing tests.