diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-09-05 14:58:03 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-09-05 14:58:03 +0200 |
commit | d0c7a71f3d960cd5c9bf39b1f7fe8341470b06e7 (patch) | |
tree | 1d21d9901c613e68f3acab90b78381372f6f4f74 /sonar-deprecated | |
parent | e1c3a706319c397b436a28b7921b695baf712063 (diff) | |
download | sonarqube-d0c7a71f3d960cd5c9bf39b1f7fe8341470b06e7.tar.gz sonarqube-d0c7a71f3d960cd5c9bf39b1f7fe8341470b06e7.zip |
SONAR-2860 Drop commons-configuration
Diffstat (limited to 'sonar-deprecated')
6 files changed, 0 insertions, 585 deletions
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/resources/ProjectUtils.java b/sonar-deprecated/src/main/java/org/sonar/api/resources/ProjectUtils.java index b754732e01b..d852edd82d6 100644 --- a/sonar-deprecated/src/main/java/org/sonar/api/resources/ProjectUtils.java +++ b/sonar-deprecated/src/main/java/org/sonar/api/resources/ProjectUtils.java @@ -20,7 +20,6 @@ package org.sonar.api.resources; import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; import java.util.Collection; import java.util.List; @@ -37,24 +36,6 @@ public final class ProjectUtils { } /** - * @deprecated since 2.6 use JavaUtils.getTargetVersion() instead. - */ - @Deprecated - public static String getJavaVersion(Project project) { - String version = project.getConfiguration() != null ? project.getConfiguration().getString("sonar.java.target") : null; - return StringUtils.isNotBlank(version) ? version : "1.5"; - } - - /** - * @deprecated since 2.6 use JavaUtils.getSourceVersion() instead. - */ - @Deprecated - public static String getJavaSourceVersion(Project project) { - String version = project.getConfiguration() != null ? project.getConfiguration().getString("sonar.java.source") : null; - return StringUtils.isNotBlank(version) ? version : "1.5"; - } - - /** * @since 2.7 * @deprecated in 4.2. Replaced by org.sonar.api.resources.InputFileUtils#toFiles() */ diff --git a/sonar-deprecated/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java b/sonar-deprecated/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java deleted file mode 100644 index 45ee16dc594..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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 - * @deprecated in 4.2. This class should be handled internally by plugins - */ -@Deprecated -public class CoberturaReportParserUtils { - - private CoberturaReportParserUtils() { - } - - public 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 { - rootCursor.advance(); - collectPackageMeasures(rootCursor.descendantElementCursor("package"), context, fileResolver); - } - }); - parser.parse(xmlFile); - } catch (XMLStreamException e) { - throw new XmlParserException(e); - } - } - - private static void collectPackageMeasures(SMInputCursor pack, SensorContext context, final FileResolver fileResolver) throws XMLStreamException { - while (pack.getNext() != null) { - Map<String, CoverageMeasuresBuilder> builderByFilename = Maps.newHashMap(); - collectFileMeasures(pack.descendantElementCursor("class"), builderByFilename); - for (Map.Entry<String, CoverageMeasuresBuilder> 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<String, CoverageMeasuresBuilder> builderByFilename) throws 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 XMLStreamException { - SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); - while (line.getNext() != null) { - int lineId = Integer.parseInt(line.getAttrValue("number")); - try { - builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH)); - } catch (ParseException e) { - throw new XmlParserException(e); - } - - 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-deprecated/src/main/java/org/sonar/plugins/cobertura/api/AbstractCoberturaParser.java b/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/AbstractCoberturaParser.java deleted file mode 100644 index c653ea92923..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/AbstractCoberturaParser.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.api; - -import org.sonar.api.batch.SensorContext; -import org.sonar.api.resources.Resource; -import org.sonar.api.utils.CoberturaReportParserUtils; -import org.sonar.api.utils.CoberturaReportParserUtils.FileResolver; - -import java.io.File; - -/** - * @since 2.4 - * @deprecated since 3.7 Used to keep backward compatibility since extraction - * of Cobertura plugin. - */ -@Deprecated -public abstract class AbstractCoberturaParser { - - public void parseReport(File xmlFile, final SensorContext context) { - CoberturaReportParserUtils.parseReport(xmlFile, context, new FileResolver() { - @Override - public Resource resolve(String filename) { - return getResource(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 deleted file mode 100644 index e1baa0dce95..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/plugins/cobertura/api/CoberturaUtils.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.api; - -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 java.io.File; - -/** - * @since 2.4 - * @deprecated since 3.7 Used to keep backward compatibility since extraction - * 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) { - File report = getReportFromProperty(project); - if (report == null) { - report = getReportFromPluginConfiguration(project); - } - if (report == null) { - report = getReportFromDefaultPath(project); - } - - if (report == null || !report.exists() || !report.isFile()) { - Logs.INFO.warn("Cobertura report not found at {}", report); - report = null; - } - return report; - } - - private static File getReportFromProperty(Project project) { - String path = (String) project.getProperty(COBERTURA_REPORT_PATH_PROPERTY); - if (path != null) { - return project.getFileSystem().resolvePath(path); - } - return null; - } - - private static File getReportFromPluginConfiguration(Project project) { - MavenPlugin mavenPlugin = MavenPlugin.getPlugin(project.getPom(), COBERTURA_GROUP_ID, COBERTURA_ARTIFACT_ID); - if (mavenPlugin != null) { - String path = mavenPlugin.getParameter("outputDirectory"); - if (path != null) { - return new File(project.getFileSystem().resolvePath(path), "coverage.xml"); - } - } - return null; - } - - private static File getReportFromDefaultPath(Project project) { - return new File(project.getFileSystem().getReportOutputDir(), "cobertura/coverage.xml"); - } - - private CoberturaUtils() { - } - -} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java deleted file mode 100644 index 60b63e84de1..00000000000 --- a/sonar-deprecated/src/test/java/org/sonar/api/utils/CoberturaReportParserUtilsTest.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.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.Matchers.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 org.sonar.api.resources.File(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 org.sonar.api.resources.File("org.sonar.MyClass")); - CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); - - final org.sonar.api.resources.File file = new org.sonar.api.resources.File("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 org.sonar.api.resources.File("org.sonar.MyClass")); - CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); - - final org.sonar.api.resources.File file = new org.sonar.api.resources.File("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 org.sonar.api.resources.File interfaze = new org.sonar.api.resources.File("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 org.sonar.api.resources.File("org.sonar.MyClass")); - CoberturaReportParserUtils.parseReport(coverage, context, JAVA_FILE_RESOLVER); - - verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass")), - argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER, 35.0))); - verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass")), - argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES, 22.0))); - - verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass")), - argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER, 4.0))); - verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass")), - argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS, 3.0))); - - verify(context, never()).saveMeasure( - argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass$InnerClassInside")), - argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER))); - verify(context, never()).saveMeasure( - argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass$InnerClassInside")), - argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER))); - verify(context, never()).saveMeasure( - argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass$InnerClassInside")), - argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS))); - verify(context, never()).saveMeasure( - argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.InnerClass$InnerClassInside")), - argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES))); - - verify(context, never()).saveMeasure( - argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.PrivateClass")), - argThat(new IsMeasure(CoreMetrics.LINES_TO_COVER))); - verify(context, never()).saveMeasure( - argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.PrivateClass")), - argThat(new IsMeasure(CoreMetrics.CONDITIONS_TO_COVER))); - verify(context, never()).saveMeasure( - argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.PrivateClass")), - argThat(new IsMeasure(CoreMetrics.UNCOVERED_CONDITIONS))); - verify(context, never()).saveMeasure( - argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "org.sonar.samples.PrivateClass")), - argThat(new IsMeasure(CoreMetrics.UNCOVERED_LINES))); - - verify(context) - .saveMeasure( - eq(new org.sonar.api.resources.File("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 org.sonar.api.resources.File("org.sonar.MyClass")); - CoberturaReportParserUtils.parseReport(getCoverageReport(), context, JAVA_FILE_RESOLVER); - verify(context).saveMeasure( - eq(new org.sonar.api.resources.File("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 org.sonar.api.resources.File("org.sonar.samples.MyClass")); - CoberturaReportParserUtils.parseReport(coverage, context, JAVA_FILE_RESOLVER); - - verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "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-deprecated/src/test/java/org/sonar/plugins/cobertura/api/CoberturaUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/plugins/cobertura/api/CoberturaUtilsTest.java deleted file mode 100644 index f8f1348645a..00000000000 --- a/sonar-deprecated/src/test/java/org/sonar/plugins/cobertura/api/CoberturaUtilsTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.api; - -import org.apache.maven.project.MavenProject; -import org.junit.Test; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.ProjectFileSystem; -import org.sonar.api.test.MavenTestUtils; - -import java.io.File; -import java.net.URISyntaxException; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class CoberturaUtilsTest { - @Test - public void shouldGetReportPathFromProperty() throws URISyntaxException { - ProjectFileSystem fileSystem = mock(ProjectFileSystem.class); - when(fileSystem.resolvePath("foo")).thenReturn(getCoverageReport()); - - Project project = mock(Project.class); - when(project.getFileSystem()).thenReturn(fileSystem); - when(project.getProperty(CoberturaUtils.COBERTURA_REPORT_PATH_PROPERTY)).thenReturn("foo"); - - File report = CoberturaUtils.getReport(project); - verify(fileSystem).resolvePath("foo"); - assertNotNull(report); - } - - @Test - public void shouldGetReportPathFromPom() { - MavenProject pom = MavenTestUtils.loadPom("/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldGetReportPathFromPom/pom.xml"); - - ProjectFileSystem fileSystem = mock(ProjectFileSystem.class); - - Project project = mock(Project.class); - when(project.getPom()).thenReturn(pom); - when(project.getFileSystem()).thenReturn(fileSystem); - - CoberturaUtils.getReport(project); - - verify(fileSystem).resolvePath("overridden/dir"); - } - - private File getCoverageReport() throws URISyntaxException { - return new File(getClass().getResource("/org/sonar/plugins/cobertura/CoberturaSensorTest/commons-chain-coverage.xml").toURI()); - } -} |