This is an automated email from the ASF dual-hosted git repository.
Claudenw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git
The following commit(s) were added to refs/heads/master by this push:
new 5098bfdc Changed file arg to DocumentName
5098bfdc is described below
commit 5098bfdca15f6f6ab383738cf012c2b8349a67cf
Author: Claude Warren <[email protected]>
AuthorDate: Sun Jul 26 10:36:01 2026 +0100
Changed file arg to DocumentName
---
.../main/java/org/apache/rat/OptionCollection.java | 6 +++--
.../java/org/apache/rat/ReportConfiguration.java | 2 +-
.../main/java/org/apache/rat/commandline/Arg.java | 31 +++++++++++++++-------
.../org/apache/rat/commandline/Converters.java | 2 +-
.../org/apache/rat/commandline/StyleSheets.java | 9 ++++---
.../java/org/apache/rat/OptionCollectionTest.java | 1 +
.../org/apache/rat/ReporterOptionsProvider.java | 2 +-
.../test/AbstractConfigurationOptionsProvider.java | 6 +++--
8 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
b/apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
index 2d4bdd63..68858a15 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
@@ -42,6 +42,7 @@ import org.apache.commons.cli.ParseException;
import org.apache.rat.api.Document;
import org.apache.rat.commandline.Arg;
import org.apache.rat.commandline.ArgumentContext;
+import org.apache.rat.commandline.Converters;
import org.apache.rat.commandline.StyleSheets;
import org.apache.rat.config.exclusion.StandardCollection;
import org.apache.rat.document.DocumentName;
@@ -145,6 +146,7 @@ public final class OptionCollection {
}
ArgumentContext argumentContext = new
ArgumentContext(workingDirectory, commandLine);
+
Converters.FILE_CONVERTER.setWorkingDirectory(argumentContext.getWorkingDirectory());
Arg.processLogLevel(argumentContext, CLIOptionCollection.INSTANCE);
if (commandLine.hasOption(HELP)) {
@@ -184,8 +186,8 @@ public final class OptionCollection {
Optional<Option> dirOpt =
CLIOptionCollection.INSTANCE.getSelected(Arg.DIR);
if (dirOpt.isPresent()) {
try {
-
configuration.addSource(getReportable(commandLine.getParsedOptionValue(
- dirOpt.get()), configuration));
+ DocumentName directoryName =
commandLine.getParsedOptionValue(dirOpt.get());
+ configuration.addSource(getReportable(directoryName.asFile(),
configuration));
} catch (ParseException e) {
throw new ConfigurationException("Unable to set parse " +
dirOpt.get(), e);
}
diff --git
a/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java
b/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java
index a17077e8..9896810e 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java
@@ -1036,7 +1036,7 @@ public class ReportConfiguration {
standardProcessing =
Processing.valueOf(attributes.get("standardProcessing"));
String styleName = attributes.get("stylesheet");
if (styleName != null) {
- styleSheet = StyleSheets.getStyleSheet(styleName);
+ styleSheet = StyleSheets.getStyleSheet(styleName,
workingDirectory);
}
String outputName = attributes.get("output");
if (outputName != null) {
diff --git a/apache-rat-core/src/main/java/org/apache/rat/commandline/Arg.java
b/apache-rat-core/src/main/java/org/apache/rat/commandline/Arg.java
index d11e9056..1ae38d39 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/commandline/Arg.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/commandline/Arg.java
@@ -218,7 +218,7 @@ public enum Arg {
* Option to read a file licenses to be removed from the approved list.
*/
LICENSES_DENIED_FILE(new
OptionGroup().addOption(Option.builder().longOpt("licenses-denied-file")
- .hasArg().argName("File").type(File.class)
+ .hasArg().argName("File").type(DocumentName.class)
.converter(Converters.FILE_CONVERTER)
.desc("Name of file containing comma separated lists of the denied
license IDs. " +
"These licenses will be removed from the list of approved
licenses. " +
@@ -326,14 +326,14 @@ public enum Arg {
*/
EXCLUDE_FILE(new OptionGroup()
.addOption(Option.builder("E").longOpt("exclude-file")
- .argName("File").hasArg().type(File.class)
+ .argName("File").hasArg().type(DocumentName.class)
.converter(Converters.FILE_CONVERTER)
.deprecated(DeprecatedAttributes.builder().setForRemoval(true).setSince("0.17")
.setDescription(StdMsgs.useMsg("--input-exclude-file")).get())
.desc("Reads <Expression> entries from a file. Entries
will be excluded from processing.")
.build())
.addOption(Option.builder().longOpt("input-exclude-file")
- .argName("File").hasArg().type(File.class)
+ .argName("File").hasArg().type(DocumentName.class)
.converter(Converters.FILE_CONVERTER)
.desc("Reads <Expression> entries from a file. Entries
will be excluded from processing.")
.build()),
@@ -408,12 +408,12 @@ public enum Arg {
*/
INCLUDE_FILE(new OptionGroup()
.addOption(Option.builder().longOpt("input-include-file")
- .argName("File").hasArg().type(File.class)
+ .argName("File").hasArg().type(DocumentName.class)
.converter(Converters.FILE_CONVERTER)
.desc("Reads <Expression> entries from a file. Entries
will override excluded files.")
.build())
.addOption(Option.builder().longOpt("includes-file")
- .argName("File").hasArg().type(File.class)
+ .argName("File").hasArg().type(DocumentName.class)
.converter(Converters.FILE_CONVERTER)
.desc("Reads <Expression> entries from a file. Entries
will override excluded files.")
.deprecated(DeprecatedAttributes.builder().setForRemoval(true).setSince("0.17")
@@ -485,7 +485,8 @@ public enum Arg {
* Stop processing an input stream and declare an input file.
*/
DIR(new
OptionGroup().addOption(Option.builder().option("d").longOpt("dir").hasArg()
- .type(File.class)
+ .type(DocumentName.class)
+ .converter(Converters.FILE_CONVERTER)
.desc("Used to indicate end of list when using options that take
multiple arguments.").argName("DirOrArchive")
.deprecated(DeprecatedAttributes.builder().setForRemoval(true).setSince("0.17")
.setDescription("Use the standard '--' to signal the end
of arguments.").get()).build()),
@@ -517,14 +518,14 @@ public enum Arg {
if ("x".equals(key)) {
// display deprecated message.
context.getCommandLine().hasOption("x");
-
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet("xml"));
+
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet("xml",
context.getWorkingDirectory()));
} else {
String[] style =
context.getCommandLine().getOptionValues(selected);
if (style.length != 1) {
DefaultLog.getInstance().error("Please specify a
single stylesheet");
throw new ConfigurationException("Please specify a
single stylesheet");
}
-
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet(style[0]));
+
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet(style[0],
context.getWorkingDirectory()));
}
}),
@@ -614,7 +615,17 @@ public enum Arg {
.build()),
(context, selected) -> {
try {
+ String optionValue =
context.getCommandLine().getOptionValue(selected);
DocumentName documentName =
context.getCommandLine().getParsedOptionValue(selected);
+ if (documentName == null) {
+ DefaultLog.getInstance().error(String.format("Can not
get option: %s/%s (%s) from %s with value of %s",
+ selected.getOpt(), selected.getLongOpt(),
selected.getDescription(), selected.getKey(),
+ optionValue));
+ for (Option opt :
context.getCommandLine().getOptions()) {
+
DefaultLog.getInstance().error(String.format("Available option: '%s' = '%s'",
+ opt.getKey(), opt.getValue()));
+ }
+ }
File document = documentName.asFile();
File parent = document.getParentFile();
if (!parent.mkdirs() && !parent.isDirectory()) {
@@ -977,8 +988,8 @@ public enum Arg {
try {
Class<? extends T> clazz = (Class<? extends T>) selected.getType();
String[] values = commandLine.getOptionValues(selected);
- T[] result = (T[]) Array.newInstance(clazz, values.length);
- 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]));
}
return result;
diff --git
a/apache-rat-core/src/main/java/org/apache/rat/commandline/Converters.java
b/apache-rat-core/src/main/java/org/apache/rat/commandline/Converters.java
index 15582168..1f6fa272 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/commandline/Converters.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/commandline/Converters.java
@@ -115,7 +115,7 @@ public final class Converters {
} else {
builder.setBaseName(workingDirectory);
}
- return builder.setName(normalizedFileName).build();
+ return builder.setName(normalizedFileName).build();
}
}
}
diff --git
a/apache-rat-core/src/main/java/org/apache/rat/commandline/StyleSheets.java
b/apache-rat-core/src/main/java/org/apache/rat/commandline/StyleSheets.java
index ea0c1113..0cf53891 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/commandline/StyleSheets.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/commandline/StyleSheets.java
@@ -27,6 +27,7 @@ import java.util.Objects;
import org.apache.rat.ConfigurationException;
import org.apache.rat.ReportConfiguration;
+import org.apache.rat.document.DocumentName;
import static java.lang.String.format;
@@ -50,7 +51,6 @@ public enum StyleSheets {
* The pretty-printed XML style sheet.
*/
XML("xml", "Produces output in pretty-printed XML.");
-
/**
* The name of the style sheet. Must map to bundled resource XSLT file
*/
@@ -85,12 +85,15 @@ public enum StyleSheets {
* @param name the short name for or the path to a style sheet.
* @return the IODescriptor for the style sheet.
*/
- public static ReportConfiguration.IODescriptor<InputStream>
getStyleSheet(final String name) {
+ public static ReportConfiguration.IODescriptor<InputStream>
getStyleSheet(final String name, final DocumentName workingDirectory) {
URL url =
StyleSheets.class.getClassLoader().getResource(format("org/apache/rat/%s.xsl",
name));
if (url != null) {
return new ReportConfiguration.IODescriptor<>(name,
url::openStream);
}
- Path p = Paths.get(name);
+ // normalize the stylesheet name and resolve it against the working
directory so that relative names are resolved
+ // on the workingDirectory but fully qualified names are resolved
against the root directory.
+ String normalizedName = workingDirectory.fsInfo().normalize(name);
+ Path p = Paths.get(workingDirectory.getName()).resolve(normalizedName);
if (p.toFile().exists()) {
return new ReportConfiguration.IODescriptor<>(name, () ->
Files.newInputStream(p));
}
diff --git
a/apache-rat-core/src/test/java/org/apache/rat/OptionCollectionTest.java
b/apache-rat-core/src/test/java/org/apache/rat/OptionCollectionTest.java
index 070484f2..08b3f796 100644
--- a/apache-rat-core/src/test/java/org/apache/rat/OptionCollectionTest.java
+++ b/apache-rat-core/src/test/java/org/apache/rat/OptionCollectionTest.java
@@ -180,6 +180,7 @@ public class OptionCollectionTest {
@Test
public void testDeprecatedUseLogged() throws IOException {
TestingLog log = new TestingLog();
+ assertThat(testPath.resolve("target").toFile().mkdir()).isTrue();
try {
DefaultLog.setInstance(log);
String[] args = {"--dir", "target", "-a"};
diff --git
a/apache-rat-core/src/test/java/org/apache/rat/ReporterOptionsProvider.java
b/apache-rat-core/src/test/java/org/apache/rat/ReporterOptionsProvider.java
index 12fe7aa4..b56538d1 100644
--- a/apache-rat-core/src/test/java/org/apache/rat/ReporterOptionsProvider.java
+++ b/apache-rat-core/src/test/java/org/apache/rat/ReporterOptionsProvider.java
@@ -930,7 +930,7 @@ class ReporterOptionsProvider extends
AbstractOptionsProvider implements Argumen
String actualText = baos.toString(StandardCharsets.UTF_8);
TextUtils.assertContainsExactly(1, "<resource
encoding=\"ISO-8859-1\" mediaType=\"text/plain\" name=\"/stylesheet\"
type=\"STANDARD\">", actualText);
- try (InputStream expected =
StyleSheets.getStyleSheet("xml").ioSupplier().get();
+ try (InputStream expected = StyleSheets.getStyleSheet("xml",
null).ioSupplier().get();
InputStream actual = config.getStyleSheet().get()) {
assertThat(IOUtils.contentEquals(expected, actual)).as("'xml'
does not match").isTrue();
}
diff --git
a/apache-rat-core/src/test/java/org/apache/rat/test/AbstractConfigurationOptionsProvider.java
b/apache-rat-core/src/test/java/org/apache/rat/test/AbstractConfigurationOptionsProvider.java
index 84e30dc5..9c4f94db 100644
---
a/apache-rat-core/src/test/java/org/apache/rat/test/AbstractConfigurationOptionsProvider.java
+++
b/apache-rat-core/src/test/java/org/apache/rat/test/AbstractConfigurationOptionsProvider.java
@@ -814,11 +814,12 @@ public abstract class
AbstractConfigurationOptionsProvider extends AbstractOptio
// run the test
String[] args = {null};
+ DocumentName workingDirectory = DocumentName.builder(new
File(".")).build();
assertDoesNotThrow(() -> {
for (String sheet : new String[]{"plain-rat", "missing-headers",
"unapproved-licenses", file.getAbsolutePath()}) {
args[0] = sheet;
ReportConfiguration config =
generateConfig(ImmutablePair.of(option, args));
- try (InputStream expected =
StyleSheets.getStyleSheet(sheet).ioSupplier().get();
+ try (InputStream expected = StyleSheets.getStyleSheet(sheet,
workingDirectory).ioSupplier().get();
InputStream actual = config.getStyleSheet().get()) {
assertThat(IOUtils.contentEquals(expected, actual)).as(()
-> String.format("'%s' does not match", sheet)).isTrue();
}
@@ -843,9 +844,10 @@ public abstract class AbstractConfigurationOptionsProvider
extends AbstractOptio
}
protected void xmlTest() {
+ DocumentName workingDirectory = DocumentName.builder(new
File(".")).build();
assertDoesNotThrow(() -> {
ReportConfiguration config =
generateConfig(ImmutablePair.of(Arg.OUTPUT_STYLE.find("xml"), null));
- try (InputStream expected =
StyleSheets.getStyleSheet("xml").ioSupplier().get();
+ try (InputStream expected = StyleSheets.getStyleSheet("xml",
workingDirectory).ioSupplier().get();
InputStream actual = config.getStyleSheet().get()) {
assertThat(IOUtils.contentEquals(expected, actual)).as("'xml'
does not match").isTrue();
}