Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
be3944a
initial working code
Claudenw Mar 22, 2026
714caee
modified OptionCollection to use CLIOptionCollection
Claudenw Mar 22, 2026
6fed7b6
Switched to cased string preserving the parts from the parsing
Claudenw Mar 8, 2026
e8af517
fixed CasedString checkstyle issues
Claudenw Mar 8, 2026
b8e0a83
cleaned up sonar issues
Claudenw Mar 8, 2026
d97da52
added additional tests
Claudenw Mar 8, 2026
a72886c
fixed checkstyle issues
Claudenw Mar 8, 2026
0e2e7be
added tests
Claudenw Mar 22, 2026
685d583
Switched to UIOptionCollections
Claudenw Apr 27, 2026
be916d1
Added AntOptionCollection.java
Claudenw Apr 27, 2026
1ef787c
updated Arg documentation
Claudenw Apr 27, 2026
8c3dcb9
updated RatTool tests
Claudenw May 2, 2026
a5497d0
fixed review issues
Claudenw May 4, 2026
e7613b4
fixed AntDocumentationTest
Claudenw May 4, 2026
d586526
added CLIOptionTests
Claudenw May 4, 2026
bb78eea
added OptionCollectionParser tests
Claudenw May 4, 2026
fc15408
updated ArgumentTracker
Claudenw May 4, 2026
b6c92f6
fixed errors
Claudenw May 4, 2026
781b260
attempted fix
Claudenw May 4, 2026
a3e1c07
cleaned up code issues
Claudenw May 6, 2026
b93bc7f
initial updates
Claudenw May 6, 2026
4d66c38
fixed test generation
Claudenw May 8, 2026
be58d1e
added NOSONAR for some methods
Claudenw May 8, 2026
09e6b23
fixed checkstyle issue
Claudenw May 8, 2026
364e2c9
fixed typo
Claudenw May 8, 2026
8f96dd9
RAT-540: minor changes during review
ottlinger May 17, 2026
55c2092
Remove unused import
ottlinger May 21, 2026
2adfe32
RAT-540: Fix typo
ottlinger May 21, 2026
9b86850
RAT-540: Minor changes during review
ottlinger May 21, 2026
31f95ac
RAT-540: Minor review cleanups
ottlinger May 24, 2026
4129233
RAT-540: Reformat poms
ottlinger May 24, 2026
2a48c6d
RAT-540: Minor changes during review
ottlinger May 24, 2026
5cf538e
RAT-540: Fix typos in Velocity files
ottlinger May 25, 2026
1eb8f2d
RAT-540: Fix typos/little errors during review
ottlinger May 25, 2026
1ccbd0d
RAT-540: Minor cleanups during review
ottlinger May 25, 2026
95dff0e
RAT-540: Add changelog
ottlinger May 25, 2026
e2e7d5d
Merge branch 'master' into create-UIOptionCollections
ottlinger May 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions apache-rat-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,24 @@
<directory>src/main/filtered-resources</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<configuration>
<inputExcludes>
<!-- exclude the definition file(s) -->
<exclude>**/default.xml</exclude>
<exclude>**/example-configuration.xml</exclude>
<!-- exclude test generation files that contain unapproved license text -->
<exclude>**/ReporterOptionsProvider.java</exclude>
<exclude>**/GPLLicenseTest.java</exclude>
<!-- These files have bad license headers because they are used to test bad license headers -->
<exclude>src/test/resources/**</exclude>
<exclude>src/it/resources/ReportTest/**</exclude>
</inputExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<configuration>
<inputExcludes>
<!-- exclude the definition file(s) -->
<exclude>**/default.xml</exclude>
<exclude>**/example-configuration.xml</exclude>
<!-- exclude test generation files that contain unapproved license text -->
<exclude>**/ReporterOptionsProvider.java</exclude>
<exclude>**/GPLLicenseTest.java</exclude>
<!-- These files have bad license headers because they are used to test bad license headers -->
<exclude>src/test/resources/**</exclude>
<exclude>src/it/resources/ReportTest/**</exclude>
</inputExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -181,8 +177,20 @@
</build>
<dependencies>
<dependency>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-testdata</artifactId>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity.tools</groupId>
<artifactId>velocity-tools-generic</artifactId>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -217,11 +225,6 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.rat.documentation.options;
package org.apache.rat;

import org.apache.commons.cli.Option;
import org.apache.commons.lang3.StringUtils;
import org.apache.rat.ui.ArgumentTracker;
import org.apache.rat.ui.UIOption;
import org.apache.rat.ui.UIOptionCollection;

public class CLIOption extends AbstractOption {

public static String createName(final Option option) {
return StringUtils.defaultIfBlank(option.getLongOpt(), option.getOpt());
}
/**
* The CLI option definition.
*/
public final class CLIOption extends UIOption<CLIOption> {

public CLIOption(final Option option) {
super(option, createName(option));
public CLIOption(final UIOptionCollection<CLIOption> collection, final Option option) {
super(collection, option, ArgumentTracker.extractName(option));
}

@Override
Expand All @@ -37,17 +39,17 @@ public String getText() {
if (option.getLongOpt() != null) {
result.append("--").append(option.getLongOpt());
if (option.getOpt() != null) {
result.append(" or -").append(option.getArgs());
result.append(" or -").append(option.getOpt());
}
} else {
result.append("-").append(option.getArgs());
result.append("-").append(option.getOpt());
}
return result.toString();
}

@Override
protected String cleanupName(final Option option) {
return createName(option);
return ArgumentTracker.extractKey(option);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.rat;

import org.apache.commons.cli.Option;
import org.apache.rat.ui.UIOptionCollection;

public final class CLIOptionCollection extends UIOptionCollection<CLIOption> {
/** The Help option */
static final Option HELP = new Option("?", "help", false, "Print help for the RAT command line interface and exit.");

/** The instance of the collection */
public static final CLIOptionCollection INSTANCE = new CLIOptionCollection();

private CLIOptionCollection() {
super(new Builder().uiOption(HELP));
}

private static final class Builder extends UIOptionCollection.Builder<CLIOption, Builder> {
private Builder() {
super(CLIOption::new);
}
}
}
42 changes: 32 additions & 10 deletions apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -66,7 +67,9 @@ private OptionCollection() {
// do not instantiate
}

/** The Option comparator to sort the help */
/**
* The Option comparator to sort the help.
*/
public static final Comparator<Option> OPTION_COMPARATOR = new OptionComparator();

/** The Help option */
Expand Down Expand Up @@ -140,9 +143,8 @@ public static ReportConfiguration parseCommands(final File workingDirectory, fin
// for "commandLine"
}

Arg.processLogLevel(commandLine);

ArgumentContext argumentContext = new ArgumentContext(workingDirectory, commandLine);
Arg.processLogLevel(argumentContext, CLIOptionCollection.INSTANCE);

if (commandLine.hasOption(HELP)) {
helpCmd.accept(opts);
Expand Down Expand Up @@ -174,15 +176,17 @@ public static ReportConfiguration parseCommands(final File workingDirectory, fin
* @see #parseCommands(File, String[], Consumer)
* @see #parseCommands(File, String[], Consumer, boolean)
*/
static ReportConfiguration createConfiguration(final ArgumentContext argumentContext) {
argumentContext.processArgs();
public static ReportConfiguration createConfiguration(final ArgumentContext argumentContext) {
argumentContext.processArgs(CLIOptionCollection.INSTANCE);
final ReportConfiguration configuration = argumentContext.getConfiguration();
final CommandLine commandLine = argumentContext.getCommandLine();
if (Arg.DIR.isSelected()) {
Optional<Option> dirOpt = CLIOptionCollection.INSTANCE.getSelected(Arg.DIR);
if (dirOpt.isPresent()) {
try {
configuration.addSource(getReportable(commandLine.getParsedOptionValue(Arg.DIR.getSelected()), configuration));
configuration.addSource(getReportable(commandLine.getParsedOptionValue(
dirOpt.get()), configuration));
} catch (ParseException e) {
throw new ConfigurationException("Unable to set parse " + Arg.DIR.getSelected(), e);
throw new ConfigurationException("Unable to set parse " + dirOpt.get(), e);
}
}
for (String s : commandLine.getArgs()) {
Expand All @@ -200,7 +204,7 @@ static ReportConfiguration createConfiguration(final ArgumentContext argumentCon
* @return the Options comprised of the Options defined in this class.
*/
public static Options buildOptions() {
return Arg.getOptions().addOption(HELP);
return CLIOptionCollection.INSTANCE.getOptions();
}

/**
Expand All @@ -211,7 +215,7 @@ public static Options buildOptions() {
* @param config the ReportConfiguration.
* @return the IReportable instance containing the files.
*/
static IReportable getReportable(final File base, final ReportConfiguration config) {
public static IReportable getReportable(final File base, final ReportConfiguration config) {
File absBase = base.getAbsoluteFile();
DocumentName documentName = DocumentName.builder(absBase).build();
if (!absBase.exists()) {
Expand Down Expand Up @@ -354,12 +358,30 @@ public enum ArgumentType {
this.description = description;
}

/**
* Gets the display name.
* @return the display name.
*/
public String getDisplayName() {
return displayName;
}

/**
* Gets the description.
* @return the description.
*/
public Supplier<String> description() {
return description;
}

/**
* Get the matching Argument type.
* @param displayName the display name for the desired type.
* @return An optional with the ArgumentType or an empty optional if none exists.
*/
public static Optional<ArgumentType> forDisplayName(final String displayName) {
return Arrays.stream(ArgumentType.values()).filter(argType -> argType.displayName.equals(displayName))
.findAny();
}
}
}
Loading
Loading