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


##########
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()) {
             sources.add(generatedPlugin);
         }
+
         extendJavaProjectBuilder(builder, sources, project.getArtifacts());
     }
 
+    private boolean isExcludedDirectory(Collection<File> excludedDirectories, 
File sourceFile) {

Review Comment:
   We can move this method to `PluginToolsRequest` we will not have a code 
duplicated



##########
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()) {
             sources.add(generatedPlugin);
         }
+
         extendJavaProjectBuilder(builder, sources, project.getArtifacts());
     }
 
+    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();
+            }

Review Comment:
   We can try to use 
   
   ```java
   PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + 
pattern);
   ```
   
   https://docs.oracle.com/javase/tutorial/essential/io/find.html



-- 
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