Skip to content

Commit 990f7d7

Browse files
Christoph Läubrichlaeubi
authored andcommitted
Only wait for relevant jobs in JavaStepDefinitionOpener
1 parent 040b0b2 commit 990f7d7

6 files changed

Lines changed: 74 additions & 2 deletions

File tree

io.cucumber.eclipse.editor/src/io/cucumber/eclipse/editor/validation/BatchVerificationJob.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.LinkedHashMap;
55
import java.util.Map;
66

7+
import org.eclipse.core.resources.IProject;
78
import org.eclipse.core.resources.IResource;
89
import org.eclipse.core.runtime.IProgressMonitor;
910
import org.eclipse.core.runtime.IStatus;
@@ -75,4 +76,20 @@ public BatchUpdater getUpdater() {
7576
return updater;
7677
}
7778

79+
@Override
80+
public boolean matches(IProject project) {
81+
for (IDocument doc : updater.documents) {
82+
IResource resource = GherkinEditorDocumentManager.resourceForDocument(doc);
83+
if (resource != null && resource.getProject() == project) {
84+
return true;
85+
}
86+
}
87+
for (IResource resource : updater.resources) {
88+
if (resource.getProject() == project) {
89+
return true;
90+
}
91+
}
92+
return false;
93+
}
94+
7895
}

io.cucumber.eclipse.editor/src/io/cucumber/eclipse/editor/validation/DocumentValidator.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.eclipse.core.resources.IProject;
1010
import org.eclipse.core.resources.IResource;
1111
import org.eclipse.core.runtime.IPath;
12+
import org.eclipse.core.runtime.OperationCanceledException;
1213
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
1314
import org.eclipse.core.runtime.jobs.IJobChangeListener;
1415
import org.eclipse.core.runtime.jobs.Job;
@@ -367,4 +368,32 @@ public void close() {
367368
return batch;
368369
}
369370

371+
/**
372+
* Waits for all validation jobs for the specified project to complete.
373+
* <p>
374+
* This method finds all running verification jobs that are processing resources
375+
* from the given project and joins on them, waiting for their completion.
376+
* This is more efficient than waiting for all validation jobs when only
377+
* a specific project's validation is needed.
378+
* </p>
379+
*
380+
* @param project the project whose validation jobs should be joined
381+
* @throws InterruptedException if the wait is interrupted
382+
* @throws OperationCanceledException if the operation is canceled
383+
*/
384+
public static void joinValidation(IProject project) throws InterruptedException, OperationCanceledException {
385+
if (project == null) {
386+
return;
387+
}
388+
Job[] jobs = Job.getJobManager().find(IGlueValidator.class);
389+
for (Job job : jobs) {
390+
if (job instanceof VerificationJob) {
391+
VerificationJob verificationJob = (VerificationJob) job;
392+
if (verificationJob.matches(project)) {
393+
job.join();
394+
}
395+
}
396+
}
397+
}
398+
370399
}

io.cucumber.eclipse.editor/src/io/cucumber/eclipse/editor/validation/ResourceVerificationJob.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Collection;
44
import java.util.List;
55

6+
import org.eclipse.core.resources.IProject;
67
import org.eclipse.core.resources.IResource;
78

89
import io.cucumber.eclipse.editor.document.GherkinEditorDocument;
@@ -42,4 +43,9 @@ protected Collection<GherkinEditorDocument> getEditorDocuments() {
4243
return document == null ? List.of() : List.of(document);
4344
}
4445

46+
@Override
47+
public boolean matches(IProject project) {
48+
return project == resource.getProject();
49+
}
50+
4551
}

io.cucumber.eclipse.editor/src/io/cucumber/eclipse/editor/validation/TextBufferVerificationJob.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.Collection;
44
import java.util.List;
55

6+
import org.eclipse.core.resources.IProject;
7+
import org.eclipse.core.resources.IResource;
68
import org.eclipse.jface.text.IDocument;
79

810
import io.cucumber.eclipse.editor.document.GherkinEditorDocument;
@@ -42,4 +44,13 @@ protected Collection<GherkinEditorDocument> getEditorDocuments() {
4244
return editorDocument == null ? List.of() : List.of(editorDocument);
4345
}
4446

47+
@Override
48+
public boolean matches(IProject project) {
49+
IResource resource = GherkinEditorDocumentManager.resourceForDocument(document);
50+
if (resource != null) {
51+
return resource.getProject() == project;
52+
}
53+
return false;
54+
}
55+
4556
}

io.cucumber.eclipse.editor/src/io/cucumber/eclipse/editor/validation/VerificationJob.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Map;
88
import java.util.stream.Collectors;
99

10+
import org.eclipse.core.resources.IProject;
1011
import org.eclipse.core.resources.IResource;
1112
import org.eclipse.core.runtime.IProgressMonitor;
1213
import org.eclipse.core.runtime.IStatus;
@@ -171,4 +172,12 @@ private void validateGlue(List<GherkinEditorDocument> validDocuments, IProgressM
171172
*/
172173
protected abstract Collection<GherkinEditorDocument> getEditorDocuments();
173174

175+
/**
176+
* Checks if this verification job is currently handling any resource from the given project.
177+
*
178+
* @param project the project to check
179+
* @return true if any document being validated by this job belongs to the given project
180+
*/
181+
public abstract boolean matches(IProject project);
182+
174183
}

io.cucumber.eclipse.java/src/io/cucumber/eclipse/java/steps/JavaStepDefinitionOpener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import io.cucumber.eclipse.editor.EditorLogging;
3535
import io.cucumber.eclipse.editor.Tracing;
3636
import io.cucumber.eclipse.editor.hyperlinks.IStepDefinitionOpener;
37-
import io.cucumber.eclipse.editor.validation.IGlueValidator;
37+
import io.cucumber.eclipse.editor.validation.DocumentValidator;
3838
import io.cucumber.eclipse.java.JDTUtil;
3939
import io.cucumber.eclipse.java.plugins.CucumberCodeLocation;
4040
import io.cucumber.eclipse.java.plugins.MatchedPickleStep;
@@ -106,7 +106,7 @@ public void handleEvent(Event event) {
106106
@Override
107107
public void run(IProgressMonitor monitor) throws CoreException {
108108
try {
109-
Job.getJobManager().join(IGlueValidator.class, monitor);
109+
DocumentValidator.joinValidation(project.getProject());
110110
} catch (OperationCanceledException | InterruptedException e) {
111111
cancelled.set(true);
112112
display.wake();

0 commit comments

Comments
 (0)