private static final Logger logger = LoggerFactory.getLogger(FileSystemSourcePreloader.class);
@Override
public void preloadSources(final Config config, final TestRunCoverageStatistics totalStats) throws IOException {
final ScriptInstrumenter instrumenter = new HtmlUnitBasedScriptInstrumenter(config);
final String sourcesToPreload = config.getSourcesToPreload();
final URI baseUri = config.getBaseUri();
if (sourcesToPreload == null || !config.getOutputStrategy().contains(OutputStrategy.TOTAL) || !UriUtil.isFileUri(baseUri)) {
return;
}
final String sourcesToPreloadEncoding = config.getSourcesToPreloadEncoding();
logger.info("Using {} to preload sources", sourcesToPreloadEncoding);
final List<File> filesToPreload = FileUtils.getFiles(new File(baseUri), sourcesToPreload, null);
logger.info("Preloading {} files", filesToPreload.size());
for (final File file : filesToPreload) {
logger.debug("Preloading {}", file);
final String source = CharStreams.toString(Files.newReaderSupplier(file, Charset.forName(sourcesToPreloadEncoding)));
instrumenter.instrument(source, file.toURI().toString(), 0);
}
for (final ScriptData data : instrumenter.getScriptDataList()) {
final Map<String, Long> coverageData = Maps.newHashMap();
for (final Integer lineNumber : data.getLineNumbersOfAllStatements()) {
coverageData.put(String.valueOf(lineNumber), 0L);
}