Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 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
f77c0a5
initial changes
Claudenw May 10, 2026
2a8c2f7
created testhelper and updated tests
Claudenw May 10, 2026
79dc560
fixed tests
Claudenw May 10, 2026
ac8abe1
Change to Reporter.Output usage
Claudenw May 24, 2026
12fe353
updated javadoc
Claudenw May 24, 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
25 changes: 14 additions & 11 deletions apache-rat-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<directory>src/main/filtered-resources</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.rat</groupId>
Expand All @@ -60,9 +59,6 @@
</inputExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<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
2 changes: 1 addition & 1 deletion apache-rat-core/src/it/java/org/apache/rat/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void integrationTest(String testName, Document commandLineDoc) throws Exc
try {
Object value = shell.run(groovyScript, new String[]{outputFile.getAbsolutePath(), logFile.getAbsolutePath()});
if (value != null) {
fail(String.format("%s", value));
fail(String.format("%s: %s", testName, value));
}
} catch (AssertionError e) {
throw new AssertionError(String.format("%s: %s", testName, e.getMessage()), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ myArgs[3] = src.getAbsolutePath()

ReportConfiguration configuration = OptionCollection.parseCommands(src, myArgs, { opts -> })
assertNotNull(configuration)
configuration.validate(DefaultLog.getInstance().&error)
configuration.validate()
Reporter reporter = new Reporter(configuration)
ClaimStatistic statistic = reporter.execute()
ClaimStatistic statistic = reporter.execute().getStatistic()

assertEquals(3, statistic.getCounter(ClaimStatistic.Counter.APPROVED))
assertEquals(2, statistic.getCounter(ClaimStatistic.Counter.ARCHIVES))
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);
}
}
}
38 changes: 29 additions & 9 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 @@ -140,9 +141,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 +174,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 +202,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 +213,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 +356,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 non exists.
*/
public static Optional<ArgumentType> forDisplayName(final String displayName) {
return Arrays.stream(ArgumentType.values()).filter(argType -> argType.displayName.equals(displayName))
.findAny();
}
}
}
Loading
Loading