Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAT-98: report skipped files #417

Draft
wants to merge 50 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6cc603d
initial design comments
Claudenw Dec 14, 2024
dbedb9a
fixes for tests
Claudenw Dec 21, 2024
72dc7c5
fixes for RAT-335
Claudenw Dec 22, 2024
466d015
fixes for. gitignore and other descending processors
Claudenw Dec 25, 2024
95a5cb8
cleaned up checkstyle issues
Claudenw Dec 25, 2024
d8a735a
cleaned up checkstyle issues
Claudenw Dec 25, 2024
37b1bf9
fixed and cleaned up plugin tests
Claudenw Dec 26, 2024
8ee3bfc
fixed and cleaned up plugin tests
Claudenw Dec 26, 2024
b7b04d0
fixed and cleaned up plugin tests
Claudenw Dec 26, 2024
0940d9c
fixed and cleaned up plugin tests
Claudenw Dec 26, 2024
5562022
updated and fixed plugin tests
Claudenw Dec 27, 2024
f353948
fixed last tests in plugin module
Claudenw Dec 27, 2024
a657337
fixed Ant task issues
Claudenw Dec 27, 2024
b148f63
added missing files
Claudenw Dec 27, 2024
3c5e14b
fixed tests on Windows
Claudenw Dec 27, 2024
604e3f0
turned on mvn debugging
Claudenw Dec 27, 2024
b0f1d8e
Fixed command line file name processing
Claudenw Dec 28, 2024
fcd891c
added test failure info
Claudenw Dec 28, 2024
22c83c1
Added more info to decompose messages
Claudenw Dec 28, 2024
5f1552e
updated some tests
Claudenw Jan 1, 2025
dbb52bc
clean up of remaingin core tests
Claudenw Jan 2, 2025
e2f7841
fixed archive processing and naming issues
Claudenw Jan 4, 2025
c10ea16
fixed checkstyle issues
Claudenw Jan 4, 2025
5c6268c
Merge branch 'apache:master' into RAT-98_report_skipped_files
Claudenw Jan 4, 2025
2721619
added debug to test
Claudenw Jan 4, 2025
8daf63e
added debug to test
Claudenw Jan 4, 2025
5509b57
added debug to test
Claudenw Jan 4, 2025
7ad10dc
Added detail to decomposition
Claudenw Jan 4, 2025
a2b4dd4
used decomposition in more tests
Claudenw Jan 4, 2025
5f7b1ab
used decomposition in more tests
Claudenw Jan 4, 2025
9bae615
cleaned up decomposition reports
Claudenw Jan 4, 2025
f0aa020
cleaned up decomposition reports
Claudenw Jan 4, 2025
63236cb
Added wild logging to find Windows problem
Claudenw Jan 4, 2025
5bf4f2e
removed excess builds
Claudenw Jan 4, 2025
a2c5bc1
Added wild logging to find Windows problem
Claudenw Jan 4, 2025
f3b229a
debugging for tests
Claudenw Jan 5, 2025
6a9d1d9
debugging for tests
Claudenw Jan 5, 2025
8bcefdb
debugging for tests
Claudenw Jan 5, 2025
ef39c6b
debugging for tests
Claudenw Jan 5, 2025
3d6ee7a
debugging for tests
Claudenw Jan 5, 2025
4f4c61d
removed unused imports
Claudenw Jan 5, 2025
7113e5f
possible fix
Claudenw Jan 5, 2025
96c47e7
debugging for tests
Claudenw Jan 5, 2025
8c821c1
debugging for tests
Claudenw Jan 5, 2025
cb53df6
put full testing back
Claudenw Jan 5, 2025
e92087a
RAT-98: Fix typos
ottlinger Jan 6, 2025
c897fcc
Minor cleanup
ottlinger Jan 6, 2025
9e201ea
Fix for windows bug
Claudenw Jan 7, 2025
f0a9aef
Merge branch 'RAT-98_report_skipped_files' of github.com:Claudenw/cre…
Claudenw Jan 7, 2025
3d4311f
removed dead lines / updated javadoc
Claudenw Jan 7, 2025
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
5 changes: 5 additions & 0 deletions apache-rat-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,10 @@
<artifactId>groovy-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
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 @@ -163,7 +163,7 @@ public static Stream<Arguments> args() throws RatException {
@Override
public void report(Document document) {
if (!document.isIgnored()) {
String[] tokens = document.getName().tokenize(document.getName().localized());
String[] tokens = DocumentName.FSInfo.getDefault().tokenize(document.getName().localized());
results.add(Arguments.of(tokens[1], document));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ myArgs[1] = "UNAPPROVED:-1"
myArgs[2] = "--"
myArgs[3] = src.getAbsolutePath()

ReportConfiguration configuration = OptionCollection.parseCommands(myArgs, { opts -> })
ReportConfiguration configuration = OptionCollection.parseCommands(src, myArgs, { opts -> })
assertNotNull(configuration)
configuration.validate(DefaultLog.getInstance().&error)
Reporter reporter = new Reporter(configuration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--output-style
xml
--input-exclude
**/.gitignore
--input-exclude-parsed-scm
GIT
--
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,11 @@ private static Map<String, String> mapOf(String... parts) {
output = new File(args[0])
content = output.text

//Map<ClaimStatistic.Counter, String> data = new HashMap<>()
//data.put(ClaimStatistic.Counter.APPROVED, "2")
//data.put(ClaimStatistic.Counter.ARCHIVES, "0")
//data.put(ClaimStatistic.Counter.BINARIES, "0")
//data.put(ClaimStatistic.Counter.DOCUMENT_TYPES, "3")
//data.put(ClaimStatistic.Counter.IGNORED, "6")
//data.put(ClaimStatistic.Counter.LICENSE_CATEGORIES, "2")
//data.put(ClaimStatistic.Counter.LICENSE_NAMES, "2")
//data.put(ClaimStatistic.Counter.NOTICES, "1")
//data.put(ClaimStatistic.Counter.STANDARDS, "6")
//data.put(ClaimStatistic.Counter.UNAPPROVED, "4")
//data.put(ClaimStatistic.Counter.UNKNOWN, "4")

Document document = XmlUtils.toDom(new FileInputStream(args[0]))
XPath xPath = XPathFactory.newInstance().newXPath()

//for (ClaimStatistic.Counter counter : ClaimStatistic.Counter.values()) {
// String xpath = String.format("/rat-report/statistics/statistic[@name='%s']", counter.displayName())
// Map<String, String> map = mapOf("approval",
// counter == ClaimStatistic.Counter.UNAPPROVED ? "false" : "true",
// "count", data.get(counter),
// "description", counter.getDescription())
// XmlUtils.assertAttributes(document, xPath, xpath, map)
//}

//// license categories
//XmlUtils.assertAttributes(document, xPath, "/rat-report/statistics/licenseCategory[@name='?????']",
// mapOf("count", "4" ))
//
//XmlUtils.assertAttributes(document, xPath, "/rat-report/statistics/licenseCategory[@name='AL ']",
// mapOf("count", "2" ))
//
//// license names
//XmlUtils.assertAttributes(document, xPath, "/rat-report/statistics/licenseName[@name='Apache License Version 2.0']",
// mapOf("count", "2" ))
//
//XmlUtils.assertAttributes(document, xPath, "/rat-report/statistics/licenseName[@name='Unknown license']",
// mapOf("count", "4" ))

List<String> ignoredFiles = new ArrayList<>(Arrays.asList(
"/dir1/dir1.txt",
"/dir1/file1.log",
"/dir1/.gitignore",
"/dir2/dir2.md",
"/dir3/dir3.log",
Expand All @@ -102,24 +65,4 @@ XmlUtils.assertAttributes(document, xPath, "/rat-report/statistics/documentType[
mapOf("count", "1" ))

XmlUtils.assertAttributes(document, xPath, "/rat-report/statistics/documentType[@name='STANDARD']",
mapOf("count", "6" ))

/*
TextUtils.assertPatternInTarget("^ Approved:\\s+8 ", content)
TextUtils.assertPatternInTarget("^ Archives:\\s+1 ", content)
TextUtils.assertPatternInTarget("^ Binaries:\\s+2 ", content)
TextUtils.assertPatternInTarget("^ Document types:\\s+5 ", content)
TextUtils.assertPatternInTarget("^ Ignored:\\s+1 ", content)
TextUtils.assertPatternInTarget("^ License categories:\\s+4 ", content)
TextUtils.assertPatternInTarget("^ License names:\\s+5", content)
TextUtils.assertPatternInTarget("^ Notices:\\s+2 ", content)
TextUtils.assertPatternInTarget("^ Standards:\\s+8 ", content)
TextUtils.assertPatternInTarget("^ Unapproved:\\s+2 ", content)
TextUtils.assertPatternInTarget("^ Unknown:\\s+2 ", content)

logOutput = new File(args[1])
log = logOutput.text

TextUtils.assertPatternNotInTarget("^ERROR:", log)
TextUtils.assertPatternNotInTarget("^WARN:", log)
*/
mapOf("count", "4" ))
40 changes: 20 additions & 20 deletions apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,28 @@ private static String asString(final Object[] args) {
/**
* Parses the standard options to create a ReportConfiguration.
*
* @param workingDirectory The directory to resolve relative file names against.
* @param args the arguments to parse
* @param helpCmd the help command to run when necessary.
* @return a ReportConfiguration or null if Help was printed.
* @throws IOException on error.
*/
public static ReportConfiguration parseCommands(final String[] args, final Consumer<Options> helpCmd) throws IOException {
return parseCommands(args, helpCmd, false);
public static ReportConfiguration parseCommands(final File workingDirectory, final String[] args, final Consumer<Options> helpCmd) throws IOException {
return parseCommands(workingDirectory, args, helpCmd, false);
}

/**
* Parses the standard options to create a ReportConfiguration.
*
* @param workingDirectory The directory to resolve relative file names against.
* @param args the arguments to parse
* @param helpCmd the help command to run when necessary.
* @param noArgs If true then the commands do not need extra arguments
* @return a ReportConfiguration or {@code null} if Help was printed.
* @throws IOException on error.
*/
public static ReportConfiguration parseCommands(final String[] args, final Consumer<Options> helpCmd, final boolean noArgs) throws IOException {
public static ReportConfiguration parseCommands(final File workingDirectory, final String[] args,
final Consumer<Options> helpCmd, final boolean noArgs) throws IOException {
Options opts = buildOptions();
CommandLine commandLine;
try {
Expand All @@ -166,27 +169,23 @@ public static ReportConfiguration parseCommands(final String[] args, final Consu

Arg.processLogLevel(commandLine);

ArgumentContext argumentContext = new ArgumentContext(workingDirectory, commandLine);
if (commandLine.hasOption(HELP)) {
helpCmd.accept(opts);
return null;
}

if (commandLine.hasOption(HELP_LICENSES)) {
new Licenses(createConfiguration(commandLine), new PrintWriter(System.out)).printHelp();
return null;
}

if (commandLine.hasOption(HELP_LICENSES)) {
new Licenses(createConfiguration(commandLine), new PrintWriter(System.out)).printHelp();
new Licenses(createConfiguration(argumentContext), new PrintWriter(System.out)).printHelp();
return null;
}

if (commandLine.hasOption(Arg.HELP_LICENSES.option())) {
new Licenses(createConfiguration(commandLine), new PrintWriter(System.out)).printHelp();
new Licenses(createConfiguration(argumentContext), new PrintWriter(System.out)).printHelp();
return null;
}

ReportConfiguration configuration = createConfiguration(commandLine);
ReportConfiguration configuration = createConfiguration(argumentContext);
if (!noArgs && !configuration.hasSource()) {
String msg = "No directories or files specified for scanning. Did you forget to close a multi-argument option?";
DefaultLog.getInstance().error(msg);
Expand All @@ -201,14 +200,15 @@ public static ReportConfiguration parseCommands(final String[] args, final Consu
* Create the report configuration.
* Note: this method is package private for testing.
* You probably want one of the {@code ParseCommands} methods.
* @param commandLine the parsed command line.
* @param argumentContext The context to execute in.
* @return a ReportConfiguration
* @see #parseCommands(String[], Consumer)
* @see #parseCommands(String[], Consumer, boolean)
* @see #parseCommands(File, String[], Consumer)
* @see #parseCommands(File, String[], Consumer, boolean)
*/
static ReportConfiguration createConfiguration(final CommandLine commandLine) {
final ReportConfiguration configuration = new ReportConfiguration();
new ArgumentContext(configuration, commandLine).processArgs();
static ReportConfiguration createConfiguration(final ArgumentContext argumentContext) {
argumentContext.processArgs();
final ReportConfiguration configuration = argumentContext.getConfiguration();
final CommandLine commandLine = argumentContext.getCommandLine();
if (Arg.DIR.isSelected()) {
try {
configuration.addSource(getReportable(commandLine.getParsedOptionValue(Arg.DIR.getSelected()), configuration));
Expand Down Expand Up @@ -249,10 +249,10 @@ static IReportable getReportable(final File base, final ReportConfiguration conf
DefaultLog.getInstance().error("Directory '" + documentName + "' does not exist.");
return null;
}
DocumentNameMatcher documentNameMatcher = config.getNameMatcher(documentName);
DocumentNameMatcher documentExcluder = config.getDocumentExcluder(documentName);

Document doc = new FileDocument(documentName, absBase, documentNameMatcher);
if (!documentNameMatcher.matches(doc.getName())) {
Document doc = new FileDocument(documentName, absBase, documentExcluder);
if (!documentExcluder.matches(doc.getName())) {
DefaultLog.getInstance().error("Directory '" + documentName + "' is in excluded list.");
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion apache-rat-core/src/main/java/org/apache/rat/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.rat;

import java.io.File;

import org.apache.commons.cli.Options;
import org.apache.rat.document.RatDocumentAnalysisException;
import org.apache.rat.help.Help;
Expand All @@ -39,7 +41,7 @@ public final class Report {
*/
public static void main(final String[] args) throws Exception {
DefaultLog.getInstance().info(new VersionInfo().toString());
ReportConfiguration configuration = OptionCollection.parseCommands(args, Report::printUsage);
ReportConfiguration configuration = OptionCollection.parseCommands(new File("."), args, Report::printUsage);
if (configuration != null) {
configuration.validate(DefaultLog.getInstance()::error);
Reporter reporter = new Reporter(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,11 @@ public void addIncludedPatterns(final Iterable<String> patterns) {
}

/**
* Get the DocumentNameMatcher based on the directory.
* Get the DocumentNameMatcher that excludes files found in the directory tree..
* @param baseDir the DocumentName for the base directory.
* @return the DocumentNameMatcher for the base directory.
*/
public DocumentNameMatcher getNameMatcher(final DocumentName baseDir) {
public DocumentNameMatcher getDocumentExcluder(final DocumentName baseDir) {
return exclusionProcessor.getNameMatcher(baseDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ public static InputStream markSupportedInputStream(final InputStream stream) {
* @throws RatDocumentAnalysisException on error.
*/
public static String process(final Document document) throws RatDocumentAnalysisException {
Metadata metadata = new Metadata();
try (InputStream stream = markSupportedInputStream(document.inputStream())) {
metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, document.getName().getName());
Metadata metadata = new Metadata();
metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, document.getName().getShortName());
String result = TIKA.detect(stream, metadata);
String[] parts = result.split("/");
MediaType mediaType = new MediaType(parts[0], parts[1]);
Expand All @@ -146,7 +146,6 @@ public static String process(final Document document) throws RatDocumentAnalysis
document.getMetaData().setDocumentType(Document.Type.NOTICE);
}
}

return result;
} catch (IOException e) {
throw new RatDocumentAnalysisException(e);
Expand Down
12 changes: 6 additions & 6 deletions apache-rat-core/src/main/java/org/apache/rat/api/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public enum Type {
}

/** The path matcher used by this document */
protected final DocumentNameMatcher nameMatcher;
protected final DocumentNameMatcher nameExcluder;
/** The metadata for this document */
private final MetaData metaData;
/** The fully qualified name of this document */
Expand All @@ -61,11 +61,11 @@ public enum Type {
/**
* Creates an instance.
* @param name the native NameSet of the resource.
* @param nameMatcher the document name matcher to filter directories/files.
* @param nameExcluder the document name matcher to filter directories/files.
*/
protected Document(final DocumentName name, final DocumentNameMatcher nameMatcher) {
protected Document(final DocumentName name, final DocumentNameMatcher nameExcluder) {
this.name = name;
this.nameMatcher = nameMatcher;
this.nameExcluder = nameExcluder;
this.metaData = new MetaData();
}

Expand All @@ -81,8 +81,8 @@ public final DocumentName getName() {
* Gets the file filter this document was created with.
* @return the file filter this document was created with.
*/
public final DocumentNameMatcher getNameMatcher() {
return nameMatcher;
public final DocumentNameMatcher getNameExcluder() {
return nameExcluder;
}

@Override
Expand Down
Loading
Loading