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


##########
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:
   Hm... yes, I can do that. If the toolchains plugin is used (which was the 
only way to ensure correct Java platform classes before this PR), then it's 
probably the correct java version.
   Some future version of PMD might double check this (but we don't verify at 
the moment, that the provided language version for Java matches the classes on 
the auxclasspath).
   



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