Search in sources :

Example 51 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class UtCoverageSensorTest method testNoExecutionIfNoCoverageFile.

@Test
public void testNoExecutionIfNoCoverageFile() {
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 52 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class MeasureSensorTest method testNoExecutionIfNoMeasureFile.

@Test
public void testNoExecutionIfNoMeasureFile() {
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 53 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonar-web by SonarSource.

the class WebSensor method saveMetrics.

private static void saveMetrics(SensorContext context, WebSourceCode sourceCode) {
    InputFile inputFile = sourceCode.inputFile();
    saveComplexityDistribution(context, sourceCode);
    for (Map.Entry<Metric<Integer>, Integer> entry : sourceCode.getMeasures().entrySet()) {
        context.<Integer>newMeasure().on(inputFile).forMetric(entry.getKey()).withValue(entry.getValue()).save();
    }
    for (WebIssue issue : sourceCode.getIssues()) {
        NewIssue newIssue = context.newIssue().forRule(issue.ruleKey()).gap(issue.cost());
        Integer line = issue.line();
        NewIssueLocation location = newIssue.newLocation().on(inputFile).message(issue.message());
        if (line != null) {
            location.at(inputFile.selectLine(line));
        }
        newIssue.at(location);
        newIssue.save();
    }
}
Also used : NewIssueLocation(org.sonar.api.batch.sensor.issue.NewIssueLocation) WebIssue(org.sonar.plugins.web.checks.WebIssue) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) Metric(org.sonar.api.measures.Metric) Map(java.util.Map) InputFile(org.sonar.api.batch.fs.InputFile)

Example 54 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class DecimalScaleSensor method analyse.

@Override
public void analyse(Project module, SensorContext context) {
    if (context.settings().getBoolean(DecimalScaleProperty.KEY)) {
        FilePredicate all = context.fileSystem().predicates().all();
        Iterable<InputFile> files = context.fileSystem().inputFiles(all);
        double value = 0.0001;
        for (InputFile file : files) {
            LOG.info("Value for {}: {}", file.relativePath(), value);
            context.newMeasure().on(file).forMetric(DecimalScaleMetric.definition()).withValue(value).save();
            value += 0.0001;
        }
    }
}
Also used : FilePredicate(org.sonar.api.batch.fs.FilePredicate) InputFile(org.sonar.api.batch.fs.InputFile)

Example 55 with InputFile

use of org.sonar.api.batch.fs.InputFile in project sonarqube by SonarSource.

the class CreateIssueByInternalKeySensor method execute.

@Override
public void execute(SensorContext context) {
    FileSystem fs = context.fileSystem();
    FilePredicates p = fs.predicates();
    for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) {
        createIssues(file, context);
    }
}
Also used : FileSystem(org.sonar.api.batch.fs.FileSystem) FilePredicates(org.sonar.api.batch.fs.FilePredicates) InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

InputFile (org.sonar.api.batch.fs.InputFile)102 Test (org.junit.Test)61 File (java.io.File)45 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)39 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)20 TaskResult (org.sonar.scanner.mediumtest.TaskResult)19 IOException (java.io.IOException)10 FilePredicates (org.sonar.api.batch.fs.FilePredicates)8 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)7 List (java.util.List)6 FileSystem (org.sonar.api.batch.fs.FileSystem)6 BlameLine (org.sonar.api.batch.scm.BlameLine)6 ArrayList (java.util.ArrayList)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 DefaultBlameOutput (org.sonar.scanner.scm.DefaultBlameOutput)4 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)3 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)3 MutableTestPlan (org.sonar.api.test.MutableTestPlan)3 Block (org.sonar.duplications.block.Block)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2