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

Add buildship auto sync preference #2224

Merged
merged 1 commit into from
Sep 16, 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
Expand Up @@ -77,6 +77,7 @@
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus;
import org.eclipse.jdt.ls.internal.gradle.checksums.ValidationResult;
import org.eclipse.jdt.ls.internal.gradle.checksums.WrapperValidator;
import org.eclipse.lsp4j.ExecuteCommandParams;
Expand Down Expand Up @@ -444,8 +445,9 @@ public static BuildConfiguration getBuildConfiguration(Path rootFolder) {
gradleArguments.addAll(preferences.getGradleArguments());
List<String> gradleJvmArguments = preferences.getGradleJvmArguments();
boolean offlineMode = preferences.isImportGradleOfflineEnabled();
boolean autoSync = preferences.getUpdateBuildConfigurationStatus().equals(FeatureStatus.automatic);
boolean overrideWorkspaceConfiguration = !(distribution instanceof WrapperGradleDistribution) || offlineMode || (gradleArguments != null && !gradleArguments.isEmpty()) || (gradleJvmArguments != null && !gradleJvmArguments.isEmpty())
|| gradleUserHome != null || javaHome != null;
|| gradleUserHome != null || javaHome != null || autoSync;
// @formatter:off
BuildConfiguration build = BuildConfiguration.forRootProjectDirectory(rootFolder.toFile())
.overrideWorkspaceConfiguration(overrideWorkspaceConfiguration)
Expand All @@ -455,6 +457,7 @@ public static BuildConfiguration getBuildConfiguration(Path rootFolder) {
.gradleUserHome(gradleUserHome)
.jvmArguments(gradleJvmArguments)
.offlineMode(offlineMode)
.autoSync(autoSync)
.build();
// @formatter:on
return build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ public void fileChanged(String uriString, CHANGE_TYPE changeType) {
return;
}
try {
Optional<IBuildSupport> bs = getBuildSupport(resource.getProject());
IProject project = resource.getProject();
Optional<IBuildSupport> bs = getBuildSupport(project);
if (bs.isPresent()) {
IBuildSupport buildSupport = bs.get();

Expand All @@ -238,7 +239,11 @@ public void fileChanged(String uriString, CHANGE_TYPE changeType) {
FeatureStatus status = preferenceManager.getPreferences().getUpdateBuildConfigurationStatus();
switch (status) {
case automatic:
updateProject(resource.getProject(), true);
if (ProjectUtils.isGradleProject(project)) {
// See https://github.com/redhat-developer/vscode-java/issues/2673
return;
}
updateProject(project, true);
break;
case disabled:
appendBuildFileMarker(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.eclipse.jdt.ls.core.internal.TestVMType;
import org.eclipse.jdt.ls.core.internal.WorkspaceHelper;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -414,6 +415,21 @@ public void testGradleOfflineMode() {
}
}

@Test
public void testGradleAutoSync() {
FeatureStatus status = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getUpdateBuildConfigurationStatus();
try {
Path rootPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().toPath();
BuildConfiguration build = GradleProjectImporter.getBuildConfiguration(rootPath);
assertFalse(build.isAutoSync());
JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setUpdateBuildConfigurationStatus(FeatureStatus.automatic);
build = GradleProjectImporter.getBuildConfiguration(rootPath);
assertTrue(build.isAutoSync());
} finally {
JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setUpdateBuildConfigurationStatus(status);
}
}

@Test
public void testGradleJvmArguments() {
List<String> jvmArguments = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getGradleJvmArguments();
Expand Down