This is an automated email from the ASF dual-hosted git repository. claude pushed a commit to branch feature/restructure in repository https://gitbox.apache.org/repos/asf/creadur-rat.git
commit 52f01b5d89500b1433f03a3df49b4e5a31af127b Author: Claude Warren <[email protected]> AuthorDate: Fri Dec 26 17:36:51 2025 +0000 updated Maven test code --- apache-rat-cli/spotbugs-ignore.xml | 16 - .../src/main/java/org/apache/rat/cli/Help.java | 1 - apache-rat-core/pom.xml | 565 +++++++++++---------- .../main/java/org/apache/rat/OptionCollection.java | 6 +- .../apache/rat/documentation/velocity/RatTool.java | 25 - .../testhelpers/data/OptionTestDataProvider.java | 27 +- .../testhelpers/data/ReportTestDataProvider.java | 62 ++- .../src/test/resources/tikaFiles/binary}/Image.pdf | Bin .../test/resources/tikaFiles/standard/Image.pdf | Bin 2390 -> 0 bytes apache-rat-plugin-parent/impl/pom.xml | 10 +- .../java/org/apache/rat/maven/RatCheckMojo.java | 45 +- .../java/org/apache/rat/maven/SettingsStub.java | 18 + apache-rat-plugin-parent/pom.xml | 143 +++--- apache-rat-plugin-parent/spotbugs-ignore.xml | 8 +- .../java/org/apache/rat/maven/CodeGenerator.java | 12 +- .../java/org/apache/rat/maven/MavenGenerator.java | 190 ------- .../java/org/apache/rat/maven/MavenOption.java | 51 -- .../java/org/apache/rat/maven/TestGenerator.java | 16 +- .../resources/org/apache/rat/maven/TestMethod.vm | 2 +- .../main/resources/org/apache/rat/maven/TestPom.vm | 5 +- apache-rat-tasks/spotbugs-ignore.xml | 8 +- apache-rat-tools/spotbugs-ignore.xml | 7 +- pom.xml | 31 +- spotbugs-ignore.xml | 8 +- 24 files changed, 502 insertions(+), 754 deletions(-) diff --git a/apache-rat-cli/spotbugs-ignore.xml b/apache-rat-cli/spotbugs-ignore.xml index a2ea5729..39e672f5 100644 --- a/apache-rat-cli/spotbugs-ignore.xml +++ b/apache-rat-cli/spotbugs-ignore.xml @@ -16,21 +16,5 @@ limitations under the License. --> <FindBugsFilter> - <Match> - <!-- - Convenience constructors that allow setting a charset are not available in Java8 for PrintStream. - --> - <Class name="org.apache.rat.cli.Report"/> - <Bug pattern="DM_DEFAULT_ENCODING"/> - </Match> - - - <Match> - <Bug pattern='PATH_TRAVERSAL_IN'/> - </Match> - - <Match> - <Bug pattern='EI_EXPOSE_REP'/> - </Match> </FindBugsFilter> diff --git a/apache-rat-cli/src/main/java/org/apache/rat/cli/Help.java b/apache-rat-cli/src/main/java/org/apache/rat/cli/Help.java index f426115c..00da957f 100644 --- a/apache-rat-cli/src/main/java/org/apache/rat/cli/Help.java +++ b/apache-rat-cli/src/main/java/org/apache/rat/cli/Help.java @@ -20,7 +20,6 @@ package org.apache.rat.cli; import java.io.PrintWriter; import java.io.Writer; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; diff --git a/apache-rat-core/pom.xml b/apache-rat-core/pom.xml index 572aadf3..b6390ccc 100644 --- a/apache-rat-core/pom.xml +++ b/apache-rat-core/pom.xml @@ -15,284 +15,289 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-project</artifactId> - <version>1.0.0-SNAPSHOT</version> - </parent> - <artifactId>apache-rat-core</artifactId> - <packaging>jar</packaging> - <name>Apache Creadur RAT::Core</name> - <description>The core functionality of RAT that is used by all clients.</description> - <build> - <resources> - <resource> - <filtering>false</filtering> - <directory>src/main/resources</directory> - </resource> - <resource> - <filtering>true</filtering> - <directory>src/main/filtered-resources</directory> - </resource> - </resources> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <configuration> - <inputExcludes> - <!-- exclude the definition file(s) --> - <exclude>**/default.xml</exclude> - <exclude>**/example-configuration.xml</exclude> - <!-- exclude test generation files that contain unapproved license text --> - <exclude>**/ReporterOptionsProvider.java</exclude> - <exclude>**/GPLLicenseTest.java</exclude> - <exclude>/src/test/resources/GitIgnoreBuilderTest/**</exclude> - <exclude>/src/test/resources/exampleData/**</exclude> - <excldue>/src/test/resources/jira/RAT147/**</excldue> - <exclude>/src/test/resources/org/apache/rat/MatcherContainerResource.txt</exclude> - <exclude>/src/test/resources/tikaFiles/**</exclude> - <exclude>/src/test/resources/violations/**</exclude> - </inputExcludes> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <artifactId>maven-clean-plugin</artifactId> - <executions> - <execution> - <phase>initialize</phase> - <goals> - <goal>clean</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <configuration> - <archive> - <manifestEntries> - <Extension-Name>rat</Extension-Name> - <Specification-Title>Apache Creadur RAT</Specification-Title> - <Specification-Vendor>apache.org</Specification-Vendor> - <Specification-Version>${project.version}</Specification-Version> - <Implementation-Vendor-Id>apache.org</Implementation-Vendor-Id> - <Implementation-Title>Apache Creadur RAT</Implementation-Title> - <Implementation-Vendor>Apache Software Foundation</Implementation-Vendor> - <Implementation-Version>${project.version}</Implementation-Version> - </manifestEntries> - </archive> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <executions> - <execution> - <id>unpack dependencies</id> - <phase>prepare-package</phase> - <goals> - <goal>unpack-dependencies</goal> - </goals> - <configuration> - <includeScope>runtime</includeScope> - <outputDirectory>${project.build.outputDirectory}</outputDirectory> - <overWriteIfNewer>true</overWriteIfNewer> - <excludes>META-INF/**</excludes> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <executions> - <execution> - <id>attach-sources</id> - <phase>compile</phase> - <goals> - <goal>jar-no-fork</goal> - <goal>test-jar-no-fork</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-checkstyle-plugin</artifactId> - <configuration> - <consoleOutput>true</consoleOutput> - <failsOnError>true</failsOnError> - <failOnViolation>true</failOnViolation> - <violationSeverity>warning</violationSeverity> - <excludeGeneratedSources>true</excludeGeneratedSources> - <configLocation>../src/conf/checkstyle.xml</configLocation> - <suppressionsLocation>../src/conf/checkstyle-suppressions.xml</suppressionsLocation> - </configuration> - <executions> - <execution> - <goals> - <goal>check</goal> - </goals> - <phase>compile</phase> - </execution> - </executions> - </plugin> - <plugin> - <groupId>com.github.spotbugs</groupId> - <artifactId>spotbugs-maven-plugin</artifactId> - <configuration> - <excludeFilterFile>spotbugs-ignore.xml</excludeFilterFile> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <id>add-integration-test-source</id> - <phase>generate-test-sources</phase> - <goals> - <goal>add-test-source</goal> - </goals> - <configuration> - <sources> - <source>src/it/java</source> - </sources> - </configuration> - </execution> - <execution> - <id>add-integration-test-resources</id> - <phase>generate-test-resources</phase> - <goals> - <goal>add-test-resource</goal> - </goals> - <configuration> - <resources> - <resource> - <directory>src/it/resources</directory> - <excludes> - <exclude>notes.md</exclude> - </excludes> - </resource> - </resources> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <artifactId>maven-resources-plugin</artifactId> - <executions> - <execution> - <id>copy-release-notes</id> - <phase>generate-resources</phase> - <goals> - <goal>copy-resources</goal> - </goals> - <configuration> - <outputDirectory>${project.build.outputDirectory}/META-INF</outputDirectory> - <overwrite>true</overwrite> - <resources> - <resource> - <directory>${project.basedir}/..</directory> - <includes> - <include>RELEASE_NOTES.txt</include> - </includes> - </resource> - </resources> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.apache.velocity</groupId> - <artifactId>velocity-engine-core</artifactId> - </dependency> - <dependency> - <groupId>org.reflections</groupId> - <artifactId>reflections</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-collections4</artifactId> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-compress</artifactId> - <exclusions> - <!-- Not actually used (yet) so no point including it --> - <exclusion> - <groupId>org.tukaani</groupId> - <artifactId>xz</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-text</artifactId> - </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-api</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-params</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>commons-cli</groupId> - <artifactId>commons-cli</artifactId> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.tika</groupId> - <artifactId>tika-core</artifactId> - </dependency> - <dependency> - <groupId>org.apache.tika</groupId> - <artifactId>tika-parser-text-module</artifactId> - </dependency> - <dependency> - <!-- this dependency is actually used by integration testing code --> - <!-- TODO RAT-527: migrate to newer version under ASF umbrella: 5.x including itests --> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy-all</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.google.jimfs</groupId> - <artifactId>jimfs</artifactId> - <scope>test</scope> - </dependency> - </dependencies> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-project</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + <artifactId>apache-rat-core</artifactId> + <packaging>jar</packaging> + <name>Apache Creadur RAT::Core</name> + <description>The core functionality of RAT that is used by all clients.</description> + <build> + <resources> + <resource> + <filtering>false</filtering> + <directory>src/main/resources</directory> + </resource> + <resource> + <filtering>true</filtering> + <directory>src/main/filtered-resources</directory> + </resource> + </resources> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-plugin</artifactId> + <configuration> + <inputExcludes> + <!-- exclude the definition file(s) --> + <exclude>**/default.xml</exclude> + <exclude>**/example-configuration.xml</exclude> + <!-- exclude test generation files that contain unapproved license text --> + <exclude>**/ReporterOptionsProvider.java</exclude> + <exclude>**/GPLLicenseTest.java</exclude> + <exclude>/src/test/resources/GitIgnoreBuilderTest/**</exclude> + <exclude>/src/test/resources/exampleData/**</exclude> + <excldue>/src/test/resources/jira/RAT147/**</excldue> + <exclude>/src/test/resources/org/apache/rat/MatcherContainerResource.txt</exclude> + <exclude>/src/test/resources/tikaFiles/**</exclude> + <exclude>/src/test/resources/violations/**</exclude> + </inputExcludes> + </configuration> + </plugin> + </plugins> + </pluginManagement> + <plugins> + <plugin> + <artifactId>maven-clean-plugin</artifactId> + <executions> + <execution> + <phase>initialize</phase> + <goals> + <goal>clean</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifestEntries> + <Extension-Name>rat</Extension-Name> + <Specification-Title>Apache Creadur RAT</Specification-Title> + <Specification-Vendor>apache.org</Specification-Vendor> + <Specification-Version>${project.version}</Specification-Version> + <Implementation-Vendor-Id>apache.org</Implementation-Vendor-Id> + <Implementation-Title>Apache Creadur RAT</Implementation-Title> + <Implementation-Vendor>Apache Software Foundation</Implementation-Vendor> + <Implementation-Version>${project.version}</Implementation-Version> + </manifestEntries> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>unpack dependencies</id> + <phase>prepare-package</phase> + <goals> + <goal>unpack-dependencies</goal> + </goals> + <configuration> + <includeScope>runtime</includeScope> + <outputDirectory>${project.build.outputDirectory}</outputDirectory> + <overWriteIfNewer>true</overWriteIfNewer> + <excludes>META-INF/**</excludes> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <executions> + <execution> + <id>attach-sources</id> + <phase>compile</phase> + <goals> + <goal>jar-no-fork</goal> + <goal>test-jar-no-fork</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <configuration> + <consoleOutput>true</consoleOutput> + <failsOnError>true</failsOnError> + <failOnViolation>true</failOnViolation> + <violationSeverity>warning</violationSeverity> + <excludeGeneratedSources>true</excludeGeneratedSources> + <configLocation>../src/conf/checkstyle.xml</configLocation> + <suppressionsLocation>../src/conf/checkstyle-suppressions.xml</suppressionsLocation> + </configuration> + <executions> + <execution> + <goals> + <goal>check</goal> + </goals> + <phase>compile</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>com.github.spotbugs</groupId> + <artifactId>spotbugs-maven-plugin</artifactId> + <configuration> + <excludeFilterFile>spotbugs-ignore.xml</excludeFilterFile> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>add-integration-test-source</id> + <phase>generate-test-sources</phase> + <goals> + <goal>add-test-source</goal> + </goals> + <configuration> + <sources> + <source>src/it/java</source> + </sources> + </configuration> + </execution> + <execution> + <id>add-integration-test-resources</id> + <phase>generate-test-resources</phase> + <goals> + <goal>add-test-resource</goal> + </goals> + <configuration> + <resources> + <resource> + <directory>src/it/resources</directory> + <excludes> + <exclude>notes.md</exclude> + </excludes> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>copy-release-notes</id> + <phase>generate-resources</phase> + <goals> + <goal>copy-resources</goal> + </goals> + <configuration> + <outputDirectory>${project.build.outputDirectory}/META-INF</outputDirectory> + <overwrite>true</overwrite> + <resources> + <resource> + <directory>${project.basedir}/..</directory> + <includes> + <include>RELEASE_NOTES.txt</include> + </includes> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity-engine-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.velocity.tools</groupId> + <artifactId>velocity-tools-generic</artifactId> + </dependency> + <dependency> + <groupId>org.reflections</groupId> + <artifactId>reflections</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-collections4</artifactId> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-compress</artifactId> + <exclusions> + <!-- Not actually used (yet) so no point including it --> + <exclusion> + <groupId>org.tukaani</groupId> + <artifactId>xz</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-text</artifactId> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-params</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-cli</groupId> + <artifactId>commons-cli</artifactId> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tika</groupId> + <artifactId>tika-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.tika</groupId> + <artifactId>tika-parser-text-module</artifactId> + </dependency> + <dependency> + <!-- this dependency is actually used by integration testing code --> + <!-- TODO RAT-527: migrate to newer version under ASF umbrella: 5.x including itests --> + <groupId>org.codehaus.groovy</groupId> + <artifactId>groovy-all</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.jimfs</groupId> + <artifactId>jimfs</artifactId> + <scope>test</scope> + </dependency> + </dependencies> </project> 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 0ec7283e..448e36ed 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 @@ -21,6 +21,7 @@ package org.apache.rat; import java.io.File; import java.io.IOException; import java.io.PrintWriter; +import java.io.Serial; import java.io.Serializable; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -128,7 +129,9 @@ public final class OptionCollection { ArgumentContext argumentContext = new ArgumentContext(workingDirectory, commandLine); populateConfiguration(argumentContext); if (commandLine.hasOption(Arg.HELP_LICENSES.option())) { - new Licenses(argumentContext.getConfiguration(), new PrintWriter(argumentContext.getConfiguration().getOutput().get(), false, StandardCharsets.UTF_8)).printHelp(); + new Licenses(argumentContext.getConfiguration(), + new PrintWriter(argumentContext.getConfiguration().getOutput().get(), + false, StandardCharsets.UTF_8)).printHelp(); } return argumentContext; @@ -201,6 +204,7 @@ public final class OptionCollection { */ private static final class OptionComparator implements Comparator<Option>, Serializable { /** The serial version UID. */ + @Serial private static final long serialVersionUID = 5305467873966684014L; private String getKey(final Option opt) { diff --git a/apache-rat-core/src/main/java/org/apache/rat/documentation/velocity/RatTool.java b/apache-rat-core/src/main/java/org/apache/rat/documentation/velocity/RatTool.java index a48f2a11..31dff2af 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/documentation/velocity/RatTool.java +++ b/apache-rat-core/src/main/java/org/apache/rat/documentation/velocity/RatTool.java @@ -124,31 +124,6 @@ public class RatTool { public List<String> uiNames() { return new ArrayList<>(uiMap.keySet()); } -// -// /** -// * Gets a map client option name to CLI Option. -// * @return a map client option name to CLI Option. -// */ -// public Map<String, CLIOption> cliOptions() { -// Map<String, CLIOption> result = new TreeMap<>(); -// for (Option option : OptionCollection.buildOptions().getOptions()) { -// CLIOption cliOption = new CLIOption(option); -// result.put(cliOption.getName(), cliOption); -// } -// return result; -// } - -// /** -// * Gets a map client option name to Maven Option. -// * @return a map client option name to Maven Option. -// */ -// public Map<String, MavenOption> mvnOptions() { -// Map<String, MavenOption> result = new TreeMap<>(); -// for (MavenOption mavenOption : MavenOption.getMavenOptions()) { -// result.put(CLIOption.createName(mavenOption.getOption()), mavenOption); -// } -// return result; -// } /** * Escapes a text string. diff --git a/apache-rat-core/src/test/java/org/apache/rat/testhelpers/data/OptionTestDataProvider.java b/apache-rat-core/src/test/java/org/apache/rat/testhelpers/data/OptionTestDataProvider.java index 40f9968f..0fb22155 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/testhelpers/data/OptionTestDataProvider.java +++ b/apache-rat-core/src/test/java/org/apache/rat/testhelpers/data/OptionTestDataProvider.java @@ -18,21 +18,17 @@ */ package org.apache.rat.testhelpers.data; -import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; -import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -53,7 +49,6 @@ import org.apache.rat.commandline.StyleSheets; import org.apache.rat.config.exclusion.StandardCollection; import org.apache.rat.document.DocumentName; import org.apache.rat.document.DocumentNameMatcher; -import org.apache.rat.document.DocumentNameMatcherTest; import org.apache.rat.license.ILicense; import org.apache.rat.license.ILicenseFamily; import org.apache.rat.license.LicenseSetFactory; @@ -81,10 +76,6 @@ public class OptionTestDataProvider { /** the list of include args */ static final String[] INCLUDE_ARGS = {"B.bar", "justbaz"}; - static String dump(final DocumentNameMatcher nameMatcher, final DocumentName name) { - return DocumentNameMatcherTest.processDecompose(nameMatcher, name); - } - static String dump(final Option option, final String fname, final DocumentNameMatcher matcher, final DocumentName name) { StringBuilder sb = new StringBuilder(); matcher.decompose(name).forEach(s -> sb.append(s).append("\n")); @@ -98,11 +89,11 @@ public class OptionTestDataProvider { public Map<String, TestData> getUITestMap() { final ConfigurationException noLicenses = new ConfigurationException("At least one license must be defined"); Map<String, TestData> result = getOptionTestMap(); - result.get("configurationNoDefaults").setException(noLicenses); - result.get("licensesApproved/withoutDefaults").setException(noLicenses); - result.get("licensesApprovedFile/withoutDefaults").setException(noLicenses); - result.get("licenseFamiliesApproved/withoutDefaults").setException(noLicenses); - result.get("licenseFamiliesApprovedFile/withoutDefaults").setException(noLicenses); + result.get("configuration-no-defaults").setException(noLicenses); + result.get("licenses-approved/withoutDefaults").setException(noLicenses); + result.get("licenses-approved-file/withoutDefaults").setException(noLicenses); + result.get("license-families-approved/withoutDefaults").setException(noLicenses); + result.get("license-families-approved-file/withoutDefaults").setException(noLicenses); return result; } @@ -166,7 +157,7 @@ public class OptionTestDataProvider { private void validate(List<TestData> result) { Set<Option> options = new HashSet<>(Arg.getOptions(new Options()).getOptions()); - result.stream().forEach(testData -> options.remove(testData.getOption())); + result.forEach(testData -> options.remove(testData.getOption())); // TODO fix this once deprecated options are removed options.forEach(opt -> DefaultLog.getInstance().warn("Option " + opt.getKey() + " was not tested.")); //assertThat(options).describedAs("All options are not accounted for.").isEmpty(); @@ -269,7 +260,6 @@ public class OptionTestDataProvider { private List<TestData> inputExcludeSizeTest() { Option option = Arg.EXCLUDE_SIZE.option(); - String[] args = {"5"}; String[] notExcluded = {"Hello.txt", "HelloWorld.txt"}; String[] excluded = {"Hi.txt"}; @@ -558,7 +548,7 @@ DataUtils.NO_SETUP, private List<TestData> configTest(final Option option) { Consumer<Path> setupFiles = basePath -> { Path ratDir = basePath.resolve(".rat"); - ratDir.toFile().mkdirs(); + FileUtils.mkDir(ratDir.toFile()); Path oneXml = ratDir.resolve("One.xml"); DataUtils.generateTextConfig(oneXml, "ONE", "one"); @@ -630,7 +620,7 @@ DataUtils.NO_SETUP, ImmutablePair.of(Arg.EDIT_ADD.find("edit-license"), null)), DataUtils.NO_SETUP, validatorData -> assertThat(validatorData.getConfiguration().getCopyrightMessage()).isEqualTo("MyCopyright")); -return Arrays.asList(test1, test1); +return Arrays.asList(test1, test2); } protected List<TestData> editCopyrightTest() { @@ -672,7 +662,6 @@ return Arrays.asList(test1, test1); protected List<TestData> logLevelTest() { Option option = Arg.LOG_LEVEL.find("log-level"); List<TestData> result = new ArrayList<>(); - String[] args = {null}; Log.Level logLevel = DefaultLog.getInstance().getLevel(); for (final Log.Level level : Log.Level.values()) { diff --git a/apache-rat-core/src/test/java/org/apache/rat/testhelpers/data/ReportTestDataProvider.java b/apache-rat-core/src/test/java/org/apache/rat/testhelpers/data/ReportTestDataProvider.java index 3c07b1dc..799fb76b 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/testhelpers/data/ReportTestDataProvider.java +++ b/apache-rat-core/src/test/java/org/apache/rat/testhelpers/data/ReportTestDataProvider.java @@ -33,12 +33,13 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.TreeMap; import java.util.function.Consumer; import java.util.function.Supplier; import javax.xml.xpath.XPath; @@ -100,7 +101,7 @@ public class ReportTestDataProvider { * @see #getOptionTests(Collection) */ public Map<String, TestData> getOptionTestMap(Collection<Option> unsupportedTests) { - Map<String, TestData> map = new HashMap<>(); + Map<String, TestData> map = new TreeMap<>(); for (TestData test : getOptionTests(unsupportedTests)) { map.put(test.getTestName(), test); } @@ -157,7 +158,7 @@ public class ReportTestDataProvider { private void validate(List<TestData> result) { Set<Option> options = new HashSet<>(Arg.getOptions(new Options()).getOptions()); - result.stream().forEach(testData -> options.remove(testData.getOption())); + result.forEach(testData -> options.remove(testData.getOption())); // TODO fix this once deprecated options are removed options.forEach(opt -> DefaultLog.getInstance().warn("Option " + opt.getKey() + " was not tested.")); //assertThat(options).describedAs("All options are not accounted for.").isEmpty(); @@ -199,6 +200,7 @@ public class ReportTestDataProvider { assertThat(claimStatistic.getCounter(ClaimStatistic.Counter.STANDARDS)).isEqualTo(5); assertThat(claimStatistic.getCounter(ClaimStatistic.Counter.IGNORED)).isEqualTo(1); }); + String[] ignored = {"B.bar", "justbaz", "some.foo", ".rat"}; String[] standard = {"well._afile", "notbaz"}; TestData test2 = new TestData("", Collections.singletonList(ImmutablePair.of(option, args.get())), @@ -385,8 +387,6 @@ public class ReportTestDataProvider { // include tests private List<TestData> execIncludeTest(final Option option, String[] args, Consumer<Path> setupFiles) { Option excludeOption = Arg.EXCLUDE.option(); - String[] notExcluded = {"B.bar", "justbaz", "notbaz"}; - String[] excluded = {"some.foo"}; Consumer<Path> setup = setupFiles.andThen(basePath -> { File baseDir = basePath.toFile(); writeFile(baseDir, "notbaz"); @@ -550,10 +550,7 @@ public class ReportTestDataProvider { TestData test3 = new TestData("withLicenseDef", Arrays.asList(ImmutablePair.of(option, args), ImmutablePair.of(configOpt, new String[]{".rat/catz.xml"})), setup.andThen(mkRat).andThen( - basePath -> { - Path ratDir = basePath.resolve(".rat"); - DataUtils.generateSpdxConfig(basePath.resolve(".rat").resolve("catz.xml"), "catz", "catz"); - }), + basePath -> DataUtils.generateSpdxConfig(basePath.resolve(".rat").resolve("catz.xml"), "catz", "catz")), validatorData -> { assertThat(validatorData.getStatistic().getCounter(ClaimStatistic.Counter.STANDARDS)).isEqualTo(2); assertThat(validatorData.getStatistic().getCounter(ClaimStatistic.Counter.APPROVED)).isEqualTo(2); @@ -584,7 +581,7 @@ public class ReportTestDataProvider { return execLicensesApprovedTest(Arg.LICENSES_APPROVED_FILE.find("licenses-approved-file"), new String[]{".rat/licensesApproved.txt"}, mkRat.andThen( - basePath -> writeFile(basePath.resolve(".rat").toFile(), "licensesApproved.txt", Arrays.asList("catz")))); + basePath -> writeFile(basePath.resolve(".rat").toFile(), "licensesApproved.txt", List.of("catz")))); } protected List<TestData> licensesApprovedTest() { @@ -662,9 +659,7 @@ public class ReportTestDataProvider { protected List<TestData> licenseFamiliesApprovedFileTest() { return execLicenseFamiliesApprovedTest(Arg.FAMILIES_APPROVED_FILE.find("license-families-approved-file"), new String[]{".rat/familiesApproved.txt"}, - mkRat.andThen( basePath -> { - writeFile(basePath.resolve(".rat").toFile(), "familiesApproved.txt", Collections.singletonList("catz")); - })); + mkRat.andThen( basePath -> writeFile(basePath.resolve(".rat").toFile(), "familiesApproved.txt", Collections.singletonList("catz")))); } protected List<TestData> licenseFamiliesApprovedTest() { @@ -925,25 +920,27 @@ public class ReportTestDataProvider { File resultFile = validatorData.getBaseDir().resolve("NoLicense.java.new").toFile(); assertThat(resultFile).exists(); contents = String.join("\n", IOUtils.readLines(new FileReader(resultFile))); - assertThat(contents).isEqualTo("/*\n" + - " * Licensed to the Apache Software Foundation (ASF) under one\n" + - " * or more contributor license agreements. See the NOTICE file\n" + - " * distributed with this work for additional information\n" + - " * regarding copyright ownership. The ASF licenses this file\n" + - " * to you under the Apache License, Version 2.0 (the\n" + - " * \"License\"); you may not use this file except in compliance\n" + - " * with the License. You may obtain a copy of the License at\n" + - " * \n" + - " * http://www.apache.org/licenses/LICENSE-2.0\n" + - " * \n" + - " * Unless required by applicable law or agreed to in writing,\n" + - " * software distributed under the License is distributed on an\n" + - " * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" + - " * KIND, either express or implied. See the License for the\n" + - " * specific language governing permissions and limitations\n" + - " * under the License.\n" + - " */\n\n" + - "class NoLicense {}"); + assertThat(contents).isEqualTo(""" + /* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + *\s + * http://www.apache.org/licenses/LICENSE-2.0 + *\s + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + class NoLicense {}"""); } catch (IOException e) { throw new RuntimeException(e); } @@ -1016,6 +1013,7 @@ public class ReportTestDataProvider { File localArchive = new File(basePath.toFile(), "dummy.jar"); try (InputStream in = ReportTestDataProvider.class.getResourceAsStream("/tikaFiles/archive/dummy.jar"); OutputStream out = Files.newOutputStream(localArchive.toPath())) { + Objects.requireNonNull(in); IOUtils.copy(in, out); } catch (IOException e) { throw new RuntimeException(e); diff --git a/apache-rat-cli/src/it/resources/ReportTest/RAT_259/elements/Image.pdf b/apache-rat-core/src/test/resources/tikaFiles/binary/Image.pdf similarity index 100% rename from apache-rat-cli/src/it/resources/ReportTest/RAT_259/elements/Image.pdf rename to apache-rat-core/src/test/resources/tikaFiles/binary/Image.pdf diff --git a/apache-rat-core/src/test/resources/tikaFiles/standard/Image.pdf b/apache-rat-core/src/test/resources/tikaFiles/standard/Image.pdf deleted file mode 100644 index 110b45e1..00000000 Binary files a/apache-rat-core/src/test/resources/tikaFiles/standard/Image.pdf and /dev/null differ diff --git a/apache-rat-plugin-parent/impl/pom.xml b/apache-rat-plugin-parent/impl/pom.xml index 8a91eda6..fff77c59 100644 --- a/apache-rat-plugin-parent/impl/pom.xml +++ b/apache-rat-plugin-parent/impl/pom.xml @@ -51,6 +51,10 @@ <directory>src/test/filtered-resources</directory> <filtering>true</filtering> </testResource> + <testResource> + <directory>src/test/resources</directory> + <filtering>false</filtering> + </testResource> </testResources> <pluginManagement> <plugins> @@ -199,7 +203,7 @@ <argument>-t</argument> <argument>${project.build.testSourceDirectory}</argument> <argument>-r</argument> - <argument>${project.build.testSourceDirectory}/../../resources</argument> + <argument>${project.build.testSourceDirectory}/../resources</argument> <argument>-p</argument> <argument>org.apache.rat.maven</argument> </arguments> @@ -493,12 +497,12 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-plugin</artifactId> - <version>${mavenPluginPluginVersion}</version> + <version>${mavenPluginToolsVersion}</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-report-plugin</artifactId> - <version>${mavenPluginPluginVersion}</version> + <version>${mavenPluginToolsVersion}</version> </plugin> </plugins> </reporting> diff --git a/apache-rat-plugin-parent/impl/src/main/java/org/apache/rat/maven/RatCheckMojo.java b/apache-rat-plugin-parent/impl/src/main/java/org/apache/rat/maven/RatCheckMojo.java index d45ca0fa..81093e4e 100644 --- a/apache-rat-plugin-parent/impl/src/main/java/org/apache/rat/maven/RatCheckMojo.java +++ b/apache-rat-plugin-parent/impl/src/main/java/org/apache/rat/maven/RatCheckMojo.java @@ -20,8 +20,10 @@ package org.apache.rat.maven; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.Writer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.List; @@ -37,12 +39,10 @@ import org.apache.rat.Reporter; import org.apache.rat.api.RatException; import org.apache.rat.commandline.Arg; import org.apache.rat.commandline.StyleSheets; -import org.apache.rat.config.exclusion.StandardCollection; import org.apache.rat.license.LicenseSetFactory.LicenseFilter; import org.apache.rat.report.claim.ClaimStatistic; import org.apache.rat.ui.ArgumentTracker; import org.apache.rat.utils.DefaultLog; -import org.apache.rat.utils.Log; import static java.lang.String.format; @@ -55,7 +55,9 @@ import static java.lang.String.format; @Mojo(name = "check", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) public final class RatCheckMojo extends AbstractRatMojo { - /** The output from the last {@link #execute()}. */ + /** + * The output from the last {@link #execute()}. + */ private Reporter.Output output; public RatCheckMojo() { @@ -66,7 +68,9 @@ public final class RatCheckMojo extends AbstractRatMojo { return output; } - /** The default output file if no other is specified. */ + /** + * The default output file if no other is specified. + */ @Parameter(defaultValue = "${project.build.directory}/rat.txt", readonly = true) private File defaultReportFile; @@ -110,21 +114,19 @@ public final class RatCheckMojo extends AbstractRatMojo { ReportConfiguration config = getConfiguration(); logLicenses(config.getLicenses(LicenseFilter.ALL)); if (verbose) { - config.reportExclusions(logWoutput = reporter.execute(); - writeMojoRatReport(output); - iriter); + config.reportExclusions(logWriter); } try { final Reporter reporter = new Reporter(config); - f (verbose) { + output = reporter.execute(); + writeMojoRatReport(output); + if (verbose) { output.writeSummary(DefaultLog.getInstance().asWriter()); } // produce the requested output. output.format(config.getStyleSheet(), config.getOutput()); // check for errors and fail if necessary check(config, output); - } catch (MojoFailureException e) { - throw e; } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } @@ -135,6 +137,7 @@ public final class RatCheckMojo extends AbstractRatMojo { /** * Saves the Maven Mojo version of the XML for later. + * * @param output the output to write to the XML file. */ private void writeMojoRatReport(final Reporter.Output output) { @@ -157,7 +160,7 @@ public final class RatCheckMojo extends AbstractRatMojo { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); output.format(StyleSheets.UNAPPROVED_LICENSES.getStyleSheet(), () -> baos); - getLog().warn(baos.toString(StandardCharsets.UTF_8.name())); + getLog().warn(baos.toString(StandardCharsets.UTF_8)); } catch (RuntimeException rte) { throw rte; } catch (Exception e) { @@ -169,19 +172,17 @@ public final class RatCheckMojo extends AbstractRatMojo { String.join(", ", config.getClaimValidator().listIssues(statistics)), getRatTxtFile()); - if (!ignoreErrors) { - throw new RatCheckException(msg); - } else { - getLog().info(msg); - } - } else { - DefaultLog.getInstance().info("No issues found."); - } - } catch (IOException e) { - throw new MojoFailureException(e); - } + if (!ignoreErrors) { + throw new RatCheckException(msg); + } else { + getLog().info(msg); + } + } else { + DefaultLog.getInstance().info("No issues found."); + } } + /** * Reads the location of the RAT text file from the Mojo. * diff --git a/apache-rat-plugin-parent/impl/src/test/java/org/apache/rat/maven/SettingsStub.java b/apache-rat-plugin-parent/impl/src/test/java/org/apache/rat/maven/SettingsStub.java index 32961756..c4ed72e6 100644 --- a/apache-rat-plugin-parent/impl/src/test/java/org/apache/rat/maven/SettingsStub.java +++ b/apache-rat-plugin-parent/impl/src/test/java/org/apache/rat/maven/SettingsStub.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.rat.maven; import java.util.Collections; diff --git a/apache-rat-plugin-parent/pom.xml b/apache-rat-plugin-parent/pom.xml index 73f6d871..7451f5dd 100644 --- a/apache-rat-plugin-parent/pom.xml +++ b/apache-rat-plugin-parent/pom.xml @@ -15,65 +15,88 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>apache-rat-project</artifactId> - <groupId>org.apache.rat</groupId> - <version>1.0.0-SNAPSHOT</version> - </parent> - <artifactId>apache-rat-plugin-parent</artifactId> - <packaging>pom</packaging> - <name>Apache Creadur RAT::Maven plugin parent</name> - <description>A plugin for Apache Maven that runs Apache RAT - to audit the source to be distributed.</description> - <inceptionYear>2007</inceptionYear> - <prerequisites> - <maven>${mavenMinVersion}</maven> - </prerequisites> - <properties> - <rat.version>1.0.0-SNAPSHOT</rat.version> - <currentVersion>${project.version}</currentVersion> - <doxiaVersion>2.0.0</doxiaVersion> - <mavenVersion>3.9.11</mavenVersion> - <mavenPluginTestingVersion>3.4.0</mavenPluginTestingVersion> - <mavenPluginPluginVersion>3.15.2</mavenPluginPluginVersion> - </properties> - <modules> - <module>tools</module> - <module>impl</module> - </modules> - <dependencyManagement> - <dependencies> - <dependency> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>apache-rat-project</artifactId> <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-core</artifactId> - <version>${rat.version}</version> - </dependency> - <dependency> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-core-tests</artifactId> - <version>${rat.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <version>${mavenPluginPluginVersion}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-testing</groupId> - <artifactId>maven-plugin-testing-harness</artifactId> - <version>${mavenPluginTestingVersion}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>${mavenVersion}</version> - <scope>provided</scope> - </dependency> - </dependencies> - </dependencyManagement> + <version>1.0.0-SNAPSHOT</version> + </parent> + <artifactId>apache-rat-plugin-parent</artifactId> + <packaging>pom</packaging> + <name>Apache Creadur RAT::Maven plugin parent</name> + <description>A plugin for Apache Maven that runs Apache RAT + to audit the source to be distributed. + </description> + <inceptionYear>2007</inceptionYear> + <prerequisites> + <maven>${mavenMinVersion}</maven> + </prerequisites> + <properties> + <rat.version>1.0.0-SNAPSHOT</rat.version> + <currentVersion>${project.version}</currentVersion> + <doxiaVersion>2.0.0</doxiaVersion> + <mavenVersion>3.9.12</mavenVersion> + <mavenPluginTestingVersion>3.4.0</mavenPluginTestingVersion> + <mavenPluginToolsVersion>3.15.2</mavenPluginToolsVersion> + </properties> + <modules> + <module>tools</module> + <module>impl</module> + </modules> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-core</artifactId> + <version>${rat.version}</version> + </dependency> + <dependency> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-core-tests</artifactId> + <version>${rat.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>${mavenPluginToolsVersion}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-testing</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + <version>${mavenPluginTestingVersion}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>${mavenVersion}</version> + <scope>provided</scope> + </dependency> + </dependencies> + </dependencyManagement> + <build> + <plugins> + <plugin> + <groupId>com.github.spotbugs</groupId> + <artifactId>spotbugs-maven-plugin</artifactId> + <configuration> + <maxAllowedViolations>0</maxAllowedViolations> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>${mavenPluginToolsVersion}</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-report-plugin</artifactId> + <version>${mavenPluginToolsVersion}</version> + </plugin> + </plugins> + </build> </project> diff --git a/apache-rat-plugin-parent/spotbugs-ignore.xml b/apache-rat-plugin-parent/spotbugs-ignore.xml index 2957d104..39e672f5 100644 --- a/apache-rat-plugin-parent/spotbugs-ignore.xml +++ b/apache-rat-plugin-parent/spotbugs-ignore.xml @@ -16,11 +16,5 @@ limitations under the License. --> <FindBugsFilter> - <Match> - <!-- - Convenience constructors that allow setting a charset are not available in Java8 for FileReader. - <Class name="org.apache.rat.config.exclusion.fileProcessors.GlobIgnoreMatcher"/> - <Bug pattern="DM_DEFAULT_ENCODING"/> - --> - </Match> + </FindBugsFilter> diff --git a/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/CodeGenerator.java b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/CodeGenerator.java index ba6a818e..1f8b957f 100644 --- a/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/CodeGenerator.java +++ b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/CodeGenerator.java @@ -22,9 +22,9 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; -import java.nio.file.Paths; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.util.Arrays; -import java.util.stream.Collectors; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; @@ -53,7 +53,7 @@ public final class CodeGenerator { /** The Syntax for this command */ private static final String SYNTAX = String.format("java -cp ... %s [options]", CodeGenerator.class.getName()); /** The package name for this AbstractMaven file */ - private final CasedString packageName = new CasedString(CasedString.StringCase.DOT, "org.apache.rat.maven");; + private final CasedString packageName = new CasedString(CasedString.StringCase.DOT, "org.apache.rat.maven"); /** The base source directory */ private final String baseDirectory; /** The template for the methods within {@code AbstractMaven}. */ @@ -123,10 +123,10 @@ public final class CodeGenerator { final String methods = gatherMethods(); final VelocityContext context = new VelocityContext(); context.put("methods", methods); - File javaFile = Paths.get(baseDirectory).resolve(packageName.toCase(CasedString.StringCase.SLASH)) + File javaFile = Path.of(baseDirectory).resolve(packageName.toCase(CasedString.StringCase.SLASH)) .resolve("AbstractMaven.java").toFile(); FileUtils.mkDir(javaFile.getParentFile()); - try (FileWriter fileWriter = new FileWriter(javaFile)) { + try (FileWriter fileWriter = new FileWriter(javaFile, StandardCharsets.UTF_8)) { javaTemplate.merge(context, fileWriter); } } @@ -207,7 +207,7 @@ public final class CodeGenerator { private String gatherMethods() { final VelocityContext context = new VelocityContext(); final StringWriter methodWriter = new StringWriter(); - for (MavenOption mavenOption : OptionFactory.getOptions(MavenOption.FACTORY_CONFIG).collect(Collectors.toList())) { + for (MavenOption mavenOption : OptionFactory.getOptions(MavenOption.FACTORY_CONFIG).toList()) { context.put("option", mavenOption); String desc = createDesc(mavenOption); context.put("desc", desc); diff --git a/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/MavenGenerator.java b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/MavenGenerator.java deleted file mode 100644 index c2aa2b36..00000000 --- a/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/MavenGenerator.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.rat.maven; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; - -import org.apache.commons.cli.Option; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.LineIterator; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.StringEscapeUtils; -import org.apache.commons.text.WordUtils; -import org.apache.rat.OptionCollection; -import org.apache.rat.utils.CasedString; -import org.apache.rat.utils.CasedString.StringCase; - -import static java.lang.String.format; - -/** - * A simple tool to convert CLI options to a Maven Mojo base class. - */ -public final class MavenGenerator { - - private MavenGenerator() { - } - - private static String argsKey(final Option option) { - return StringUtils.defaultIfEmpty(option.getLongOpt(), option.getOpt()); - } - - /** - * Creates the Maven MojoClass - * Requires 3 arguments: - * <ol> - * <li>the package name for the class</li> - * <li>the simple class name</li> - * <li>the directory in which to write the class file.</li> - * </ol> - * - * @param args the arguments - * @throws IOException on error - */ - public static void main(final String[] args) throws IOException { - if (args == null || args.length < 3) { - System.err.println("At least three arguments are required: package, simple class name, target directory."); - return; - } - - String packageName = args[0]; - String className = args[1]; - String destDir = args[2]; - List<MavenOption> options = MavenOption.getMavenOptions(); - String pkgName = String.join(File.separator, new CasedString(StringCase.DOT, packageName).getSegments()); - File file = new File(new File(new File(destDir), pkgName), className + ".java"); - System.out.println("Creating " + file); - file.getParentFile().mkdirs(); - try (InputStream template = MavenGenerator.class.getResourceAsStream("/Maven.tpl"); - FileWriter writer = new FileWriter(file)) { - if (template == null) { - throw new RuntimeException("Template /Maven.tpl not found"); - } - LineIterator iter = IOUtils.lineIterator(new InputStreamReader(template, StandardCharsets.UTF_8)); - while (iter.hasNext()) { - String line = iter.next(); - switch (line.trim()) { - case "${static}": - for (Map.Entry<String, String> entry : MavenOption.getRenameMap().entrySet()) { - writer.append(format(" xlateName.put(\"%s\", \"%s\");%n", entry.getKey(), entry.getValue())); - } -// for (Option option : MavenOption.getFilteredOptions()) { -// writer.append(format(" unsupportedArgs.add(\"%s\");%n", argsKey(option))); -// } - for (MavenOption option : options) { - if (option.isDeprecated()) { - writer.append(format(" deprecatedArgs.put(\"%s\", \"%s\");%n", argsKey(option.getOption()), - format("Use of deprecated option '%s'. %s", option.getName(), option.getDeprecated()))); - } - } - break; - case "${methods}": - writeMethods(writer, options); - break; - case "${package}": - writer.append(format("package %s;%n", packageName)); - break; - case "${constructor}": - writer.append(format(" protected %s() {\n" + - " setDeprecationReporter();\n" + - " }%n", className)); - break; - case "${class}": - writer.append(format("public abstract class %s extends AbstractMojo {%n", className)); - break; - case "${commonArgs}": - try (InputStream argsTpl = MavenGenerator.class.getResourceAsStream("/Args.tpl")) { - if (argsTpl == null) { - throw new RuntimeException("Args.tpl not found"); - } - IOUtils.copy(argsTpl, writer, StandardCharsets.UTF_8); - } - break; - default: - writer.append(line).append(System.lineSeparator()); - break; - } - } - } - } - - private static String getComment(final MavenOption option) { - String desc = option.getDescription(); - if (desc == null) { - throw new IllegalStateException(format("Description for %s may not be null", option.getName())); - } - if (!desc.contains(".")) { - throw new IllegalStateException(format("First sentence of description for %s must end with a '.'", option.getName())); - } - String arg; - if (option.hasArg()) { - arg = desc.substring(desc.indexOf(" ") + 1, desc.indexOf(".") + 1); - arg = WordUtils.capitalize(arg.substring(0, 1)) + arg.substring(1); - } else { - arg = "The state"; - } - if (option.hasArg() && option.getArgName() != null) { - OptionCollection.ArgumentType.valueOf(option.getArgName()); -// if (sup == null) { -// throw new IllegalStateException(format("Argument type %s must be in OptionCollection.ARGUMENT_TYPES", option.getArgName())); -// } - desc = format("%s Argument%s should be %s%s. (See Argument Types for clarification)", desc, option.hasArgs() ? "s" : "", - option.hasArgs() ? "" : "a ", option.getArgName()); - } - StringBuilder sb = new StringBuilder() - .append(format(" /**%n * %s%n * @param %s %s%n", StringEscapeUtils.escapeHtml4(desc), - option.getName(), StringEscapeUtils.escapeHtml4(arg))); - if (option.isDeprecated()) { - sb.append(format(" * @deprecated %s%n", StringEscapeUtils.escapeHtml4(option.getDeprecated()))); - } - return sb.append(format(" */%n")).toString(); - } - - private static void writeMethods(final FileWriter writer, final List<MavenOption> options) throws IOException { - for (MavenOption option : options) { - writer.append(getComment(option)) - .append(option.getMethodSignature(" ", option.hasArgs())).append(" {").append(System.lineSeparator()) - .append(getBody(option)) - .append(" }").append(System.lineSeparator()); - if (option.hasArgs()) { - // create multi argument method - writer.append(getComment(option)) - .append(option.getMethodSignature(" ", false)).append(" {").append(System.lineSeparator()) - .append(getBody(option)) - .append(" }").append(System.lineSeparator()); - } - } - } - - private static String getBody(final MavenOption option) { - if (option.hasArg()) { - return format(" %sArg(%s, %s);%n", option.hasArgs() ? "add" : "set", option.keyValue(), option.getName()); - } else { - return format(" if (%1$s) {%n setArg(%2$s, null);%n" + - " } else {%n removeArg(%2$s);%n }%n", - option.getName(), option.keyValue()); - } - } -} diff --git a/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/MavenOption.java b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/MavenOption.java index 5c0d5633..f8c82930 100644 --- a/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/MavenOption.java +++ b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/MavenOption.java @@ -18,23 +18,17 @@ */ package org.apache.rat.maven; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Set; import java.util.function.Predicate; -import java.util.stream.Collectors; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.collections4.map.UnmodifiableMap; import org.apache.commons.collections4.set.UnmodifiableSet; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.WordUtils; -import org.apache.rat.OptionCollection; import org.apache.rat.commandline.Arg; import org.apache.rat.ui.AbstractOption; import org.apache.rat.ui.OptionFactory; @@ -86,11 +80,6 @@ public final class MavenOption extends AbstractOption<MavenOption> { FACTORY_CONFIG = new OptionFactory.Config<>(MavenOption.MAVEN_FILTER, MavenOption::new, MavenOption.ADDITIONAL_OPTIONS); } - public static List<MavenOption> getMavenOptions() { - return OptionCollection.buildOptions(ADDITIONAL_OPTIONS).getOptions().stream().filter(MAVEN_FILTER) - .map(MavenOption::new).collect(Collectors.toList()); - } - /** * Constructor. * @@ -100,10 +89,6 @@ public final class MavenOption extends AbstractOption<MavenOption> { super(option, createName(option)); } - public static Map<String, String> getRenameMap() { - return Collections.unmodifiableMap(RENAME_MAP); - } - /** * Creates the Maven element name for the specified option. * @param option The option to process. @@ -140,42 +125,6 @@ public final class MavenOption extends AbstractOption<MavenOption> { return result; } - public String getPropertyAnnotation(final String fname) { - StringBuilder sb = new StringBuilder("@Parameter"); - String property = option.hasArgs() ? null : format("property = \"rat.%s\"", fname); - String defaultValue = option.isDeprecated() ? null : getDefaultValue(); - if (property != null || defaultValue != null) { - sb.append("("); - if (property != null) { - sb.append(property).append(defaultValue != null ? ", " : StringUtils.EMPTY); - } - if (defaultValue != null) { - sb.append(format("defaultValue = \"%s\"", defaultValue)); - } - sb.append(")"); - } - return sb.toString(); - } - - public String getMethodSignature(final String indent, final boolean multiple) { - StringBuilder sb = new StringBuilder(); - if (isDeprecated()) { - sb.append(format("%s@Deprecated%n", indent)); - } - String fname = WordUtils.capitalize(name); - String args = option.hasArg() ? "String" : "boolean"; - if (multiple) { - if (!(fname.endsWith("s") || fname.endsWith("Approved") || fname.endsWith("Denied"))) { - fname = fname + "s"; - } - args = args + "[]"; - } - - return sb.append(format("%1$s%5$s%n%1$spublic void set%3$s(%4$s %2$s)", - indent, name, fname, args, getPropertyAnnotation(fname))) - .toString(); - } - @Override public String getExample() { if (UNSUPPORTED_SET.contains(option)) { diff --git a/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/TestGenerator.java b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/TestGenerator.java index 56a6cb78..1385b3a3 100644 --- a/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/TestGenerator.java +++ b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/TestGenerator.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; @@ -46,6 +47,8 @@ import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.runtime.RuntimeConstants; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * Generates the Maven mojo tests. */ @@ -67,6 +70,7 @@ public final class TestGenerator { /** The template for the test maven stubs */ private final Template stubTemplate; + @SuppressFBWarnings("PATH_TRAVERSAL_IN") private TestGenerator(final String packageName, final String resourceDirectory, final String testDirectory) { this.packageName = new CasedString(CasedString.StringCase.DOT, packageName); this.resourceDirectory = Paths.get(resourceDirectory); @@ -158,13 +162,13 @@ public final class TestGenerator { /** * Write the {@code MavenTest.java} file - * @param context - * @throws IOException + * @param context The velocity context to write the test file with. + * @throws IOException on error */ private void writeTestFiles(final VelocityContext context) throws IOException { File javaFile = testDirectory.resolve("MavenTest.java").toFile(); FileUtils.mkDir(javaFile.getParentFile()); - try (FileWriter fileWriter = new FileWriter(javaFile)) { + try (FileWriter fileWriter = new FileWriter(javaFile, StandardCharsets.UTF_8)) { javaTemplate.merge(context, fileWriter); } } @@ -174,7 +178,7 @@ public final class TestGenerator { * Generates method definitions (one for each pom file) to be included in {@code MavenTest.java}. * @param context het velocity context. * @return a String comprising all the method definitions. - * @throws IOException + * @throws IOException on IO error */ private String writeTestPoms(final VelocityContext context) throws IOException { @@ -209,7 +213,7 @@ public final class TestGenerator { context.put("rat_configuration", configuration.toString()); File pomFile = testPath.resolve("pom.xml").toFile(); - try (FileWriter writer = new FileWriter(pomFile)) { + try (FileWriter writer = new FileWriter(pomFile, StandardCharsets.UTF_8)) { pomTemplate.merge(context, writer); } @@ -217,7 +221,7 @@ public final class TestGenerator { File stubFile = testDirectory.resolve("stubs") .resolve(testData.getClassName() + ".java").toFile(); FileUtils.mkDir(stubFile.getParentFile()); - try (FileWriter fileWriter = new FileWriter(stubFile)) { + try (FileWriter fileWriter = new FileWriter(stubFile, StandardCharsets.UTF_8)) { stubTemplate.merge(context, fileWriter); } diff --git a/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestMethod.vm b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestMethod.vm index f0bcd491..e21feb34 100644 --- a/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestMethod.vm +++ b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestMethod.vm @@ -24,7 +24,7 @@ @Basedir("${basedir}") public void ${funcName}Test(RatCheckMojo mojo) throws MojoExecutionException { TestData testData = testDataMap.get("${testName}"); - testData.setupFiles(Paths.get("impl/${basedir}")); + testData.setupFiles(Paths.get("${basedir}")); if (testData.getExpectedException() != null) { assertThatThrownBy(mojo::execute).hasMessageContaining(testData.getExpectedException().getMessage()); } else { diff --git a/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestPom.vm b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestPom.vm index 7fa3acff..588ae3db 100644 --- a/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestPom.vm +++ b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestPom.vm @@ -32,12 +32,9 @@ <version>${plugin_version}</version> <configuration> ${rat_configuration} - <!-- Specify where this pom will output files --> -## <outputDirectory>target/test-harness/project-to-test</outputDirectory> - <!-- The defined stubs --> <project implementation="${packageName}.stubs.${stubName}"/> - <settings implementation="org.apache.rat.maven.SettingsStub"/> +## <settings implementation="org.apache.rat.maven.SettingsStub"/> </configuration> </plugin> </plugins> diff --git a/apache-rat-tasks/spotbugs-ignore.xml b/apache-rat-tasks/spotbugs-ignore.xml index e8c3e32c..39e672f5 100644 --- a/apache-rat-tasks/spotbugs-ignore.xml +++ b/apache-rat-tasks/spotbugs-ignore.xml @@ -16,11 +16,5 @@ limitations under the License. --> <FindBugsFilter> - <Match> - <!-- - Convenience constructors that allow setting a charset are not available in Java8 for PrintStream. - <Class name="org.apache.rat.anttasks.Report"/> - <Bug pattern="DM_DEFAULT_ENCODING"/> - --> - </Match> + </FindBugsFilter> diff --git a/apache-rat-tools/spotbugs-ignore.xml b/apache-rat-tools/spotbugs-ignore.xml index 2d4d66ea..39e672f5 100644 --- a/apache-rat-tools/spotbugs-ignore.xml +++ b/apache-rat-tools/spotbugs-ignore.xml @@ -16,10 +16,5 @@ limitations under the License. --> <FindBugsFilter> - <Match> - <!-- - Convenience constructors that allow setting a charset are not available in Java8 for PrintStream. - <Bug pattern="DM_DEFAULT_ENCODING"/> - --> - </Match> + </FindBugsFilter> diff --git a/pom.xml b/pom.xml index 5adf0270..a784d72c 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,11 @@ agnostic home for software distribution comprehension and audit tools. </distributionManagement> <dependencyManagement> <dependencies> + <dependency> + <groupId>com.github.spotbugs</groupId> + <artifactId>spotbugs-annotations</artifactId> + <version>4.9.8</version> + </dependency> <dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> @@ -439,6 +444,12 @@ agnostic home for software distribution comprehension and audit tools. </plugin> </plugins> </reporting> + <dependencies> + <dependency> + <groupId>com.github.spotbugs</groupId> + <artifactId>spotbugs-annotations</artifactId> + </dependency> + </dependencies> <build> <defaultGoal>clean install</defaultGoal> <pluginManagement> @@ -554,16 +565,16 @@ agnostic home for software distribution comprehension and audit tools. <targetJdk>${javaVersion}</targetJdk> </configuration> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <version>${mavenPluginPluginVersion}</version> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-report-plugin</artifactId> - <version>${mavenPluginPluginVersion}</version> - </plugin> +<!-- <plugin>--> +<!-- <groupId>org.apache.maven.plugins</groupId>--> +<!-- <artifactId>maven-plugin-plugin</artifactId>--> +<!-- <version>${mavenPluginPluginVersion}</version>--> +<!-- </plugin>--> +<!-- <plugin>--> +<!-- <groupId>org.apache.maven.plugins</groupId>--> +<!-- <artifactId>maven-plugin-report-plugin</artifactId>--> +<!-- <version>${mavenPluginPluginVersion}</version>--> +<!-- </plugin>--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> diff --git a/spotbugs-ignore.xml b/spotbugs-ignore.xml index 8e4ed55a..39e672f5 100644 --- a/spotbugs-ignore.xml +++ b/spotbugs-ignore.xml @@ -16,11 +16,5 @@ limitations under the License. --> <FindBugsFilter> - <Match> - <!-- Uses tryWithResources, thus closes resource properly: - [ERROR] Medium: org.apache.rat.configuration.builders.ChildContainerBuilder.setResource(String) may fail to close stream - [org.apache.rat.configuration.builders.ChildContainerBuilder] At ChildContainerBuilder.java:[line 62] OS_OPEN_STREAM - <Class name="org.apache.rat.configuration.builders.ChildContainerBuilder"/> - <Bug pattern="OS_OPEN_STREAM"/--> - </Match> + </FindBugsFilter>
