From 0188ed33d09f809104dac0c98333221f517c15a4 Mon Sep 17 00:00:00 2001 From: Claude Warren Date: Sat, 11 May 2024 21:23:03 +0200 Subject: [PATCH 01/19] fixed RAT-265 and initial tests for command line processing --- .../src/main/java/org/apache/rat/Report.java | 60 ++++-- .../resources/org/apache/rat/rat-config.xsd | 4 +- .../test/java/org/apache/rat/ReportTest.java | 180 +++++++++++++++++- .../java/org/apache/rat/ReporterTest.java | 3 + src/changes/changes.xml | 4 + 5 files changed, 226 insertions(+), 25 deletions(-) diff --git a/apache-rat-core/src/main/java/org/apache/rat/Report.java b/apache-rat-core/src/main/java/org/apache/rat/Report.java index 3241fb8c5..bc88cd619 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/Report.java +++ b/apache-rat-core/src/main/java/org/apache/rat/Report.java @@ -41,6 +41,7 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Converter; import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.DeprecatedAttributes; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionGroup; @@ -130,9 +131,14 @@ public String desc() { /** * Adds license headers to files missing headers. */ - private static final OptionGroup ADD = new OptionGroup() - .addOption(new Option("a", false, - "(deprecated) Add the default license header to any file with an unknown license. Use '-A' or ---addLicense instead.")) + private static final DeprecatedAttributes addAttributes = DeprecatedAttributes.builder().setForRemoval(true).setSince("1.17.0") + .setDescription("Use '-A' or --addLicense instead.").get(); + static final OptionGroup ADD = new OptionGroup() + .addOption(Option.builder("a").hasArg(false) + .desc(format( "[%s]", addAttributes)) + .deprecated( addAttributes ) + .build()) + .addOption(new Option("A", "addLicense", false, "Add the default license header to any file with an unknown license that is not in the exclusion list. " + "By default new files will be created with the license header, " @@ -147,19 +153,24 @@ public String desc() { .desc("Define the output file where to write a report to (default is System.out).") .converter(Converter.FILE).build(); + static final DeprecatedAttributes dirAttributes = DeprecatedAttributes.builder().setForRemoval(true).setSince("1.17.0") + .setDescription("Use '--'").get(); static final Option DIR = Option.builder().option("d").longOpt("dir").hasArg() - .desc("(deprecated, use '--') Used to indicate source when using --exclude.").argName("DirOrArchive").build(); + .desc(format( "[%s] %s", dirAttributes, "Used to indicate end of list when using --exclude.")).argName("DirOrArchive") + .deprecated( dirAttributes).build(); /** * Forces changes to be written to new files. */ static final Option FORCE = new Option("f", "force", false, - "Forces any changes in files to be written directly to the source files (i.e. new files are not created)."); + format("Forces any changes in files to be written directly to the source files (i.e. new files are not created). Only valid with --%s", + ADD.getOptions().stream().filter(o -> !o.isDeprecated()).findAny().get().getLongOpt())); /** * Defines the copyright header to add to the file. */ static final Option COPYRIGHT = Option.builder().option("c").longOpt("copyright").hasArg() - .desc("The copyright message to use in the license headers, usually in the form of \"Copyright 2008 Foo\"") + .desc(format("The copyright message to use in the license headers, usually in the form of \"Copyright 2008 Foo\". Only valid with --%s", + ADD.getOptions().stream().filter(o -> !o.isDeprecated()).findAny().get().getLongOpt())) .build(); /** * Name of File to exclude from report consideration. @@ -309,8 +320,10 @@ public static ReportConfiguration parseCommands(String[] args, Consumer public static ReportConfiguration parseCommands(String[] args, Consumer helpCmd, boolean noArgs) throws IOException { Options opts = buildOptions(); CommandLine cl; + Consumer