Skip to content

Refactor UIOption - #708

Open
Claudenw wants to merge 12 commits into
masterfrom
UIOption_update
Open

Refactor UIOption#708
Claudenw wants to merge 12 commits into
masterfrom
UIOption_update

Conversation

@Claudenw

@Claudenw Claudenw commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Refactor UIOption, AntOption, and MavenOption along with their collections to provide cleaner implementations for multi threaded use as well as a better division of responsibility.

  • Implemented Builders for UIOption and UIOption derived classes.
  • Adjusted UIOptionCollection to utilize UIOption.Builder
  • Simplified ArgumentContext construction by creating the CommandLine instance within the context.
  • Adapted command line parsing to accept UIOptionCollection as the source of arguments.
  • added isNull() to CasedString to indicate when the string will be null.
  • Updated tools to utilize new UIOption builders and collections.

@Claudenw Claudenw self-assigned this Aug 6, 2026
@Claudenw
Claudenw marked this pull request as ready for review August 6, 2026 15:53
@Claudenw
Claudenw requested a review from ottlinger August 7, 2026 12:38
…tions to provide cleaner implementations for multi threaded use as well as a better division of responsibility.

 -  Implemented Builders for UIOption and UIOption derived classes.
 -  Adjusted UIOPtionCollection to utilize UIOption.Builder
 -  Simplified ArgumentContext construction by creating the CommandLine instance within the context.
 -  Adapted command line parsing to accept UIOptionCollection as the source of arguments.
 -  added isNull() to CasedString to indicate when the string will be null.
 -  Updated tools to utilize new UIOption builders and collections.
Comment thread apache-rat-core/src/main/java/org/apache/rat/commandline/Arg.java
Comment thread apache-rat-core/src/main/java/org/apache/rat/ui/UIOption.java
Comment thread apache-rat-core/src/main/java/org/apache/rat/utils/CasedString.java
@Claudenw

Copy link
Copy Markdown
Contributor Author

@ottlinger I like your changes. If you are happy approve and merge.

@ottlinger ottlinger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM apart from the small questions - can you reread the comments pls? @Claudenw

for (int i = 0; i < values.length; i++) {
T[] result = (T[]) Array.newInstance(clazz, values == null ? 0 : values.length);
for (int i = 0; i < result.length; i++) {
result[i] = clazz.cast(selected.getConverter().apply(values[i]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There still remains a compiler warning that array access values[i] may produce a NPE

Objects.requireNonNull(optionCollection, "OptionCollection may not be null");
Objects.requireNonNull(option, "Option may not be null");
if (name == null || name.isNull()) {
throw new IllegalArgumentException("name may not be null or contain a null value");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it really "may not be null" or should it be "must not be null" here?

*/
public S uiOptions(final Option... uiOption) {
uiOptions.addAll(Arrays.asList(uiOption));
public B uiOptions(final Option... options) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The IDE marks this method as never used? Will it be used in upcoming PRs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe so. When building a UI there are options that are specific to the UI (like the Maven option that excluded common patterns) that the UI will add. I think there are cases where there will be more than one.

return sb.toString();
};
/** A null cased string */
// must follow CAMEL_JOINER def.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we make this a real Javadoc reference?

argumentContext.processArgs(baseOptionCollection);
final ReportConfiguration configuration = argumentContext.getConfiguration();
final CommandLine commandLine = argumentContext.getCommandLine();
Optional<Option> dirOpt = baseOptionCollection.getSelected(Arg.DIR);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Claudenw
The IDE issues a warning here:
"Unchecked assignment: 'java.util.Optional' to 'Optional<Option>'. Reason 'baseOptionCollection' has raw type, so result of getSelected is erased
Is that an issue due to the new type hierarchy here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed but will probalby change when the UI builds are extracted.

*/
@SuppressFBWarnings("EI_EXPOSE_REP2")
public final class OptionCollectionParser {
public final class OptionCollectionParser<T extends UIOption<T>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Inner class "OptionComparator" is never used? Should it be removed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The field is instantiated, but never used at line 81.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

@sonarqubecloud

Copy link
Copy Markdown

@Claudenw
Claudenw requested a review from ottlinger September 11, 2026 16:30
@Claudenw

Copy link
Copy Markdown
Contributor Author

@ottlinger I think I addressed all the issues. Please let me know if there are any outstanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants