Skip to content

Commit 765526d

Browse files
committed
Add additional waits when necessary
HFS+ under MacOSX has only second accuracy for file modification times date resolution.
1 parent 7e4468c commit 765526d

File tree

4 files changed

+50
-19
lines changed

4 files changed

+50
-19
lines changed

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/EclipseUtils.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.Map;
1515
import java.util.Map.Entry;
1616
import java.util.Set;
17-
import java.util.concurrent.CountDownLatch;
1817
import java.util.concurrent.TimeUnit;
1918
import java.util.regex.Pattern;
2019

@@ -28,7 +27,6 @@
2827
import org.eclipse.core.resources.ResourcesPlugin;
2928
import org.eclipse.core.runtime.CoreException;
3029
import org.eclipse.core.runtime.IPath;
31-
import org.eclipse.core.runtime.NullProgressMonitor;
3230
import org.eclipse.core.runtime.Path;
3331
import org.eclipse.core.runtime.jobs.Job;
3432
import org.eclipse.jdt.core.IClasspathEntry;
@@ -49,21 +47,7 @@
4947
* @author Philippe Herlin
5048
* @author Brian Remedios
5149
*/
52-
public class EclipseUtils {
53-
static class OpenMonitor extends NullProgressMonitor {
54-
private final CountDownLatch latch;
55-
56-
OpenMonitor(final CountDownLatch latch) {
57-
this.latch = latch;
58-
}
59-
60-
@Override
61-
public void done() {
62-
super.done();
63-
latch.countDown();
64-
}
65-
}
66-
50+
public final class EclipseUtils {
6751
/**
6852
* Because this class is a utility class, it cannot be instantiated
6953
*/
@@ -377,6 +361,8 @@ public static void createFolders(IProject testProject, String fullpath) throws C
377361

378362
public static void waitForJobs() throws InterruptedException {
379363
long start = System.currentTimeMillis();
364+
Thread.sleep(500);
365+
380366
while (!Job.getJobManager().isIdle()) {
381367
Thread.sleep(500);
382368

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.eclipse;
6+
7+
import java.util.concurrent.CountDownLatch;
8+
import java.util.concurrent.TimeUnit;
9+
10+
import org.eclipse.core.runtime.NullProgressMonitor;
11+
12+
public class WaitingMonitor extends NullProgressMonitor {
13+
private final CountDownLatch latch = new CountDownLatch(1);
14+
15+
@Override
16+
public void done() {
17+
super.done();
18+
latch.countDown();
19+
}
20+
21+
public void await() throws InterruptedException {
22+
latch.await(30, TimeUnit.SECONDS);
23+
}
24+
}

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCmdTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.sourceforge.pmd.RuleSet;
3232
import net.sourceforge.pmd.eclipse.EclipseUtils;
3333
import net.sourceforge.pmd.eclipse.LoggingRule;
34+
import net.sourceforge.pmd.eclipse.WaitingMonitor;
3435
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
3536
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
3637
import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences;
@@ -120,8 +121,16 @@ private IFile createMissingOverrideTestCase(IProject project) throws Exception {
120121
+ " void run() {\n" // line 2
121122
+ " }\n"
122123
+ "}");
123-
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
124-
project.refreshLocal(IResource.DEPTH_INFINITE, null);
124+
125+
WaitingMonitor monitor;
126+
monitor = new WaitingMonitor();
127+
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
128+
monitor.await();
129+
130+
monitor = new WaitingMonitor();
131+
project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
132+
monitor.await();
133+
125134
return sourceFile;
126135
}
127136

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/ExternalRuleSetFileTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import net.sourceforge.pmd.RuleSet;
2121
import net.sourceforge.pmd.eclipse.EclipseUtils;
22+
import net.sourceforge.pmd.eclipse.LoggingRule;
2223
import net.sourceforge.pmd.eclipse.internal.ResourceUtil;
2324
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
2425
import net.sourceforge.pmd.eclipse.runtime.cmd.BuildProjectCommand;
@@ -30,6 +31,9 @@
3031
public class ExternalRuleSetFileTest {
3132
private static final Logger LOG = LoggerFactory.getLogger(ExternalRuleSetFileTest.class);
3233

34+
@org.junit.Rule
35+
public LoggingRule loggingRule = new LoggingRule();
36+
3337
private static final String PMD_PROPERTIES_FILENAME = ".pmd";
3438

3539
private static final String PROJECT_RULESET_FILENAME = ".pmd-ruleset.xml";
@@ -91,6 +95,7 @@ public void changedExternalRulesetShouldBeReloaded() throws Exception {
9195
Assert.assertEquals(1, projectRuleSet.getRules().size());
9296

9397
// now let's change the ruleSetFile without eclipse knowing about it ("externally")
98+
waitASecond();
9499
File ruleSetFileReal = ruleSetFile.getLocation().toFile();
95100
ResourceUtil.copyResource(this, "ruleset2.xml", ruleSetFileReal);
96101

@@ -121,6 +126,7 @@ public void changedExternalRulesetShouldBeReloadedForPmdDisabledProjects() throw
121126
Assert.fail("File " + PROJECT_RULESET_FILENAME + " already exists!");
122127
}
123128
File ruleSetFileReal = ruleSetFile.getLocation().toFile();
129+
waitASecond();
124130
ResourceUtil.copyResource(this, "ruleset1.xml", ruleSetFileReal);
125131

126132
// now create the .pmd project properties without eclipse knowing about it ("externally")
@@ -192,6 +198,7 @@ public void externallyChangedProjectPropertiesShouldBeReloaded() throws Exceptio
192198
Assert.fail("File .pmd does not exist!");
193199
}
194200
File projectPropertiesFileReal = projectPropertiesFile.getLocation().toFile();
201+
waitASecond();
195202
ResourceUtil.copyResource(this, "pmd-properties", projectPropertiesFileReal);
196203
LOG.debug("Overwritten {}", projectPropertiesFile);
197204

@@ -215,4 +222,9 @@ public void externallyChangedProjectPropertiesShouldBeReloaded() throws Exceptio
215222
// need rebuild flag should be reset now
216223
Assert.assertFalse(model.isNeedRebuild());
217224
}
225+
226+
// HFS+ under MacOS has a date resolution of 1 second only
227+
private void waitASecond() throws InterruptedException {
228+
Thread.sleep(1000);
229+
}
218230
}

0 commit comments

Comments
 (0)