ascopes commented on code in PR #1046:
URL:
https://github.com/apache/maven-plugin-tools/pull/1046#discussion_r2870931370
##########
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:
By this are you suggesting converting the path into a glob first to check
it? Or directly feeding the configured strings as patterns to check it?
Trying to remember if we always ensure these paths are relative, I believe
this is why I implemented this in a backwards way at the time, as it wasn't
immediately clear as to the preconditions we can guarantee here.
--
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]