Skip to content

RAT-552: Fix excludeSubProjects silently dropped when exclude is also set - #755

Open
arturobernalg wants to merge 7 commits into
apache:masterfrom
arturobernalg:fix/rat-552-exclude-subprojects-with-deprecated-excludes
Open

arturobernalg wants to merge 7 commits into
apache:masterfrom
arturobernalg:fix/rat-552-exclude-subprojects-with-deprecated-excludes

Conversation

@arturobernalg

@arturobernalg arturobernalg commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

excludeSubProjects becomes ineffective as soon as the deprecated excludes config is also used, because ArgumentTracker#validateSet (and the same logic generated from Args.tpl for BaseRatMojo/the Ant task) treats input-exclude and the deprecated exclude as mutually exclusive, which is wrong for a multi-valued option: both should accumulate.

validateSet now returns immediately for a multi-valued option, and values from every alias merge into the non-deprecated key once more than one alias is actually used (not unconditionally, since that broke commons-cli's own deprecation notice for the common case — see the second commit).

Applied in both ArgumentTracker and Args.tpl (shared by the Maven plugin and the Ant task).

Tests: a unit test reproducing the silent drop, and a new apache-rat-plugin IT (src/it/RAT-552) combining excludeSubProjects with a deprecated <excludes>.

@ottlinger

Copy link
Copy Markdown
Contributor

Thanks for your help here - would you mind taking a look at RAT-97 as well as it addresses errors with the same parameter?

@ottlinger
ottlinger requested a review from Claudenw October 20, 2026 07:45

@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 - thanks for your contribution.
I've applied minor changes and added a changelog entry.

@Claudenw do you see problems with the new layout in 1.0.0? Thanks

arturobernalg and others added 6 commits October 20, 2026 13:43
… set

ArgumentTracker.validateSet (and the generated Maven-plugin/Ant-task
counterpart in Args.tpl) rejected a value for a non-deprecated,
multi-valued option whenever its deprecated alias already had a value.
This made excludeSubProjects ineffective in the Maven plugin as soon as
the deprecated excludes configuration was also used, since the
sub-project patterns are added internally through the non-deprecated
input-exclude option.

Multi-valued options now always accumulate, merging values from every
alias of the group under the key of the non-deprecated option, so a
deprecated and non-deprecated spelling of the same option no longer
discard each other.
…s used

Unconditionally storing a multi-valued option's values under its
non-deprecated alias broke commons-cli's own deprecation warning: the
literal flag name that ends up in the argument list built by args() is
what triggers that notice, so remapping it away even when the caller
never touched the other alias silently suppressed the warning in the
common case (caught by apache-rat-tasks' GeneratedReportTest in CI).

Values now stay under whichever alias was actually used until a second
alias of the same group is written to; only then are the two merged
under the non-deprecated key, which is the only case that actually
needs merging.
@arturobernalg
arturobernalg force-pushed the fix/rat-552-exclude-subprojects-with-deprecated-excludes branch from 0e1bd03 to 74a4afd Compare October 20, 2026 11:44
@Claudenw

Copy link
Copy Markdown
Contributor

@ottlinger I think the solution is in the wrong place, but I may be convinced otherwise.

@arturobernalg excludeSubProjects is a Maven only option, and this is the root of my quandary.

RAT is a CLI first implementation. So all general implementations start in the RAT CLI code. The RAT CLI configurations are supposed to drive the other UI (Ant, Maven, and eventually Gradle).

The UI should not allow multiple configuration options from the same Arg group. That is how we do deprecation.

The issue is that the Maven UI does not determine if the current or deprecated Arg group option was used. It should do that and add the modules to the correct one.

This means that the addition of the exccludeSubProjects files to the exclude list must be done later than it is. Currently this is in the AbstractRatMojo at line 441, however that all changes in #749 .

However, I see the point of your change in that if any UI ends up using 2 or more Arg group options the correct processing is completed.

We do have on Arg group that has 2 deprecated options, however it has only one argument.

OUTPUT_STYLE(new OptionGroup()
            .addOption(Option.builder().longOpt("output-style").hasArg().argName("StyleSheet")
                    .desc("XSLT stylesheet to use when creating the report. "
                            + "Either an external xsl file may be specified or one of the internal named sheets.")
                    .build())
            .addOption(Option.builder("s").longOpt("stylesheet").hasArg().argName("StyleSheet")
                    .deprecated(DeprecatedAttributes.builder().setSince("0.17").setForRemoval(true).setDescription(StdMsgs.useMsg("--output-style")).get())
                    .desc("XSLT stylesheet to use when creating the report.")
                    .build())
            .addOption(Option.builder("x").longOpt("xml")
                    .deprecated(DeprecatedAttributes.builder()
                            .setSince("0.17")
                            .setForRemoval(true)
                            .setDescription(StdMsgs.useMsg("--output-style with the 'xml' argument")).get())
                    .desc("forces XML output rather than the textual report.")
                    .build()),
    ```

Would you write a test that shows that if there is an Arg group that accepts multiple arguments and has 2 deprecated options that your solution still holds?

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.

3 participants