Search in sources :

Example 46 with InputFile

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

the class MultilineIssuesSensor 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)

Example 47 with InputFile

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

the class OverallCoverageSensorTest 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 48 with InputFile

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

the class OverallCoverageSensorTest method testLineHitAndConditions.

@Test
public void testLineHitAndConditions() throws IOException {
    File coverage = new File(baseDir, "src/foo.xoo.overallcoverage");
    FileUtils.write(coverage, "1:3:4:2");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).setLines(10).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
    assertThat(context.lineHits("foo:src/foo.xoo", 1)).isEqualTo(3);
    assertThat(context.conditions("foo:src/foo.xoo", 1)).isEqualTo(4);
    assertThat(context.coveredConditions("foo:src/foo.xoo", 1)).isEqualTo(2);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 49 with InputFile

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

the class UtCoverageSensorTest method testLineHitNoConditions.

@Test
public void testLineHitNoConditions() throws IOException {
    File coverage = new File(baseDir, "src/foo.xoo.coverage");
    FileUtils.write(coverage, "1:3\n\n#comment");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).setLines(10).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
    assertThat(context.lineHits("foo:src/foo.xoo", 1)).isEqualTo(3);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 50 with InputFile

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

the class UtCoverageSensorTest method testLineHitAndConditions.

@Test
public void testLineHitAndConditions() throws IOException {
    File coverage = new File(baseDir, "src/foo.xoo.coverage");
    FileUtils.write(coverage, "1:3:4:2");
    InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).setLines(10).build();
    context.fileSystem().add(inputFile);
    sensor.execute(context);
    assertThat(context.lineHits("foo:src/foo.xoo", 1)).isEqualTo(3);
    assertThat(context.conditions("foo:src/foo.xoo", 1)).isEqualTo(4);
    assertThat(context.coveredConditions("foo:src/foo.xoo", 1)).isEqualTo(2);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

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