diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 043f724f..b3cf720f 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -16,6 +16,7 @@ This is a minor release. ### 🐛 Fixed Issues ### ✨ Merged pull requests +* [#431](https://github.com/pmd/pmd-eclipse-plugin/pull/431): chore: Improve logging during tests at waitForPMDJobs - [Andreas Dangel](https://github.com/adangel) (@adangel) ### 📦 Dependency updates diff --git a/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/EclipseUtils.java b/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/EclipseUtils.java index 63753d62..193d791f 100644 --- a/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/EclipseUtils.java +++ b/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/EclipseUtils.java @@ -8,13 +8,16 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -36,6 +39,8 @@ import org.eclipse.jdt.launching.IVMInstall; import org.eclipse.jdt.launching.JavaRuntime; import org.junit.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants; import net.sourceforge.pmd.eclipse.runtime.builder.PMDNature; @@ -50,6 +55,8 @@ * @author Brian Remedios */ public final class EclipseUtils { + private static final Logger LOG = LoggerFactory.getLogger(EclipseUtils.class); + /** * Because this class is a utility class, it cannot be instantiated */ @@ -365,22 +372,60 @@ public static void createFolders(IProject testProject, String fullpath) throws C } public static void waitForPMDJobs() throws InterruptedException { + LOG.debug("waitForPMDJobs started..."); long start = System.currentTimeMillis(); String jobName = new ReviewCodeCmd().getName(); - while (hasPMDJob(Job.getJobManager().find(null), jobName)) { + while (findPMDJob(Job.getJobManager().find(null), jobName) != null) { Thread.sleep(500); - if (System.currentTimeMillis() - start > TimeUnit.MINUTES.toMillis(1)) { + if (System.currentTimeMillis() - start > TimeUnit.MINUTES.toMillis(2)) { + Job job = findPMDJob(Job.getJobManager().find(null), jobName); + if (job != null) { + final String state; + switch (job.getState()) { + case Job.SLEEPING: + state = "sleeping"; + break; + case Job.RUNNING: + state = "running"; + break; + case Job.WAITING: + state = "waiting"; + break; + case Job.NONE: + state = "none"; + break; + default: + state = "unknown"; + break; + } + LOG.debug("Still running after {} ms? {}. state={}, testClass={}", + System.currentTimeMillis() - start, + job.getName(), state, determineTestClass()); + } Assert.fail("Timeout while waiting for Job " + jobName + " to finish"); } } + LOG.debug("waitForPMDJobs finished in {} ms ({})", System.currentTimeMillis() - start, determineTestClass()); + } + + private static String determineTestClass() { + Exception exception = new Exception(); + List methods = Arrays.stream(exception.getStackTrace()) + .filter(e -> e.getClassName().endsWith("Test")) + .map(e -> e.getClassName() + "#" + e.getMethodName()) + .collect(Collectors.toList()); + if (methods.isEmpty()) { + return "unknown"; + } + return methods.get(methods.size() - 1); // take the last method - the entry point into the test class } - private static boolean hasPMDJob(Job[] jobs, String jobName) { + private static Job findPMDJob(Job[] jobs, String jobName) { for (Job job : jobs) { if (job.getName().equals(jobName)) { - return true; + return job; } } - return false; + return null; } } diff --git a/net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/MarkerPropertyTester.java b/net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/MarkerPropertyTester.java index 0401dd17..e48cbcf9 100644 --- a/net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/MarkerPropertyTester.java +++ b/net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/MarkerPropertyTester.java @@ -19,6 +19,11 @@ public boolean test(Object receiver, String property, Object[] args, Object expe IMarker marker = (IMarker) receiver; + // during shutdown, the files/resources might have already been closed + if (!marker.exists()) { + return false; + } + try { return marker.getType().startsWith(PMDPlugin.PLUGIN_ID); } catch (CoreException e) {