Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading