Search in sources :

Example 1 with HtmlUnitBasedScriptInstrumenter

use of com.github.timurstrekalov.saga.core.instrumentation.HtmlUnitBasedScriptInstrumenter in project saga by timurstrekalov.

the class FileSystemSourcePreloader method preloadSources.

@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);
        }
        totalStats.add(data.generateScriptCoverageStatistics(baseUri, coverageData));
    }
}
Also used : HtmlUnitBasedScriptInstrumenter(com.github.timurstrekalov.saga.core.instrumentation.HtmlUnitBasedScriptInstrumenter) ScriptInstrumenter(com.github.timurstrekalov.saga.core.instrumentation.ScriptInstrumenter) HtmlUnitBasedScriptInstrumenter(com.github.timurstrekalov.saga.core.instrumentation.HtmlUnitBasedScriptInstrumenter) ScriptData(com.github.timurstrekalov.saga.core.model.ScriptData) URI(java.net.URI) File(java.io.File)

Aggregations

HtmlUnitBasedScriptInstrumenter (com.github.timurstrekalov.saga.core.instrumentation.HtmlUnitBasedScriptInstrumenter)1 ScriptInstrumenter (com.github.timurstrekalov.saga.core.instrumentation.ScriptInstrumenter)1 ScriptData (com.github.timurstrekalov.saga.core.model.ScriptData)1 File (java.io.File)1 URI (java.net.URI)1