Shared properties metadata file preference setting

This commit is contained in:
aboyko
2023-02-13 18:41:04 -05:00
parent fbbb6fbcfd
commit a19082813f
16 changed files with 267 additions and 137 deletions

View File

@@ -472,8 +472,9 @@
name="Spring - Live Process Information"
requiresUIAccess="false"/>
<computer
class="org.springframework.tooling.boot.ls.commands.RewriteCommandsQuickAccessProvider"
name="Spring - OpenRewrite Recipes">
class="org.springframework.tooling.boot.ls.commands.SpringQuickAccessProvider"
name="Spring"
requiresUIAccess="false">
</computer>
</extension>
<extension

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Pivotal, Inc.
* Copyright (c) 2017, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -44,4 +44,6 @@ public class Constants {
public static final String PREF_REWRITE_PROJECT_REFACTORINGS = "boot-java.rewrite.project-refactorings";
public static final String PREF_START_LS_EARLY = "start.boot-ls.early";
public static final String PREF_COMMON_PROPS_METADATA = "boot-java.common.properties-metadata";
}

View File

@@ -240,6 +240,11 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi
"scan-directories", FileListEditor.getValuesFromPreference(preferenceStore.getString(Constants.PREF_REWRITE_RECIPES_SCAN_DIRS)),
"scan-files", FileListEditor.getValuesFromPreference(preferenceStore.getString(Constants.PREF_REWRITE_RECIPES_SCAN_FILES))
));
bootJavaObj.put("common", Map.of(
"properties-metadata", preferenceStore.getString(Constants.PREF_COMMON_PROPS_METADATA)
));
settings.put("boot-java", bootJavaObj);
putValidationPreferences(settings);

View File

@@ -1,92 +0,0 @@
/*******************************************************************************
* Copyright (c) 2022 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.boot.ls.commands;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.ui.quickaccess.IQuickAccessComputer;
import org.eclipse.ui.quickaccess.IQuickAccessComputerExtension;
import org.eclipse.ui.quickaccess.QuickAccessElement;
import org.springframework.tooling.boot.ls.BootLanguageServerPlugin;
@SuppressWarnings("restriction")
public class RewriteCommandsQuickAccessProvider implements IQuickAccessComputer, IQuickAccessComputerExtension {
private static final String CMD_REWRITE_RELOAD = "sts/rewrite/reload";
@Override
public QuickAccessElement[] computeElements(String query, IProgressMonitor monitor) {
return new QuickAccessElement[] {
new QuickAccessElement() {
@Override
public String getLabel() {
return "Reload OpenRewrite Recipes, Code Actions, Problem and Quick Fix Descriptors";
}
@Override
public ImageDescriptor getImageDescriptor() {
return null;
}
@Override
public String getId() {
return CMD_REWRITE_RELOAD;
}
@Override
public void execute() {
List<LanguageServer> usedLanguageServers = LanguageServiceAccessor.getActiveLanguageServers(serverCapabilities -> true);
if (usedLanguageServers.isEmpty()) {
return;
}
ExecuteCommandParams commandParams = new ExecuteCommandParams();
commandParams.setCommand(CMD_REWRITE_RELOAD);
commandParams.setArguments(Collections.emptyList());
try {
CompletableFuture.allOf(usedLanguageServers.stream().map(ls ->
ls.getWorkspaceService().executeCommand(commandParams)).toArray(CompletableFuture[]::new)).get(2, TimeUnit.SECONDS);
}
catch (Exception e) {
BootLanguageServerPlugin.getDefault().getLog().error("Failed to reload OpenRewrite Recipes!", e);
}
}
}
};
}
@Override
public QuickAccessElement[] computeElements() {
return new QuickAccessElement[0];
}
@Override
public void resetState() {
}
@Override
public boolean needsRefresh() {
return false;
}
}

View File

@@ -0,0 +1,110 @@
/*******************************************************************************
* Copyright (c) 2023 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.boot.ls.commands;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.ui.quickaccess.IQuickAccessComputer;
import org.eclipse.ui.quickaccess.IQuickAccessComputerExtension;
import org.eclipse.ui.quickaccess.QuickAccessElement;
import org.springframework.tooling.boot.ls.BootLanguageServerPlugin;
@SuppressWarnings("restriction")
public class SpringQuickAccessProvider implements IQuickAccessComputer, IQuickAccessComputerExtension {
final private QuickAccessElement reloadPropertiesAction = createForNoArgsLsCommand(
"sts/common-properties/reload",
"Reload Shared Properties Metadata",
"Failed to reload shared properties metadata file!"
);
final private QuickAccessElement reloadRecipesAction = createForNoArgsLsCommand(
"sts/rewrite/reload",
"Reload OpenRewrite Recipes, Code Actions, Problem and Quick Fix Descriptors",
"Failed to reload OpenRewrite Recipes!"
);
private static QuickAccessElement createForNoArgsLsCommand(String commandId, String label, String errorMsg) {
return new QuickAccessElement() {
@Override
public String getLabel() {
return label;
}
@Override
public ImageDescriptor getImageDescriptor() {
return null;
}
@Override
public String getId() {
return commandId;
}
@Override
public void execute() {
List<LanguageServer> usedLanguageServers = LanguageServiceAccessor.getActiveLanguageServers(serverCapabilities -> true);
if (usedLanguageServers.isEmpty()) {
return;
}
ExecuteCommandParams commandParams = new ExecuteCommandParams();
commandParams.setCommand(commandId);
commandParams.setArguments(Collections.emptyList());
try {
CompletableFuture.allOf(usedLanguageServers.stream().map(ls ->
ls.getWorkspaceService().executeCommand(commandParams)).toArray(CompletableFuture[]::new)).get(2, TimeUnit.SECONDS);
}
catch (Exception e) {
BootLanguageServerPlugin.getDefault().getLog().error(errorMsg, e);
}
}
};
}
@Override
public QuickAccessElement[] computeElements() {
return new QuickAccessElement[] {
reloadPropertiesAction,
reloadRecipesAction
};
}
@Override
public void resetState() {
}
@Override
public boolean needsRefresh() {
return false;
}
@Override
public QuickAccessElement[] computeElements(String query, IProgressMonitor monitor) {
return new QuickAccessElement[] {
reloadPropertiesAction,
reloadRecipesAction
};
}
}

View File

@@ -10,8 +10,11 @@
*******************************************************************************/
package org.springframework.tooling.boot.ls.prefs;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -40,6 +43,12 @@ public class BootJavaPreferencesPage extends FieldEditorPreferencePage implement
addField(new BooleanFieldEditor(Constants.PREF_CHANGE_DETECTION, "Live Boot Change Detection", fieldEditorParent));
Composite c = new Composite(fieldEditorParent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(c);
FileFieldEditor propMetadataFileEditor = new FileFieldEditor(Constants.PREF_COMMON_PROPS_METADATA, "Shared Properties", true, c);
propMetadataFileEditor.setFileExtensions(new String[] {"json"});
addField(propMetadataFileEditor);
}
}