Search in sources :

Example 1 with AnalysisInfo

use of com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo in project bsl-language-server by 1c-syntax.

the class JUnitReporterTest method report.

@Test
void report() throws IOException {
    // given
    List<Diagnostic> diagnostics = new ArrayList<>();
    diagnostics.add(new Diagnostic(Ranges.create(0, 1, 2, 3), "message", DiagnosticSeverity.Error, "test-source", "test"));
    diagnostics.add(new Diagnostic(Ranges.create(0, 1, 2, 4), "message4", DiagnosticSeverity.Error, "test-source2", "test3"));
    diagnostics.add(new Diagnostic(Ranges.create(3, 1, 4, 4), "message4", DiagnosticSeverity.Error, "test-source2", "test3"));
    DocumentContext documentContext = TestUtils.getDocumentContext(Paths.get("./src/test/java/diagnostics/CanonicalSpellingKeywordsDiagnostic.bsl").toUri(), "");
    String sourceDir = ".";
    FileInfo fileInfo = new FileInfo(sourceDir, documentContext, diagnostics);
    AnalysisInfo analysisInfo = new AnalysisInfo(LocalDateTime.now(), Collections.singletonList(fileInfo), sourceDir);
    DiagnosticReporter reporter = new JUnitReporter();
    // when
    reporter.report(analysisInfo, Path.of(sourceDir));
    // then
    ObjectMapper mapper = new XmlMapper();
    JUnitTestSuites report = mapper.readValue(file, JUnitTestSuites.class);
    assertThat(report).isNotNull();
}
Also used : FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) AnalysisInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AnalysisInfo

use of com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo in project bsl-language-server by 1c-syntax.

the class JsonReporterTest method report.

@Test
void report() throws IOException {
    // given
    Diagnostic diagnostic = new Diagnostic(Ranges.create(0, 1, 2, 3), "message", DiagnosticSeverity.Error, "test-source", "test");
    DocumentContext documentContext = TestUtils.getDocumentContext("");
    String sourceDir = ".";
    FileInfo fileInfo = new FileInfo(sourceDir, documentContext, Collections.singletonList(diagnostic));
    AnalysisInfo analysisInfo = new AnalysisInfo(LocalDateTime.now(), Collections.singletonList(fileInfo), sourceDir);
    JsonReporter reporter = new JsonReporter();
    // when
    reporter.report(analysisInfo, Path.of(sourceDir));
    // then
    ObjectMapper mapper = new AnalysisInfoObjectMapper();
    mapper.findAndRegisterModules();
    AnalysisInfo report = mapper.readValue(file, AnalysisInfo.class);
    Assertions.assertThat(report.getFileinfos()).hasSize(1);
}
Also used : FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) AnalysisInfoObjectMapper(com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper) Diagnostic(org.eclipse.lsp4j.Diagnostic) AnalysisInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AnalysisInfoObjectMapper(com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with AnalysisInfo

use of com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo in project bsl-language-server by 1c-syntax.

the class TSLintReporterTest method report.

@Test
void report() throws IOException {
    // given
    Diagnostic diagnostic = new Diagnostic(Ranges.create(0, 1, 2, 3), "message", DiagnosticSeverity.Error, "test-source", "test");
    DocumentContext documentContext = TestUtils.getDocumentContext("");
    String sourceDir = ".";
    FileInfo fileInfo = new FileInfo(sourceDir, documentContext, Collections.singletonList(diagnostic));
    AnalysisInfo analysisInfo = new AnalysisInfo(LocalDateTime.now(), Collections.singletonList(fileInfo), sourceDir);
    TSLintReporter reporter = new TSLintReporter();
    // when
    reporter.report(analysisInfo, Path.of(sourceDir));
    // then
    ObjectMapper mapper = new ObjectMapper();
    List<TSLintReportEntry> report = mapper.readValue(file, new TypeReference<ArrayList<TSLintReportEntry>>() {
    });
    assertThat(report).hasSize(1);
}
Also used : FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) AnalysisInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with AnalysisInfo

use of com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo in project bsl-language-server by 1c-syntax.

the class JsonReporter method report.

@Override
public void report(AnalysisInfo analysisInfo, Path outputDir) {
    ObjectMapper mapper = new AnalysisInfoObjectMapper();
    try {
        File reportFile = new File(outputDir.toFile(), "./bsl-json.json");
        mapper.writeValue(reportFile, analysisInfo);
        LOGGER.info("JSON report saved to {}", reportFile.getAbsolutePath());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : AnalysisInfoObjectMapper(com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AnalysisInfoObjectMapper(com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper)

Example 5 with AnalysisInfo

use of com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo in project sonar-bsl-plugin-community by 1c-syntax.

the class LanguageServerDiagnosticsLoaderSensor method getAnalysisInfo.

@Nullable
private static AnalysisInfo getAnalysisInfo(File analysisResultsFile) {
    String json;
    try {
        json = FileUtils.readFileToString(analysisResultsFile, StandardCharsets.UTF_8);
    } catch (IOException e) {
        LOGGER.error("Can't read analysis report file", e);
        return null;
    }
    ObjectMapper objectMapper = new AnalysisInfoObjectMapper();
    try {
        return objectMapper.readValue(json, AnalysisInfo.class);
    } catch (IOException e) {
        LOGGER.error("Can't parse analysis report file", e);
        return null;
    }
}
Also used : AnalysisInfoObjectMapper(com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AnalysisInfoObjectMapper(com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper) Nullable(javax.annotation.Nullable)

Aggregations

FileInfo (com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo)10 AnalysisInfo (com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Diagnostic (org.eclipse.lsp4j.Diagnostic)8 DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)7 Test (org.junit.jupiter.api.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 File (java.io.File)4 ArrayList (java.util.ArrayList)4 AnalysisInfoObjectMapper (com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper)3 IOException (java.io.IOException)3 Path (java.nio.file.Path)2 Location (com.contrastsecurity.sarif.Location)1 PhysicalLocation (com.contrastsecurity.sarif.PhysicalLocation)1 Result (com.contrastsecurity.sarif.Result)1 SarifSchema210 (com.contrastsecurity.sarif.SarifSchema210)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)1 DiagnosticInfo (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo)1 CleanupContextBeforeClassAndAfterClass (com.github._1c_syntax.bsl.languageserver.util.CleanupContextBeforeClassAndAfterClass)1