org.sonar.api.batch.fs.internal.FileMetadata Java Examples

The following examples show how to use org.sonar.api.batch.fs.internal.FileMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LuaSquidSensorTest.java    From sonar-lua with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void analyse2() throws FileNotFoundException {
  DefaultFileSystem fs = new DefaultFileSystem(TEST_DIR);
  tester.setFileSystem(fs);
  DefaultInputFile inputFile = new DefaultInputFile("key", "timeFormatter.lua")
    .setType(InputFile.Type.MAIN)
    .setLanguage(Lua.KEY)
    .initMetadata(new FileMetadata().readMetadata(new FileReader(new File(TEST_DIR, "timeFormatter.lua"))));
  fs.add(inputFile);

  sensor.execute(tester);

  String componentKey = inputFile.key();
  assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY_IN_CLASSES).value()).isEqualTo(0);
  assertThat(tester.measure(componentKey, CoreMetrics.NCLOC).value()).isEqualTo(0);
  assertThat(tester.measure(componentKey, CoreMetrics.COMMENT_LINES).value()).isEqualTo(59);
  assertThat(tester.measure(componentKey, CoreMetrics.STATEMENTS).value()).isEqualTo(0);
  assertThat(tester.measure(componentKey, CoreMetrics.FUNCTIONS).value()).isEqualTo(0);
  assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY).value()).isEqualTo(0);
  assertThat(tester.measure(componentKey, CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("0=1;5=0;10=0;20=0;30=0;60=0;90=0");
  assertThat(tester.measure(componentKey, CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("1=0;2=0;4=0;6=0;8=0;10=0;12=0");



  assertThat(tester.allIssues()).hasSize(0);
}
 
Example #2
Source File: HighlightSymbolTableBuilderTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
private NewSymbolTable newSymbolTable(String filename) throws FileNotFoundException  {
  File moduleBaseDir = new File("src/test/resources/highlighter/");
  sensorContext = SensorContextTester.create(moduleBaseDir);
  inputFile = new TestInputFileBuilder("moduleKey", filename)
    .setModuleBaseDir(moduleBaseDir.toPath())
    .setCharset(StandardCharsets.UTF_8)
    .build();
  inputFile.setMetadata(new FileMetadata().readMetadata(new FileInputStream(inputFile.file()), inputFile.charset(), inputFile.absolutePath()));

  return sensorContext.newSymbolTable().onFile(inputFile);
}
 
Example #3
Source File: TestUtils.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
public static DefaultInputFile createTestInputFile(File file, String contents, Charset encoding) {
  final DefaultInputFile inputFile = new TestInputFileBuilder("module1", file.getName()).setCharset(encoding).build();
  try {
    Files.write(file.toPath(), contents.getBytes(encoding));
    inputFile.setMetadata(new FileMetadata().readMetadata(new FileInputStream(file), encoding, file.getAbsolutePath()));
  } catch (IOException e) {
    throw Throwables.propagate(e);
  }
  return inputFile;
}
 
Example #4
Source File: LuaSquidSensorTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void analyse() throws FileNotFoundException {
  DefaultFileSystem fs = new DefaultFileSystem(TEST_DIR);
  tester.setFileSystem(fs);
  DefaultInputFile inputFile = new DefaultInputFile("key", "smallFile.lua")
    .setType(InputFile.Type.MAIN)
    .setLanguage(Lua.KEY)
    .initMetadata(new FileMetadata().readMetadata(new FileReader(new File(TEST_DIR, "smallFile.lua"))));
  fs.add(inputFile);
  inputFile = new DefaultInputFile("key", "bom.lua")
    .setType(InputFile.Type.MAIN)
    .setLanguage(Lua.KEY)
    .initMetadata(new FileMetadata().readMetadata(new FileReader(new File(TEST_DIR, "bom.lua"))));
  fs.add(inputFile);

  sensor.execute(tester);

  String componentKey = "key:smallFile.lua";
  assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY_IN_CLASSES).value()).isEqualTo(0);
  assertThat(tester.measure(componentKey, CoreMetrics.NCLOC).value()).isEqualTo(4);
  assertThat(tester.measure(componentKey, CoreMetrics.COMMENT_LINES).value()).isEqualTo(1);
  assertThat(tester.measure(componentKey, CoreMetrics.STATEMENTS).value()).isEqualTo(0);
  assertThat(tester.measure(componentKey, CoreMetrics.FUNCTIONS).value()).isEqualTo(3);

  assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY).value()).isEqualTo(4);
  assertThat(tester.measure(componentKey, CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("0=1;5=0;10=0;20=0;30=0;60=0;90=0");
  assertThat(tester.measure(componentKey, CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("1=2;2=0;4=1;6=0;8=0;10=0;12=0");

 
}
 
Example #5
Source File: CoberturaSensorTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void shouldParseReport() throws Exception {
  DefaultInputFile inputFile = new DefaultInputFile("key", "src/example/file.lua")
    .setLanguage(Lua.KEY)
    .setType(InputFile.Type.MAIN)
    .initMetadata(new FileMetadata().readMetadata(new FileReader(TEST_DIR + "src/example/file.lua")));

  tester.fileSystem().add(inputFile);

  tester.settings().setProperty(LuaPlugin.COBERTURA_REPORT_PATH, "coverage.xml");
  sensor.execute(tester);

  String componentKey = "key:src/example/file.lua";
  Integer[] expectedConditions = {2, null, null, null, null, null, null, null, null, null};
  Integer[] expectedCoveredConditions = {1, null, null, null, null, null, null, null, null, null};
  Integer[] expectedHits = {0, null, null, null, null, null, 0, null, null, null};
  for (int line = 1; line <= expectedConditions.length; line++) {
    assertThat(tester.coveredConditions(componentKey, CoverageType.UNIT, line)).as("line " + line).isEqualTo(expectedCoveredConditions[line - 1]);
    assertThat(tester.conditions(componentKey, CoverageType.UNIT, line)).as("line " + line).isEqualTo(expectedConditions[line - 1]);
    assertThat(tester.lineHits(componentKey, CoverageType.UNIT, line)).as("line " + line).isEqualTo(expectedHits[line - 1]);

    assertThat(tester.coveredConditions(componentKey, CoverageType.IT, line)).isNull();
    assertThat(tester.lineHits(componentKey, CoverageType.IT, line)).isNull();
    assertThat(tester.coveredConditions(componentKey, CoverageType.OVERALL, line)).isNull();
    assertThat(tester.lineHits(componentKey, CoverageType.OVERALL, line)).isNull();
  }
}