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 7aa4ff63 RAT-422:  checkstyle fixes for configuration (#366)
7aa4ff63 is described below

commit 7aa4ff63fbee46891402d2cf5563bd42d927d42e
Author: Claude Warren <[email protected]>
AuthorDate: Wed Oct 30 18:23:20 2024 +0000

    RAT-422:  checkstyle fixes for configuration (#366)
    
    * fixed checkstyle issues
    
    * reinstated missing reflection called method
    
    * Added test to verify that inspection invoked methods exist
    
    * update javadoc
    
    * Add missing javadoc
    
    * Minor fixes
    
    * Fix typo
    
    * Updated tests for annotated BUILD_PARAMETERS
    
    * fixed unused variables issue
    
    ---------
    
    Co-authored-by: P. Ottlinger <[email protected]>
    Co-authored-by: P. Ottlinger <[email protected]>
---
 .../rat/analysis/matchers/SimpleRegexMatcher.java  |  7 +-
 .../apache/rat/config/parameters/Description.java  |  1 -
 .../rat/config/parameters/DescriptionBuilder.java  |  4 +-
 .../org/apache/rat/configuration/XMLConfig.java    | 48 +++++------
 .../rat/configuration/XMLConfigurationReader.java  | 18 ++---
 .../configuration/builders/MatcherRefBuilder.java  |  9 +++
 .../config/parameters/DescriptionBuilderTest.java  | 93 +++++++++++++++++++++-
 .../configuration/builders/RegexBuilderTest.java   |  4 +-
 src/changes/changes.xml                            |  3 +
 9 files changed, 147 insertions(+), 40 deletions(-)

diff --git 
a/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SimpleRegexMatcher.java
 
b/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SimpleRegexMatcher.java
index a7002e42..64fe61cf 100644
--- 
a/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SimpleRegexMatcher.java
+++ 
b/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SimpleRegexMatcher.java
@@ -48,7 +48,12 @@ public class SimpleRegexMatcher extends 
AbstractHeaderMatcher {
         this.pattern = pattern;
     }
 
-    public String getPattern() {
+    /**
+     * Gets the expression of the underlying matching pattern.
+     * @return the underlying pattern's construction expression.
+     */
+    public String getExpression() {
+        // called by reflection
         return pattern.pattern();
     }
 
diff --git 
a/apache-rat-core/src/main/java/org/apache/rat/config/parameters/Description.java
 
b/apache-rat-core/src/main/java/org/apache/rat/config/parameters/Description.java
index 9b1b302e..c5524971 100644
--- 
a/apache-rat-core/src/main/java/org/apache/rat/config/parameters/Description.java
+++ 
b/apache-rat-core/src/main/java/org/apache/rat/config/parameters/Description.java
@@ -20,7 +20,6 @@ package org.apache.rat.config.parameters;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Map;
 import java.util.TreeMap;
diff --git 
a/apache-rat-core/src/main/java/org/apache/rat/config/parameters/DescriptionBuilder.java
 
b/apache-rat-core/src/main/java/org/apache/rat/config/parameters/DescriptionBuilder.java
index d8dee5a4..52d16b63 100644
--- 
a/apache-rat-core/src/main/java/org/apache/rat/config/parameters/DescriptionBuilder.java
+++ 
b/apache-rat-core/src/main/java/org/apache/rat/config/parameters/DescriptionBuilder.java
@@ -78,7 +78,7 @@ public final class DescriptionBuilder {
      * @param clazz source class.
      * @return the Descriptions of the child elements.
      */
-    private static List<Description> getConfigComponents(final Class<?> clazz) 
{
+    static List<Description> getConfigComponents(final Class<?> clazz) {
         if (clazz == null || clazz == String.class || clazz == Object.class) {
             return Collections.emptyList();
         }
@@ -131,7 +131,7 @@ public final class DescriptionBuilder {
                 return matcherBuilder.value();
             }
         } catch (NoSuchMethodException | SecurityException e) {
-            throw new IllegalStateException("the 'build' method of the Builder 
interface must always be public");
+            throw new IllegalStateException("The 'build' method of the Builder 
interface must always be public");
         }
     }
 
diff --git 
a/apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfig.java 
b/apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfig.java
index e55516e0..136a87b4 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfig.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfig.java
@@ -23,44 +23,44 @@ import java.util.Arrays;
 /**
  * Configuration definitions for XMLConfiguration reader and writer.
  */
-public class XMLConfig {
+public final class XMLConfig {
 
     /** id attribute name */
-    public final static String ATT_ID = "id";
+    public static final String ATT_ID = "id";
     /** name attribute name */
-    public final static String ATT_NAME = "name";
+    public static final String ATT_NAME = "name";
     /** license reference attribute name */
-    public final static String ATT_LICENSE_REF = "license_ref";
+    public static final String ATT_LICENSE_REF = "license_ref";
     /** class name attribute name */
-    public final static String ATT_CLASS_NAME = "class";
+    public static final String ATT_CLASS_NAME = "class";
     /** resource file name attribute name. */
-    public final static String ATT_RESOURCE = "resource";
+    public static final String ATT_RESOURCE = "resource";
     /** root of the configuration file */
-    public final static String ROOT = "rat-config";
+    public static final String ROOT = "rat-config";
     /** families element name */
-    public final static String FAMILIES = "families";
+    public static final String FAMILIES = "families";
     /** licenses element name */
-    public final static String LICENSES = "licenses";
+    public static final String LICENSES = "licenses";
     /** license element name */
-    public final static String LICENSE = "license";
+    public static final String LICENSE = "license";
     /** approved element name */
-    public final static String APPROVED = "approved";
+    public static final String APPROVED = "approved";
     /** family element name */
-    public final static String FAMILY = "family";
+    public static final String FAMILY = "family";
     /** note element name */
-    public final static String NOTE = "note";
+    public static final String NOTE = "note";
     /** matchers element name */
-    public final static String MATCHERS = "matchers";
+    public static final String MATCHERS = "matchers";
     /** matcher element name */
-    public final static String MATCHER = "matcher";
+    public static final String MATCHER = "matcher";
 
     /** License property names that should be children */
-    static final String[] LICENSE_CHILDREN = { "note", "matcher" };
+    static final String[] LICENSE_CHILDREN = { NOTE, MATCHER };
     /**
      * License property names that should not be displayed contents should be 
placed
      * inline
      */
-    static final String[] LICENSE_INLINE = { "matcher" };
+    static final String[] LICENSE_INLINE = { MATCHER };
 
     /**
      * Matcher properties that should be directly inlined Entries are matcher 
node
@@ -77,33 +77,33 @@ public class XMLConfig {
     /**
      * Returns true if the specified child node should be placed inline in the 
XML
      * document.
-     * 
+     *
      * @param parent the parent node name.
      * @param child the child node name.
      * @return true if the child should be inlined.
      */
-    public static boolean isInlineNode(String parent, String child) {
+    public static boolean isInlineNode(final String parent, final String 
child) {
         return Arrays.stream(INLINE_NODES).anyMatch(s -> s[0].equals(parent) 
&& s[1].equals(child));
     }
 
     /**
      * Returns true if the child should be a child node of a license node, as
      * opposed to a attribute of the license.
-     * 
+     *
      * @param child the name of the child node.
      * @return true if the child should be a child node.
      */
-    public static boolean isLicenseChild(String child) {
+    public static boolean isLicenseChild(final String child) {
         return Arrays.asList(LICENSE_CHILDREN).contains(child);
     }
 
     /**
      * Return true if the child should be inlined in the parent node.
-     * 
+     *
      * @param child the name of the child node.
      * @return true if the child should be inlined.
      */
-    public static boolean isLicenseInline(String child) {
+    public static boolean isLicenseInline(final String child) {
         return Arrays.asList(LICENSE_INLINE).contains(child);
     }
-}
\ No newline at end of file
+}
diff --git 
a/apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfigurationReader.java
 
b/apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfigurationReader.java
index 425ddebe..6b6cc990 100644
--- 
a/apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfigurationReader.java
+++ 
b/apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfigurationReader.java
@@ -73,7 +73,7 @@ public final class XMLConfigurationReader implements 
LicenseReader, MatcherReade
     private final Element rootElement;
     /** The families element in the document */
     private final Element familiesElement;
-    /** The licenses element in the doucment */
+    /** The licenses element in the document */
     private final Element licensesElement;
     /** The approved element in the document */
     private final Element approvedElement;
@@ -171,7 +171,7 @@ public final class XMLConfigurationReader implements 
LicenseReader, MatcherReade
     }
 
     /**
-     * Applies the {@code consumer} to each node in the {@code list}.  
Generally used for extracting info from a
+     * Applies the {@code consumer} to each node in the {@code list}. 
Generally used for extracting info from a
      * {@code NodeList}.
      * @param list the NodeList to process
      * @param consumer the consumer to apply to each node in the list.
@@ -302,7 +302,7 @@ public final class XMLConfigurationReader implements 
LicenseReader, MatcherReade
      * Sets the value of the element described by the description in the 
builder with the value from childDescription.
      * @param description the property in the builder to set.
      * @param childDescription the description of the child property to 
extract.
-     * @param builder the bulider to set the value in.
+     * @param builder the builder to set the value in.
      * @param child the child to extract the value from.
      */
     private void setValue(final Description description, final Description 
childDescription, final IHeaderMatcher.Builder builder,
@@ -315,12 +315,12 @@ public final class XMLConfigurationReader implements 
LicenseReader, MatcherReade
     }
 
     /**
-     * Process the ELEEMENT_NODEs children of the parent whose names match 
child
-     * descriptions. All children children are processed with the 
childProcessor. If
+     * Process the ELEMENT_NODEs children of the parent whose names match child
+     * descriptions. All children of children are processed with the 
childProcessor. If
      * the childProcessor handles the node it is not included in the resulting 
list.
      * @param description the Description of the parent node.
      * @param parent the node being processed
-     * @param childProcessor the BiProcessor to handle process each child. if 
the
+     * @param childProcessor the BiProcessor to handle process each child. If 
the
      * processor handles the child it must return {@code true}.
      * @return A Pair comprising a boolean flag indicating children were 
found, and
      * a list of all child nodes that were not processed by the childProcessor.
@@ -376,7 +376,7 @@ public final class XMLConfigurationReader implements 
LicenseReader, MatcherReade
 
             for (Description childDescription : childDescriptions) {
                 if (XMLConfig.isInlineNode(description.getCommonName(), 
childDescription.getCommonName())) {
-                    // can only process text inline if there were not child 
nodes.
+                    // can only process text inline if there were no child 
nodes.
                     if (childDescription.getChildType() == String.class) {
                         if (!foundChildren) {
                             callSetter(childDescription, builder, 
matcherNode.getTextContent());
@@ -588,8 +588,8 @@ public final class XMLConfigurationReader implements 
LicenseReader, MatcherReade
         /** The builder we are delegating to */
         private final AbstractBuilder delegate;
         /**
-         * The map of matchers that the system is building during processing.  
We will utilize this to set the
-         * matcher value later.
+         * The map of matchers that the system is building during processing.
+         * We will utilize this to set the matcher value later.
          */
         private final Map<String, IHeaderMatcher> matchers;
 
diff --git 
a/apache-rat-core/src/main/java/org/apache/rat/configuration/builders/MatcherRefBuilder.java
 
b/apache-rat-core/src/main/java/org/apache/rat/configuration/builders/MatcherRefBuilder.java
index 7c52121e..68598d4c 100644
--- 
a/apache-rat-core/src/main/java/org/apache/rat/configuration/builders/MatcherRefBuilder.java
+++ 
b/apache-rat-core/src/main/java/org/apache/rat/configuration/builders/MatcherRefBuilder.java
@@ -141,5 +141,14 @@ public class MatcherRefBuilder extends AbstractBuilder {
             checkProxy();
             return wrapped.matches(header);
         }
+
+        /**
+         * Gets the matcher ID that this proxy references.
+         * @return The matcher ID that this proxy references.
+         */
+        public String getRefId() {
+            // called by introspection
+            return proxyId;
+        }
     }
 }
diff --git 
a/apache-rat-core/src/test/java/org/apache/rat/config/parameters/DescriptionBuilderTest.java
 
b/apache-rat-core/src/test/java/org/apache/rat/config/parameters/DescriptionBuilderTest.java
index 5f221eb2..00ffabf3 100644
--- 
a/apache-rat-core/src/test/java/org/apache/rat/config/parameters/DescriptionBuilderTest.java
+++ 
b/apache-rat-core/src/test/java/org/apache/rat/config/parameters/DescriptionBuilderTest.java
@@ -18,19 +18,39 @@
  */
 package org.apache.rat.config.parameters;
 
+import static java.lang.String.format;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+import org.apache.rat.BuilderParams;
 import org.apache.rat.analysis.matchers.AndMatcher;
 import org.apache.rat.analysis.matchers.CopyrightMatcher;
+import org.apache.rat.api.Document;
+import org.apache.rat.document.impl.DocumentName;
+import org.apache.rat.document.impl.FileDocument;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 public class DescriptionBuilderTest {
 
     @Test
     public void matcherMapBuildTest() {
-
         Description underTest = 
DescriptionBuilder.buildMap(CopyrightMatcher.class);
         assertEquals(ComponentType.MATCHER, underTest.getType());
         assertEquals("copyright", underTest.getCommonName());
@@ -50,7 +70,78 @@ public class DescriptionBuilderTest {
         assertTrue(underTest.getChildren().containsKey("resource"));
         assertTrue(underTest.getChildren().containsKey("enclosed"));
         Description desc = underTest.getChildren().get("enclosed");
+    }
+
+    /**
+     * Test to verify that all Description based inspection invoked methods 
exist.
+     * @param clazz The class to check
+     * @param desc The description of an element in that class.
+     */
+    @ParameterizedTest
+    @MethodSource("descriptionSource")
+    public void textConfigParameters(Class<?> clazz, Description desc) {
+        if (desc.getType() == ComponentType.BUILD_PARAMETER) {
+            try {
+                Method m = BuilderParams.class.getMethod(desc.getCommonName());
+                assertNotNull(m);
+            } catch (NoSuchMethodException e) {
+                fail(format("BuilderParams does not have a %s method", 
desc.getCommonName()), e);
+            }
+        } else {
+            try {
+                // verify that the class has the getter for the description.
+                assertNotNull(desc.getter(clazz));
+            } catch (NoSuchMethodException e) {
+                fail(format("Missing method: %s.%s", clazz, 
desc.methodName("get")), e);
+            }
+        }
+    }
 
+    /** Class to build a list of documents that are class files. */
+    private static class DocumentProcessor implements Consumer<Document> {
+        SortedSet<Document> documents = new TreeSet<>();
+        @Override
+        public void accept(Document document) {
+            if (document.isDirectory()) {
+                document.listChildren().forEach(this);
+            } else {
+                if (document.getName().getName().endsWith(".class")) {
+                    documents.add(document);
+                }
+            }
+        }
     }
 
+    /**
+     * Scans the build classes directory to locate all class files that have 
Description annotations and ensure its validity.
+     * @return A stream of class and descriptions to validate.
+     * @throws IOException on IO error
+     * @throws URISyntaxException if URI is incorrect.
+     * @throws ClassNotFoundException if class can not be found.
+     */
+    public static Stream<Arguments> descriptionSource() throws IOException, 
URISyntaxException, ClassNotFoundException {
+        List<Arguments> arguments = new ArrayList<>();
+        ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
+        URL url = classLoader.getResource("");
+        File baseDir = new File(url.toURI());
+        baseDir = new File(baseDir.getParent(), "classes");
+        DocumentName documentName = new DocumentName(baseDir);
+        FileDocument fileDocument =  new FileDocument(documentName, baseDir, x 
-> true);
+        DocumentProcessor processor = new DocumentProcessor();
+        processor.accept(fileDocument);
+
+        for (Document document : processor.documents) {
+            String className = document.getName().localized(".");
+            className = className.substring(1, className.length() - 
".class".length());
+            Class<?> clazz = Class.forName(className);
+            List<Description> descriptionList = 
DescriptionBuilder.getConfigComponents(clazz);
+            if (descriptionList != null) {
+                descriptionList.forEach( desc -> {
+                    arguments.add(Arguments.of(clazz, desc));
+                });
+            }
+        }
+
+        return arguments.stream();
+    }
 }
diff --git 
a/apache-rat-core/src/test/java/org/apache/rat/configuration/builders/RegexBuilderTest.java
 
b/apache-rat-core/src/test/java/org/apache/rat/configuration/builders/RegexBuilderTest.java
index 94254e64..23ebe5ed 100644
--- 
a/apache-rat-core/src/test/java/org/apache/rat/configuration/builders/RegexBuilderTest.java
+++ 
b/apache-rat-core/src/test/java/org/apache/rat/configuration/builders/RegexBuilderTest.java
@@ -49,7 +49,7 @@ public class RegexBuilderTest {
         IHeaderMatcher matcher = licenses.first().getMatcher();
         assertEquals(SimpleRegexMatcher.class, matcher.getClass());
         SimpleRegexMatcher result = (SimpleRegexMatcher) matcher;
-        assertEquals(".", result.getPattern());
+        assertEquals(".", result.getExpression());
     }
 
     @Test
@@ -73,6 +73,6 @@ public class RegexBuilderTest {
         assertEquals("foo", matcher.getId());
         assertEquals(SimpleRegexMatcher.class, matcher.getClass());
         SimpleRegexMatcher result = (SimpleRegexMatcher) matcher;
-        assertEquals(".", result.getPattern());
+        assertEquals(".", result.getExpression());
     }
 }
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2250faa8..2986225a 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-422" type="fix" dev="claudenw">
+        Fix checkstyle issues in configuration.
+      </action>
       <action issue="RAT-435" type="fix" dev="claudenw">
         Fix checkstyle issues in root package.
       </action>

Reply via email to