Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Подключение spring-native #2809

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ plugins {
id("me.qoomon.git-versioning") version "6.1.4"
id("com.github.ben-manes.versions") version "0.42.0"
id("org.springframework.boot") version "2.6.7"
id("org.springframework.experimental.aot") version "0.11.5"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("io.github.1c-syntax.bslls-dev-tools") version "0.7.0"
id("ru.vyarus.pom") version "2.2.1"
Expand All @@ -27,6 +28,7 @@ repositories {
mavenLocal()
mavenCentral()
maven(url = "https://jitpack.io")
maven(url = "https://repo.spring.io/release")
}

group = "io.github.1c-syntax"
Expand Down Expand Up @@ -81,6 +83,7 @@ dependencies {

// AOP
implementation("org.aspectj", "aspectjrt", "1.9.7")
aotMainImplementation("org.aspectj", "aspectjrt", "1.9.7")

// commons utils
implementation("commons-io", "commons-io", "2.11.0")
Expand Down Expand Up @@ -347,3 +350,19 @@ nexusStaging {
tasks.withType<GenerateModuleMetadata> {
enabled = false
}

graalvmNative {
binaries {
named("main") {
sharedLibrary.set(false)
buildArgs.add("--tool:lsp")
buildArgs.add("--trace-class-initialization=com.github._1c_syntax.mdclasses.common.CompatibilityMode")
buildArgs.add("--initialize-at-build-time=com.github._1c_syntax.mdclasses.common.CompatibilityMode")

buildArgs.add("-H:JNIConfigurationFiles=$rootDir/graalvm/jni-config.json")
buildArgs.add("-H:DynamicProxyConfigurationFiles=$rootDir/graalvm/proxy-config.json")
buildArgs.add("-H:ReflectionConfigurationFiles=$rootDir/graalvm/reflect-config.json")
buildArgs.add("-H:ResourceConfigurationFiles=$rootDir/graalvm/resource-config.json")
}
}
}
1 change: 1 addition & 0 deletions lombok.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ lombok.anyConstructor.addConstructorProperties=true
lombok.addLombokGeneratedAnnotation=true
lombok.log.fieldName=LOGGER
lombok.extern.findbugs.addSuppressFBWarnings = true
lombok.copyableannotations += org.springframework.beans.factory.annotation.Qualifier
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pluginManagement {
repositories {
gradlePluginPortal()
maven(url = "https://jitpack.io")
maven(url = "https://repo.spring.io/release")
mavenLocal()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
import com.github._1c_syntax.utils.Absolute;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import me.tongfei.progressbar.ProgressBar;
import me.tongfei.progressbar.ProgressBarBuilder;
import me.tongfei.progressbar.ProgressBarStyle;
import org.apache.commons.io.FileUtils;
import org.eclipse.lsp4j.Diagnostic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import picocli.CommandLine.Command;

Expand Down Expand Up @@ -141,7 +144,9 @@ private static class ReportersKeys extends ArrayList<String> {
description = "Silent mode")
private boolean silentMode;

private final ReportersAggregator aggregator;
@Setter(onMethod = @__({@Autowired, @Lazy}))
private ReportersAggregator aggregator;

private final LanguageServerConfiguration configuration;
private final ServerContext context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.eclipse.lsp4j.TextDocumentItem;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Component;

import javax.annotation.CheckForNull;
Expand All @@ -54,7 +54,7 @@
@Slf4j
@Component
@RequiredArgsConstructor
public abstract class ServerContext {
public class ServerContext {
private final Map<URI, DocumentContext> documents = Collections.synchronizedMap(new HashMap<>());
private final Lazy<Configuration> configurationMetadata = new Lazy<>(this::computeConfigurationMetadata);
@CheckForNull
Expand All @@ -64,6 +64,7 @@ public abstract class ServerContext {
private final Map<String, Map<ModuleType, DocumentContext>> documentsByMDORef
= Collections.synchronizedMap(new HashMap<>());
private final ReadWriteLock contextLock = new ReentrantReadWriteLock();
private final ObjectProvider<DocumentContext> documentContextProvider;

public void populateContext() {
if (configurationRoot == null) {
Expand Down Expand Up @@ -162,9 +163,6 @@ public Configuration getConfiguration() {
return configurationMetadata.getOrCompute();
}

@Lookup
protected abstract DocumentContext lookupDocumentContext(URI absoluteURI);

@SneakyThrows
private DocumentContext createDocumentContext(File file, int version) {
String content = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
Expand All @@ -174,7 +172,7 @@ private DocumentContext createDocumentContext(File file, int version) {
private DocumentContext createDocumentContext(URI uri, String content, int version) {
URI absoluteURI = Absolute.uri(uri);

var documentContext = lookupDocumentContext(absoluteURI);
var documentContext = documentContextProvider.getObject(absoluteURI);
documentContext.rebuild(content, version);

documents.put(absoluteURI, documentContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.lsp4j.Diagnostic;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -36,13 +37,16 @@
@Component
@RequiredArgsConstructor
@Slf4j
public abstract class DiagnosticComputer {
public class DiagnosticComputer {

@Qualifier("diagnostics")
private final ObjectProvider<List<BSLDiagnostic>> diagnosticsProvider;

public List<Diagnostic> compute(DocumentContext documentContext) {

DiagnosticIgnoranceComputer.Data diagnosticIgnorance = documentContext.getDiagnosticIgnorance();

return diagnostics(documentContext).parallelStream()
return diagnosticsProvider.getObject(documentContext).parallelStream()
.flatMap((BSLDiagnostic diagnostic) -> {
try {
return diagnostic.getDiagnostics(documentContext).stream();
Expand All @@ -62,7 +66,4 @@ public List<Diagnostic> compute(DocumentContext documentContext) {
.collect(Collectors.toList());

}

@Lookup("diagnostics")
protected abstract List<BSLDiagnostic> diagnostics(DocumentContext documentContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.github._1c_syntax.utils.StringInterner;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -68,21 +69,28 @@ public Map<String, DiagnosticInfo> diagnosticInfosByCode() {

@Bean("diagnosticInfosByDiagnosticClass")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public Map<Class<? extends BSLDiagnostic>, DiagnosticInfo> diagnosticInfosByDiagnosticClass() {
return diagnosticInfosByCode().values().stream()
public Map<Class<? extends BSLDiagnostic>, DiagnosticInfo> diagnosticInfosByDiagnosticClass(
@Qualifier("diagnosticInfosByCode") Map<String, DiagnosticInfo> diagnosticInfosByCode
) {
return diagnosticInfosByCode.values().stream()
.collect(Collectors.toMap(DiagnosticInfo::getDiagnosticClass, Function.identity()));
}

@Bean("diagnosticInfos")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public Collection<DiagnosticInfo> diagnosticInfos() {
return diagnosticInfosByCode().values();
public Collection<DiagnosticInfo> diagnosticInfos(
@Qualifier("diagnosticInfosByCode") Map<String, DiagnosticInfo> diagnosticInfosByCode
) {
return diagnosticInfosByCode.values();
}

@Bean
@Scope("prototype")
public DiagnosticInfo diagnosticInfo(@Autowired(required = false) Class<? extends BSLDiagnostic> diagnosticClass) {
return diagnosticInfosByDiagnosticClass().get(diagnosticClass);
public DiagnosticInfo diagnosticInfo(
@Autowired(required = false) Class<? extends BSLDiagnostic> diagnosticClass,
Map<Class<? extends BSLDiagnostic>, DiagnosticInfo> diagnosticInfosByDiagnosticClass
) {
return diagnosticInfosByDiagnosticClass.get(diagnosticClass);
}

private DiagnosticInfo createDiagnosticInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
import com.github._1c_syntax.mdclasses.supportconf.SupportVariant;
import lombok.RequiredArgsConstructor;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
Expand All @@ -54,16 +55,19 @@

@Configuration
@RequiredArgsConstructor
public abstract class DiagnosticsConfiguration {
public class DiagnosticsConfiguration {

private final LanguageServerConfiguration configuration;
private final DiagnosticObjectProvider diagnosticObjectProvider;

@Qualifier("diagnosticInfos")
private final ObjectProvider<Collection<DiagnosticInfo>> diagnosticInfosProvider;

@Bean
@Scope("prototype")
public List<BSLDiagnostic> diagnostics(DocumentContext documentContext) {

Collection<DiagnosticInfo> diagnosticInfos = diagnosticInfos();
Collection<DiagnosticInfo> diagnosticInfos = diagnosticInfosProvider.getObject();

DiagnosticsOptions diagnosticsOptions = configuration.getDiagnosticsOptions();

Expand All @@ -88,9 +92,6 @@ public List<BSLDiagnostic> diagnostics(DocumentContext documentContext) {
}
}

@Lookup("diagnosticInfos")
protected abstract Collection<DiagnosticInfo> diagnosticInfos();

private static boolean needToComputeDiagnostics(
DocumentContext documentContext,
DiagnosticsOptions diagnosticsOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

import com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
Expand All @@ -36,13 +34,9 @@
@RequiredArgsConstructor
public class ReportersAggregator {

@Autowired
private final List<DiagnosticReporter> reporters;

@Autowired
@Qualifier("filteredReporters")
@Lazy
// Don't remove @Autowired annotation. It's needed for injecting filteredReporters bean correctly.
private final List<DiagnosticReporter> filteredReporters;

public void report(AnalysisInfo analysisInfo, Path outputDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.github._1c_syntax.bsl.languageserver.reporters.DiagnosticReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -36,7 +35,6 @@
public class ReportersConfiguration {

@Bean
@Lazy
public List<DiagnosticReporter> filteredReporters(
Collection<DiagnosticReporter> allReporters,
AnalyzeCommand command
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spring.main.banner-mode=off
spring.main.log-startup-info=false
logging.level.org.springframework.boot.autoconfigure.logging=INFO
logging.level.org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler=warn
logging.level.org.springframework.nativex.NativeListener=warn
logging.level.com.zaxxer.hikari=warn
logging.level.org.hibernate=warn
logging.level.org.hibernate.engine.jdbc.spi.SqlExceptionHelper=fatal
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application-measures.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spring.main.banner-mode=off
spring.main.log-startup-info=false
logging.level.org.springframework.boot.autoconfigure.logging=INFO
logging.level.org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler=warn
logging.level.org.springframework.nativex.NativeListener=warn
logging.level.com.zaxxer.hikari=warn
logging.level.org.hibernate=warn
logging.level.org.hibernate.engine.jdbc.spi.SqlExceptionHelper=fatal
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spring.main.banner-mode=off
spring.main.log-startup-info=false
logging.level.org.springframework.boot.autoconfigure.logging=INFO
logging.level.org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler=warn
logging.level.org.springframework.nativex.NativeListener=warn
logging.level.com.zaxxer.hikari=warn
logging.level.org.hibernate=warn
logging.level.org.hibernate.engine.jdbc.spi.SqlExceptionHelper=fatal
Expand Down