Skip to content

Commit

Permalink
GH-1083: integrate fingerprint of validation settings into diagnostic…
Browse files Browse the repository at this point in the history
…s cache
  • Loading branch information
martinlippert committed Aug 4, 2023
1 parent 073b53a commit d13cea2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ public Editor newEditorFromFileUri(String docUri, LanguageId languageId) throws
}

public void changeConfiguration(Settings settings) {
getServer().getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(settings));
getServer().getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(settings.getRawSettings()));
}

public SimpleLanguageServer getServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public void removeSymbols(IJavaProject project, String docURI) {
reconcilers.add(new BeanMethodNotPublicReconciler(server.getQuickfixRegistry()));

BiFunction<AtomicReference<TextDocument>, BiConsumer<String, Diagnostic>, IProblemCollector> problemCollectorFactory = (docRef, aggregator) -> server.createProblemCollector(docRef, aggregator);
springIndexerJava = new SpringIndexerJava(handler, specificProviders, this.cache, projectFinder(), server.getProgressService(), reconcilers, problemCollectorFactory);
springIndexerJava = new SpringIndexerJava(handler, specificProviders, this.cache, projectFinder(), server.getProgressService(), reconcilers, problemCollectorFactory, config.getJavaValidationSettingsJson());

factoriesIndexer = new SpringFactoriesIndexer(handler, cache);

Expand Down Expand Up @@ -278,14 +278,12 @@ public void removeSymbols(IJavaProject project, String docURI) {

config.addListener(evt -> {
log.info("update settings of spring indexer - start");

CompletableFuture.runAsync(() ->
configureIndexer(SymbolIndexConfig.builder()
.scanXml(config.isSpringXMLSupportEnabled())
.xmlScanFolders(config.xmlBeansFoldersToScan())
.scanTestJavaSources(config.isScanJavaTestSourcesEnabled())
.build()
), this.updateQueue);

configurationChanged(SymbolIndexConfig.builder()
.scanXml(config.isSpringXMLSupportEnabled())
.xmlScanFolders(config.xmlBeansFoldersToScan())
.scanTestJavaSources(config.isScanJavaTestSourcesEnabled())
.build());

log.info("update settings of spring indexer - done");
});
Expand All @@ -309,6 +307,15 @@ public void serverInitialized() {
});
}

public void configurationChanged(SymbolIndexConfig config) {
CompletableFuture.runAsync(() -> configureIndexer(config), this.updateQueue);

Collection<? extends IJavaProject> projects = projectFinder().all();
for (IJavaProject project : projects) {
initializeProject(project, true);
}
}

public void configureIndexer(SymbolIndexConfig config) {
synchronized (this) {
if (config.isScanXml() && !(Arrays.asList(this.indexers).contains(springIndexerXML))) {
Expand All @@ -326,11 +333,7 @@ public void configureIndexer(SymbolIndexConfig config) {
}
}
springIndexerJava.setScanTestJavaSources(config.isScanTestJavaSources());
}

Collection<? extends IJavaProject> projects = projectFinder().all();
for (IJavaProject project : projects) {
initializeProject(project, true);
springIndexerJava.setValidationSeveritySettings(this.config.getJavaValidationSettingsJson());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import com.google.gson.JsonObject;

/**
* @author Martin Lippert
Expand Down Expand Up @@ -104,14 +105,18 @@ public static enum SCAN_PASS {
private final ProgressService progressService;

private boolean scanTestJavaSources = false;
private JsonObject validationSeveritySettings;

private FileScanListener fileScanListener = null; //used by test code only

private final SpringIndexerJavaDependencyTracker dependencyTracker = new SpringIndexerJavaDependencyTracker();
private final BiFunction<AtomicReference<TextDocument>, BiConsumer<String, Diagnostic>, IProblemCollector> problemCollectorCreator;


public SpringIndexerJava(SymbolHandler symbolHandler, AnnotationHierarchyAwareLookup<SymbolProvider> symbolProviders, IndexCache cache,
JavaProjectFinder projectFimder, ProgressService progressService, List<AnnotationReconciler> reconcilers,
BiFunction<AtomicReference<TextDocument>, BiConsumer<String, Diagnostic>, IProblemCollector> problemCollectorCreator) {
BiFunction<AtomicReference<TextDocument>, BiConsumer<String, Diagnostic>, IProblemCollector> problemCollectorCreator,
JsonObject validationSeveritySettings) {
this.symbolHandler = symbolHandler;
this.symbolProviders = symbolProviders;
this.reconcilers = reconcilers;
Expand All @@ -120,6 +125,7 @@ public SpringIndexerJava(SymbolHandler symbolHandler, AnnotationHierarchyAwareLo
this.progressService = progressService;

this.problemCollectorCreator = problemCollectorCreator;
this.validationSeveritySettings = validationSeveritySettings;
}

public SpringIndexerJavaDependencyTracker getDependencyTracker() {
Expand Down Expand Up @@ -776,7 +782,8 @@ private IndexCacheKey getCacheKey(IJavaProject project, String elementType) {
.map(file -> file.getAbsolutePath() + "#" + file.lastModified())
.collect(Collectors.joining(","));

return new IndexCacheKey(project.getElementName(), "java", elementType, DigestUtils.md5Hex(GENERATION + "-" + classpathIdentifier).toUpperCase());
// return new IndexCacheKey(project.getElementName(), "java", elementType, DigestUtils.md5Hex(GENERATION + "-" + classpathIdentifier).toUpperCase());
return new IndexCacheKey(project.getElementName(), "java", elementType, DigestUtils.md5Hex(GENERATION + "-" + validationSeveritySettings.toString() + "-" + classpathIdentifier).toUpperCase());
}

public void setScanTestJavaSources(boolean scanTestJavaSources) {
Expand Down Expand Up @@ -840,6 +847,10 @@ private void addTestsJavaSourcesToIndex() {
}
}

public void setValidationSeveritySettings(JsonObject javaValidationSettingsJson) {
this.validationSeveritySettings = javaValidationSettingsJson;
}

public void setFileScanListener(FileScanListener fileScanListener) {
this.fileScanListener = fileScanListener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,36 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
import org.springframework.ide.vscode.boot.app.BootLanguageServerInitializer;
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
import org.springframework.ide.vscode.boot.bootiful.SymbolProviderTestConf;
import org.springframework.ide.vscode.boot.java.Boot2JavaProblemType;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import com.google.gson.Gson;
import com.google.gson.JsonElement;

/**
* @author Martin Lippert
*/
Expand All @@ -46,6 +51,7 @@
public class SpringValidationBeanMethodNotPublicTest {

@Autowired private BootLanguageServerHarness harness;
@Autowired private BootJavaConfig config;
@Autowired private BootLanguageServerInitializer serverInit;
@Autowired private JavaProjectFinder projectFinder;

Expand Down Expand Up @@ -87,6 +93,36 @@ void testFindPublicBeanMethodInConfigClass() throws Exception {
assertEquals(1, diagnostics.size());
}

@Test
void testChangingSeverityOfFindPublicBeanMethodInConfigClass() throws Exception {
String docUri = directory.toPath().resolve("src/main/java/org/test/BeanMethodNotPublic.java").toUri().toString();

PublishDiagnosticsParams diagnosticsMessage = harness.getDiagnostics(docUri);
List<Diagnostic> diagnostics = diagnosticsMessage.getDiagnostics();

Diagnostic diagnostic = diagnostics.get(0);
assertEquals(Boot2JavaProblemType.JAVA_PUBLIC_BEAN_METHOD.getCode(), diagnostic.getCode().getLeft());
assertEquals(1, diagnostics.size());
assertEquals(DiagnosticSeverity.Hint, diagnostic.getSeverity());

String changedSettings = "{\"spring-boot\": {\"ls\": {\"problem\": {\"boot2\": {\"JAVA_PUBLIC_BEAN_METHOD\": \"ERROR\"}}}}}";
JsonElement settingsAsJson = new Gson().fromJson(changedSettings, JsonElement.class);
Settings settings = new Settings(settingsAsJson);

harness.changeConfiguration(settings);

CompletableFuture<Void> initProject = indexer.waitOperation();
initProject.get(5, TimeUnit.SECONDS);

diagnosticsMessage = harness.getDiagnostics(docUri);
diagnostics = diagnosticsMessage.getDiagnostics();

diagnostic = diagnostics.get(0);
assertEquals(Boot2JavaProblemType.JAVA_PUBLIC_BEAN_METHOD.getCode(), diagnostic.getCode().getLeft());
assertEquals(1, diagnostics.size());
assertEquals(DiagnosticSeverity.Error, diagnostic.getSeverity());
}

@Test
void testPublishEmptyDiagnosticsWhenNoProblemsAreFound() throws Exception {
String docUri = directory.toPath().resolve("src/main/java/org/test/BeanClass1.java").toUri().toString();
Expand Down

0 comments on commit d13cea2

Please sign in to comment.