Skip to content

Commit

Permalink
RAT-397: Merges from master
Browse files Browse the repository at this point in the history
  • Loading branch information
ottlinger committed Feb 13, 2025
2 parents 4fc0292 + fd1202b commit 815a9ca
Show file tree
Hide file tree
Showing 172 changed files with 4,608 additions and 2,720 deletions.
3 changes: 2 additions & 1 deletion .asf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ github:
- RAT
- WHISKER
- TENTACLES

notifications:
commits: [email protected]
commits: [email protected]
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ on:
pull_request:

env:
DEVELOCITY_ACCESS_KEY: ${{ secrets.GE_ACCESS_TOKEN }}
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}

jobs:
build:
Expand Down
3 changes: 2 additions & 1 deletion .mvn/develocity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<develocity
xmlns="https://www.gradle.com/develocity-maven" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.gradle.com/develocity-maven https://www.gradle.com/schema/develocity-maven.xsd">
<projectId>creadur-rat</projectId>
<server>
<url>https://ge.apache.org</url>
<url>https://develocity.apache.org</url>
<allowUntrusted>false</allowUntrusted>
</server>
<buildScan>
Expand Down
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<extension>
<groupId>com.gradle</groupId>
<artifactId>develocity-maven-extension</artifactId>
<version>1.23</version>
<version>1.23.1</version>
</extension>
<extension>
<groupId>com.gradle</groupId>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ASF Jenkins: [![ASF Jenkins Build Status](https://ci-builds.apache.org/buildStat

GA: [![Github Action master branch status](https://github.com/apache/creadur-rat/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/apache/creadur-rat/actions)

[![Revved up by Develocity](https://img.shields.io/badge/Revved%20up%20by-Develocity-06A0CE?logo=Gradle&labelColor=02303A)](https://ge.apache.org/scans?list.sortColumn=buildDuration&list.sortOrder=asc&search.buildToolType=maven&search.names=not:CI%20stage&search.rootProjectNames=Apache%20Creadur%20Rat&search.tasks=install&search.timeZoneId=Europe%2FBerlin&search.values=Build%20Parent-pom)
[![Revved up by Develocity](https://img.shields.io/badge/Revved%20up%20by-Develocity-06A0CE?logo=Gradle&labelColor=02303A)](https://develocity.apache.org/scans?list.sortColumn=buildDuration&list.sortOrder=asc&search.buildToolType=maven&search.names=not:CI%20stage&search.rootProjectNames=Apache%20Creadur%20Rat&search.tasks=install&search.timeZoneId=Europe%2FBerlin&search.values=Build%20Parent-pom)

## What is RAT?

Expand Down
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" ))
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,51 @@
*/

// Copy a set of resource files from the parent project to target/classes/META-INF,
// so that they become a part of the generated jar file. See RAT-379.
// so that they become a part of the generated jar file. See RAT-379 for details.

import java.io.FileNotFoundException;
import java.nio.file.attribute.FileTime;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileTime
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardCopyOption

final Path sourceDir = Paths.get("${sourceDir}")
final Path targetDir = Paths.get("${targetDir}")

final Path sourceDir = Paths.get("${sourceDir}");
final Path targetDir = Paths.get("${targetDir}");
if (!Files.isDirectory(sourceDir)) {
final String msg = "Source directory not found: " + sourceDir.toAbsolutePath();
log.error(msg);
throw new FileNotFoundException(msg);
final String msg = "Source directory not found: " + sourceDir.toAbsolutePath()
System.err.println(msg)
throw new FileNotFoundException(msg)
}
log.debug("copyResourcesFromParent: Using source directory " + sourceDir + ", resolved to " + sourceDir.toAbsolutePath());
log.debug("copyResourcesFromParent: Using target directory " + targetDir + ", resolved to " + targetDir.toAbsolutePath());
Files.createDirectories(targetDir);
for (StringTokenizer st = new StringTokenizer("${filesToCopy}", ","); st.hasMoreTokens(); ) {
final String token = st.nextToken();
final Path sourceFile = sourceDir.resolve(token);

// System.out.println("copyResourcesFromParent: Using source directory " + sourceDir + ", resolved to " + sourceDir.toAbsolutePath())
// System.out.println("copyResourcesFromParent: Using target directory " + targetDir + ", resolved to " + targetDir.toAbsolutePath())
Files.createDirectories(targetDir)

for (StringTokenizer st = new StringTokenizer("${filesToCopy}", ","); st.hasMoreTokens(); ) {
final String token = st.nextToken()
final Path sourceFile = sourceDir.resolve(token)
if (!Files.isRegularFile(sourceFile)) {
final String msg = "Source file " + token + " not found in source directory " + sourceDir;
log.error("copyResourcesFromParent: " + msg);
log.error("copyResourcesFromParent: A possible reason is, that you did clone only the apache-rat-core subproject from Git.");
throw new FileNotFoundException(msg);
final String msg = "Source file " + token + " not found in source directory " + sourceDir
System.err.println("copyResourcesFromParent: " + msg)
System.err.println("copyResourcesFromParent: A possible reason is, that you did clone only the apache-rat-core subproject from Git.")
throw new FileNotFoundException(msg)
}
final Path targetFile = targetDir.resolve(token);
final boolean replacing = Files.isRegularFile(targetFile);
final Path targetFile = targetDir.resolve(token)
final boolean replacing = Files.isRegularFile(targetFile)
if (replacing) {
final FileTime sourceTime = Files.getLastModifiedTime(sourceFile);
final FileTime targetTime = Files.getLastModifiedTime(targetFile);
if (sourceTime != null && targetTime != null && sourceTime.compareTo(targetTime) >= 0) {
log.debug("copyResourcesFromParent: Skipping source file "
+ sourceFile + ", because target file " + targetFile + " appears to be uptodate.");
continue;
final FileTime sourceTime = Files.getLastModifiedTime(sourceFile)
final FileTime targetTime = Files.getLastModifiedTime(targetFile)
if (sourceTime != null && targetTime != null && sourceTime >= targetTime) {
System.out.println("Skipping " + sourceFile + ", as target " + targetFile + " appears to be up-to-date already.")
continue
}
}
log.debug("copyResourcesFromParent: Copying source file " + sourceFile
+ " to target file " + targetFile);
System.out.println("Copying " + sourceFile
+ " to " + targetFile)
if (replacing) {
Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING);
Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING)
} else {
Files.copy(sourceFile, targetFile);
Files.copy(sourceFile, targetFile)
}
}
2 changes: 1 addition & 1 deletion apache-rat-core/src/main/java/org/apache/rat/Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static LicenseSetFactory readConfigFiles(final Collection<URI> uris) {
}

LicenseSetFactory result = new LicenseSetFactory(licenses);
approvedLicenseCategories.forEach(result::addLicenseCategory);
approvedLicenseCategories.forEach(result::approveLicenseCategory);
return result;
}

Expand Down
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
Loading

0 comments on commit 815a9ca

Please sign in to comment.