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 @@ -22,6 +22,7 @@ This is a minor release.
* [#432](https://github.com/pmd/pmd-eclipse-plugin/pull/432): refactor: Remove custom JavaProject cache - [Andreas Dangel](https://github.com/adangel) (@adangel)
* [#449](https://github.com/pmd/pmd-eclipse-plugin/pull/449): chore: Upload surefire reports for failed unit tests - [Andreas Dangel](https://github.com/adangel) (@adangel)
* [#451](https://github.com/pmd/pmd-eclipse-plugin/pull/451): chore: Make ViolationDetailsDialogTest more reliable - [Andreas Dangel](https://github.com/adangel) (@adangel)
* [#452](https://github.com/pmd/pmd-eclipse-plugin/pull/452): chore: Wait for workspace jobs to complete before teardown of tests - [Andreas Dangel](https://github.com/adangel) (@adangel)

### 📦 Dependency updates

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
Expand Down Expand Up @@ -371,6 +373,25 @@ public static void createFolders(IProject testProject, String fullpath) throws C
}
}

public static void waitForJobsToComplete() throws InterruptedException {
long start = System.currentTimeMillis();
String testClass = determineTestClass();
LOG.debug("waitForJobsToComplete started ({})...", testClass);
IJobManager jobManager = Job.getJobManager();
jobManager.suspend();
try {
Job[] jobs = jobManager.find(null);
for (Job job : jobs) {
if (job instanceof WorkspaceJob) {
job.join();
}
}
} finally {
jobManager.resume();
}
LOG.debug("waitForJobsToComplete finished in {} ms ({})", System.currentTimeMillis() - start, testClass);
}

public static void waitForPMDJobs() throws InterruptedException {
LOG.debug("waitForPMDJobs started...");
long start = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void addPMDNatureForNonJavaProject() throws Exception {

Assert.assertTrue(testProject.hasNature(PMDNature.PMD_NATURE));

EclipseUtils.waitForJobsToComplete();
if (testProject.exists() && testProject.isAccessible()) {
EclipseUtils.removePMDNature(testProject);
testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ public void setUp() throws Exception {
IProjectProperties properties = PMDPlugin.getDefault().getPropertiesManager()
.loadProjectProperties(testProject);
properties.setPmdEnabled(true);

testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
EclipseUtils.waitForPMDJobs();
}

@After
public void tearDown() throws Exception {
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
Expand All @@ -94,6 +98,7 @@ public void testReviewCmdBasic() throws CoreException {
cmd.addResource(this.testProject);
cmd.performExecute();
cmd.join();

final Map<IFile, Set<MarkerInfo2>> markers = cmd.getMarkers();

// We do not test PMD, only a non-empty report is enough
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void checkCodeForNonJavaProject() throws Exception {
// only one file has an extension, that could be mapped to a language, and therefore pmd was executed
Assert.assertEquals(1, cmd.getFileCount());

EclipseUtils.waitForJobsToComplete();
if (testProject.exists() && testProject.isAccessible()) {
EclipseUtils.removePMDNature(testProject);
testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
EclipseUtils.waitForJobsToComplete();
// 1. Delete the test project
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
try {
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
this.testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
this.testProject.delete(true, true, null);
this.testProject = null;
}
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
this.testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
this.testProject.delete(true, true, null);
this.testProject = null;
}
} catch (final Exception e) {
System.out.println("Exception " + e.getClass().getName() + " when tearing down. Ignored.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
try {
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
this.testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
this.testProject.delete(true, true, null);
this.testProject = null;
}
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
this.testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
this.testProject.delete(true, true, null);
this.testProject = null;
}
} catch (final Exception e) {
System.out.println("Exception " + e.getClass().getName() + " when tearing down. Ignored.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import net.sourceforge.pmd.eclipse.AbstractSWTBotTest;
import net.sourceforge.pmd.eclipse.EclipseUtils;
import net.sourceforge.pmd.eclipse.LoggingRule;
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
Expand Down Expand Up @@ -61,19 +62,19 @@ public void setUp() throws Exception {
properties.sync();
}

@org.junit.Rule
public LoggingRule loggingRule = new LoggingRule();

@After
public void tearDown() throws Exception {
try {
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
this.testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
this.testProject.delete(true, true, null);
this.testProject = null;
}
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
this.testProject.refreshLocal(IResource.DEPTH_INFINITE, null);
this.testProject.delete(true, true, null);
this.testProject = null;
}
} catch (final Exception e) {
System.out.println("Exception " + e.getClass().getName() + " when tearing down. Ignored.");
}
}

Expand All @@ -89,12 +90,8 @@ public void openDialogViaProblemView() throws Exception {
bot.waitUntil(new DefaultCondition() {
@Override
public boolean test() throws Exception {
try {
// Try to find all violation nodes - if all exist, tree is ready
return warningsNode.getItems().length >= 4;
} catch (Exception e) {
return false;
}
// Try to find all violation nodes - if all exist, tree is ready
return warningsNode.getItems().length >= 4;
}

@Override
Expand All @@ -103,6 +100,24 @@ public String getFailureMessage() {
}
});

// Wait for the marker by partial match or iterate through nodes
bot.waitUntil(new DefaultCondition() {
@Override
public boolean test() throws Exception {
for (SWTBotTreeItem node : warningsNode.getItems()) {
if (node.getText().contains("UnnecessaryModifier")) {
return true;
}
}
return false;
}

@Override
public String getFailureMessage() {
return "Violation UnnecessaryModifier not found in ProblemsView";
}
});

// Now search for the marker by partial match or iterate through nodes
SWTBotTreeItem markerItem = null;
for (SWTBotTreeItem node : warningsNode.getItems()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ private void setUpProject(String projectName) {

@After
public void tearDown() throws Exception {
try {
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
this.testProject.delete(true, true, null);
this.testProject = null;
}
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
this.testProject.delete(true, true, null);
this.testProject = null;
}
} catch (CoreException e) {
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
EclipseUtils.waitForJobsToComplete();
if (this.testProject != null) {
if (this.testProject.exists() && this.testProject.isAccessible()) {
EclipseUtils.removePMDNature(this.testProject);
Expand Down