Copilot commented on code in PR #1046:
URL: 
https://github.com/apache/maven-plugin-tools/pull/1046#discussion_r2638024904


##########
maven-plugin-plugin/src/it/gh-944-exclude-source-directory/pom.xml:
##########
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<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>
+
+  <groupId>org.apache.maven.its.mplugin-382</groupId>
+  <artifactId>mplugin-382-exclude-provided-dependency</artifactId>

Review Comment:
   The groupId and artifactId in the test POM do not match the test directory 
name. The test is named 'gh-944-exclude-source-directory' but uses groupId 
'org.apache.maven.its.mplugin-382' and artifactId 
'mplugin-382-exclude-provided-dependency'. This appears to be copy-pasted from 
a different test (mplugin-382) and should be updated to reflect the actual test 
case for consistency and clarity.
   ```suggestion
     <groupId>org.apache.maven.its.gh-944-exclude-source-directory</groupId>
     <artifactId>gh-944-exclude-source-directory</artifactId>
   ```



##########
maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java:
##########
@@ -630,21 +630,43 @@ protected void extendJavaProjectBuilderWithSourcesJar(
         }
     }
 
-    private void extendJavaProjectBuilder(JavaProjectBuilder builder, final 
MavenProject project) {
+    private void extendJavaProjectBuilder(
+            PluginToolsRequest request, JavaProjectBuilder builder, final 
MavenProject project) {
         List<File> sources = new ArrayList<>();
 
         for (String source : project.getCompileSourceRoots()) {
-            sources.add(new File(source));
+            File sourceFile = new File(source);
+
+            // Allow users to exclude certain paths such as generated sources 
from being scanned, in the case that
+            // this may be problematic for them (e.g. using obscure 
unsupported syntax by the parser, comments that
+            // cannot be controlled, etc.)
+            if (!isExcludedDirectory(request.getExcludedScanDirectories(), 
sourceFile)) {
+                sources.add(sourceFile);
+            }
         }
 
         // TODO be more dynamic
         File generatedPlugin = new File(project.getBasedir(), 
"target/generated-sources/plugin");
         if 
(!project.getCompileSourceRoots().contains(generatedPlugin.getAbsolutePath()) 
&& generatedPlugin.exists()) {

Review Comment:
   The `generatedPlugin` directory at line 649-652 is not checked against the 
excluded directories, while the compile source roots are. This creates an 
inconsistency where users cannot exclude the generated-sources/plugin directory 
even if it causes parsing issues. Consider applying the same exclusion logic to 
this path for consistency.
   ```suggestion
           if 
(!project.getCompileSourceRoots().contains(generatedPlugin.getAbsolutePath())
                   && generatedPlugin.exists()
                   && 
!isExcludedDirectory(request.getExcludedScanDirectories(), generatedPlugin)) {
   ```



##########
maven-plugin-plugin/src/it/gh-944-exclude-source-directory/invoker.properties:
##########
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = process-classes

Review Comment:
   The integration test is missing a verify.groovy or verify.bsh script to 
validate that the test actually passes correctly. Without this, the test only 
verifies that the build doesn't fail, but doesn't verify that excluded 
directories were actually skipped or that the plugin.xml was generated 
correctly. Add a verification script to check that the generated plugin 
descriptor does not contain references to code from the excluded directory.



##########
maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/javadoc/JavaJavadocMojoDescriptorExtractor.java:
##########
@@ -573,4 +579,17 @@ protected void validate(MojoDescriptor mojoDescriptor) 
throws InvalidParameterEx
             }
         }
     }
+
+    private boolean isExcludedDirectory(Collection<File> excludedDirectories, 
File sourceFile) {
+        for (File excludedScanDirectory : excludedDirectories) {
+            File candidateFile = sourceFile;
+            while (candidateFile != null) {
+                if (excludedScanDirectory.equals(candidateFile)) {
+                    return true;
+                }
+                candidateFile = candidateFile.getParentFile();
+            }
+        }
+        return false;
+    }

Review Comment:
   The `isExcludedDirectory` method is duplicated in both 
JavaJavadocMojoDescriptorExtractor and JavaAnnotationsMojoDescriptorExtractor 
with identical implementation. This violates the DRY principle and makes 
maintenance harder. Consider extracting this method to a shared utility class 
or to the PluginToolsRequest interface as a default method.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to