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 d744b255074c4215f804ebdc7834badc4eeec68a Author: Claude Warren <[email protected]> AuthorDate: Tue Dec 23 15:31:53 2025 +0000 initial cut plugin code generator --- .../java/org/apache/rat/utils/CasedString.java | 10 +- .../java/org/apache/rat/testhelpers/FileUtils.java | 5 +- apache-rat-plugin-parent/pom.xml | 26 +++ apache-rat-plugin-parent/tools/pom.xml | 25 ++- .../java/org/apache/rat/maven/MavenGenerator.java | 9 +- .../java/org/apache/rat/maven/MavenOption.java | 40 ++++- .../java/org/apache/rat/maven/TestGenerator.java | 190 +++++++++++++++++++++ .../java/org/apache/rat/maven/package-info.java | 22 +++ .../resources/org/apache/rat/maven/TestFunc.vm | 10 ++ .../org/apache/rat/maven/TestGenerator.vm} | 44 +++-- .../resources/org/apache/rat/maven/TestJava.vm | 57 +++++++ .../test/java/org/apache/rat/maven/MavenTest.java | 63 +++++++ pom.xml | 21 --- 13 files changed, 454 insertions(+), 68 deletions(-) diff --git a/apache-rat-core/src/main/java/org/apache/rat/utils/CasedString.java b/apache-rat-core/src/main/java/org/apache/rat/utils/CasedString.java index 79b29d10..1e943a2d 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/utils/CasedString.java +++ b/apache-rat-core/src/main/java/org/apache/rat/utils/CasedString.java @@ -83,7 +83,15 @@ public class CasedString { * in the string. If specific capitalization is required use {@link String#toUpperCase()}, {@link String#toLowerCase()}, * * or the commons-text methods {@link WordUtils#capitalize(String)}, or {@link WordUtils#uncapitalize(String)} as required. */ - DOT(c -> c == '.', false, a -> String.join(".", a)); + DOT(c -> c == '.', false, a -> String.join(".", a)), + + /** + * Slash case tags phrases of words like 'phrase.case'. This conversion does not change the capitalization of any characters + * in the string. If specific capitalization is required use {@link String#toUpperCase()}, {@link String#toLowerCase()}, + * * or the commons-text methods {@link WordUtils#capitalize(String)}, or {@link WordUtils#uncapitalize(String)} as required. + */ + SLASH(c -> c == '/', false, a -> String.join("/", a)); + /** The segment value for a null string */ private static final String[] NULL_SEGMENT = new String[0]; diff --git a/apache-rat-core/src/test/java/org/apache/rat/testhelpers/FileUtils.java b/apache-rat-core/src/test/java/org/apache/rat/testhelpers/FileUtils.java index 5cb956ed..c514abb5 100644 --- a/apache-rat-core/src/test/java/org/apache/rat/testhelpers/FileUtils.java +++ b/apache-rat-core/src/test/java/org/apache/rat/testhelpers/FileUtils.java @@ -25,7 +25,6 @@ import java.io.PrintWriter; import java.util.Arrays; import java.util.Collections; -import static org.assertj.core.api.Fail.fail; public class FileUtils { @@ -64,14 +63,14 @@ public class FileUtils { */ static public File writeFile(File dir, final String name, final Iterable<String> lines) { if (dir == null) { - fail("base directory not specified"); + throw new IllegalArgumentException("base directory not specified"); } mkDir(dir); File file = new File(dir, name); try (PrintWriter writer = new PrintWriter(new FileWriter(file))) { lines.forEach(writer::println); } catch (IOException e) { - fail(e.getMessage()); + throw new RuntimeException(e.getMessage(), e); } return file; } diff --git a/apache-rat-plugin-parent/pom.xml b/apache-rat-plugin-parent/pom.xml index 8209c602..d746bda7 100644 --- a/apache-rat-plugin-parent/pom.xml +++ b/apache-rat-plugin-parent/pom.xml @@ -32,11 +32,37 @@ <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> + <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> </project> diff --git a/apache-rat-plugin-parent/tools/pom.xml b/apache-rat-plugin-parent/tools/pom.xml index 1d243471..ed2ee557 100644 --- a/apache-rat-plugin-parent/tools/pom.xml +++ b/apache-rat-plugin-parent/tools/pom.xml @@ -26,6 +26,11 @@ <packaging>jar</packaging> <name>Apache Creadur RAT::Tools</name> <description>Tools to manage and report on RAT for Maven</description> + <properties> + + </properties> + + <build> <resources> <resource> @@ -93,23 +98,22 @@ <dependency> <groupId>org.apache.rat</groupId> <artifactId>apache-rat-core</artifactId> + <version>${rat.version}</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> </dependency> <dependency> - <groupId>org.apache.velocity.tools</groupId> - <artifactId>velocity-tools-generic</artifactId> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-core-tests</artifactId> + <version>${rat.version}</version> </dependency> <dependency> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-core</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - <classifier>tests</classifier> - <scope>test</scope> + <groupId>org.apache.velocity.tools</groupId> + <artifactId>velocity-tools-generic</artifactId> </dependency> + <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> @@ -144,5 +148,10 @@ <artifactId>assertj-core</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.maven.plugin-testing</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> 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 index b77b80b4..6020bcdd 100644 --- 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 @@ -26,7 +26,6 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; -import java.util.function.Supplier; import org.apache.commons.cli.Option; import org.apache.commons.io.IOUtils; @@ -147,10 +146,10 @@ public final class MavenGenerator { arg = "The state"; } if (option.hasArg() && option.getArgName() != null) { - Supplier<String> sup = OptionCollection.ArgumentType.valueOf(option.getArgName()); - if (sup == null) { - throw new IllegalStateException(format("Argument type %s must be in OptionCollection.ARGUMENT_TYPES", option.getArgName())); - } + 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()); } 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 02bfdd63..1327e00b 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 @@ -27,7 +27,9 @@ 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.lang3.StringUtils; import org.apache.commons.text.WordUtils; import org.apache.rat.OptionCollection; @@ -40,18 +42,19 @@ import static java.lang.String.format; /** * A representation of a CLI option as a Maven option */ -public class MavenOption extends AbstractOption { +public class MavenOption extends AbstractOption<MavenOption> { /** * Default values for CLI options */ - private static final Map<Arg, String> DEFAULT_VALUES = new HashMap<>(); + static final Map<Arg, String> DEFAULT_VALUES = new HashMap<>(); /** * List of CLI options that are not supported by Maven. */ - private static final Set<Option> UNSUPPORTED_LIST = new HashSet<>(); + static final Set<Option> UNSUPPORTED_LIST = new HashSet<>(); /** A mapping of external name to internal name if not standard. */ - private static final Map<String, String> RENAME_MAP = new HashMap<>(); - + static final Map<String, String> RENAME_MAP = new HashMap<>(); + /** The additional options for the maven plugin */ + static final Options ADDITIONAL_OPTIONS = new Options(); /** * Filter to remove options not supported by Maven. */ @@ -62,14 +65,13 @@ public class MavenOption extends AbstractOption { DEFAULT_VALUES.put(Arg.OUTPUT_FILE, "${project.build.directory}/rat.txt"); UNSUPPORTED_LIST.addAll(Arg.DIR.group().getOptions()); UNSUPPORTED_LIST.addAll(Arg.LOG_LEVEL.group().getOptions()); - UNSUPPORTED_LIST.add(OptionCollection.HELP); Set<Option> filteredOptions = getFilteredOptions(); MAVEN_FILTER = option -> !(filteredOptions.contains(option) || option.getLongOpt() == null); } public static List<MavenOption> getMavenOptions() { - return OptionCollection.buildOptions().getOptions().stream().filter(MAVEN_FILTER) + return OptionCollection.buildOptions(ADDITIONAL_OPTIONS).getOptions().stream().filter(MAVEN_FILTER) .map(MavenOption::new).collect(Collectors.toList()); } @@ -116,6 +118,11 @@ public class MavenOption extends AbstractOption { return cleanupName(option); } + @Override + public Options getAdditionalOptions() { + return ADDITIONAL_OPTIONS; + } + @Override public String getDefaultValue() { Arg arg = Arg.findArg(option); @@ -173,4 +180,23 @@ public class MavenOption extends AbstractOption { return format("<%s />", getName()); } } + + public String getExample(final String[] args) { + StringBuilder sb = new StringBuilder("<").append(getName()); + if (hasArg()) { + sb.append(">"); + if (hasArgs()) { + sb.append(System.lineSeparator()); + for (String arg : args) { + sb.append(String.format(" <%1$s>%2$s</%1$s>%n", getArgName(), arg)); + } + } else { + sb.append(args[0]); + } + sb.append("</").append(getName()).append(">"); + } else { + sb.append("/>"); + } + return sb.toString(); + } } 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 new file mode 100644 index 00000000..b7a84dd5 --- /dev/null +++ b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/TestGenerator.java @@ -0,0 +1,190 @@ +/* + * 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.StringWriter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.rat.DeprecationReporter; +import org.apache.rat.VersionInfo; +import org.apache.rat.testhelpers.FileUtils; +import org.apache.rat.testhelpers.data.ReportTestDataProvider; +import org.apache.rat.testhelpers.data.TestData; +import org.apache.rat.utils.CasedString; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.runtime.RuntimeConstants; + +public final class TestGenerator { + private static final String SYNTAX = String.format("java -cp ... %s [options]", TestGenerator.class.getName()); + private final VelocityEngine velocityEngine; + private final CasedString packageName; + private final String resourceDirectory; + private final String testDirectory; + private final Template pomTemplate; + private final Template javaTemplate; + private final Template funcTemplate; + + private TestGenerator(String packageName, String resourceDirectory, String testDirectory) { + this.packageName = new CasedString(CasedString.StringCase.DOT, packageName); + this.resourceDirectory = resourceDirectory; + this.testDirectory = testDirectory; + + velocityEngine = new VelocityEngine(); + velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); + velocityEngine.setProperty("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + velocityEngine.init(); + + // retrieve the templates + CasedString casedTemplateName = new CasedString(CasedString.StringCase.DOT, TestGenerator.class.getName()); + String[] nameParts = Arrays.copyOf(casedTemplateName.getSegments(), casedTemplateName.getSegments().length); + pomTemplate = velocityEngine.getTemplate(casedTemplateName.toCase(CasedString.StringCase.SLASH) + ".vm"); + nameParts[nameParts.length - 1] = "TestJava.vm"; + javaTemplate = velocityEngine.getTemplate(CasedString.StringCase.SLASH.assemble(nameParts)); + nameParts[nameParts.length - 1] = "TestFunc.vm"; + funcTemplate = velocityEngine.getTemplate(CasedString.StringCase.SLASH.assemble(nameParts)); + } + + private Path testPath() { + return Paths.get(testDirectory).resolve(packageName.toCase(CasedString.StringCase.SLASH)); + } + + private Path resourcePath() { + return Paths.get(resourceDirectory).resolve(packageName.toCase(CasedString.StringCase.SLASH)); + } + + private static Options getOptions() { + return new Options() + .addOption(Option.builder("r").longOpt("resources").required().hasArg().desc("The path to the base resource directory").build()) + .addOption(Option.builder("h").longOpt("help").desc("Print this message").build()) + .addOption(Option.builder("t").longOpt("tests").required().hasArg().desc("The path to the base of the generated test code directory").build()) + .addOption(Option.builder("p").longOpt("package").required().hasArg().desc("The package name to generate").build()); + } + + + + public static void main(final String[] args) throws IOException, ParseException { + + CommandLine commandLine = null; + try { + commandLine = DefaultParser.builder().setDeprecatedHandler(DeprecationReporter.getLogReporter()) + .build().parse(getOptions(), args); + } catch (ParseException pe) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp(SYNTAX, pe.getMessage(), getOptions(), ""); + System.exit(1); + } + + if (commandLine.hasOption("h")) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp(SYNTAX, getOptions()); + System.exit(0); + } + TestGenerator testGenerator = new TestGenerator(commandLine.getOptionValue("p"), + commandLine.getOptionValue("r"), commandLine.getOptionValue("t")); + + testGenerator.execute(); +// +// // create the basePath +// final String packageName = args[1]; +// final CasedString casedPackageName = new CasedString(CasedString.StringCase.DOT, packageName); +// final Path basePath = Paths.get(args[0]).resolve(casedPackageName.toCase(CasedString.StringCase.SLASH)); +// +// VelocityEngine velocityEngine = initializeVelocityEngine(); +// +// // retrieve templates +// CasedString casedTemplateName = new CasedString(CasedString.StringCase.DOT, TestGenerator.class.getName()); +// String[] nameParts = Arrays.copyOf(casedTemplateName.getSegments(), casedTemplateName.getSegments().length); +// Template pomTemplate = velocityEngine.getTemplate(casedTemplateName.toCase(CasedString.StringCase.SLASH) + ".vm"); +// nameParts[nameParts.length - 1] = "TestJava.vm"; +// Template javaTemplate = velocityEngine.getTemplate(CasedString.StringCase.SLASH.assemble(nameParts)); +// nameParts[nameParts.length - 1] = "TestFunc.vm"; +// Template funcTemplate = velocityEngine.getTemplate(CasedString.StringCase.SLASH.assemble(nameParts)); + + } + + private void execute() throws IOException { + VelocityContext context = new VelocityContext(); + context.put("packageName", packageName.toString()); + + final VersionInfo versionInfo = new VersionInfo(TestGenerator.class); + context.put("rat_version", versionInfo.getSpecVersion()); + context.put("plugin_version", versionInfo.getVersion()); + context.put("tests", writeTestPoms(context)); + writeTestFile(context); + } + + private void writeTestFile(VelocityContext context) throws IOException { + File javaFile = Paths.get(testDirectory).resolve(packageName.toCase(CasedString.StringCase.SLASH)) + .resolve("MavenTest.java").toFile(); + try (FileWriter fileWriter = new FileWriter(javaFile)) { + javaTemplate.merge(context, fileWriter); + } + } + + private String writeTestPoms(VelocityContext context) throws IOException { + + StringWriter funcCode = new StringWriter(); + + for (final TestData testData : new ReportTestDataProvider().getOptionTests(MavenOption.UNSUPPORTED_LIST)) { + context.put("pomFile", testData.getTestName() + "/pom.xml"); + Path testPath = resourcePath().resolve(testData.getTestName()); + context.put("baseDir", testPath.toFile().getAbsolutePath()); + FileUtils.mkDir(testPath.toFile()); + CasedString testName = new CasedString(CasedString.StringCase.SLASH, testData.getTestName()); + + context.put("artifactId", testName.toCase(CasedString.StringCase.KEBAB)); + context.put("testName", testData.getTestName()); + context.put("funcName", String.join("", testName.getSegments())); + + StringBuilder configuration = new StringBuilder(); + for (Pair<Option, String[]> pair : testData.getArgs()) { + if (pair.getKey() != null) { + MavenOption option = new MavenOption(pair.getKey()); + configuration.append(option.getExample(pair.getRight())).append(System.lineSeparator()); + } + } + context.put("rat_configuration", configuration.toString()); + + File pomFile = testPath.resolve("pom.xml").toFile(); + try (FileWriter writer = new FileWriter(pomFile)) { + pomTemplate.merge(context, writer); + } + + funcTemplate.merge(context, funcCode); + + } + return funcCode.toString(); + } + +} diff --git a/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/package-info.java b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/package-info.java new file mode 100644 index 00000000..6be482b3 --- /dev/null +++ b/apache-rat-plugin-parent/tools/src/main/java/org/apache/rat/maven/package-info.java @@ -0,0 +1,22 @@ +/* + * 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. + */ +/** + * RAT Maven plugin tools. + */ +package org.apache.rat.maven; diff --git a/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestFunc.vm b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestFunc.vm new file mode 100644 index 00000000..4e1fd514 --- /dev/null +++ b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestFunc.vm @@ -0,0 +1,10 @@ +/** + * Generated test for ${testName} + */ +@Test +@InjectMojo(goal = "validate", pom = "${pomFile}") +public void ${funcName}Test(RatCheckMojo mojo) { + TestData testData = testDataMap.get("${testName}"); + ValidatorData validatorData = new ValidatorData(mojo.getOutput(), mojo.getConfiguration(), "${baseDir}"); + testData.getValidator().accept(validatorData); +} diff --git a/apache-rat-plugin-parent/pom.xml b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestGenerator.vm similarity index 57% copy from apache-rat-plugin-parent/pom.xml copy to apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestGenerator.vm index 8209c602..71cadc20 100644 --- a/apache-rat-plugin-parent/pom.xml +++ b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestGenerator.vm @@ -16,27 +16,25 @@ 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::Plugin4Maven</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> - <currentVersion>${project.version}</currentVersion> - <doxiaVersion>2.0.0</doxiaVersion> - </properties> - <modules> - <module>tools</module> - <module>impl</module> - </modules> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.rat.maven.test</groupId> + <artifactId>${artifactId}</artifactId> + <version>${rat_version}</version> + <packaging>jar</packaging> + <name>${testName} Tools</name> + <description>Test for ${testName}.</description> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-plugin</artifactId> + <version>${plugin_version}</version> + <configuration> + ${rat_configuration} + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> </project> diff --git a/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestJava.vm b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestJava.vm new file mode 100644 index 00000000..edcaa77c --- /dev/null +++ b/apache-rat-plugin-parent/tools/src/main/resources/org/apache/rat/maven/TestJava.vm @@ -0,0 +1,57 @@ +/* + * 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 ${packageName}; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Fail.fail; + +import java.nio.file.Path; +import java.util.Map; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; +import org.apache.rat.testhelpers.data.ReportTestDataProvider; +import org.apache.rat.testhelpers.data.TestData; +import org.apache.rat.testhelpers.data.ValidatorData; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.api.io.TempDir; + +@MojoTest +public class MavenTest { + + @TempDir + static Path tempDir; + + static ReportTestDataProvider reportTestDataProvider = new ReportTestDataProvider(); + + + final Map<String, TestData> testDataMap = reportTestDataProvider.getOptionTestMap(MavenOption.UNSUPPORTED_LIST); + + private final static XPath xPath = XPathFactory.newInstance().newXPath(); + + @AfterAll + @EnabledOnOs(OS.WINDOWS) + static void cleanup() { + System.gc(); // hacky workaround for windows bug. + } + + ${tests} +} diff --git a/apache-rat-plugin-parent/tools/src/test/java/org/apache/rat/maven/MavenTest.java b/apache-rat-plugin-parent/tools/src/test/java/org/apache/rat/maven/MavenTest.java new file mode 100644 index 00000000..c7dce2da --- /dev/null +++ b/apache-rat-plugin-parent/tools/src/test/java/org/apache/rat/maven/MavenTest.java @@ -0,0 +1,63 @@ +package org.apache.rat.maven;/* + * 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. + */ + + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Fail.fail; + +import java.nio.file.Path; +import java.util.Map; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; +import org.apache.rat.testhelpers.data.ReportTestDataProvider; +import org.apache.rat.testhelpers.data.TestData; +import org.apache.rat.testhelpers.data.ValidatorData; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.api.io.TempDir; + +@MojoTest +public class MavenTest { + + @TempDir + static Path tempDir; + + static ReportTestDataProvider reportTestDataProvider = new ReportTestDataProvider(); + + + final Map<String, TestData> testDataMap = reportTestDataProvider.getOptionTestMap(MavenOption.UNSUPPORTED_LIST); + + private final static XPath xPath = XPathFactory.newInstance().newXPath(); + + @AfterAll + @EnabledOnOs(OS.WINDOWS) + static void cleanup() { + System.gc(); // hacky workaround for windows bug. + } + + @Test + @InjectMojo(goal = "validate", pom = "${pomFile}") + public void ${testName}Test(RatCheckMojo mojo) { + TestData testData = testDataMap.get(${testName}); + ValidatorData validatorData = new ValidatorData(mojo.getOutput(), mojo.getConfiguration(), ${baseDir}); + testData.getValidator().accept(validatorData); + } +} diff --git a/pom.xml b/pom.xml index 88f77bcf..10aa1f14 100644 --- a/pom.xml +++ b/pom.xml @@ -56,13 +56,10 @@ agnostic home for software distribution comprehension and audit tools. <maven.compiler.target>${javaVersion}</maven.compiler.target> <!-- This is the version of Maven required to use the RAT Maven Plugin --> <mavenMinVersion>3.2.5</mavenMinVersion> - <mavenVersion>3.9.12</mavenVersion> <creadur.jira.id>RAT</creadur.jira.id> <velocity.core.version>2.4.1</velocity.core.version> <velocity.tools.version>3.1</velocity.tools.version> <!-- maven plugin versions --> - <mavenPluginTestingVersion>3.4.0</mavenPluginTestingVersion> - <mavenPluginPluginVersion>3.15.2</mavenPluginPluginVersion> <mavenChangesVersion>3.0.0-M3</mavenChangesVersion> <mavenJavadocPluginVersion>3.12.0</mavenJavadocPluginVersion> <mavenPmdPluginVersion>3.28.0</mavenPmdPluginVersion> @@ -206,24 +203,6 @@ agnostic home for software distribution comprehension and audit tools. <version>${ant.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> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId>
