Package org.sonar.api.batch.sensor.duplication

Examples of org.sonar.api.batch.sensor.duplication.DuplicationTokenBuilder


* Tokenize xoo files (separator is whitespace) for duplication detection
*/
public class XooTokenizerSensor implements Sensor {

  private void computeTokens(InputFile inputFile, SensorContext context) {
    DuplicationTokenBuilder tokenBuilder = context.duplicationTokenBuilder(inputFile);
    File ioFile = inputFile.file();
    int lineId = 0;
    try {
      for (String line : FileUtils.readLines(ioFile)) {
        lineId++;
        for (String token : Splitter.on(" ").split(line)) {
          tokenBuilder.addToken(lineId, token);
        }
      }
      tokenBuilder.done();
    } catch (IOException e) {
      throw new IllegalStateException("Unable to read file " + ioFile, e);
    }
  }
View Full Code Here


  public void testExecution() throws IOException {
    File source = new File(baseDir, "src/foo.xoo");
    FileUtils.write(source, "token1 token2 token3\ntoken4");
    DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
    fileSystem.add(inputFile);
    DuplicationTokenBuilder builder = mock(DuplicationTokenBuilder.class);
    when(context.duplicationTokenBuilder(inputFile)).thenReturn(builder);

    sensor.execute(context);

    verify(builder).addToken(1, "token1");
View Full Code Here

TOP

Related Classes of org.sonar.api.batch.sensor.duplication.DuplicationTokenBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.