Runtime load recipes yml/jar. Offscreen doc quick fix.

This commit is contained in:
aboyko
2022-09-16 18:52:48 -04:00
parent 01008b3375
commit 1a708a44e8
46 changed files with 1145 additions and 148 deletions

View File

@@ -131,6 +131,12 @@
id="org.springframework.tooling.boot.ls.preferences"
name="Spring Boot Language Server">
</page>
<page
category="org.springframework.tooling.boot.ls.preferences"
class="org.springframework.tooling.boot.ls.RewritePreferencePage"
id="org.springframework.tooling.boot.ls.rewrite"
name="Rewrite">
</page>
</extension>
@@ -338,9 +344,13 @@
<extension
point="org.eclipse.ui.quickAccess">
<computer
class="org.springframework.tooling.boot.ls.commands.LiveProcessCommandsQuickAccessProvider"
class="org.springframework.tooling.boot.ls.commands.RewriteCommandsQuickAccessProvider"
name="Spring - Live Process Information"
requiresUIAccess="false"/>
<computer
class="org.springframework.tooling.boot.ls.QuickAccessComputer1"
name="Spring - Rewrite Recipes">
</computer>
</extension>
<extension
point="org.springsource.ide.eclipse.commons.boot.ls.remoteapps.RemoteBootAppsDataHolder.Contributor">

View File

@@ -96,7 +96,6 @@ public class BootJavaPreferencesPage extends FieldEditorPreferencePage implement
addField(new BooleanFieldEditor(Constants.PREF_VALIDATION_SPEL_EXPRESSIONS, "SpEL Expression Syntax Validation", fieldEditorParent));
addField(new BooleanFieldEditor(Constants.PREF_REWRITE_RECONCILE, "Experimental reconciling for Java source based on Rewrite project", fieldEditorParent));
}
}

View File

@@ -33,4 +33,7 @@ public class Constants {
public static final String PREF_REWRITE_RECONCILE = "boot-java.rewrite.reconcile";
public static final String PREF_REWRITE_RECIPES_SCAN_FILES = "boot-java.rewrite.scan-files";
public static final String PREF_REWRITE_RECIPES_SCAN_DIRS = "boot-java.rewrite.scan-directories";
}

View File

@@ -32,9 +32,9 @@ import org.eclipse.lsp4j.jsonrpc.messages.Message;
import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage;
import org.eclipse.lsp4j.services.LanguageServer;
import org.springframework.tooling.boot.ls.prefs.CategoryProblemsSeverityPrefsPage;
import org.springframework.tooling.boot.ls.prefs.FileListEditor;
import org.springframework.tooling.boot.ls.prefs.ProblemCategoryData;
import org.springframework.tooling.boot.ls.prefs.ProblemCategoryData.CategoryToggleData;
import org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator;
import org.springsource.ide.eclipse.commons.boot.ls.remoteapps.RemoteBootAppsDataHolder;
import org.springsource.ide.eclipse.commons.boot.ls.remoteapps.RemoteBootAppsDataHolder.RemoteAppData;
import org.springsource.ide.eclipse.commons.livexp.core.ValueListener;
@@ -187,7 +187,12 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi
bootJavaObj.put("change-detection", bootChangeDetection);
bootJavaObj.put("validation", validation);
bootJavaObj.put("remote-apps", getAllRemoteApps());
bootJavaObj.put("rewrite", Map.of("reconcile", preferenceStore.getBoolean(Constants.PREF_REWRITE_RECONCILE)));
bootJavaObj.put("rewrite", Map.of(
"reconcile", preferenceStore.getBoolean(Constants.PREF_REWRITE_RECONCILE),
"scan-directories", FileListEditor.getValuesFromPreference(preferenceStore.getString(Constants.PREF_REWRITE_RECIPES_SCAN_DIRS)),
"scan-files", FileListEditor.getValuesFromPreference(preferenceStore.getString(Constants.PREF_REWRITE_RECIPES_SCAN_FILES))
));
settings.put("boot-java", bootJavaObj);
putValidationPreferences(settings);

View File

@@ -0,0 +1,33 @@
package org.springframework.tooling.boot.ls;
import java.util.List;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.PathEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.springframework.tooling.boot.ls.prefs.FileListEditor;
public class RewritePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(BootLanguageServerPlugin.getDefault().getPreferenceStore());
}
@Override
protected void createFieldEditors() {
Composite fieldEditorParent = getFieldEditorParent();
addField(new BooleanFieldEditor(Constants.PREF_REWRITE_RECONCILE, "Experimental reconciling for Java source based on Rewrite project", fieldEditorParent));
addField(new FileListEditor(Constants.PREF_REWRITE_RECIPES_SCAN_FILES, "JAR and YAML files to scan for Recipes", "Select JARs and YAML files:", fieldEditorParent, List.of("jar", "yml", "yaml")));
addField(new PathEditor(Constants.PREF_REWRITE_RECIPES_SCAN_DIRS, "Directories to scan for Recipes", "Select directory to scan for Recipes", fieldEditorParent));
}
}

View File

@@ -0,0 +1,92 @@
/*******************************************************************************
* 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 Rewrite Recipes";
}
@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 Rewrite Recipes!", e);
}
}
}
};
}
@Override
public QuickAccessElement[] computeElements() {
return new QuickAccessElement[0];
}
@Override
public void resetState() {
}
@Override
public boolean needsRefresh() {
return false;
}
}

View File

@@ -48,6 +48,7 @@ import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
@SuppressWarnings("restriction")
public class RewriteRefactoringsHandler extends AbstractHandler {
private static class DurationTypeConverter implements JsonSerializer<Duration>, JsonDeserializer<Duration> {

View File

@@ -45,6 +45,7 @@ import org.osgi.framework.FrameworkUtil;
import org.springframework.tooling.boot.ls.commands.RecipeDescriptor.OptionDescriptor;
import org.springframework.tooling.boot.ls.commands.RecipeTreeModel.CheckedState;
@SuppressWarnings("restriction")
public class SelectRecipesDialog extends StatusDialog {
private static final int MARGIN = 5;

View File

@@ -0,0 +1,72 @@
/*******************************************************************************
* 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.prefs;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.jface.preference.PathEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
public class FileListEditor extends PathEditor {
private String lastPath;
private String dirChooserLabelText;
private List<String> fileFilters;
public FileListEditor(String name, String labelText,
String dirChooserLabelText, Composite parent, List<String> fileFilters) {
super(name, labelText, dirChooserLabelText, parent);
this.dirChooserLabelText = dirChooserLabelText;
this.fileFilters = fileFilters;
}
@Override
protected String getNewInputObject() {
FileDialog dialog = new FileDialog(getShell(), SWT.SHEET);
dialog.setFilterExtensions(fileFilters.toArray(String[]::new));
if (dirChooserLabelText != null) {
dialog.setText(dirChooserLabelText);
}
if (lastPath != null) {
if (new File(lastPath).exists()) {
dialog.setFilterPath(lastPath);
}
}
String file = dialog.open();
if (file != null) {
String parentFolder = new File(file).getParent();
if (parentFolder == null) {
return null;
}
lastPath = parentFolder;
}
return file;
}
public static List<String> getValuesFromPreference(String rawValue) {
StringTokenizer st = new StringTokenizer(rawValue, File.pathSeparator
+ "\n\r");//$NON-NLS-1$
ArrayList<String> l = new ArrayList<>();
while (st.hasMoreElements()) {
l.add((String)st.nextElement());
}
return l;
}
}