Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -37,7 +37,6 @@
<directory>src/main/filtered-resources</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.rat</groupId>
Expand All @@ -56,9 +55,6 @@
</inputExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -177,8 +173,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 @@ -213,11 +221,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
73 changes: 73 additions & 0 deletions apache-rat-core/src/main/java/org/apache/rat/CLIOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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
*
* http://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.commons.lang3.StringUtils;
import org.apache.rat.ui.ArgumentTracker;
import org.apache.rat.ui.UIOption;
import org.apache.rat.ui.UIOptionCollection;

/**
* The CLI option definition.
*/
public final class CLIOption extends UIOption<CLIOption> {

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

@Override
public String getText() {
StringBuilder result = new StringBuilder();
if (option.getLongOpt() != null) {
result.append("--").append(option.getLongOpt());
if (option.getOpt() != null) {
result.append(" or -").append(option.getArgs());
}
} else {
result.append("-").append(option.getArgs());
}
return result.toString();
}

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

@Override
public String getExample() {
StringBuilder sb = new StringBuilder("-");
if (option.getLongOpt() != null) {
sb.append("-").append(option.getLongOpt());
} else {
sb.append(option.getOpt());
}
if (option.hasArg()) {
String argName = StringUtils.defaultIfBlank(option.getArgName(), "Arg");
sb.append(" ").append(argName);
if (option.hasArgs()) {
sb.append(" [").append(argName).append("2 [").append(argName)
.append("3 [...]]] --");
}
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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)
.mapper(CLIOption::new));
}

private static final class Builder extends UIOptionCollection.Builder<CLIOption, Builder> {
private Builder() {
super();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,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 @@ -175,14 +174,15 @@ public static ReportConfiguration parseCommands(final File workingDirectory, fin
* @see #parseCommands(File, String[], Consumer, boolean)
*/
static ReportConfiguration createConfiguration(final ArgumentContext argumentContext) {
argumentContext.processArgs();
argumentContext.processArgs(CLIOptionCollection.INSTANCE);
final ReportConfiguration configuration = argumentContext.getConfiguration();
final CommandLine commandLine = argumentContext.getCommandLine();
if (Arg.DIR.isSelected()) {
if (CLIOptionCollection.INSTANCE.isSelected(Arg.DIR)) {
try {
configuration.addSource(getReportable(commandLine.getParsedOptionValue(Arg.DIR.getSelected()), configuration));
configuration.addSource(getReportable(commandLine.getParsedOptionValue(
CLIOptionCollection.INSTANCE.getSelected(Arg.DIR).get()), configuration));
} catch (ParseException e) {
throw new ConfigurationException("Unable to set parse " + Arg.DIR.getSelected(), e);
throw new ConfigurationException("Unable to set parse " + CLIOptionCollection.INSTANCE.getSelected(Arg.DIR).get(), e);
}
}
for (String s : commandLine.getArgs()) {
Expand All @@ -200,7 +200,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 Down
Loading
Loading