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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -75,4 +76,20 @@ public BatchUpdater getUpdater() {
return updater;
}

@Override
public boolean matches(IProject project) {
for (IDocument doc : updater.documents) {
IResource resource = GherkinEditorDocumentManager.resourceForDocument(doc);
if (resource != null && resource.getProject() == project) {
return true;
}
}
for (IResource resource : updater.resources) {
if (resource.getProject() == project) {
return true;
}
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
Expand Down Expand Up @@ -367,4 +368,32 @@ public void close() {
return batch;
}

/**
* Waits for all validation jobs for the specified project to complete.
* <p>
* This method finds all running verification jobs that are processing resources
* from the given project and joins on them, waiting for their completion.
* This is more efficient than waiting for all validation jobs when only
* a specific project's validation is needed.
* </p>
*
* @param project the project whose validation jobs should be joined
* @throws InterruptedException if the wait is interrupted
* @throws OperationCanceledException if the operation is canceled
*/
public static void joinValidation(IProject project) throws InterruptedException, OperationCanceledException {
if (project == null) {
return;
}
Job[] jobs = Job.getJobManager().find(IGlueValidator.class);
for (Job job : jobs) {
if (job instanceof VerificationJob) {
VerificationJob verificationJob = (VerificationJob) job;
if (verificationJob.matches(project)) {
job.join();
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;

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

@Override
public boolean matches(IProject project) {
return project == resource.getProject();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Collection;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.text.IDocument;

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

@Override
public boolean matches(IProject project) {
IResource resource = GherkinEditorDocumentManager.resourceForDocument(document);
if (resource != null) {
return resource.getProject() == project;
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -171,4 +172,12 @@ private void validateGlue(List<GherkinEditorDocument> validDocuments, IProgressM
*/
protected abstract Collection<GherkinEditorDocument> getEditorDocuments();

/**
* Checks if this verification job is currently handling any resource from the given project.
*
* @param project the project to check
* @return true if any document being validated by this job belongs to the given project
*/
public abstract boolean matches(IProject project);

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import io.cucumber.eclipse.editor.EditorLogging;
import io.cucumber.eclipse.editor.Tracing;
import io.cucumber.eclipse.editor.hyperlinks.IStepDefinitionOpener;
import io.cucumber.eclipse.editor.validation.IGlueValidator;
import io.cucumber.eclipse.editor.validation.DocumentValidator;
import io.cucumber.eclipse.java.JDTUtil;
import io.cucumber.eclipse.java.plugins.CucumberCodeLocation;
import io.cucumber.eclipse.java.plugins.MatchedPickleStep;
Expand Down Expand Up @@ -106,7 +106,7 @@ public void handleEvent(Event event) {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
Job.getJobManager().join(IGlueValidator.class, monitor);
DocumentValidator.joinValidation(project.getProject());
} catch (OperationCanceledException | InterruptedException e) {
cancelled.set(true);
display.wake();
Expand Down