SonarDuplicationsIndex index = createIndex(project, languageKey, sourceFiles);
detect(index, context, sourceFiles);
}
private SonarDuplicationsIndex createIndex(@Nullable Project project, String language, Iterable<InputFile> sourceFiles) {
final SonarDuplicationsIndex index = indexFactory.create(project, language);
TokenChunker tokenChunker = JavaTokenProducer.build();
StatementChunker statementChunker = JavaStatementBuilder.build();
BlockChunker blockChunker = new BlockChunker(BLOCK_SIZE);
for (InputFile inputFile : sourceFiles) {
LOG.debug("Populating index from {}", inputFile);
String resourceEffectiveKey = ((DeprecatedDefaultInputFile) inputFile).key();
List<Statement> statements;
Reader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(inputFile.file()), fs.encoding());
statements = statementChunker.chunk(tokenChunker.chunk(reader));
} catch (FileNotFoundException e) {
throw new SonarException("Cannot find file " + inputFile.file(), e);
} finally {
IOUtils.closeQuietly(reader);
}
List<Block> blocks = blockChunker.chunk(resourceEffectiveKey, statements);
index.insert(inputFile, blocks);
}
return index;
}