Skip to content

Commit

Permalink
RAT-98: Updated tests for gitignore changes & deprecated options (#417)
Browse files Browse the repository at this point in the history
* added working directory

* removed accidentally added invoker.properties files

* adoped changes from master

* updated from master

* refactored DocumentName

* Update changes.xml

Added changelog entry

---------

Co-authored-by: P. Ottlinger <[email protected]>
  • Loading branch information
Claudenw and ottlinger authored Feb 13, 2025
1 parent a9b1166 commit 4f9c6fb
Show file tree
Hide file tree
Showing 44 changed files with 161 additions and 228 deletions.
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
@@ -0,0 +1,7 @@
*.md

# This makes it ignore dir3/dir3.log and dir3/file3.log
*.log

# This makes it "unignore" dir3/file3.log
!file*.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.txt
!dir1.md
file1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license
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 @@ -94,7 +94,7 @@ public static Builder builder(final FileSystem fileSystem) {
}

/**
* Creates a builder from a File. The {@link #baseName} is set to the file name if it is a directory otherwise
* Creates a builder from a File. The {@link #baseName} is set to the file name if it is a directory otherwise
* it is set to the directory containing the file.
* @param file The file to set defaults from.
* @return the builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
> * Rat [Exclude Expressions](../exclusion_expression.html): The expressions that are used to match file names

A FileProcessor is a module that locates files with a specific name in the directory tree and reads from them file patterns that are translated into Rat exclude expressions. These files are normally found in the file directory tree and their restrictions normally only applies to files at the same directory level as the processed file or below. This type of file is implemented by the `org.apache.rat.config.exclusion.fileProcessors.DescendingFileProcessor`.
A FileProcessor is a module that locates files with a specific name in the directory tree and reads from them file patterns that are translated into Rat exclude expressions. These files are normally found in the file directory tree and their restrictions normally only applies to files at the same directory level as the processed file or below. This type of file is implemented by the `org.apache.rat.config.exclusion.MatcherSet.Builder`.

The `DescendingFileProcessor` takes a file name and one or more comment prefixes as in the constructor. The file name is normally a file that is generally hidden on Linux systems like ".gitignore" or ".hgignore". The `DescendingFileProcessor` will scan the directories looking for files with the specified name. If one is found it is passed to the `process(DocumentName)` method which reads the document and returns a list of exclude expressions.

Expand Down
1 change: 1 addition & 0 deletions apache-rat-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target/
/invoker_target/
/src/site/apt/argument_types.txt
/invoker_target/
14 changes: 13 additions & 1 deletion apache-rat-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<exclude>src/it/CustomLicense/src/**/</exclude>
<!-- RAT-171: needs to be added since SCM ignores are only parsed in project root -->
<exclude>**/.bzrignore</exclude>
<exlcude>invoker_target/**</exlcude>
<exclude>src/test/resources/XmlOutputExamples/**/*</exclude>
</excludes>
</configuration>
Expand Down Expand Up @@ -246,7 +247,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
<cloneProjectsTo>${project.build.directory}/invoker</cloneProjectsTo>
<cloneProjectsTo>${project.basedir}/invoker_target</cloneProjectsTo>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<addTestClassPath>true</addTestClassPath>
<settingsFile>src/it/settings.xml</settingsFile>
Expand All @@ -262,6 +263,17 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>invoker_target</directory>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down
17 changes: 17 additions & 0 deletions apache-rat-plugin/src/it/CustomLicense/.rat/customConfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<rat-config>
<families>
<family id="CC" name="Creative Commons"/>"
</families>
<licenses>
<license family="CC" id="CC-BY-NC-ND"
name="Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International">
<any>
<text>Attribution-NonCommercial-NoDerivatives</text>
</any>
</license>
</licenses>
<approved>
<family license_ref='CC'/>
</approved>
</rat-config>
28 changes: 5 additions & 23 deletions apache-rat-plugin/src/it/CustomLicense/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,13 @@
<artifactId>apache-rat-plugin</artifactId>
<version>@pom.version@</version>
<configuration>
<addDefaultLicenses>false</addDefaultLicenses>
<families>
<family>
<id>CC</id>
<name>Creative Commons</name>
</family>
</families>
<licenses>
<license>
<family>CC</family>
<id>CC-BY-NC-ND</id>
<notes/>
<name>Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International</name>
<any>
<text>Attribution-NonCommercial-NoDerivatives</text>
</any>
</license>
</licenses>
<approvedLicenses>
<approvedLicense>CC</approvedLicense>
</approvedLicenses>
<excludes>
<outputStyle>xml</outputStyle>
<config>.rat/customConfig.xml</config>
<inputExcludes>
<exclude>.rat/**</exclude>
<exclude>pom.xml</exclude>
<exclude>invoker.properties</exclude>
</excludes>
</inputExcludes>
</configuration>
</plugin>
</plugins>
Expand Down
10 changes: 5 additions & 5 deletions apache-rat-plugin/src/it/RAT-268/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
<artifactId>apache-rat-plugin</artifactId>
<version>@pom.version@</version>
<configuration>
<counter-mins>
<counter-min>STANDARDS:0</counter-min>
</counter-mins>
<excludes>
<counterMins>
<counter>STANDARDS:0</counter>
</counterMins>
<inputExcludes>
<exclude>**/src.apt</exclude>
</excludes>
</inputExcludes>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.apache.rat.testhelpers.XmlUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
Expand Down Expand Up @@ -246,7 +245,6 @@ void it3() throws Exception {
/**
* Tests defining licenses in configuration
*/
@Disabled("Disabled until gitignore processing is correct")
@Test
void it5() throws Exception {
final RatCheckMojo mojo = newRatMojo("it5");
Expand Down Expand Up @@ -352,7 +350,6 @@ void rat343() throws Exception {
/**
* Tests verifying gitignore parsing
*/
@Disabled("Disabled until gitignore processing is correct")
@Test
void rat335() throws Exception {
final RatCheckMojo mojo = newRatMojo("RAT-335");
Expand Down Expand Up @@ -439,7 +436,6 @@ void rat335() throws Exception {
* So for this test we must create such a file which is specific for the current
* working directory.
*/
@Disabled("Disabled until gitignore processing is correct")
@Test
void rat362() throws Exception {
final RatCheckMojo mojo = newRatMojo("RAT-362");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file intentionally has no Apache License Header.
1 change: 1 addition & 0 deletions apache-rat-plugin/src/test/resources/unit/RAT-107/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file intentionally has no Apache License Header.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file intentionally has no Apache License Header.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file intentionally has no Apache License Header.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file intentionally has no Apache License Header.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file intentionally has no Apache License Header.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file intentionally has no Apache License Header.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file intentionally has no Apache License Header.
7 changes: 7 additions & 0 deletions apache-rat-plugin/src/test/resources/unit/RAT-335/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.md

# This makes it ignore dir3/dir3.log and dir3/file3.log
*.log

# This makes it "unignore" dir3/file3.log
!file*.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.txt
!dir1.md
file1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license

This file was deleted.

1 change: 1 addition & 0 deletions apache-rat-plugin/src/test/resources/unit/RAT-335/root.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license
2 changes: 2 additions & 0 deletions apache-rat-plugin/src/test/resources/unit/RAT-362/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/foo.md
target
1 change: 1 addition & 0 deletions apache-rat-plugin/src/test/resources/unit/RAT-362/foo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File without a valid license

This file was deleted.

5 changes: 0 additions & 5 deletions apache-rat-plugin/src/test/resources/unit/it5/.bzrignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<rat-config>
<families>
<family id="CC" name="Creative Commons"/>"
<family id="YAL" name="Yet another license family"/>"
</families>
<licenses>
<license family="CC" id="CC-BY-NC-ND"
name="Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International">
<text>Attribution-NonCommercial-NoDerivatives</text>
</license>
<license family="YAL"
name="Yet another license">
<any>
<text>Yet another license</text>
<spdx name="YAL"/>
</any>
</license>
</licenses>
<approved>
<family license_ref='CC'/>
</approved>
</rat-config>
Loading

0 comments on commit 4f9c6fb

Please sign in to comment.