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


##########
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:
   here I would like to try `getToolchainFromBuildContext` first, if toolchains 
plugin is used we will have the same version



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