This is an automated email from the ASF dual-hosted git repository.

claude pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git


The following commit(s) were added to refs/heads/master by this push:
     new db59f5e9 RAT-438: Cleaned up checkstyle and associated issues (#376)
db59f5e9 is described below

commit db59f5e9c181e2c65dede50efbd7da3cfbfcdabc
Author: Claude Warren <[email protected]>
AuthorDate: Fri Nov 1 08:39:07 2024 +0000

    RAT-438: Cleaned up checkstyle and associated issues (#376)
    
    * Cleaned up checkstyle and associated issues
    
    * Minor fixes
    
    * Remove redundant throws
    
    * Remove unused cfg reference
    
    * Prevent possible NPE
    
    * Remove unused boolean return value
    
    * Minor fixes
    
    * Simplify regex
    
    * Update MavenGenerator.java
    
    Removed unused var
    
    * Fix possible NPE if file cannot be read
    
    * Fix possible NPE if file cannot be read
    
    * Fix possible NPE if file cannot be read
    
    * Minor fix
    
    ---------
    
    Co-authored-by: P. Ottlinger <[email protected]>
---
 .../java/org/apache/rat/tools/AbstractOption.java  | 46 ++++++------
 .../org/apache/rat/tools/AntDocumentation.java     | 65 ++++-------------
 .../java/org/apache/rat/tools/AntGenerator.java    | 11 ++-
 .../main/java/org/apache/rat/tools/AntOption.java  |  6 +-
 .../java/org/apache/rat/tools/ArgumentTypes.java   |  4 +-
 .../java/org/apache/rat/tools/MavenGenerator.java  | 15 ++--
 .../java/org/apache/rat/tools/MavenOption.java     | 10 +--
 .../src/main/java/org/apache/rat/tools/Naming.java | 38 ++++++----
 .../org/apache/rat/tools/xsd/XsdGenerator.java     | 70 +++++++-----------
 .../java/org/apache/rat/tools/xsd/XsdWriter.java   | 85 +++++++++++++++++++---
 .../org/apache/rat/tools/xsd/package-info.java     | 21 ++++++
 src/changes/changes.xml                            |  3 +
 12 files changed, 210 insertions(+), 164 deletions(-)

diff --git 
a/apache-rat-tools/src/main/java/org/apache/rat/tools/AbstractOption.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/AbstractOption.java
index 66572d06..be42c95e 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/AbstractOption.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/AbstractOption.java
@@ -18,21 +18,21 @@
  */
 package org.apache.rat.tools;
 
-import org.apache.commons.cli.Option;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.rat.commandline.Arg;
-
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.commons.cli.Option;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.rat.commandline.Arg;
+
 import static java.lang.String.format;
 
 public abstract class AbstractOption {
     /** The pattern to match CLI options in text */
-    protected static final Pattern pattern = Pattern.compile( 
"\\-(\\-[a-z0-9]+){1,}");
+    protected static final Pattern PATTERN = Pattern.compile("-(-[a-z0-9]+)+");
     /** The CLI that the Maven option is wrapping */
     protected final Option option;
     /** The Maven name for the option */
@@ -57,35 +57,37 @@ public abstract class AbstractOption {
         return arg == null ? null : arg.defaultValue();
     }
 
-    abstract protected String cleanupName(final Option option);
+    protected abstract String cleanupName(Option option);
 
     /**
      * Replaces CLI pattern options with Maven pattern options.
      * @param str the string to clean.
      * @return the string with CLI names replaced with Maven names.
      */
-    protected String cleanup(String str) {
-        if (StringUtils.isNotBlank(str)) {
+    protected String cleanup(final String str) {
+        String workingStr = str;
+        if (StringUtils.isNotBlank(workingStr)) {
             Map<String, String> maps = new HashMap<>();
-            Matcher matcher = pattern.matcher(str);
+            Matcher matcher = PATTERN.matcher(workingStr);
             while (matcher.find()) {
                 String key = matcher.group();
                 String optKey = key.substring(2);
-                Optional<Option> maybeResult = 
Arg.getOptions().getOptions().stream().filter(o -> optKey.equals(o.getOpt()) || 
optKey.equals(o.getLongOpt())).findFirst();
+                Optional<Option> maybeResult = 
Arg.getOptions().getOptions().stream()
+                        .filter(o -> optKey.equals(o.getOpt()) || 
optKey.equals(o.getLongOpt())).findFirst();
                 maybeResult.ifPresent(value -> maps.put(key, 
cleanupName(value)));
             }
             for (Map.Entry<String, String> entry : maps.entrySet()) {
-                str = str.replaceAll(Pattern.quote(format("%s", 
entry.getKey())), entry.getValue());
+                workingStr = workingStr.replaceAll(Pattern.quote(format("%s", 
entry.getKey())), entry.getValue());
             }
         }
-        return str;
+        return workingStr;
     }
 
     /**
      * Gets the Maven name for the CLI option.
      * @return The Maven name for the CLI option.
      */
-    final public String getName() {
+    public final String getName() {
         return name;
     }
 
@@ -94,7 +96,7 @@ public abstract class AbstractOption {
      *
      * @return the description or an empty string.
      */
-    final public String getDescription() {
+    public final String getDescription() {
         return cleanup(option.getDescription());
     }
 
@@ -103,7 +105,7 @@ public abstract class AbstractOption {
      * Normally "String".
      * @return the simple class name for the type.
      */
-    final public Class<?> getType() {
+    public final Class<?> getType() {
         return option.hasArg() ? ((Class<?>) option.getType()) : boolean.class;
     }
 
@@ -111,7 +113,7 @@ public abstract class AbstractOption {
      * Gets the argument name if there is one.
      * @return the Argument name
      */
-    final public String getArgName() {
+    public final String getArgName() {
         return option.getArgName();
     }
 
@@ -119,7 +121,7 @@ public abstract class AbstractOption {
      * Determines if the option is deprecated.
      * @return {@code true} if the option is deprecated
      */
-    final public boolean isDeprecated() {
+    public final boolean isDeprecated() {
         return option.isDeprecated();
     }
 
@@ -127,7 +129,7 @@ public abstract class AbstractOption {
      * Determines if the option is required.
      * @return {@code true} if the option is required.
      */
-    final public boolean isRequired() {
+    public final boolean isRequired() {
         return option.isRequired();
     }
 
@@ -135,7 +137,7 @@ public abstract class AbstractOption {
      * Determine if the enclosed option expects an argument.
      * @return {@code true} if the enclosed option expects at least one 
argument.
      */
-    final public boolean hasArg() {
+    public final boolean hasArg() {
         return option.hasArg();
     }
 
@@ -143,7 +145,7 @@ public abstract class AbstractOption {
      * Returns {@code true} if the option has multiple arguments.
      * @return {@code true} if the option has multiple arguments.
      */
-    final public boolean hasArgs() {
+    public final boolean hasArgs() {
         return option.hasArgs();
     }
 
@@ -151,7 +153,7 @@ public abstract class AbstractOption {
      * The key value for the option.
      * @return the key value for the CLI argument map.
      */
-    final public String keyValue() {
+    public final String keyValue() {
         return format("\"%s\"", 
StringUtils.defaultIfEmpty(option.getLongOpt(), option.getOpt()));
     }
 
@@ -159,7 +161,7 @@ public abstract class AbstractOption {
      * Gets the deprecated string if the option is deprecated, or an empty 
string otherwise.
      * @return the deprecated string if the option is deprecated, or an empty 
string otherwise.
      */
-    final public String getDeprecated() {
+    public final String getDeprecated() {
         return  option.isDeprecated() ? 
cleanup(StringUtils.defaultIfEmpty(option.getDeprecated().toString(), 
StringUtils.EMPTY)) : StringUtils.EMPTY;
     }
 }
diff --git 
a/apache-rat-tools/src/main/java/org/apache/rat/tools/AntDocumentation.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/AntDocumentation.java
index 1330b493..1e1cb6fd 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/AntDocumentation.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/AntDocumentation.java
@@ -19,6 +19,7 @@
 package org.apache.rat.tools;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
@@ -34,19 +35,11 @@ import java.util.function.Predicate;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.DefaultParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
+
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.rat.ConfigurationException;
-import org.apache.rat.DeprecationReporter;
 import org.apache.rat.OptionCollection;
-import org.apache.rat.ReportConfiguration;
 import org.apache.rat.commandline.Arg;
-import org.apache.rat.help.AbstractHelp;
 import org.apache.rat.utils.DefaultLog;
 
 import static java.lang.String.format;
@@ -55,8 +48,6 @@ import static java.lang.String.format;
  * A simple tool to convert CLI options into an Ant report base class.
  */
 public final class AntDocumentation {
-
-    private final ReportConfiguration config;
     /** The directory to write to. */
     private final File outputDir;
 
@@ -70,64 +61,31 @@ public final class AntDocumentation {
      * @throws IOException on error
      */
     public static void main(final String[] args) throws IOException {
-        // process the command line to get the output directory.
-        Options opts = OptionCollection.buildOptions();
-        CommandLine commandLine;
-        try {
-            commandLine = 
DefaultParser.builder().setDeprecatedHandler(DeprecationReporter.getLogReporter())
-                    .setAllowPartialMatching(true).build().parse(opts, args);
-        } catch (ParseException e) {
-            DefaultLog.getInstance().error(e.getMessage());
-            DefaultLog.getInstance().error("Please use the \"--help\" option 
to see a list of valid commands and options", e);
-            throw new ConfigurationException(e);
-        }
 
-        String[] remainingArgs = commandLine.getArgs();
-        if (remainingArgs.length == 0) {
+        if (args.length == 0) {
             System.err.println("Output directory must be specified");
-            printUsage(opts);
             System.exit(1);
         }
-        File outputDir = new File(remainingArgs[0]);
+        File outputDir = new File(args[0]);
         if (outputDir.exists()) {
             if (!outputDir.isDirectory()) {
-                DefaultLog.getInstance().error(format("%s is not a directory", 
remainingArgs[0]));
+                DefaultLog.getInstance().error(format("%s is not a directory", 
args[0]));
                 System.exit(1);
             }
         } else {
             if (!outputDir.mkdirs()) {
-                DefaultLog.getInstance().error(format("Can not create 
directory %s", remainingArgs[0]));
+                DefaultLog.getInstance().error(format("Can not create 
directory %s", args[0]));
                 System.exit(1);
             }
         }
-        // remove any excess arguments and create the configuration.
-        List<String> argsList = new ArrayList<>(Arrays.asList(args));
-        argsList.removeAll(Arrays.asList(remainingArgs));
-
-        ReportConfiguration config = 
OptionCollection.parseCommands(argsList.toArray(new String[0]), 
AntDocumentation::printUsage, true);
-        if (config != null) {
-            new AntDocumentation(config, outputDir).execute();
-        }
-    }
-
-    private static void printUsage(final Options opts) {
-        HelpFormatter f = new HelpFormatter();
-        f.setOptionComparator(OptionCollection.OPTION_COMPARATOR);
-        f.setWidth(AbstractHelp.HELP_WIDTH);
-        String header = "\nAvailable options";
-        String footer = "";
-        String cmdLine = format("java -jar 
apache-rat/target/apache-rat-CURRENT-VERSION.jar %s",
-                AntDocumentation.class.getName());
-        f.printHelp(cmdLine, header, opts, footer, false);
-        System.exit(0);
+        new AntDocumentation(outputDir).execute();
     }
 
-   private AntDocumentation(final ReportConfiguration config, final File 
outputDir) {
-        this.config = config;
+   private AntDocumentation(final File outputDir) {
         this.outputDir = outputDir;
     }
 
-    public void execute() throws IOException {
+    public void execute() {
         List<AntOption> options = 
Arg.getOptions().getOptions().stream().filter(AntGenerator.getFilter()).map(AntOption::new)
                 .collect(Collectors.toList());
 
@@ -214,12 +172,15 @@ public final class AntDocumentation {
     private static class AptFormat  {
 
         /**
-         * copy the "license.apt" from the resources to the writer.
+         * Copy the "license.apt" from the resources to the writer.
          * @param writer the writer to write to.
          * @throws IOException on error.
          */
         public static void writeLicense(final Writer writer) throws 
IOException {
             try (InputStream in = 
AntDocumentation.class.getResourceAsStream("/license.apt")) {
+                if(in == null) {
+                    throw new FileNotFoundException("Could not find 
license.apt");
+                }
                 IOUtils.copy(in, writer, StandardCharsets.UTF_8);
             }
         }
diff --git 
a/apache-rat-tools/src/main/java/org/apache/rat/tools/AntGenerator.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/AntGenerator.java
index 2fb8cf3a..becd09b7 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/AntGenerator.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/AntGenerator.java
@@ -18,8 +18,6 @@
  */
 package org.apache.rat.tools;
 
-import static java.lang.String.format;
-
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileWriter;
@@ -47,6 +45,8 @@ import org.apache.rat.commandline.Arg;
 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 into an Ant report base class.
  */
@@ -93,10 +93,10 @@ public final class AntGenerator {
      *     <li>the directory in which to write the class file.</li>
      * </ol>
      * @param args the arguments.
-     * @throws IOException on error
+     * @throws IOException on error.
      */
     public static void main(final String[] args) throws IOException {
-        if(args == null || args.length < 3) {
+        if (args == null || args.length < 3) {
             System.err.println("At least three arguments are required: 
package, simple class name, target directory.");
             return;
         }
@@ -149,6 +149,9 @@ public final class AntGenerator {
                         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;
diff --git a/apache-rat-tools/src/main/java/org/apache/rat/tools/AntOption.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/AntOption.java
index 92b66163..41b31320 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/AntOption.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/AntOption.java
@@ -18,16 +18,16 @@
  */
 package org.apache.rat.tools;
 
-import static java.lang.String.format;
-
 import org.apache.commons.cli.Option;
 import org.apache.commons.text.StringEscapeUtils;
 import org.apache.commons.text.WordUtils;
 
+import static java.lang.String.format;
+
 /**
  * A class that wraps the CLI option and provides Ant specific values.
  */
-public class AntOption extends AbstractOption{
+public class AntOption extends AbstractOption {
 
     /**
      * Constructor.
diff --git 
a/apache-rat-tools/src/main/java/org/apache/rat/tools/ArgumentTypes.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/ArgumentTypes.java
index cb837a8c..21d6aa31 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/ArgumentTypes.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/ArgumentTypes.java
@@ -18,13 +18,13 @@
  */
 package org.apache.rat.tools;
 
-import org.apache.rat.help.Help;
-
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
 
+import org.apache.rat.help.Help;
+
 /**
  * A simple tool to convert CLI options to Maven and Ant format and produce a 
CSV file.
  * <br>
diff --git 
a/apache-rat-tools/src/main/java/org/apache/rat/tools/MavenGenerator.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/MavenGenerator.java
index 1d61e077..b2cd8655 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/MavenGenerator.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/MavenGenerator.java
@@ -18,8 +18,6 @@
  */
 package org.apache.rat.tools;
 
-import static java.lang.String.format;
-
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -46,6 +44,8 @@ import org.apache.rat.commandline.Arg;
 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 Maven Mojo base class
  */
@@ -94,7 +94,7 @@ public final class MavenGenerator {
      * @throws IOException on error
      */
     public static void main(final String[] args) throws IOException {
-        if(args == null || args.length < 3) {
+        if (args == null || args.length < 3) {
             System.err.println("At least three arguments are required: 
package, simple class name, target directory.");
             return;
         }
@@ -139,6 +139,9 @@ public final class MavenGenerator {
                         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;
@@ -158,10 +161,10 @@ public final class MavenGenerator {
         if (!desc.contains(".")) {
             throw new IllegalStateException(format("First sentence of 
description for %s must end with a '.'", option.getName()));
         }
-        String arg = null;
+        String arg;
         if (option.hasArg()) {
             arg = desc.substring(desc.indexOf(" "), desc.indexOf(".") + 1);
-            arg = WordUtils.capitalize(arg.substring(0,1)) + arg.substring(1);
+            arg = WordUtils.capitalize(arg.substring(0, 1)) + arg.substring(1);
         } else {
             arg = "the state";
         }
@@ -170,8 +173,6 @@ public final class MavenGenerator {
             if (sup == null) {
                 throw new IllegalStateException(format("Argument type %s must 
be in OptionCollection.ARGUMENT_TYPES", option.getArgName()));
             }
-            String typeDesc = sup.get();
-            typeDesc = WordUtils.uncapitalize(typeDesc.substring(0,1)) + 
typeDesc.substring(1);
             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-tools/src/main/java/org/apache/rat/tools/MavenOption.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/MavenOption.java
index 60681df7..1ae6e5cc 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/MavenOption.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/MavenOption.java
@@ -18,22 +18,22 @@
  */
 package org.apache.rat.tools;
 
-import static java.lang.String.format;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.commons.cli.Option;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.WordUtils;
 import org.apache.rat.commandline.Arg;
 
-import java.util.HashMap;
-import java.util.Map;
+import static java.lang.String.format;
 
 /**
  * A representation of a CLI option as a Maven option
  */
 public class MavenOption extends AbstractOption {
-
-    private static final Map<Arg,String> DEFAULT_VALUES = new HashMap<>();
+    /** Default values for CLI options */
+    private static final Map<Arg, String> DEFAULT_VALUES = new HashMap<>();
 
     static {
         DEFAULT_VALUES.put(Arg.OUTPUT_FILE, 
"${project.build.directory}/rat.txt");
diff --git a/apache-rat-tools/src/main/java/org/apache/rat/tools/Naming.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/Naming.java
index 6eeac4b4..b5bff5c2 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/Naming.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/Naming.java
@@ -18,8 +18,6 @@
  */
 package org.apache.rat.tools;
 
-import static java.lang.String.format;
-
 import java.io.CharArrayWriter;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -47,6 +45,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.rat.OptionCollection;
 import org.apache.rat.help.AbstractHelp;
 
+import static java.lang.String.format;
+
 /**
  * A simple tool to convert CLI options to Maven and Ant format and produce a 
CSV file.
  * <br>
@@ -54,27 +54,33 @@ import org.apache.rat.help.AbstractHelp;
  * <ul>
  *     <li>--ant   Produces Ant options in result</li>
  *     <li>--maven Produces Maven options in result</li>
- *     <li>--csv   Produces CSV output text is produced</li>
+ *     <li>--csv   Produces CSV output text</li>
  * </ul>
  * Note: if neither --ant nor --maven are included both will be listed.
  */
 public final class Naming {
 
     private Naming() { }
-
+    /** The maximum width of the output. */
     private static final Option WIDTH = 
Option.builder().longOpt("width").type(Integer.class)
             .desc("Set the display width of the output").hasArg().build();
+    /** Option to output Maven names. */
     private static final Option MAVEN = 
Option.builder().longOpt("maven").desc("Produce Maven name mapping").build();
+    /** Option to output Ant names. */
     private static final Option ANT = 
Option.builder().longOpt("ant").desc("Produce Ant name mapping").build();
+    /** Option to output CSV format. */
     private static final Option CSV = 
Option.builder().longOpt("csv").desc("Produce CSV format").build();
+    /** Options to output cli names. */
     private static final Option CLI = 
Option.builder().longOpt("cli").desc("Produce CLI name mapping").build();
+    /** Option for including deprecated options. */
     private static final Option INCLUDE_DEPRECATED = 
Option.builder().longOpt("include-deprecated")
             .desc("Include deprecated options.").build();
-
+    /** The all option. */
     private static final Options OPTIONS = new 
Options().addOption(MAVEN).addOption(ANT).addOption(CLI)
             .addOption(CSV)
             .addOption(INCLUDE_DEPRECATED)
             .addOption(WIDTH);
+
     /**
      * Creates the CSV file.
      * Requires 1 argument:
@@ -85,7 +91,7 @@ public final class Naming {
      * @param args arguments, only 1 is required.
      */
     public static void main(final String[] args) throws IOException, 
ParseException {
-        if(args == null || args.length < 1) {
+        if (args == null || args.length < 1) {
             System.err.println("At least one argument is required: path to 
file is missing.");
             return;
         }
@@ -116,7 +122,7 @@ public final class Naming {
 
         Function<Option, String> descriptionFunction;
 
-        if (cl.hasOption(CLI) || (antFilter != null && mavenFilter != null)) {
+        if (cl.hasOption(CLI) || antFilter != null && mavenFilter != null) {
             descriptionFunction = o -> {
                 StringBuilder desc = new StringBuilder();
             if (o.isDeprecated()) {
@@ -154,8 +160,8 @@ public final class Naming {
         }
     }
 
-    private static List<String> fillColumns(List<String> columns, Option 
option, boolean addCLI, Predicate<Option> mavenFilter,
-                                            Predicate<Option> antFilter, 
Function<Option, String> descriptionFunction) {
+    private static List<String> fillColumns(final List<String> columns, final 
Option option, final boolean addCLI, final Predicate<Option> mavenFilter,
+                                            final Predicate<Option> antFilter, 
final Function<Option, String> descriptionFunction) {
         if (addCLI) {
             if (option.hasLongOpt()) {
                 columns.add("--" + option.getLongOpt());
@@ -177,8 +183,9 @@ public final class Naming {
         return columns;
     }
 
-    private static void printCSV(List<String> columns, Predicate<Option> 
filter, boolean addCLI, Predicate<Option> mavenFilter,
-                                 Predicate<Option> antFilter, Function<Option, 
String> descriptionFunction, Writer underWriter) throws IOException {
+    private static void printCSV(final List<String> columns, final 
Predicate<Option> filter, final boolean addCLI, final Predicate<Option> 
mavenFilter,
+                                 final Predicate<Option> antFilter, final 
Function<Option, String> descriptionFunction,
+                                 final Writer underWriter) throws IOException {
         try (CSVPrinter printer = new CSVPrinter(underWriter, 
CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.ALL).build())) {
             printer.printRecord(columns);
             for (Option option : OptionCollection.buildOptions().getOptions()) 
{
@@ -190,7 +197,7 @@ public final class Naming {
         }
     }
 
-    private static int[] calculateColumnWidth(int width, int columnCount, 
List<List<String>> page) {
+    private static int[] calculateColumnWidth(final int width, final int 
columnCount, final List<List<String>> page) {
         int[] columnWidth = new int[columnCount];
         for (List<String> row : page) {
             for (int i = 0; i < columnCount; i++) {
@@ -198,7 +205,7 @@ public final class Naming {
             }
         }
         int extra = 0;
-        int averageWidth = (width - ((columnCount-1) * 2)) / columnCount;
+        int averageWidth = (width - ((columnCount - 1) * 2)) / columnCount;
         int[] overage = new int[columnCount];
         int totalOverage = 0;
         for (int i = 0; i < columnCount; i++) {
@@ -219,8 +226,9 @@ public final class Naming {
         return columnWidth;
     }
 
-    private static void printText(List<String> columns, Predicate<Option> 
filter, boolean addCLI, Predicate<Option> mavenFilter,
-                                  Predicate<Option> antFilter, 
Function<Option, String> descriptionFunction, Writer underWriter, int width) 
throws IOException {
+    private static void printText(final List<String> columns, final 
Predicate<Option> filter, final boolean addCLI,
+                                  final Predicate<Option> mavenFilter, final 
Predicate<Option> antFilter,
+                                  final Function<Option, String> 
descriptionFunction, final Writer underWriter, final int width) throws 
IOException {
         List<List<String>> page = new ArrayList<>();
 
         int columnCount = columns.size();
diff --git 
a/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdGenerator.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdGenerator.java
index e6ecddf2..f9820bfa 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdGenerator.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdGenerator.java
@@ -18,16 +18,6 @@
  */
 package org.apache.rat.tools.xsd;
 
-import org.apache.rat.OptionCollection;
-import org.apache.rat.ReportConfiguration;
-import org.apache.rat.commandline.StyleSheets;
-import org.apache.rat.config.parameters.ComponentType;
-import org.apache.rat.config.parameters.Description;
-import org.apache.rat.config.parameters.DescriptionBuilder;
-import org.apache.rat.configuration.MatcherBuilderTracker;
-import org.apache.rat.configuration.XMLConfig;
-import org.apache.rat.license.SimpleLicense;
-
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -40,8 +30,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.rat.tools.xsd.XsdWriter.Type;
-
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
@@ -49,21 +37,28 @@ import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.rat.commandline.StyleSheets;
+import org.apache.rat.config.parameters.ComponentType;
+import org.apache.rat.config.parameters.Description;
+import org.apache.rat.config.parameters.DescriptionBuilder;
+import org.apache.rat.configuration.MatcherBuilderTracker;
+import org.apache.rat.configuration.XMLConfig;
+import org.apache.rat.license.SimpleLicense;
+import org.apache.rat.tools.xsd.XsdWriter.Type;
+
 /**
  * Generates the XSD for a configuration.
  */
 public class XsdGenerator {
-    /** The configuration to generate the XSD for. */
-    private final ReportConfiguration cfg;
     /** The XsdWriter being written to. */
     private XsdWriter writer;
     /** A map of component type to XML element name / property type */
-    private static final Map<ComponentType, String> typeMap = new HashMap<>();
+    private static final Map<ComponentType, String> TYPE_MAP = new HashMap<>();
 
     static {
-        typeMap.put(ComponentType.MATCHER, XMLConfig.MATCHER);
-        typeMap.put(ComponentType.PARAMETER, "xs:string");
-        typeMap.put(ComponentType.LICENSE, XMLConfig.LICENSE);
+        TYPE_MAP.put(ComponentType.MATCHER, XMLConfig.MATCHER);
+        TYPE_MAP.put(ComponentType.PARAMETER, "xs:string");
+        TYPE_MAP.put(ComponentType.LICENSE, XMLConfig.LICENSE);
     }
 
     /**
@@ -73,10 +68,8 @@ public class XsdGenerator {
      * @throws IOException on IO errors.
      * @throws TransformerException if the XSD can not be pretty printed.
      */
-    public static void main(String[] args) throws IOException, 
TransformerException {
-        ReportConfiguration configuration = 
OptionCollection.parseCommands(args, (options) -> {
-        });
-        XsdGenerator generator = new XsdGenerator(configuration);
+    public static void main(final String[] args) throws IOException, 
TransformerException {
+        XsdGenerator generator = new XsdGenerator();
 
         TransformerFactory tf = TransformerFactory.newInstance();
         Transformer transformer;
@@ -93,14 +86,6 @@ public class XsdGenerator {
         }
     }
 
-    /**
-     * Constructs an XsdGenerator for the structures in the configuration.
-     * @param cfg the configuration to generate the XSD for.
-     */
-    public XsdGenerator(ReportConfiguration cfg) {
-        this.cfg = cfg;
-    }
-
     /**
      * Create an input stream from the output of the generator.
      * @return an InputStream that contains the output of the generator.
@@ -151,12 +136,15 @@ public class XsdGenerator {
         Description desc = DescriptionBuilder.buildMap(SimpleLicense.class);
         List<Description> children = new ArrayList<>();
         List<Description> attributes = new ArrayList<>();
-        for (Description child : desc.getChildren().values()) {
-            if (XMLConfig.isLicenseChild(child.getCommonName())) {
-                children.add(child);
-            } else {
-                if (child.getType() == ComponentType.PARAMETER) {
-                    attributes.add(child);
+
+        if(desc != null && desc.getChildren() != null) {
+            for (Description child : desc.getChildren().values()) {
+                if (XMLConfig.isLicenseChild(child.getCommonName())) {
+                    children.add(child);
+                } else {
+                    if (child.getType() == ComponentType.PARAMETER) {
+                        attributes.add(child);
+                    }
                 }
             }
         }
@@ -236,8 +224,8 @@ public class XsdGenerator {
         }
     }
 
-    private boolean element(Description desc) throws IOException {
-        String typeName = typeMap.get(desc.getType());
+    private void element(final Description desc) throws IOException {
+        String typeName = TYPE_MAP.get(desc.getType());
         if (typeName != null) {
             writer.open(Type.ELEMENT,
                     "name", desc.getCommonName(),
@@ -245,13 +233,11 @@ public class XsdGenerator {
                     "minOccurs", desc.isRequired() ? "1" : "0",
                     "maxOccurs", desc.isCollection() ? "unbounded" : "1"
                     ).close(Type.ELEMENT);
-            return true;
         }
-        return false;
     }
 
-    private void attribute(Description attr) throws IOException {
-        if(attr.getType() == ComponentType.PARAMETER) {
+    private void attribute(final Description attr) throws IOException {
+        if (attr.getType() == ComponentType.PARAMETER) {
             writer.attribute(attr.getCommonName(), "form", "unqualified", 
"use", attr.isRequired() ? "required" : "optional");
         }
     }
diff --git 
a/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdWriter.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdWriter.java
index a8f669e9..f032284b 100644
--- a/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdWriter.java
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/XsdWriter.java
@@ -18,29 +18,62 @@
  */
 package org.apache.rat.tools.xsd;
 
-import org.apache.rat.report.xml.writer.impl.base.XmlWriter;
-
 import java.io.IOException;
 import java.io.Writer;
 
+import org.apache.rat.report.xml.writer.impl.base.XmlWriter;
+
+/**
+ * A writer that writes XSD nodes.
+ */
 public class XsdWriter {
+    /** The XML Writer that this writer uses */
     private final XmlWriter writer;
 
+    /** Types of elements in the XSD */
     public enum Type {
-        ELEMENT("xs:element"), ATTRIBUTE("xs:attribute"),
-        COMPLEX("xs:complexType"), SEQUENCE("xs:sequence"), 
SIMPLE("xs:simpleContent"),
-        EXTENSION("xs:extension"), CHOICE("xs:choice"), 
COMPLEX_CONTENT("xs:complexContent");
+        /** An element */
+        ELEMENT("xs:element"),
+        /** An attribute */
+        ATTRIBUTE("xs:attribute"),
+        /** A complex type */
+        COMPLEX("xs:complexType"),
+        /** A sequence */
+        SEQUENCE("xs:sequence"),
+        /** A simple type */
+        SIMPLE("xs:simpleContent"),
+        /** An extension */
+        EXTENSION("xs:extension"),
+        /** A choice */
+        CHOICE("xs:choice"),
+        /** A complex type */
+        COMPLEX_CONTENT("xs:complexContent");
+        /** The element name associated with the type */
         private final String elementName;
 
-        Type(String name) {
+        /**
+         * Type constructor.
+         *
+         * @param name The element name associated with the type.
+         */
+        Type(final String name) {
             elementName = name;
         }
     }
 
-    public XsdWriter(Writer writer) {
+    /**
+     * Creates an XSD writer that wraps a standard Writer.
+     * @param writer the writer to wrap.
+     */
+    public XsdWriter(final Writer writer) {
         this.writer = new XmlWriter(writer);
     }
 
+    /**
+     * Initializes the writer. Writes the initial "xs:schema tag" .
+     * @return the Writer.
+     * @throws IOException on error.
+     */
     public XsdWriter init() throws IOException {
         writer.startDocument()
         .openElement("xs:schema")
@@ -49,11 +82,20 @@ public class XsdWriter {
         return this;
     }
 
+    /**
+     * Finishes the process. Closes the document.
+     * @throws IOException on error.
+     */
     public void finish() throws IOException {
         writer.closeDocument();
     }
 
-    private void writeAttributes(String[] attributeMap) throws IOException {
+    /**
+     * Writes an attribute map, each pair of items in the string list are 
considered attribute name and value.
+     * @param attributeMap the array of attribute names and values.
+     * @throws IOException on error.
+     */
+    private void writeAttributes(final String[] attributeMap) throws 
IOException {
         if (attributeMap != null) {
             for (int i = 0; i < attributeMap.length; i += 2) {
                 writer.attribute(attributeMap[i], attributeMap[i + 1]);
@@ -61,22 +103,41 @@ public class XsdWriter {
         }
     }
 
-    public XsdWriter open(Type type, String... attributeMap) throws 
IOException {
+    /**
+     * Opens (Starts) an element of the specified type along with its 
attributes.
+     * @param type the Type to start.
+     * @param attributeMap the attributes for the element.
+     * @return this.
+     * @throws IOException on error.
+     */
+    public XsdWriter open(final Type type, final String... attributeMap) 
throws IOException {
         writer.openElement(type.elementName);
         writeAttributes(attributeMap);
         return this;
     }
 
-    public XsdWriter attribute(String name, String... attributeMap) throws 
IOException {
+    /**
+     * Writes the attributes
+     * @param name The name of the attribute.
+     * @param attributeMap the attributes of the attribute.
+     * @return this.
+     * @throws IOException on error.
+     */
+    public XsdWriter attribute(final String name, final String... 
attributeMap) throws IOException {
         writer.openElement("xs:attribute").attribute("name", name);
         writeAttributes(attributeMap);
         writer.closeElement();
         return this;
     }
 
-    public XsdWriter close(Type type) throws IOException {
+    /**
+     * Closes (Ends) the element for the type.
+     * @param type The type to close.
+     * @return this.
+     * @throws IOException on error
+     */
+    public XsdWriter close(final Type type) throws IOException {
         writer.closeElement(type.elementName);
         return this;
     }
-
 }
diff --git 
a/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/package-info.java 
b/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/package-info.java
new file mode 100644
index 00000000..53286186
--- /dev/null
+++ b/apache-rat-tools/src/main/java/org/apache/rat/tools/xsd/package-info.java
@@ -0,0 +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.
+*/
+
+/**
+* Contains XSD file generation tools.
+*/
+package org.apache.rat.tools.xsd;
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2863f139..c75c6afe 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -72,6 +72,9 @@ The <action> type attribute can be one of:
     </release>
     -->
     <release version="0.17-SNAPSHOT" date="xxxx-yy-zz" description="Current 
SNAPSHOT - release to be done">
+      <action issue="RAT-438" type="fix" dev="claudenw">
+        Fix checkstyle issues in tools module.
+      </action>
       <action issue="RAT-422" type="fix" dev="claudenw">
         Fix checkstyle issues in configuration.
       </action>


Reply via email to