Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for jobs to complete when resolving the classpaths #1476

Merged
merged 1 commit into from
Jun 16, 2020

Conversation

jdneo
Copy link
Contributor

@jdneo jdneo commented Jun 11, 2020

When I'm working for this PR: redhat-developer/vscode-java#1484, I found that the test case getClasspath will randomly fail, see: https://travis-ci.org/github/redhat-developer/vscode-java/jobs/697117335

It's because if we try to get the classpath when the m2e is updating the projects, the return results might only contain the source classes without dependency jars. so I add a wait here.

Signed-off-by: Sheng Chen sheche@microsoft.com

*/
public static ClasspathResult getClasspaths(String uri, ClasspathOptions options) throws CoreException, URISyntaxException {
public static ClasspathResult getClasspaths(String uri, ClasspathOptions options) throws CoreException, URISyntaxException, InterruptedException {
JobHelpers.waitForJobsToComplete(new NullProgressMonitor());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's too broad. You'll wait for unrelated jobs to finish

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I narrow to:

JobHelpers.waitForJobs(IConstants.UPDATE_PROJECT_FAMILY, new NullProgressMonitor());
JobHelpers.waitForBuildJobs(10 * 1000);

Also wait for build jobs since update request will also trigger a clean build in MavenBuilder. But return the result no matter build finishes or not after 10 secs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to wait for build jobs. During a build all the classpaths are supposed to have been set already, so building projects won't change anything to that

Copy link
Contributor Author

@jdneo jdneo Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right. I found out that the case will fail after the invocation of JavaCore.setClasspathContainer(), which will trigger SetContainerOperation

I'm deciding to add following code:

IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.run(new IWorkspaceRunnable() {
    @Override
        public void run(IProgressMonitor monitor) {
    }
}, workspace.getRoot(), 0, new NullProgressMonitor());

to wait for it. (JavaModeChangeOperation will lock the workspace tree). Does this make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snjeza your opinion on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add more background here: The cases might fail with a very high possibility after BuildPathManager#mavenProjectChanged(), where the SetContainerOperation will be triggered.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can try

IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.run(new IWorkspaceRunnable() {
    @Override
        public void run(IProgressMonitor monitor) {
    }
}, workspace.getRoot(), IWorkspace.AVOID_UPDATE, new NullProgressMonitor());

@jdneo jdneo force-pushed the cs/classpath-update branch 2 times, most recently from 38b1a59 to 901d0af Compare June 12, 2020 03:24
projectsManager.updateProject(project, true);

for (int i = 0; i < 10; i++) {
options.scope = "test";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move out of loop

@jdneo
Copy link
Contributor Author

jdneo commented Jun 15, 2020

Just came up in mind that maybe implement by this way will have much less impact on the perf?

IWorkspace workspace = ResourcesPlugin.getWorkspace();
ISchedulingRule currentRule = Job.getJobManager().currentRule();
ISchedulingRule schedulingRule;
if (currentRule != null && currentRule.contains(javaProject.getSchedulingRule())) {
	schedulingRule = null;
} else {
	schedulingRule = javaProject.getSchedulingRule();
}
workspace.run(new IWorkspaceRunnable() {
	@Override
	public void run(IProgressMonitor monitor) throws CoreException {
		// get classpath
	}
}, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());

Signed-off-by: Sheng Chen <sheche@microsoft.com>
@fbricon fbricon merged commit e048ffa into eclipse-jdtls:master Jun 16, 2020
@fbricon
Copy link
Contributor

fbricon commented Jun 16, 2020

Thanks @jdneo !

@fbricon fbricon added this to the Mid June 2020 milestone Jun 16, 2020
@jdneo jdneo deleted the cs/classpath-update branch June 17, 2020 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants