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

Avoid unnecessary project updates when the default vm changes #2266

Merged
merged 1 commit into from
Oct 11, 2022
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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2020 Red Hat Inc. and others.
* Copyright (c) 2019-2022 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -302,8 +302,7 @@ public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
configureJVMSettings(javaProject, current);
}
ProjectsManager projectsManager = JavaLanguageServerPlugin.getProjectsManager();
if (projectsManager != null) {
//TODO Only trigger update if the project uses the default JVM
if (projectsManager != null && projectsManager.useDefaultVM(project, current)) {
JavaLanguageServerPlugin.logInfo("defaultVMInstallChanged -> force update of " + project.getName());
projectsManager.updateProject(project, true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016-2020 Red Hat Inc. and others.
* Copyright (c) 2016-2022 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -42,6 +42,7 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
Expand Down Expand Up @@ -163,6 +164,11 @@ public boolean fileChanged(IResource resource, CHANGE_TYPE changeType, IProgress
return IBuildSupport.super.fileChanged(resource, changeType, monitor) || isBuildFile(resource);
}

@Override
public boolean useDefaultVM(IProject project, IVMInstall defaultVM) {
return GradleProjectImporter.useDefaultVM();
}

/**
* save gradle project preferences
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ public static BuildConfiguration getBuildConfiguration(Path rootFolder) {
return build;
}

static boolean useDefaultVM() {
File javaHome = getGradleJavaHomeFile();
if (javaHome == null) {
IVMInstall javaDefaultRuntime = JavaRuntime.getDefaultVMInstall();
return javaDefaultRuntime != null
&& javaDefaultRuntime.getVMRunner(ILaunchManager.RUN_MODE) != null;
}

return false;
}

private static File getJavaHome(Preferences preferences) {
File javaHome = getGradleJavaHomeFile();
if (javaHome == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016-2020 Red Hat Inc. and others.
* Copyright (c) 2016-2022 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -25,6 +25,7 @@
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.CHANGE_TYPE;
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
Expand Down Expand Up @@ -81,6 +82,13 @@ default boolean fileChanged(IResource resource, CHANGE_TYPE changeType, IProgres
return false;
}

/**
* Check if the build support for the specified project depends on the default VM.
*/
default boolean useDefaultVM(IProject project, IVMInstall defaultVM) {
return false;
}

default void refresh(IResource resource, CHANGE_TYPE changeType, IProgressMonitor monitor) throws CoreException {
if (resource == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,22 @@ public Optional<IBuildSupport> getBuildSupport(IProject project) {
return buildSupports().filter(bs -> bs.applies(project)).findFirst();
}

/**
* Check if the build support for the specified project depends on the default VM.
*/
public boolean useDefaultVM(IProject project, IVMInstall defaultVM) {
if (project == null) {
return false;
}

IBuildSupport buildSupport = getBuildSupport(project).orElse(null);
if (buildSupport != null) {
return buildSupport.useDefaultVM(project, defaultVM);
}

return false;
}

private Stream<IBuildSupport> buildSupports() {
return Stream.of(new EclipseBuildSupport());
}
Expand Down