Skip to content

Commit

Permalink
fix: Skip builders when build server is disabled (#1424)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored Sep 26, 2023
1 parent 5fad292 commit a86cedd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -264,10 +256,4 @@ private BuildServerPreferences getBuildServerPreferences() {
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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,6 +22,7 @@
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;

Expand All @@ -29,6 +32,8 @@
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);
}
Expand Down Expand Up @@ -189,4 +194,17 @@ public static ICommand getBuildServerBuildSpec(IProjectDescription description)
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
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.*;
Expand Down Expand Up @@ -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];

Expand Down

0 comments on commit a86cedd

Please sign in to comment.