use of com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper 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);
}
use of com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper 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);
}
}
use of com.github._1c_syntax.bsl.languageserver.reporters.databind.AnalysisInfoObjectMapper 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;
}
}
Aggregations