Skip to content

Commit

Permalink
wait for build after refresh. Fix #2998
Browse files Browse the repository at this point in the history
  • Loading branch information
gayanper authored and iloveeclipse committed Oct 16, 2024
1 parent 09f7d68 commit 8cd1352
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private Map<String, String> compileAndDeploy15(String source, String className,

private void refreshProject() throws Exception {
this.project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
waitForAutoBuild(); // wait for builds to complete.
}

private void removeTempClass(String className) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.tests.junit.extension.StopableTestCase;
Expand All @@ -40,6 +47,7 @@
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.eval.EvaluationContext;
import org.eclipse.jdt.internal.eval.EvaluationResult;
import org.eclipse.jdt.internal.eval.GlobalVariable;
Expand Down Expand Up @@ -569,4 +577,40 @@ public void stop() {
}
}
}

public void waitForAutoBuild() {
if (isWorkspaceRuleAlreadyInUse(getWorkspaceRoot())) {
// Don't wait holding workspace lock on FAMILY_AUTO_BUILD, because
// we might deadlock with AutoBuildOffJob
System.out.println("\n\nAborted waitForAutoBuild() because running with the workspace rule\n\n");
return;
}
boolean wasInterrupted = false;
do {
try {
Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_AUTO_BUILD);
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
JavaModelManager.getIndexManager().waitForIndex(isIndexDisabledForTest(), null);
wasInterrupted = false;
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (InterruptedException e) {
wasInterrupted = true;
}
} while (wasInterrupted);
}

private static boolean isWorkspaceRuleAlreadyInUse(ISchedulingRule rule) {
ISchedulingRule currentJobRule = Job.getJobManager().currentRule();
boolean workspaceRuleActive = currentJobRule != null && rule.contains(currentJobRule);
return workspaceRuleActive;
}

private IWorkspaceRoot getWorkspaceRoot() {
return getWorkspace().getRoot();
}

private IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
}

0 comments on commit 8cd1352

Please sign in to comment.