private boolean analyzeLinesCoveredByTests(String sessionId, ExecutionDataStore executionDataStore) { int i = sessionId.indexOf(' '); if (i < 0) { return false; } String testClassName = sessionId.substring(0, i); String testName = sessionId.substring(i + 1); InputFile testResource = javaResourceLocator.findResourceByClassName(testClassName); if (testResource == null) { // No such test class return false; } boolean result = false; CoverageBuilder coverageBuilder = jacocoReportReader.analyzeFiles(executionDataStore, classFilesOfStore(executionDataStore)); for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) { InputFile resource = getResource(coverage); if (resource != null) { List<Integer> coveredLines = coveredLines(coverage); if (!coveredLines.isEmpty() && addCoverage(resource, testResource, testName, coveredLines)) { result = true; } } } return result; }
private boolean analyzeLinesCoveredByTests(String sessionId, ExecutionDataStore executionDataStore, SensorContext context) { int i = sessionId.indexOf(' '); if (i < 0) { return false; } String testClassName = sessionId.substring(0, i); String testName = sessionId.substring(i + 1); Resource testResource = context.getResource(javaResourceLocator.findResourceByClassName(testClassName)); if (testResource == null) { // No such test class return false; } boolean result = false; CoverageBuilder coverageBuilder = analyze2(executionDataStore); for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) { Resource resource = getResource(coverage, context); if (resource != null) { CoverageMeasuresBuilder builder = analyzeFile(resource, coverage); List<Integer> coveredLines = getCoveredLines(builder); if (!coveredLines.isEmpty() && addCoverage(resource, testResource, testName, coveredLines)) { result = true; } } } return result; }
for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) { Resource resource = getResource(coverage, context); if (resource != null) {
private boolean analyzeLinesCoveredByTests(String sessionId, ExecutionDataStore executionDataStore, SensorContext context, WildcardMatcher excludes) { int i = sessionId.indexOf(' '); if (i < 0) { return false; } String testClassName = sessionId.substring(0, i); String testName = sessionId.substring(i + 1); Resource testResource = context.getResource(javaResourceLocator.findResourceByClassName(testClassName)); if (testResource == null) { // No such test class return false; } boolean result = false; CoverageBuilder coverageBuilder = analyze2(executionDataStore); for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) { Resource resource = getResource(coverage, context); if (resource != null && !isExcluded(coverage, excludes)) { CoverageMeasuresBuilder builder = analyzeFile(resource, coverage); List<Integer> coveredLines = getCoveredLines(builder); if (!coveredLines.isEmpty() && addCoverage(resource, testResource, testName, coveredLines)) { result = true; } } } return result; }
for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) { Resource resource = getResource(coverage, context); if (resource != null) {
for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) { Resource resource = getResource(coverage, context); if (resource != null) {
for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) { Resource resource = getResource(coverage, context); if (resource != null) {
private AnalyzedNodes analyzeExternal(final IPackageFragmentRoot root) throws CoreException { IPath location = null; try { location = root.getPath(); AnalyzedNodes nodes = cache.get(location); if (nodes != null) { return nodes; } final CoverageBuilder builder = new CoverageBuilder(); final Analyzer analyzer = new Analyzer(executiondata, builder); new ResourceTreeWalker(analyzer).walk(location); nodes = new AnalyzedNodes(builder.getClasses(), builder.getSourceFiles()); cache.put(location, nodes); return nodes; } catch (Exception e) { throw new CoreException(EclEmmaStatus.BUNDLE_ANALYSIS_ERROR.getStatus( root.getElementName(), location, e)); } }
private AnalyzedNodes analyzeInternal(final IPackageFragmentRoot root) throws CoreException { IResource location = null; try { location = getClassfilesLocation(root); if (location == null) { TRACER.trace("No class files found for package fragment root {0}", //$NON-NLS-1$ root.getPath()); return AnalyzedNodes.EMPTY; } AnalyzedNodes nodes = cache.get(location); if (nodes != null) { return nodes; } final CoverageBuilder builder = new CoverageBuilder(); final Analyzer analyzer = new Analyzer(executiondata, builder); new ResourceTreeWalker(analyzer).walk(location); nodes = new AnalyzedNodes(builder.getClasses(), builder.getSourceFiles()); cache.put(location, nodes); return nodes; } catch (Exception e) { throw new CoreException(EclEmmaStatus.BUNDLE_ANALYSIS_ERROR.getStatus( root.getElementName(), location, e)); } }
private void readExecutionData(@Nullable File jacocoExecutionData, SensorContext context) { File newJacocoExecutionData = jacocoExecutionData; if (newJacocoExecutionData == null || !newJacocoExecutionData.isFile()) { JaCoCoExtensions.LOG.info("Project coverage is set to 0% as no JaCoCo execution data has been dumped: {}", newJacocoExecutionData); newJacocoExecutionData = null; } ExecutionDataVisitor executionDataVisitor = new ExecutionDataVisitor(); jacocoReportReader = new JacocoReportReader(newJacocoExecutionData).readJacocoReport(executionDataVisitor, executionDataVisitor); boolean collectedCoveragePerTest = readCoveragePerTests(executionDataVisitor); CoverageBuilder coverageBuilder = jacocoReportReader.analyzeFiles(executionDataVisitor.getMerged(), classFilesCache.values()); int analyzedResources = 0; for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) { InputFile inputFile = getResource(coverage); if (inputFile != null) { NewCoverage newCoverage = context.newCoverage().onFile(inputFile); analyzeFile(newCoverage, inputFile, coverage); newCoverage.save(); analyzedResources++; } } if (analyzedResources == 0) { JaCoCoExtensions.LOG.warn("Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?"); } else if (collectedCoveragePerTest) { JaCoCoExtensions.LOG.info("Information about coverage per test has been collected."); } else if (newJacocoExecutionData != null) { JaCoCoExtensions.LOG.info("No information about coverage per test."); } }
public final void readExecutionData(File jacocoExecutionData, SensorContext context) { ExecutionDataVisitor executionDataVisitor = new ExecutionDataVisitor(); File fileToAnalyze = jacocoExecutionData; if (fileToAnalyze == null || !fileToAnalyze.isFile()) { JaCoCoExtensions.logger().warn("Project coverage is set to 0% as no JaCoCo execution data has been dumped: {}", jacocoExecutionData); fileToAnalyze = null; } else { JaCoCoExtensions.logger().info("Analysing {}", fileToAnalyze); } JaCoCoReportReader jacocoReportReader = new JaCoCoReportReader(fileToAnalyze).readJacocoReport(executionDataVisitor, executionDataVisitor); CoverageBuilder coverageBuilder = jacocoReportReader.analyzeFiles(executionDataVisitor.getMerged(), classFilesCache.values()); int analyzedResources = 0; for (ISourceFileCoverage coverage : coverageBuilder.getSourceFiles()) { InputFile groovyFile = getInputFile(coverage); if (groovyFile != null) { NewCoverage newCoverage = context.newCoverage().onFile(groovyFile).ofType(coverageType()); analyzeFile(newCoverage, groovyFile, coverage); newCoverage.save(); analyzedResources++; } } if (analyzedResources == 0) { JaCoCoExtensions.logger().warn("Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?"); } }