fix: Skip builders when build server is disabled (#1424)

Signed-off-by: Sheng Chen <sheche@microsoft.com>
This commit is contained in:
Sheng Chen 2023-09-25 19:49:53 -07:00 коммит произвёл GitHub
Родитель 5fad292978
Коммит a86ceddabe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 31 добавлений и 15 удалений

Просмотреть файл

@ -1,7 +1,5 @@
package com.microsoft.gradle.bs.importer;
import static org.eclipse.jdt.ls.core.internal.handlers.MapFlattener.getString;
import java.io.File;
import java.net.URI;
import java.util.Arrays;
@ -57,20 +55,14 @@ public class GradleBuildServerProjectImporter extends AbstractProjectImporter {
public static final String SETTINGS_GRADLE_DESCRIPTOR = "settings.gradle";
public static final String SETTINGS_GRADLE_KTS_DESCRIPTOR = "settings.gradle.kts";
private static final String JAVA_BUILD_SERVER_GRADLE_ENABLED = "java.gradle.buildServer.enabled";
@Override
public boolean applies(IProgressMonitor monitor) throws OperationCanceledException, CoreException {
if (rootFolder == null) {
return false;
}
Preferences preferences = getPreferences();
if (!preferences.isImportGradleEnabled()) {
return false;
}
if (!isBuildServerEnabled()) {
if (!Utils.isBuildServerEnabled(getPreferences())) {
return false;
}
@ -264,10 +256,4 @@ public class GradleBuildServerProjectImporter extends AbstractProjectImporter {
pref.setJdks(EclipseVmUtil.getAllVmInstalls());
return pref;
}
private boolean isBuildServerEnabled() {
Preferences preferences = getPreferences();
String bspImporterEnabled = getString(preferences.asMap(), JAVA_BUILD_SERVER_GRADLE_ENABLED);
return "on".equalsIgnoreCase(bspImporterEnabled);
}
}

Просмотреть файл

@ -1,5 +1,7 @@
package com.microsoft.gradle.bs.importer;
import static org.eclipse.jdt.ls.core.internal.handlers.MapFlattener.getString;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
@ -20,6 +22,7 @@ import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import com.microsoft.gradle.bs.importer.builder.BuildServerBuilder;
@ -29,6 +32,8 @@ import ch.epfl.scala.bsp4j.WorkspaceBuildTargetsResult;
public class Utils {
private Utils() {}
private static final String JAVA_BUILD_SERVER_GRADLE_ENABLED = "java.gradle.buildServer.enabled";
public static boolean isGradleBuildServerProject(IProject project) {
return ProjectUtils.hasNature(project, GradleBuildServerProjectNature.NATURE_ID);
}
@ -189,4 +194,17 @@ public class Utils {
buildSpec.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD, false);
return buildSpec;
}
public static boolean isBuildServerEnabled(Preferences preferences) {
if (preferences == null) {
return false;
}
if (!preferences.isImportGradleEnabled()) {
return false;
}
String bspImporterEnabled = getString(preferences.asMap(), JAVA_BUILD_SERVER_GRADLE_ENABLED);
return "on".equalsIgnoreCase(bspImporterEnabled);
}
}

Просмотреть файл

@ -15,6 +15,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import com.microsoft.gradle.bs.importer.BuildServerConnection;
import com.microsoft.gradle.bs.importer.ImporterPlugin;
@ -32,6 +33,11 @@ public class BuildServerBuilder extends IncrementalProjectBuilder {
@Override
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
Preferences preferences = JavaLanguageServerPlugin.getPreferencesManager().getPreferences();
if (!Utils.isBuildServerEnabled(preferences)) {
return null;
}
IProject project = this.getProject();
IPath rootPath = ProjectUtils.findBelongedWorkspaceRoot(project.getLocation());
if (rootPath == null) {

Просмотреть файл

@ -25,7 +25,9 @@ import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
import org.eclipse.jdt.internal.core.*;
import org.eclipse.jdt.internal.core.util.Messages;
import org.eclipse.jdt.internal.core.util.Util;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import com.microsoft.gradle.bs.importer.Utils;
import com.microsoft.java.builder.BuildStateManager;
import java.io.*;
@ -171,6 +173,10 @@ public static void writeState(Object state, DataOutputStream out) throws IOExcep
@Override
protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) throws CoreException {
org.eclipse.jdt.ls.core.internal.preferences.Preferences preferences = JavaLanguageServerPlugin.getPreferencesManager().getPreferences();
if (!Utils.isBuildServerEnabled(preferences)) {
return null;
}
this.currentProject = getProject();
if (this.currentProject == null || !this.currentProject.isAccessible()) return new IProject[0];