adangel commented on code in PR #726:
URL: https://github.com/apache/maven-pmd-plugin/pull/726#discussion_r3961047560


##########
src/main/java/org/apache/maven/plugins/pmd/PmdReport.java:
##########
@@ -487,20 +505,114 @@ private String determineAuxClasspath() throws 
MavenReportException {
 
                 // Add the dependencies as last entries
                 classpath.addAll(dependencies);
+                classpath.removeIf(this::emptyOrNotExisting);
 
                 getLog().debug("Using aggregated aux classpath: " + classpath);
             } else {
                 classpath.addAll(
                         includeTests ? project.getTestClasspathElements() : 
project.getCompileClasspathElements());
+                classpath.removeIf(this::emptyOrNotExisting);
 
                 getLog().debug("Using aux classpath: " + classpath);
             }
+
+            classpath.addAll(determineJavaRuntimeClasses());
+
             return String.join(File.pathSeparator, classpath);
         } catch (Exception e) {
             throw new MavenReportException(e.getMessage(), e);
         }
     }
 
+    private boolean emptyOrNotExisting(String entry) {
+        Path path = Paths.get(entry);
+        if (Files.isDirectory(path)) {
+            boolean emptyDirectory = false;
+            try (Stream<Path> stream = Files.list(path)) {
+                emptyDirectory = !stream.findAny().isPresent();
+            } catch (IOException ex) {
+                throw new UncheckedIOException(ex);
+            }
+            if (emptyDirectory) {
+                getLog().debug("Ignoring empty directory for aux classpath: " 
+ path);
+                return true;
+            }
+        } else if (!Files.exists(path)) {
+            getLog().debug("Ignoring non-existing entry for aux classpath: " + 
path);
+            return true;
+        }
+        return false;
+    }
+
+    private List<String> determineJavaRuntimeClasses() {
+        if (!"java".equals(language) && null != language) {
+            return Collections.emptyList();
+        }
+        if (targetJdk == null) {
+            return Collections.emptyList();
+        }
+
+        List<Toolchain> toolchains =
+                toolchainManager.getToolchains(session, "jdk", 
Collections.singletonMap("version", targetJdk));

Review Comment:
   I've decided to use the same logic as it already exists for the current 
toolchain support:
   1. use m-pmd-p's own jdkToolchain config (if present)
   2. use toolchain from build context / toolchains plugin
   
   And only as last step select toolchain by targetJdk version. Then it's 
possible fix the warning for multiple toolchains by providing a jdkToolchain 
config and selecting a toolchain with more criteria than just the version (like 
vendor).



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