Preference setting for white-listing recipes

This commit is contained in:
aboyko
2022-10-13 17:18:16 -04:00
parent f44c773be2
commit f36090ddc3
9 changed files with 177 additions and 28 deletions

View File

@@ -33,6 +33,8 @@ public class Constants {
public static final String PREF_REWRITE_RECONCILE = "boot-java.rewrite.reconcile";
public static final String PREF_REWRITE_RECIPE_FILTERS = "boot-java.rewrite.recipe-filters";
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

@@ -35,6 +35,7 @@ import org.springframework.tooling.boot.ls.prefs.CategoryProblemsSeverityPrefsPa
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.boot.ls.prefs.StringListEditor;
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;
@@ -191,6 +192,7 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi
bootJavaObj.put("rewrite", Map.of(
"reconcile", preferenceStore.getBoolean(Constants.PREF_REWRITE_RECONCILE),
"recipe-filters", StringListEditor.decode(preferenceStore.getString(Constants.PREF_REWRITE_RECIPE_FILTERS)),
"scan-directories", FileListEditor.getValuesFromPreference(preferenceStore.getString(Constants.PREF_REWRITE_RECIPES_SCAN_DIRS)),
"scan-files", FileListEditor.getValuesFromPreference(preferenceStore.getString(Constants.PREF_REWRITE_RECIPES_SCAN_FILES))
));

View File

@@ -12,6 +12,7 @@ package org.springframework.tooling.boot.ls;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.springframework.tooling.boot.ls.prefs.StringListEditor;
/**
* Preferences initializer for Boot-Java LS extension
@@ -42,6 +43,19 @@ public class PrefsInitializer extends AbstractPreferenceInitializer {
preferenceStore.setDefault(Constants.PREF_SCAN_JAVA_TEST_SOURCES, false);
preferenceStore.setDefault(Constants.PREF_REWRITE_RECONCILE, false);
preferenceStore.setDefault(Constants.PREF_REWRITE_RECIPE_FILTERS, StringListEditor.encode(new String[] {
"org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration",
"org.openrewrite.java.spring.boot2.SpringBoot2BestPractices",
"org.openrewrite.java.spring.boot2.SpringBoot1To2Migration",
"org.openrewrite.java.testing.junit5.JUnit5BestPractices",
"org.openrewrite.java.testing.junit5.JUnit4to5Migration",
"org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_6",
"org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0",
"org.rewrite.java.security.*",
"org.springframework.rewrite.test.*",
"rewrite.test.*"
}));
}
}

View File

@@ -9,6 +9,7 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.springframework.tooling.boot.ls.prefs.FileListEditor;
import org.springframework.tooling.boot.ls.prefs.StringListEditor;
public class RewritePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
@@ -21,11 +22,18 @@ public class RewritePreferencePage extends FieldEditorPreferencePage implements
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 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 StringListEditor(fieldEditorParent, Constants.PREF_REWRITE_RECIPE_FILTERS,
"Recipe filter IDs and patterns", "Filter Value",
"Either exact ID or pattern with '*' as the wild-card:", text -> text.isBlank() ? "Cannot be blank" : null));
addField(new PathEditor(Constants.PREF_REWRITE_RECIPES_SCAN_DIRS, "Directories to scan for Recipes", "Select directory to scan for Recipes", 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,61 @@
/*******************************************************************************
* 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 org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.preference.ListEditor;
import org.eclipse.swt.widgets.Composite;
public class StringListEditor extends ListEditor {
private static final String DELIMITER = "---";
private String promptTitle;
private String promptMessage;
private IInputValidator validator;
public static String encode(String[] items) {
return String.join(DELIMITER, items);
}
public static String[] decode(String value) {
return value.split(DELIMITER);
}
@Override
protected String createList(String[] items) {
return encode(items);
}
public StringListEditor(Composite parent, String name, String label, String promptTitle, String promptMessage, IInputValidator validator) {
super(name, label, parent);
this.promptTitle = promptTitle;
this.promptMessage = promptMessage;
this.validator = validator;
}
@Override
protected String getNewInputObject() {
InputDialog dialog = new InputDialog(getShell(), promptTitle, promptMessage, "", validator);
if (dialog.open() == IDialogConstants.OK_ID) {
return dialog.getValue();
}
return null;
}
@Override
protected String[] parseString(String stringList) {
return decode(stringList);
}
}