Search in sources :

Example 1 with Absolute

use of com.github._1c_syntax.utils.Absolute in project sonar-bsl-plugin-community by 1c-syntax.

the class BSLCoreSensor method execute.

@Override
public void execute(SensorContext context) {
    LOGGER.info("Parsing files...");
    FileSystem fileSystem = context.fileSystem();
    File baseDir = fileSystem.baseDir();
    var absoluteSourceDirs = sourcesList.stream().map((String sourceDir) -> {
        Path sourcePath = Path.of(sourceDir.trim());
        if (sourcePath.isAbsolute()) {
            return sourcePath;
        } else {
            return Path.of(baseDir.toString(), sourceDir);
        }
    }).map(Absolute::path).collect(Collectors.toList());
    FilePredicates predicates = fileSystem.predicates();
    Iterable<InputFile> inputFiles = fileSystem.inputFiles(predicates.hasLanguage(BSLLanguage.KEY));
    Map<Path, List<InputFile>> inputFilesByPath = StreamSupport.stream(inputFiles.spliterator(), true).collect(Collectors.groupingBy((InputFile inputFile) -> {
        var filePath = Absolute.path(inputFile.uri());
        return absoluteSourceDirs.stream().filter(filePath::startsWith).findAny().orElse(baseDir.toPath());
    }));
    LanguageServerConfiguration languageServerConfiguration = getLanguageServerConfiguration();
    inputFilesByPath.forEach((Path sourceDir, List<InputFile> inputFilesList) -> {
        LOGGER.info("Source dir: {}", sourceDir);
        Path configurationRoot = LanguageServerConfiguration.getCustomConfigurationRoot(languageServerConfiguration, sourceDir);
        var bslServerContext = BSLLSBinding.getServerContext();
        bslServerContext.setConfigurationRoot(configurationRoot);
        bslServerContext.populateContext();
        try (ProgressBar pb = new ProgressBarBuilder().setTaskName("").setInitialMax(inputFilesList.size()).setStyle(ProgressBarStyle.ASCII).build()) {
            inputFilesList.parallelStream().forEach((InputFile inputFile) -> {
                URI uri = inputFile.uri();
                LOGGER.debug(uri.toString());
                pb.step();
                processFile(inputFile, bslServerContext);
            });
        }
        bslServerContext.clear();
    });
    BSLLSBinding.getApplicationContext().close();
}
Also used : Path(java.nio.file.Path) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) URI(java.net.URI) InputFile(org.sonar.api.batch.fs.InputFile) ProgressBarBuilder(me.tongfei.progressbar.ProgressBarBuilder) FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) List(java.util.List) ArrayList(java.util.ArrayList) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) ProgressBar(me.tongfei.progressbar.ProgressBar)

Aggregations

LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)1 File (java.io.File)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProgressBar (me.tongfei.progressbar.ProgressBar)1 ProgressBarBuilder (me.tongfei.progressbar.ProgressBarBuilder)1 FilePredicates (org.sonar.api.batch.fs.FilePredicates)1 FileSystem (org.sonar.api.batch.fs.FileSystem)1 InputFile (org.sonar.api.batch.fs.InputFile)1