run boot version validations in their own executor to avoid blocking the main message thread
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/*******************************************************************************
|
||||
* 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.ide.vscode.boot.app;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BootVersionValidationEngine {
|
||||
|
||||
private final BootVersionValidator bootVersionValidator;
|
||||
private final ExecutorService validationExecutor = Executors.newFixedThreadPool(3);
|
||||
|
||||
public BootVersionValidationEngine(ProjectObserver observer, BootVersionValidator bootVersionValidator) {
|
||||
this.bootVersionValidator = bootVersionValidator;
|
||||
|
||||
observer.addListener(new ProjectObserver.Listener() {
|
||||
|
||||
@Override
|
||||
public void deleted(IJavaProject project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void created(IJavaProject project) {
|
||||
validate(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changed(IJavaProject project) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void validate(IJavaProject project) {
|
||||
validationExecutor.submit(() -> bootVersionValidator.validate(project));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,14 +14,13 @@ import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.ProjectVersionDiagnosticProvider;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.ProjectVersionDiagnosticProvider.DiagnosticResult;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringIoProjectsProvider;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectsClient;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectsProvider;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.VersionValidators;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.ProjectVersionDiagnosticProvider.DiagnosticResult;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.preferences.VersionValidationPreferences;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -32,25 +31,9 @@ public class BootVersionValidator {
|
||||
private SimpleLanguageServer server;
|
||||
private BootJavaConfig config;
|
||||
|
||||
public BootVersionValidator(SimpleLanguageServer server, ProjectObserver observer, BootJavaConfig config) {
|
||||
public BootVersionValidator(SimpleLanguageServer server, BootJavaConfig config) {
|
||||
this.server = server;
|
||||
this.config = config;
|
||||
observer.addListener(new ProjectObserver.Listener() {
|
||||
|
||||
@Override
|
||||
public void deleted(IJavaProject project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void created(IJavaProject project) {
|
||||
validate(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changed(IJavaProject project) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void validate(IJavaProject project) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
|
||||
import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
|
||||
import org.springframework.ide.vscode.boot.app.BootVersionValidator;
|
||||
import org.springframework.ide.vscode.boot.app.BootVersionValidationEngine;
|
||||
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
|
||||
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchyAwareLookup;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.AutowiredHoverProvider;
|
||||
@@ -202,7 +202,7 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
|
||||
reconcileEngine = new BootJavaReconcileEngine(projectFinder, new JavaReconciler[] {
|
||||
jdtReconciler,
|
||||
rewriteJavaReconciler
|
||||
}, documents, appContext.getBean(BootVersionValidator.class));
|
||||
}, documents, appContext.getBean(BootVersionValidationEngine.class));
|
||||
|
||||
codeActionProvider = new BootJavaCodeActionProvider(
|
||||
projectFinder,
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -26,7 +25,7 @@ import java.util.stream.Stream;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.app.BootVersionValidator;
|
||||
import org.springframework.ide.vscode.boot.app.BootVersionValidationEngine;
|
||||
import org.springframework.ide.vscode.boot.common.IJavaProjectReconcileEngine;
|
||||
import org.springframework.ide.vscode.boot.java.reconcilers.JavaReconciler;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
|
||||
@@ -41,30 +40,24 @@ import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.commons.util.text.LazyTextDocument;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
public class BootJavaReconcileEngine implements IReconcileEngine, IJavaProjectReconcileEngine {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BootJavaReconcileEngine.class);
|
||||
private Scheduler bootVersionValidationScheduler = Schedulers.newBoundedElastic(3, Integer.MAX_VALUE, "Boot-Version-Validation", 10);
|
||||
|
||||
|
||||
private final SimpleTextDocumentService documents;
|
||||
private final JavaProjectFinder projectFinder;
|
||||
private JavaReconciler[] javaReconcilers;
|
||||
|
||||
private BootVersionValidator bootVersionValidator;
|
||||
private BootVersionValidationEngine bootVersionValidationEngine;
|
||||
|
||||
public BootJavaReconcileEngine(JavaProjectFinder projectFinder, JavaReconciler[] javaReconcilers, SimpleTextDocumentService documents, BootVersionValidator bootVersionValidator) {
|
||||
public BootJavaReconcileEngine(JavaProjectFinder projectFinder, JavaReconciler[] javaReconcilers, SimpleTextDocumentService documents, BootVersionValidationEngine bootVersionValidator) {
|
||||
this.documents = documents;
|
||||
this.projectFinder = projectFinder;
|
||||
this.javaReconcilers = javaReconcilers;
|
||||
this.bootVersionValidator = bootVersionValidator;
|
||||
this.bootVersionValidationEngine = bootVersionValidator;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,9 +118,10 @@ public class BootJavaReconcileEngine implements IReconcileEngine, IJavaProjectRe
|
||||
|
||||
@Override
|
||||
public void reconcile(IJavaProject project, Function<TextDocument, IProblemCollector> problemCollectorFactory) {
|
||||
if (bootVersionValidator != null) {
|
||||
Mono.fromFuture(CompletableFuture.runAsync(() -> bootVersionValidator.validate(project))).publishOn(bootVersionValidationScheduler).subscribe();
|
||||
if (bootVersionValidationEngine != null) {
|
||||
bootVersionValidationEngine.validate(project);
|
||||
}
|
||||
|
||||
Stream<Path> files = IClasspathUtil.getProjectJavaSourceFolders(project.getClasspath()).flatMap(folder -> {
|
||||
try {
|
||||
return Files.walk(folder.toPath()).filter(Files::isRegularFile);
|
||||
@@ -135,6 +129,7 @@ public class BootJavaReconcileEngine implements IReconcileEngine, IJavaProjectRe
|
||||
return Stream.empty();
|
||||
}
|
||||
});
|
||||
|
||||
Stream<TextDocumentIdentifier> docIds = files
|
||||
.filter(f -> f.getFileName().toString().endsWith(".java"))
|
||||
.map(f -> new TextDocumentIdentifier(f.toUri().toString()));
|
||||
|
||||
Reference in New Issue
Block a user