<commit_before>package com.github.otrosien.sonar.perl;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.stream.Stream;

import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;

import com.google.common.collect.Lists;

public class GlobalSensor implements Sensor {

    private static final Logger log = Loggers.get(GlobalSensor.class);

    private FileSystem fileSystem;

    @Override
    public void describe(SensorDescriptor descriptor) {
      descriptor
        .onlyOnLanguage(PerlLanguage.KEY)
        .name("Perl sensor")
        .onlyOnFileType(Type.MAIN);
    }

    @Override
    public void execute(SensorContext context) {
        this.fileSystem = context.fileSystem();

        FilePredicate mainFilePredicate = this.fileSystem.predicates().and(
          this.fileSystem.predicates().hasType(InputFile.Type.MAIN),
          this.fileSystem.predicates().hasLanguage(PerlLanguage.KEY));

        ArrayList<InputFile> inputFiles = Lists.newArrayList(fileSystem.inputFiles(mainFilePredicate));

        for (InputFile inputFile : inputFiles) {
            this.analyseFile(inputFile, context);
        }
    }

    private void analyseFile(InputFile inputFile, SensorContext context) {
        log.debug("Analysing file {}", inputFile);
        File file = inputFile.file();
        context.<Integer>newMeasure().on(inputFile).withValue(countLinesOfCode(file)).forMetric(CoreMetrics.NCLOC);<commit_msg>Code polish<commit_after>package com.github.otrosien.sonar.perl;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.stream.Stream;

import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;

import com.google.common.collect.Lists;

public class GlobalSensor implements Sensor {

    private static final Logger log = Loggers.get(GlobalSensor.class);

    @Override
    public void describe(SensorDescriptor descriptor) {
      descriptor
        .onlyOnLanguage(PerlLanguage.KEY)
        .name("Perl sensor")
        .onlyOnFileType(Type.MAIN);
    }

    @Override
    public void execute(SensorContext context) {
        FileSystem fileSystem = context.fileSystem();

        FilePredicate mainFilePredicate = fileSystem.predicates().and(
          fileSystem.predicates().hasType(InputFile.Type.MAIN),
          fileSystem.predicates().hasLanguage(PerlLanguage.KEY));

        ArrayList<InputFile> inputFiles = Lists.newArrayList(fileSystem.inputFiles(mainFilePredicate));

        for (InputFile inputFile : inputFiles) {
            this.analyseFile(inputFile, context);
        }
    }

    private void analyseFile(InputFile inputFile, SensorContext context) {
        log.debug("Analysing file {}", inputFile);
        File file = inputFile.file();
        context.<Integer>newMeasure().on(inputFile).withValue(countLinesOfCode(file)).forMetric(CoreMetrics.NCLOC);
{'fraction_non_alphanumeric': 0.112404125892621, 'fraction_numerical': 0.0, 'mean_word_length': 3.9567496723460027, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '985895', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1129, 'n_words': 186}