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 c23a563a Revert "Changed file arg to DocumentName"
c23a563a is described below
commit c23a563a06a03fc0c47a6505006a2357a1b3321e
Author: Claude Warren <[email protected]>
AuthorDate: Sun Jul 26 10:46:35 2026 +0100
Revert "Changed file arg to DocumentName"
This reverts commit 5098bfdca15f6f6ab383738cf012c2b8349a67cf.
---
.../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, 20 insertions(+), 39 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 68858a15..2d4bdd63 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,7 +42,6 @@ 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;
@@ -146,7 +145,6 @@ 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)) {
@@ -186,8 +184,8 @@ public final class OptionCollection {
Optional<Option> dirOpt =
CLIOptionCollection.INSTANCE.getSelected(Arg.DIR);
if (dirOpt.isPresent()) {
try {
- DocumentName directoryName =
commandLine.getParsedOptionValue(dirOpt.get());
- configuration.addSource(getReportable(directoryName.asFile(),
configuration));
+
configuration.addSource(getReportable(commandLine.getParsedOptionValue(
+ dirOpt.get()), 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 9896810e..a17077e8 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,
workingDirectory);
+ styleSheet = StyleSheets.getStyleSheet(styleName);
}
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 1ae38d39..d11e9056 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(DocumentName.class)
+ .hasArg().argName("File").type(File.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(DocumentName.class)
+ .argName("File").hasArg().type(File.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(DocumentName.class)
+ .argName("File").hasArg().type(File.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(DocumentName.class)
+ .argName("File").hasArg().type(File.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(DocumentName.class)
+ .argName("File").hasArg().type(File.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,8 +485,7 @@ 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(DocumentName.class)
- .converter(Converters.FILE_CONVERTER)
+ .type(File.class)
.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()),
@@ -518,14 +517,14 @@ public enum Arg {
if ("x".equals(key)) {
// display deprecated message.
context.getCommandLine().hasOption("x");
-
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet("xml",
context.getWorkingDirectory()));
+
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet("xml"));
} 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.getWorkingDirectory()));
+
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet(style[0]));
}
}),
@@ -615,17 +614,7 @@ 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()) {
@@ -988,8 +977,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 == null ? 0 :
values.length);
- for (int i = 0; i < result.length; i++) {
+ T[] result = (T[]) Array.newInstance(clazz, values.length);
+ for (int i = 0; i < values.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 1f6fa272..15582168 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 0cf53891..ea0c1113 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,7 +27,6 @@ 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;
@@ -51,6 +50,7 @@ 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,15 +85,12 @@ 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, final DocumentName workingDirectory) {
+ public static ReportConfiguration.IODescriptor<InputStream>
getStyleSheet(final String name) {
URL url =
StyleSheets.class.getClassLoader().getResource(format("org/apache/rat/%s.xsl",
name));
if (url != null) {
return new ReportConfiguration.IODescriptor<>(name,
url::openStream);
}
- // 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);
+ Path p = Paths.get(name);
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 08b3f796..070484f2 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,7 +180,6 @@ 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 b56538d1..12fe7aa4 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",
null).ioSupplier().get();
+ try (InputStream expected =
StyleSheets.getStyleSheet("xml").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 9c4f94db..84e30dc5 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,12 +814,11 @@ 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,
workingDirectory).ioSupplier().get();
+ try (InputStream expected =
StyleSheets.getStyleSheet(sheet).ioSupplier().get();
InputStream actual = config.getStyleSheet().get()) {
assertThat(IOUtils.contentEquals(expected, actual)).as(()
-> String.format("'%s' does not match", sheet)).isTrue();
}
@@ -844,10 +843,9 @@ 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",
workingDirectory).ioSupplier().get();
+ try (InputStream expected =
StyleSheets.getStyleSheet("xml").ioSupplier().get();
InputStream actual = config.getStyleSheet().get()) {
assertThat(IOUtils.contentEquals(expected, actual)).as("'xml'
does not match").isTrue();
}