Shared properties metadata file preference setting
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
package org.springframework.ide.vscode.boot.app;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -156,7 +158,7 @@ public class BootJavaConfig implements InitializingBean {
|
||||
}
|
||||
|
||||
public String getSpringIOApiUrl() {
|
||||
String url = getRawSettings().getString("spring-boot", "io", "api");
|
||||
String url = getRawSettings().getString("boot-java", "io", "api");
|
||||
return url == null ? SPRING_IO_API_URL : url;
|
||||
}
|
||||
|
||||
@@ -192,6 +194,11 @@ public class BootJavaConfig implements InitializingBean {
|
||||
return settings.getStringSet("boot-java", "rewrite", "scan-files");
|
||||
}
|
||||
|
||||
public Path getCommonPropertiesFile() {
|
||||
String str = settings.getString("boot-java", "common", "properties-metadata");
|
||||
return str == null || str.isBlank() ? null : Paths.get(str);
|
||||
}
|
||||
|
||||
public Settings getRawSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@@ -219,8 +219,8 @@ public class BootLanguageServerBootApp {
|
||||
}
|
||||
|
||||
@ConditionalOnMissingClass("org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness")
|
||||
@Bean BootLanguageServerParams serverParams(SimpleLanguageServer server, ValueProviderRegistry valueProviders, JavaProjectsService projectsService) {
|
||||
return BootLanguageServerParams.createDefault(server, valueProviders, projectsService);
|
||||
@Bean BootLanguageServerParams serverParams(SimpleLanguageServer server, ValueProviderRegistry valueProviders, JavaProjectsService projectsService, BootJavaConfig config) {
|
||||
return BootLanguageServerParams.createDefault(server, valueProviders, projectsService, config);
|
||||
}
|
||||
|
||||
@ConditionalOnMissingClass("org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2020 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
|
||||
@@ -23,7 +23,6 @@ import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFin
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
/**
|
||||
@@ -63,10 +62,9 @@ public class BootLanguageServerParams {
|
||||
this.typeUtilProvider = typeUtilProvider;
|
||||
}
|
||||
|
||||
public static BootLanguageServerParams createDefault(SimpleLanguageServer server, ValueProviderRegistry valueProviders, JavaProjectsService javaProjectService) {
|
||||
public static BootLanguageServerParams createDefault(SimpleLanguageServer server, ValueProviderRegistry valueProviders, JavaProjectsService javaProjectService, BootJavaConfig config) {
|
||||
// Initialize project finders, project caches and project observers
|
||||
FileObserver fileObserver = server.getWorkspaceService().getFileObserver();
|
||||
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(javaProjectService, javaProjectService, fileObserver, valueProviders);
|
||||
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(javaProjectService, javaProjectService, server, valueProviders, config);
|
||||
indexProvider.setProgressService(server.getProgressService());
|
||||
|
||||
return new BootLanguageServerParams(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 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
|
||||
@@ -12,13 +12,15 @@
|
||||
package org.springframework.ide.vscode.boot.metadata;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.ProgressService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
public class DefaultSpringPropertyIndexProvider implements SpringPropertyIndexProvider {
|
||||
@@ -30,14 +32,18 @@ public class DefaultSpringPropertyIndexProvider implements SpringPropertyIndexPr
|
||||
|
||||
private ProgressService progressService = ProgressService.NO_PROGRESS;
|
||||
|
||||
public DefaultSpringPropertyIndexProvider(JavaProjectFinder javaProjectFinder, ProjectObserver projectObserver, FileObserver fileObserver, ValueProviderRegistry valueProviders) {
|
||||
public DefaultSpringPropertyIndexProvider(JavaProjectFinder javaProjectFinder, ProjectObserver projectObserver, SimpleLanguageServer server, ValueProviderRegistry valueProviders, BootJavaConfig config) {
|
||||
this.javaProjectFinder = javaProjectFinder;
|
||||
this.indexManager = new SpringPropertiesIndexManager(valueProviders, projectObserver, fileObserver);
|
||||
this.indexManager = new SpringPropertiesIndexManager(valueProviders, projectObserver, server.getWorkspaceService().getFileObserver());
|
||||
this.indexManager.addListener(info -> {
|
||||
if (changeHandler != null) {
|
||||
changeHandler.run();
|
||||
}
|
||||
});
|
||||
server.onCommand("sts/common-properties/reload", params -> CompletableFuture.completedFuture(indexManager.reloadCommonProperties()));
|
||||
if (config != null) {
|
||||
config.addListener(v -> indexManager.setCommonPropertiesFile(config.getCommonPropertiesFile()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 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
|
||||
@@ -25,7 +25,6 @@ import org.springframework.ide.vscode.boot.configurationmetadata.ConfigurationMe
|
||||
import org.springframework.ide.vscode.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
public class PropertiesLoader {
|
||||
|
||||
@@ -70,6 +69,11 @@ public class PropertiesLoader {
|
||||
ConfigurationMetadataRepository repository = builder.build();
|
||||
return repository;
|
||||
}
|
||||
|
||||
public ConfigurationMetadataRepository loadJson(Path path) {
|
||||
loadFromJsonFile(path);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private void loadFromOutputFolder(Path outputFolderPath) {
|
||||
if (outputFolderPath != null && Files.exists(outputFolderPath)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014, 2022 Pivotal, Inc.
|
||||
* Copyright (c) 2014, 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
|
||||
@@ -10,10 +10,13 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.metadata;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.configurationmetadata.ConfigurationMetadataRepository;
|
||||
import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndex.Builder;
|
||||
import org.springframework.ide.vscode.boot.metadata.util.Listener;
|
||||
import org.springframework.ide.vscode.boot.metadata.util.ListenerManager;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
@@ -21,6 +24,9 @@ import org.springframework.ide.vscode.commons.languageserver.ProgressService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -40,6 +46,9 @@ public class SpringPropertiesIndexManager extends ListenerManager<Listener<Sprin
|
||||
private Cache<IJavaProject, SpringPropertyIndex> indexes;
|
||||
private final ValueProviderRegistry valueProviders;
|
||||
private static int progressIdCt = 0;
|
||||
|
||||
private Path commonPropertiesFile;
|
||||
private Supplier<ConfigurationMetadataRepository> commonPropertiesMetadata;
|
||||
|
||||
public SpringPropertiesIndexManager(ValueProviderRegistry valueProviders, ProjectObserver projectObserver, FileObserver fileObserver) {
|
||||
this.valueProviders = valueProviders;
|
||||
@@ -72,7 +81,11 @@ public class SpringPropertiesIndexManager extends ListenerManager<Listener<Sprin
|
||||
progressService.progressBegin(progressId, "Indexing Spring Boot Properties", null);
|
||||
}
|
||||
|
||||
SpringPropertyIndex index = new SpringPropertyIndex(valueProviders, project.getClasspath());
|
||||
Builder builder = SpringPropertyIndex.builder(valueProviders).withClasspath(project.getClasspath());
|
||||
if (commonPropertiesMetadata != null) {
|
||||
builder.withMetadata(commonPropertiesMetadata.get());
|
||||
}
|
||||
SpringPropertyIndex index = builder.build();
|
||||
|
||||
if (progressService != null) {
|
||||
progressService.progressDone(progressId);
|
||||
@@ -97,4 +110,21 @@ public class SpringPropertiesIndexManager extends ListenerManager<Listener<Sprin
|
||||
return DefaultSpringPropertyIndexProvider.class.getName()+ (progressIdCt++);
|
||||
}
|
||||
|
||||
public synchronized void setCommonPropertiesFile(Path commonPropertiesFile) {
|
||||
if (!Objects.equal(commonPropertiesFile, this.commonPropertiesFile)) {
|
||||
this.commonPropertiesFile = commonPropertiesFile;
|
||||
commonPropertiesMetadata = commonPropertiesFile == null ? null : Suppliers.memoize(() -> new PropertiesLoader().loadJson(commonPropertiesFile));
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean reloadCommonProperties() {
|
||||
if (commonPropertiesFile != null) {
|
||||
commonPropertiesMetadata = Suppliers.memoize(() -> new PropertiesLoader().loadJson(commonPropertiesFile));
|
||||
clear();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.metadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.ide.vscode.boot.configurationmetadata.ConfigurationMetadataGroup;
|
||||
@@ -27,7 +29,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
|
||||
public class SpringPropertyIndex {
|
||||
|
||||
public static final SpringPropertyIndex EMPTY_INDEX = new SpringPropertyIndex(null, null);
|
||||
public static final SpringPropertyIndex EMPTY_INDEX = new SpringPropertyIndex(null);
|
||||
|
||||
private final ValueProviderRegistry valueProviders;
|
||||
|
||||
@@ -40,30 +42,31 @@ public class SpringPropertyIndex {
|
||||
}
|
||||
};
|
||||
|
||||
public SpringPropertyIndex(ValueProviderRegistry valueProviders, IClasspath projectPath) {
|
||||
private SpringPropertyIndex(ValueProviderRegistry valueProviders) {
|
||||
this.valueProviders = valueProviders;
|
||||
if (projectPath!=null) {
|
||||
// try {
|
||||
PropertiesLoader loader = new PropertiesLoader();
|
||||
ConfigurationMetadataRepository metadata = loader.load(projectPath);
|
||||
//^^^ Should be done in bg? It seems fast enough for now.
|
||||
}
|
||||
|
||||
private void loadFromClasspath(IClasspath projectPath) {
|
||||
PropertiesLoader loader = new PropertiesLoader();
|
||||
addMetadata(loader.load(projectPath));
|
||||
//^^^ Should be done in bg? It seems fast enough for now.
|
||||
}
|
||||
|
||||
private void addMetadata(ConfigurationMetadataRepository metadata) {
|
||||
Collection<ConfigurationMetadataProperty> allEntries = metadata.getAllProperties().values();
|
||||
for (ConfigurationMetadataProperty item : allEntries) {
|
||||
properties.add(new PropertyInfo(valueProviders, item));
|
||||
}
|
||||
|
||||
Collection<ConfigurationMetadataProperty> allEntries = metadata.getAllProperties().values();
|
||||
for (ConfigurationMetadataProperty item : allEntries) {
|
||||
properties.add(new PropertyInfo(valueProviders, item));
|
||||
for (ConfigurationMetadataGroup group : metadata.getAllGroups().values()) {
|
||||
for (ConfigurationMetadataSource source : group.getSources().values()) {
|
||||
ImmutableSet.Builder<PropertySource> sources = ImmutableSet.builder();
|
||||
for (ConfigurationMetadataProperty prop : source.getProperties().values()) {
|
||||
PropertyInfo info = properties.get(prop.getId());
|
||||
sources.add(info.addSource(source));
|
||||
}
|
||||
|
||||
for (ConfigurationMetadataGroup group : metadata.getAllGroups().values()) {
|
||||
for (ConfigurationMetadataSource source : group.getSources().values()) {
|
||||
ImmutableSet.Builder<PropertySource> sources = ImmutableSet.builder();
|
||||
for (ConfigurationMetadataProperty prop : source.getProperties().values()) {
|
||||
PropertyInfo info = properties.get(prop.getId());
|
||||
sources.add(info.addSource(source));
|
||||
}
|
||||
groups.put(group.getId(), sources.build());
|
||||
}
|
||||
}
|
||||
|
||||
groups.put(group.getId(), sources.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,5 +147,40 @@ public class SpringPropertyIndex {
|
||||
public Collection<PropertySource> getGroupSources(String prefix) {
|
||||
return groups.get(prefix);
|
||||
}
|
||||
|
||||
public static final Builder builder(ValueProviderRegistry valueProviders) {
|
||||
return new Builder(valueProviders);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final ValueProviderRegistry valueProviders;
|
||||
private IClasspath projectClasspath;
|
||||
private List<ConfigurationMetadataRepository> metadataList;
|
||||
|
||||
private Builder(ValueProviderRegistry valueProviders) {
|
||||
this.valueProviders = valueProviders;
|
||||
this.metadataList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Builder withClasspath(IClasspath projectClasspath) {
|
||||
this.projectClasspath = projectClasspath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withMetadata(ConfigurationMetadataRepository metadata) {
|
||||
metadataList.add(metadata);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpringPropertyIndex build() {
|
||||
SpringPropertyIndex index = new SpringPropertyIndex(valueProviders);
|
||||
for (ConfigurationMetadataRepository m : metadataList) {
|
||||
index.addMetadata(m);
|
||||
}
|
||||
index.loadFromClasspath(projectClasspath);
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2019 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
|
||||
@@ -48,7 +48,7 @@ public class PropertyIndexHarness {
|
||||
synchronized (PropertyIndexHarness.this) {
|
||||
if (index==null) {
|
||||
IClasspath classpath = testProject == null ? null : testProject.getClasspath();
|
||||
index = new SpringPropertyIndex(valueProviders, classpath);
|
||||
index = SpringPropertyIndex.builder(valueProviders).withClasspath(classpath).build();
|
||||
for (ConfigurationMetadataProperty propertyInfo : datas.values()) {
|
||||
index.add(propertyInfo);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2020 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
|
||||
@@ -176,7 +176,7 @@ public class BootLanguageServerHarness extends LanguageServerHarness {
|
||||
|
||||
CompositeProjectOvserver projectObserver = new CompositeProjectOvserver(Arrays.asList(mavenProjectCache, gradleProjectCache));
|
||||
|
||||
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(javaProjectFinder, projectObserver, null, valueProviders);
|
||||
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(javaProjectFinder, projectObserver, server, valueProviders, null);
|
||||
indexProvider.setProgressService(server.getProgressService());
|
||||
|
||||
return new BootLanguageServerParams(
|
||||
|
||||
@@ -121,6 +121,11 @@
|
||||
"command": "vscode-spring-boot.rewrite.reload",
|
||||
"title": "Reload OpenRewrite Recipes, Code Actions, Problem and Quick Fix Descriptors",
|
||||
"category": "Spring Boot"
|
||||
},
|
||||
{
|
||||
"command": "sts/common-properties/reload",
|
||||
"title": "Reload Shared Properties Metadata",
|
||||
"category": "Spring Boot"
|
||||
}
|
||||
],
|
||||
"configuration": [
|
||||
@@ -174,6 +179,13 @@
|
||||
"default": true,
|
||||
"description": "Enable/Disable Spring running Boot application Code Lenses"
|
||||
},
|
||||
"boot-java.common.properties-metadata": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
],
|
||||
"description": "The path to a shared properties metadata JSON file."
|
||||
},
|
||||
"boot-java.change-detection.on": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
|
||||
Reference in New Issue
Block a user