Shared properties metadata file preference setting
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user