From: Julien HENRY Date: Thu, 11 Jul 2013 10:22:50 +0000 (+0200) Subject: SONAR-4481 Create a new Cobertura Report parser API X-Git-Tag: 3.7~155 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=405494e6d7ed3a35d67b295fab031bb428cfab52;p=sonarqube.git SONAR-4481 Create a new Cobertura Report parser API --- diff --git a/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/AbstractCoberturaParser.java b/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/AbstractCoberturaParser.java index a9394a29889..1f6ab554da2 100644 --- a/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/AbstractCoberturaParser.java +++ b/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/AbstractCoberturaParser.java @@ -19,26 +19,12 @@ */ package org.sonar.plugins.cobertura.api; -import com.google.common.collect.Maps; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang.StringUtils; -import org.codehaus.staxmate.in.SMHierarchicCursor; -import org.codehaus.staxmate.in.SMInputCursor; import org.sonar.api.batch.SensorContext; -import org.sonar.api.measures.CoverageMeasuresBuilder; -import org.sonar.api.measures.Measure; import org.sonar.api.resources.Resource; -import org.sonar.api.utils.StaxParser; -import org.sonar.api.utils.XmlParserException; - -import javax.xml.stream.XMLStreamException; +import org.sonar.api.utils.CoberturaReportParserUtils; +import org.sonar.api.utils.CoberturaReportParserUtils.FileResolver; import java.io.File; -import java.text.ParseException; -import java.util.Map; - -import static java.util.Locale.ENGLISH; -import static org.sonar.api.utils.ParsingUtils.parseNumber; /** * @since 2.4 @@ -49,75 +35,12 @@ import static org.sonar.api.utils.ParsingUtils.parseNumber; public abstract class AbstractCoberturaParser { public void parseReport(File xmlFile, final SensorContext context) { - try { - StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() { - - public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { - try { - rootCursor.advance(); - collectPackageMeasures(rootCursor.descendantElementCursor("package"), context); - } catch (ParseException e) { - throw new XMLStreamException(e); - } - } - }); - parser.parse(xmlFile); - } catch (XMLStreamException e) { - throw new XmlParserException(e); - } - } - - private void collectPackageMeasures(SMInputCursor pack, SensorContext context) throws ParseException, XMLStreamException { - while (pack.getNext() != null) { - Map builderByFilename = Maps.newHashMap(); - collectFileMeasures(pack.descendantElementCursor("class"), builderByFilename); - for (Map.Entry entry : builderByFilename.entrySet()) { - String filename = sanitizeFilename(entry.getKey()); - Resource file = getResource(filename); - if (fileExists(context, file)) { - for (Measure measure : entry.getValue().createMeasures()) { - context.saveMeasure(file, measure); - } - } - } - } - } - - private boolean fileExists(SensorContext context, Resource file) { - return context.getResource(file) != null; - } - - private void collectFileMeasures(SMInputCursor clazz, Map builderByFilename) throws ParseException, XMLStreamException { - while (clazz.getNext() != null) { - String fileName = clazz.getAttrValue("filename"); - CoverageMeasuresBuilder builder = builderByFilename.get(fileName); - if (builder == null) { - builder = CoverageMeasuresBuilder.create(); - builderByFilename.put(fileName, builder); - } - collectFileData(clazz, builder); - } - } - - private void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder) throws ParseException, XMLStreamException { - SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); - while (line.getNext() != null) { - int lineId = Integer.parseInt(line.getAttrValue("number")); - builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH)); - - String isBranch = line.getAttrValue("branch"); - String text = line.getAttrValue("condition-coverage"); - if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { - String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); - builder.setConditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); + CoberturaReportParserUtils.parseReport(xmlFile, context, new FileResolver() { + @Override + public Resource resolve(String filename) { + return getResource(filename); } - } - } - - private String sanitizeFilename(String s) { - String fileName = FilenameUtils.removeExtension(s); - fileName = fileName.replace('/', '.').replace('\\', '.'); - return fileName; + }); } protected abstract Resource getResource(String fileName); diff --git a/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/CoberturaUtils.java b/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/CoberturaUtils.java index 3488d166ec0..36b88a0672c 100644 --- a/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/CoberturaUtils.java +++ b/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/CoberturaUtils.java @@ -23,24 +23,25 @@ import org.sonar.api.batch.maven.MavenPlugin; import org.sonar.api.batch.maven.MavenUtils; import org.sonar.api.resources.Project; import org.sonar.api.utils.Logs; -import org.sonar.plugins.cobertura.base.CoberturaConstants; import java.io.File; /** * @since 2.4 * @deprecated since 3.7 Used to keep backward compatibility since extraction - * of Cobertura plugin. + * of Cobertura plugin. Should be duplicated in each project. */ @Deprecated public final class CoberturaUtils { public static final String COBERTURA_GROUP_ID = MavenUtils.GROUP_ID_CODEHAUS_MOJO; public static final String COBERTURA_ARTIFACT_ID = "cobertura-maven-plugin"; + public static final String COBERTURA_REPORT_PATH_PROPERTY = "sonar.cobertura.reportPath"; /** * @deprecated in 2.8, because assumes that Sonar executed from Maven. Not used any more in sonar-cobertura-plugin. * See http://jira.codehaus.org/browse/SONAR-2321 + * Used in groovy and flex plugins. */ @Deprecated public static File getReport(Project project) { @@ -60,7 +61,7 @@ public final class CoberturaUtils { } private static File getReportFromProperty(Project project) { - String path = (String) project.getProperty(CoberturaConstants.COBERTURA_REPORT_PATH_PROPERTY); + String path = (String) project.getProperty(COBERTURA_REPORT_PATH_PROPERTY); if (path != null) { return project.getFileSystem().resolvePath(path); } diff --git a/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/base/CoberturaConstants.java b/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/base/CoberturaConstants.java deleted file mode 100644 index 6cd73ac629d..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/base/CoberturaConstants.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.plugins.cobertura.base; - -/** - * @deprecated since 3.7 Used to keep backward compatibility since extraction - * of Cobertura plugin. - */ -@Deprecated -public final class CoberturaConstants { - - public static final String COBERTURA_REPORT_PATH_PROPERTY = "sonar.cobertura.reportPath"; - public static final String COBERTURA_MAXMEM_PROPERTY = "sonar.cobertura.maxmem"; - public static final String COBERTURA_MAXMEM_DEFAULT_VALUE = "64m"; - - private CoberturaConstants() { - } -} diff --git a/sonar-deprecated/src/test/java/org/sonar/plugins/cobertura/api/CoberturaUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/plugins/cobertura/api/CoberturaUtilsTest.java index 4e17519812a..afb1ae13f4b 100644 --- a/sonar-deprecated/src/test/java/org/sonar/plugins/cobertura/api/CoberturaUtilsTest.java +++ b/sonar-deprecated/src/test/java/org/sonar/plugins/cobertura/api/CoberturaUtilsTest.java @@ -24,7 +24,6 @@ import org.junit.Test; import org.sonar.api.resources.Project; import org.sonar.api.resources.ProjectFileSystem; import org.sonar.api.test.MavenTestUtils; -import org.sonar.plugins.cobertura.base.CoberturaConstants; import java.io.File; import java.net.URISyntaxException; @@ -42,7 +41,7 @@ public class CoberturaUtilsTest { Project project = mock(Project.class); when(project.getFileSystem()).thenReturn(fileSystem); - when(project.getProperty(CoberturaConstants.COBERTURA_REPORT_PATH_PROPERTY)).thenReturn("foo"); + when(project.getProperty(CoberturaUtils.COBERTURA_REPORT_PATH_PROPERTY)).thenReturn("foo"); File report = CoberturaUtils.getReport(project); verify(fileSystem).resolvePath("foo"); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java new file mode 100644 index 00000000000..4f4205d2bcf --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java @@ -0,0 +1,132 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.api.utils; + +import com.google.common.collect.Maps; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang.StringUtils; +import org.codehaus.staxmate.in.SMHierarchicCursor; +import org.codehaus.staxmate.in.SMInputCursor; +import org.sonar.api.batch.SensorContext; +import org.sonar.api.measures.CoverageMeasuresBuilder; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.Resource; + +import javax.xml.stream.XMLStreamException; + +import java.io.File; +import java.text.ParseException; +import java.util.Map; + +import static java.util.Locale.ENGLISH; +import static org.sonar.api.utils.ParsingUtils.parseNumber; + +/** + * @since 3.7 + */ +public class CoberturaReportParserUtils { + + private CoberturaReportParserUtils() { + } + + public static interface FileResolver { + + /** + * Return a SonarQube file resource from a filename present in Cobertura report + */ + Resource resolve(String filename); + } + + /** + * Parse a Cobertura xml report and create measures accordingly + */ + public static void parseReport(File xmlFile, final SensorContext context, final FileResolver fileResolver) { + try { + StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() { + + public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { + try { + rootCursor.advance(); + collectPackageMeasures(rootCursor.descendantElementCursor("package"), context, fileResolver); + } catch (ParseException e) { + throw new XMLStreamException(e); + } + } + }); + parser.parse(xmlFile); + } catch (XMLStreamException e) { + throw new XmlParserException(e); + } + } + + private static void collectPackageMeasures(SMInputCursor pack, SensorContext context, final FileResolver fileResolver) throws ParseException, XMLStreamException { + while (pack.getNext() != null) { + Map builderByFilename = Maps.newHashMap(); + collectFileMeasures(pack.descendantElementCursor("class"), builderByFilename); + for (Map.Entry entry : builderByFilename.entrySet()) { + String filename = sanitizeFilename(entry.getKey()); + Resource file = fileResolver.resolve(filename); + if (fileExists(context, file)) { + for (Measure measure : entry.getValue().createMeasures()) { + context.saveMeasure(file, measure); + } + } + } + } + } + + private static boolean fileExists(SensorContext context, Resource file) { + return context.getResource(file) != null; + } + + private static void collectFileMeasures(SMInputCursor clazz, Map builderByFilename) throws ParseException, XMLStreamException { + while (clazz.getNext() != null) { + String fileName = clazz.getAttrValue("filename"); + CoverageMeasuresBuilder builder = builderByFilename.get(fileName); + if (builder == null) { + builder = CoverageMeasuresBuilder.create(); + builderByFilename.put(fileName, builder); + } + collectFileData(clazz, builder); + } + } + + private static void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder) throws ParseException, XMLStreamException { + SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); + while (line.getNext() != null) { + int lineId = Integer.parseInt(line.getAttrValue("number")); + builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH)); + + String isBranch = line.getAttrValue("branch"); + String text = line.getAttrValue("condition-coverage"); + if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { + String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); + builder.setConditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); + } + } + } + + private static String sanitizeFilename(String s) { + String fileName = FilenameUtils.removeExtension(s); + fileName = fileName.replace('/', '.').replace('\\', '.'); + return fileName; + } + +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java new file mode 100644 index 00000000000..ecab23869c1 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java @@ -0,0 +1,228 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.api.utils; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.SensorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.JavaFile; +import org.sonar.api.resources.JavaPackage; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.Resource; +import org.sonar.api.resources.Scopes; +import org.sonar.api.test.IsMeasure; +import org.sonar.api.test.IsResource; +import org.sonar.api.utils.CoberturaReportParserUtils.FileResolver; + +import java.io.File; +import java.net.URISyntaxException; + +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyDouble; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class CoberturaReportParserUtilsTest { + + private SensorContext context; + + @Before + public void setUp() { + context = mock(SensorContext.class); + } + + private static FileResolver JAVA_FILE_RESOLVER = new FileResolver() { + + @Override + public Resource resolve(String filename) { + return new JavaFile(filename); + } + }; + + @Test + public void doNotCollectProjectCoverage() throws URISyntaxException { + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + + verify(context, never()).saveMeasure(eq(CoreMetrics.COVERAGE), anyDouble()); + } + + @Test + public void doNotCollectProjectLineCoverage() throws URISyntaxException { + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + + verify(context, never()).saveMeasure(eq(CoreMetrics.LINE_COVERAGE), anyDouble()); + verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA))); + } + + @Test + public void doNotCollectProjectBranchCoverage() throws URISyntaxException { + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + + verify(context, never()).saveMeasure(eq(CoreMetrics.BRANCH_COVERAGE), anyDouble()); + } + + @Test + public void collectPackageLineCoverage() throws URISyntaxException { + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + + verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.LINE_COVERAGE), anyDouble()); + verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.UNCOVERED_LINES), anyDouble()); + } + + @Test + public void collectPackageBranchCoverage() throws URISyntaxException { + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + + verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.BRANCH_COVERAGE), anyDouble()); + verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.UNCOVERED_CONDITIONS), anyDouble()); + } + + @Test + public void packageCoverageIsCalculatedLaterByDecorator() throws URISyntaxException { + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + + verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.COVERAGE), anyDouble()); + } + + @Test + public void collectFileLineCoverage() throws URISyntaxException { + when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass")); + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + + final JavaFile file = new JavaFile("org.apache.commons.chain.config.ConfigParser"); + verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER, 30.0))); + verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES, 5.0))); + } + + @Test + public void collectFileBranchCoverage() throws URISyntaxException { + when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass")); + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + + final JavaFile file = new JavaFile("org.apache.commons.chain.config.ConfigParser"); + verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER, 6.0))); + verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS, 2.0))); + } + + @Test + public void testDoNotSaveMeasureOnResourceWhichDoesntExistInTheContext() throws URISyntaxException { + when(context.getResource(any(Resource.class))).thenReturn(null); + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + verify(context, never()).saveMeasure(any(Resource.class), any(Measure.class)); + } + + @Test + public void javaInterfaceHasNoCoverage() throws URISyntaxException { + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + + final JavaFile interfaze = new JavaFile("org.apache.commons.chain.Chain"); + verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.COVERAGE))); + + verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.LINE_COVERAGE))); + verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER))); + verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES))); + + verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.BRANCH_COVERAGE))); + verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER))); + verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS))); + } + + @Test + public void shouldInsertCoverageAtFileLevel() throws URISyntaxException { + File coverage = new File(getClass().getResource( + "/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldInsertCoverageAtFileLevel/coverage.xml").toURI()); + when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass")); + CoberturaReportParserUtils.parseReport(coverage, context, JAVA_FILE_RESOLVER); + + verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.InnerClass")), + argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER, 35.0))); + verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.InnerClass")), + argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES, 22.0))); + + verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.InnerClass")), + argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER, 4.0))); + verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.InnerClass")), + argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS, 3.0))); + + verify(context, never()).saveMeasure( + argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.InnerClass$InnerClassInside")), + argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER))); + verify(context, never()).saveMeasure( + argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.InnerClass$InnerClassInside")), + argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER))); + verify(context, never()).saveMeasure( + argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.InnerClass$InnerClassInside")), + argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS))); + verify(context, never()).saveMeasure( + argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.InnerClass$InnerClassInside")), + argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES))); + + verify(context, never()).saveMeasure( + argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.PrivateClass")), + argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER))); + verify(context, never()).saveMeasure( + argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.PrivateClass")), + argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER))); + verify(context, never()).saveMeasure( + argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.PrivateClass")), + argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS))); + verify(context, never()).saveMeasure( + argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.PrivateClass")), + argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES))); + + verify(context) + .saveMeasure( + eq(new JavaFile("org.sonar.samples.InnerClass")), + argThat(new IsMeasure( + CoreMetrics.COVERAGE_LINE_HITS_DATA, + "22=2;25=0;26=0;29=0;30=0;31=0;34=1;35=1;36=1;37=0;39=1;41=1;44=2;46=1;47=1;50=0;51=0;52=0;53=0;55=0;57=0;60=0;61=0;64=1;71=1;73=1;76=0;77=0;80=0;81=0;85=0;87=0;91=0;93=0;96=1"))); + } + + @Test + public void collectFileLineHitsData() throws URISyntaxException { + when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass")); + CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); + verify(context).saveMeasure( + eq(new JavaFile("org.apache.commons.chain.impl.CatalogBase")), + argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA, + "48=117;56=234;66=0;67=0;68=0;84=999;86=999;98=318;111=18;121=0;122=0;125=0;126=0;127=0;128=0;131=0;133=0"))); + } + + @Test + public void shouldNotCountTwiceAnonymousClasses() throws URISyntaxException { + File coverage = new File(getClass().getResource("/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldNotCountTwiceAnonymousClasses.xml").toURI()); + when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.samples.MyClass")); + CoberturaReportParserUtils.parseReport(coverage, context, JAVA_FILE_RESOLVER); + + verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.CLASS, "org.sonar.samples.MyFile")), + argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER, 5.0))); // do not count line 26 twice + } + + private File getCoverageReport() throws URISyntaxException { + return new File(getClass().getResource("/org/sonar/api/utils/CoberturaReportParserUtilsTest/commons-chain-coverage.xml").toURI()); + } +} diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/utils/CoberturaReportParserUtilsTest/commons-chain-coverage.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/utils/CoberturaReportParserUtilsTest/commons-chain-coverage.xml new file mode 100644 index 00000000000..adb4f7b8c00 --- /dev/null +++ b/sonar-plugin-api/src/test/resources/org/sonar/api/utils/CoberturaReportParserUtilsTest/commons-chain-coverage.xml @@ -0,0 +1,10201 @@ + + + + + + /Users/simon/projects/commons-chain/src/java + --source + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldInsertCoverageAtFileLevel/coverage.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldInsertCoverageAtFileLevel/coverage.xml new file mode 100644 index 00000000000..0f9517a4adc --- /dev/null +++ b/sonar-plugin-api/src/test/resources/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldInsertCoverageAtFileLevel/coverage.xml @@ -0,0 +1,180 @@ + + + + + + /Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java + --source + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldNotCountTwiceAnonymousClasses.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldNotCountTwiceAnonymousClasses.xml new file mode 100644 index 00000000000..55fa2986d6a --- /dev/null +++ b/sonar-plugin-api/src/test/resources/org/sonar/api/utils/CoberturaReportParserUtilsTest/shouldNotCountTwiceAnonymousClasses.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + /Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java + --source + + + + + + + + + + + + + + + + + + + + + + +