diff --git a/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java b/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java index 1416a5e1cfc5b62426170110f89390e56586ba81..07a4ff680488f31c1150efbaac94e5aae4fc3a16 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java @@ -53,6 +53,7 @@ import org.jacoco.report.check.RulesChecker; import org.jacoco.report.csv.CSVFormatter; import org.jacoco.report.html.HTMLFormatter; import org.jacoco.report.xml.XMLFormatter; +import org.jacoco.core.internal.diff.JsonReadUtil; /** * Task for coverage report generation. @@ -108,6 +109,12 @@ public class ReportTask extends Task { private String name; + private String difffile; + + public void setDifffile(final String difffile) { + this.difffile = difffile; + } + /** * Sets the name of the group. * @@ -535,14 +542,21 @@ public class ReportTask extends Task { return new MultiReportVisitor(visitors); } + // 存放差量文件 + private String diffFileString = ""; + private void createReport(final IReportGroupVisitor visitor, final GroupElement group) throws IOException { if (group.name == null) { throw new BuildException("Group name must be supplied", getLocation()); } + if (null != group.difffile) { + diffFileString = group.difffile; + log("差量文件:" + JsonReadUtil.readJsonToString(group.difffile)); + } if (group.children.isEmpty()) { - final IBundleCoverage bundle = createBundle(group); + final IBundleCoverage bundle = createBundle(group, diffFileString); final SourceFilesElement sourcefiles = group.sourcefiles; final AntResourcesLocator locator = new AntResourcesLocator( sourcefiles.encoding, sourcefiles.tabWidth); @@ -560,9 +574,16 @@ public class ReportTask extends Task { } } - private IBundleCoverage createBundle(final GroupElement group) + private IBundleCoverage createBundle(final GroupElement group, + String diffFileString) throws IOException { - final CoverageBuilder builder = new CoverageBuilder(); + final CoverageBuilder builder; + if (null != diffFileString && !"".equals(diffFileString)) { + builder = new CoverageBuilder( + JsonReadUtil.readJsonToString(diffFileString)); + } else { + builder = new CoverageBuilder(); + } final Analyzer analyzer = new Analyzer(executionDataStore, builder); for (final Iterator i = group.classfiles.iterator(); i.hasNext();) { final Resource resource = (Resource) i.next();