use of com.github.timurstrekalov.saga.core.model.ScriptData in project saga by timurstrekalov.
the class TestRunCoverageStatisticsCallable method collectAndWriteRunStats.
private TestRunCoverageStatistics collectAndWriteRunStats(final URI test, final Map<String, Map<String, Long>> coverageDataForAllScripts) throws IOException {
final TestRunCoverageStatistics runStats = new TestRunCoverageStatistics(test);
runStats.setSortBy(config.getSortBy());
runStats.setOrder(config.getOrder());
final URI baseUri = config.getBaseUri();
for (final ScriptData data : getLocalBrowser().getScriptDataList()) {
final String sourceUri = data.getSourceUriAsString();
@SuppressWarnings("unchecked") final Map<String, Long> coverageDataForScript = coverageDataForAllScripts.get(sourceUri);
final ScriptCoverageStatistics scriptCoverageStatistics = data.generateScriptCoverageStatistics(baseUri, coverageDataForScript);
runStats.add(scriptCoverageStatistics);
}
return runStats;
}
use of com.github.timurstrekalov.saga.core.model.ScriptData in project saga by timurstrekalov.
the class HtmlUnitBasedScriptInstrumenter method instrument.
@Override
public String instrument(final String sourceCode, final String sourceName, final int lineNumber) {
try {
final String normalizedSourceName = handleEvals(handleInvalidUriChars(handleInlineScripts(sourceName)));
if (shouldIgnore(normalizedSourceName)) {
return sourceCode;
}
final boolean separateFile = isSeparateFile(sourceName, normalizedSourceName);
final URI sourceUri = URI.create(normalizedSourceName).normalize();
if (config.isCacheInstrumentedCode() && instrumentedScriptCache.containsKey(sourceUri)) {
final ScriptData data = instrumentedScriptCache.get(sourceUri);
scriptDataList.add(data);
return data.getInstrumentedSourceCode();
}
final ScriptData data = addNewScriptData(sourceCode, separateFile, sourceUri);
final String instrumentedCode = instrument(lineNumber, data);
data.setInstrumentedSourceCode(instrumentedCode);
maybeCache(sourceUri, data);
maybeWriteInstrumentedCodeToDisk(separateFile, sourceUri, instrumentedCode);
return instrumentedCode;
} catch (final RuntimeException e) {
logger.error("Exception caught while instrumenting code", e);
return sourceCode;
}
}
use of com.github.timurstrekalov.saga.core.model.ScriptData in project saga by timurstrekalov.
the class HtmlUnitBasedScriptInstrumenterTest method verifyClassJsData.
private void verifyClassJsData(String sourceName, String expectedSourceName) {
final ScriptInstrumenter instrumenter = new HtmlUnitBasedScriptInstrumenter(new InstanceFieldPerPropertyConfig());
instrumenter.instrument(Data.getClassJsSourceCode(), sourceName, 1);
assertEquals(1, instrumenter.getScriptDataList().size());
final ScriptData classJsData = instrumenter.getScriptDataList().get(0);
assertEquals(expectedSourceName, classJsData.getSourceUriAsString());
assertEquals(5, classJsData.getLineNumberOfFirstStatement());
assertEquals(114, classJsData.getNumberOfStatements());
assertEqualsIgnoreCRLF(Data.getClassJsInstrumented(expectedSourceName), classJsData.getInstrumentedSourceCode());
}
use of com.github.timurstrekalov.saga.core.model.ScriptData 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));
}
}
use of com.github.timurstrekalov.saga.core.model.ScriptData in project saga by timurstrekalov.
the class HtmlUnitBasedScriptInstrumenter method addNewScriptData.
private ScriptData addNewScriptData(final String sourceCode, final boolean separateFile, final URI sourceUri) {
final ScriptData data = new ScriptData(sourceUri, sourceCode, separateFile);
scriptDataList.add(data);
return data;
}
Aggregations