--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.clover;
+
+import org.apache.commons.configuration.Configuration;
+import org.sonar.api.batch.AbstractInitializer;
+import org.sonar.api.batch.CoverageExtension;
+import org.sonar.api.batch.Phase;
+import org.sonar.api.batch.Phase.Name;
+import org.sonar.api.batch.maven.DependsUponMavenPlugin;
+import org.sonar.api.batch.maven.MavenPlugin;
+import org.sonar.api.batch.maven.MavenPluginHandler;
+import org.sonar.api.resources.Project;
+
+/**
+ * Provides {@link CloverMavenPluginHandler} and configures correct path to report.
+ * Enabled only in Maven environment.
+ */
+@Phase(name = Name.PRE)
+public class CloverMavenInitializer extends AbstractInitializer implements CoverageExtension, DependsUponMavenPlugin {
+
+ private CloverMavenPluginHandler handler;
+
+ public CloverMavenInitializer(CloverMavenPluginHandler handler) {
+ this.handler = handler;
+ }
+
+ public MavenPluginHandler getMavenPluginHandler(Project project) {
+ if (project.getAnalysisType().equals(Project.AnalysisType.DYNAMIC)) {
+ return handler;
+ }
+ return null;
+ }
+
+ @Override
+ public boolean shouldExecuteOnProject(Project project) {
+ return project.getAnalysisType().isDynamic(true) &&
+ project.getFileSystem().hasJavaSourceFiles();
+ }
+
+ @Override
+ public void prepare(Project project) {
+ Configuration conf = project.getConfiguration();
+ if (!conf.containsKey(CloverConstants.REPORT_PATH_PROPERTY)) {
+ String report = getReportPathFromPluginConfiguration(project);
+ if (report == null) {
+ report = getDefaultReportPath(project);
+ }
+ conf.setProperty(CloverConstants.REPORT_PATH_PROPERTY, report);
+ }
+ }
+
+ private String getDefaultReportPath(Project project) {
+ return project.getFileSystem().getReportOutputDir() + "/clover/clover.xml";
+ }
+
+ private String getReportPathFromPluginConfiguration(Project project) {
+ MavenPlugin plugin = MavenPlugin.getPlugin(project.getPom(), CloverConstants.MAVEN_GROUP_ID, CloverConstants.MAVEN_ARTIFACT_ID);
+ if (plugin != null) {
+ String path = plugin.getParameter("outputDirectory");
+ if (path != null) {
+ return path + "/clover.xml";
+ }
+ }
+ return null;
+ }
+}
key = CloverConstants.VERSION_PROPERTY,
name = "Clover version",
description = "Override the Clover version to use. Default value is read from pom, else " + CloverConstants.DEFAULT_VERSION,
- project = true, global = true)
-})
+ project = true, global = true) })
public class CloverPlugin implements Plugin {
public String getKey() {
}
public List getExtensions() {
- return Arrays.asList(CloverMavenPluginHandler.class, CloverSensor.class);
+ return Arrays.asList(CloverMavenPluginHandler.class, CloverMavenInitializer.class, CloverSensor.class);
}
}
*/
package org.sonar.plugins.clover;
+import java.io.File;
+
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.AbstractCoverageExtension;
+import org.sonar.api.batch.CoverageExtension;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.maven.DependsUponMavenPlugin;
-import org.sonar.api.batch.maven.MavenPlugin;
-import org.sonar.api.batch.maven.MavenPluginHandler;
import org.sonar.api.resources.Project;
-import java.io.File;
-
-public class CloverSensor extends AbstractCoverageExtension implements Sensor, DependsUponMavenPlugin {
-
- private CloverMavenPluginHandler handler;
-
- public CloverSensor(CloverMavenPluginHandler handler) {
- this.handler = handler;
- }
+public class CloverSensor implements Sensor, CoverageExtension {
- public MavenPluginHandler getMavenPluginHandler(Project project) {
- if (project.getAnalysisType().equals(Project.AnalysisType.DYNAMIC)) {
- return handler;
- }
- return null;
+ public boolean shouldExecuteOnProject(Project project) {
+ return project.getFileSystem().hasJavaSourceFiles();
}
public void analyse(Project project, SensorContext context) {
- File report = getReport(project);
+ File report = getReportFromProperty(project);
if (reportExists(report)) {
new XmlReportParser(context).collect(report);
} else {
}
}
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return super.shouldExecuteOnProject(project) &&
- project.getFileSystem().hasJavaSourceFiles();
- }
-
- protected File getReport(Project pom) {
- File report = getReportFromProperty(pom);
- if (report == null) {
- report = getReportFromPluginConfiguration(pom);
- }
- if (report == null) {
- report = getReportFromDefaultPath(pom);
- }
- return report;
- }
-
- private File getReportFromProperty(Project pom) {
- String path = (String) pom.getProperty(CloverConstants.REPORT_PATH_PROPERTY);
+ private File getReportFromProperty(Project project) {
+ String path = (String) project.getProperty(CloverConstants.REPORT_PATH_PROPERTY);
if (path != null) {
- return pom.getFileSystem().resolvePath(path);
- }
- return null;
- }
-
- private File getReportFromPluginConfiguration(Project pom) {
- MavenPlugin plugin = MavenPlugin.getPlugin(pom.getPom(), CloverConstants.MAVEN_GROUP_ID, CloverConstants.MAVEN_ARTIFACT_ID);
- if (plugin != null) {
- String path = plugin.getParameter("outputDirectory");
- if (path != null) {
- return new File(pom.getFileSystem().resolvePath(path), "clover.xml");
- }
+ return project.getFileSystem().resolvePath(path);
}
return null;
}
- private File getReportFromDefaultPath(Project pom) {
- return new File(pom.getFileSystem().getReportOutputDir(), "clover/clover.xml");
- }
-
private boolean reportExists(File report) {
return report != null && report.exists() && report.isFile();
}
+
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.clover;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.resources.Project;
+
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class CloverMavenInitializerTest {
+
+ private Project project;
+ private CloverMavenInitializer initializer;
+
+ @Before
+ public void setUp() {
+ project = mock(Project.class);
+ initializer = new CloverMavenInitializer(new CloverMavenPluginHandler(new PropertiesConfiguration()));
+ }
+
+ @Test
+ public void doNotExecuteMavenPluginIfReuseReports() {
+ when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS);
+ assertThat(initializer.getMavenPluginHandler(project), nullValue());
+ }
+
+ @Test
+ public void doNotExecuteMavenPluginIfStaticAnalysis() {
+ when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
+ assertThat(initializer.getMavenPluginHandler(project), nullValue());
+ }
+
+ @Test
+ public void executeMavenPluginIfDynamicAnalysis() {
+ when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
+ assertThat(initializer.getMavenPluginHandler(project), not(nullValue()));
+ }
+
+}
*/
package org.sonar.plugins.clover;
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertThat;
+import org.junit.Test;
+
public class CloverPluginTest {
@Test
public void someExtensions() {
- assertThat(new CloverPlugin().getExtensions().size(), is(2));
+ assertThat(new CloverPlugin().getExtensions().size(), greaterThan(1));
}
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.clover;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.junit.Test;
-import org.sonar.api.resources.Project;
-
-import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class CloverSensorTest {
-
- @Test
- public void doNotExecuteMavenPluginIfReuseReports() {
- Project project = mock(Project.class);
- when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS);
- assertThat(new CloverSensor(new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), nullValue());
- }
-
- @Test
- public void doNotExecuteMavenPluginIfStaticAnalysis() {
- Project project = mock(Project.class);
- when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
- assertThat(new CloverSensor(new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), nullValue());
- }
-
- @Test
- public void executeMavenPluginIfDynamicAnalysis() {
- Project project = mock(Project.class);
- when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
- assertThat(new CloverSensor(new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), not(nullValue()));
- }
-}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.cobertura;
+
+import org.apache.commons.configuration.Configuration;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.AbstractInitializer;
+import org.sonar.api.batch.CoverageExtension;
+import org.sonar.api.batch.Phase;
+import org.sonar.api.batch.Phase.Name;
+import org.sonar.api.batch.maven.DependsUponMavenPlugin;
+import org.sonar.api.batch.maven.MavenPlugin;
+import org.sonar.api.batch.maven.MavenPluginHandler;
+import org.sonar.api.resources.Project;
+import org.sonar.plugins.cobertura.api.CoberturaUtils;
+
+/**
+ * Provides {@link CoberturaMavenPluginHandler} and configures correct path to report.
+ * Enabled only in Maven environment.
+ */
+@Phase(name = Name.PRE)
+public class CoberturaMavenInitializer extends AbstractInitializer implements CoverageExtension, DependsUponMavenPlugin {
+
+ private CoberturaMavenPluginHandler handler;
+
+ public CoberturaMavenInitializer(CoberturaMavenPluginHandler handler) {
+ this.handler = handler;
+ }
+
+ public MavenPluginHandler getMavenPluginHandler(Project project) {
+ if (project.getAnalysisType().equals(Project.AnalysisType.DYNAMIC)) {
+ return handler;
+ }
+ return null;
+ }
+
+ @Override
+ public boolean shouldExecuteOnProject(Project project) {
+ return project.getAnalysisType().isDynamic(true) &&
+ project.getFileSystem().hasJavaSourceFiles();
+ }
+
+ @Override
+ public void prepare(Project project) {
+ Configuration conf = project.getConfiguration();
+ if (conf.containsKey(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY)) {
+ String report = getReportPathFromPluginConfiguration(project);
+ if (report == null) {
+ report = getDefaultReportPath(project);
+ }
+ conf.setProperty(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY, report);
+ }
+ }
+
+ private static String getDefaultReportPath(Project project) {
+ return project.getFileSystem().getReportOutputDir() + "/cobertura/coverage.xml";
+ }
+
+ private static String getReportPathFromPluginConfiguration(Project project) {
+ MavenPlugin mavenPlugin = MavenPlugin.getPlugin(
+ project.getPom(),
+ CoberturaUtils.COBERTURA_GROUP_ID,
+ CoberturaUtils.COBERTURA_ARTIFACT_ID);
+ if (mavenPlugin != null) {
+ String path = mavenPlugin.getParameter("outputDirectory");
+ if (path != null) {
+ return path + "/coverage.xml";
+ }
+ }
+ return null;
+ }
+
+}
name = "Maxmem",
description = "Maximum memory to pass to JVM of Cobertura processes",
project = true,
- global = true)
-})
+ global = true) })
public class CoberturaPlugin implements Plugin {
public String getKey() {
List<Class<? extends Extension>> list = new ArrayList<Class<? extends Extension>>();
list.add(CoberturaSensor.class);
list.add(CoberturaMavenPluginHandler.class);
+ list.add(CoberturaMavenInitializer.class);
return list;
}
*/
package org.sonar.plugins.cobertura;
+import java.io.File;
+
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.AbstractCoverageExtension;
+import org.sonar.api.batch.CoverageExtension;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.maven.DependsUponMavenPlugin;
-import org.sonar.api.batch.maven.MavenPluginHandler;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.plugins.cobertura.api.AbstractCoberturaParser;
import org.sonar.plugins.cobertura.api.CoberturaUtils;
-import java.io.File;
-
-public class CoberturaSensor extends AbstractCoverageExtension implements Sensor, DependsUponMavenPlugin {
-
- private CoberturaMavenPluginHandler handler;
-
- public CoberturaSensor(CoberturaMavenPluginHandler handler) {
- this.handler = handler;
- }
+public class CoberturaSensor implements Sensor, CoverageExtension {
- @Override
public boolean shouldExecuteOnProject(Project project) {
- return super.shouldExecuteOnProject(project) && project.getFileSystem().hasJavaSourceFiles();
+ return project.getFileSystem().hasJavaSourceFiles();
}
public void analyse(Project project, SensorContext context) {
}
}
- public MavenPluginHandler getMavenPluginHandler(Project project) {
- if (project.getAnalysisType().equals(Project.AnalysisType.DYNAMIC)) {
- return handler;
- }
- return null;
- }
-
protected void parseReport(File xmlFile, final SensorContext context) {
LoggerFactory.getLogger(CoberturaSensor.class).info("parsing {}", xmlFile);
new AbstractCoberturaParser() {
public String toString() {
return getClass().getSimpleName();
}
+
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.cobertura;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.resources.Project;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class CoberturaMavenInitializerTest {
+
+ private Project project;
+ private CoberturaMavenInitializer initializer;
+
+ @Before
+ public void setUp() {
+ project = mock(Project.class);
+ initializer = new CoberturaMavenInitializer(new CoberturaMavenPluginHandler());
+ }
+
+ @Test
+ public void doNotExecuteMavenPluginIfReuseReports() {
+ when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS);
+ assertThat(initializer.getMavenPluginHandler(project), nullValue());
+ }
+
+ @Test
+ public void doNotExecuteMavenPluginIfStaticAnalysis() {
+ when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
+ assertThat(initializer.getMavenPluginHandler(project), nullValue());
+ }
+
+ @Test
+ public void executeMavenPluginIfDynamicAnalysis() {
+ when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
+ assertThat(initializer.getMavenPluginHandler(project), not(nullValue()));
+ assertThat(initializer.getMavenPluginHandler(project).getArtifactId(), is("cobertura-maven-plugin"));
+ }
+
+}
*/
package org.sonar.plugins.cobertura;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertThat;
-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;
-
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.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.test.IsMeasure;
import org.sonar.api.test.IsResource;
import java.io.File;
import java.net.URISyntaxException;
-public class CoberturaSensorTest {
-
- @Test
- public void doNotExecuteMavenPluginIfReuseReports() {
- Project project = mock(Project.class);
- when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS);
- assertThat(new CoberturaSensor(new CoberturaMavenPluginHandler()).getMavenPluginHandler(project), nullValue());
- }
-
- @Test
- public void doNotExecuteMavenPluginIfStaticAnalysis() {
- Project project = mock(Project.class);
- when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
- assertThat(new CoberturaSensor(new CoberturaMavenPluginHandler()).getMavenPluginHandler(project), nullValue());
- }
+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;
- @Test
- public void executeMavenPluginIfDynamicAnalysis() {
- Project project = mock(Project.class);
- when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
- assertThat(new CoberturaSensor(new CoberturaMavenPluginHandler()).getMavenPluginHandler(project), not(nullValue()));
- assertThat(new CoberturaSensor(new CoberturaMavenPluginHandler()).getMavenPluginHandler(project).getArtifactId(),
- is("cobertura-maven-plugin"));
- }
+public class CoberturaSensorTest {
@Test
public void doNotCollectProjectCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
verify(context, never()).saveMeasure(eq(CoreMetrics.COVERAGE), anyDouble());
}
@Test
public void doNotCollectProjectLineCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
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 {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
verify(context, never()).saveMeasure(eq(CoreMetrics.BRANCH_COVERAGE), anyDouble());
verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.BRANCH_COVERAGE_HITS_DATA)));
@Test
public void collectPackageLineCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
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 {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
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 {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.COVERAGE), anyDouble());
}
public void collectFileLineCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
final JavaFile file = new JavaFile("org.apache.commons.chain.config.ConfigParser");
// verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.LINE_COVERAGE, 83.3)));
public void collectFileBranchCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
final JavaFile file = new JavaFile("org.apache.commons.chain.config.ConfigParser");
verify(context).saveMeasure(eq(file), argThat(new IsMeasure(CoreMetrics.BRANCH_COVERAGE, 66.7)));
public void testDoNotSaveMeasureOnResourceWhichDoesntExistInTheContext() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
when(context.getResource(any(Resource.class))).thenReturn(null);
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
verify(context, never()).saveMeasure(any(Resource.class), any(Measure.class));
}
@Test
public void javaInterfaceHasNoCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
final JavaFile interfaze = new JavaFile("org.apache.commons.chain.Chain");
verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.COVERAGE)));
"/org/sonar/plugins/cobertura/CoberturaSensorTest/shouldInsertCoverageAtFileLevel/coverage.xml").toURI());
SensorContext context = mock(SensorContext.class);
when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
- new CoberturaSensor(null).parseReport(coverage, context);
+ new CoberturaSensor().parseReport(coverage, context);
verify(context).saveMeasure(argThat(new IsResource(Resource.SCOPE_ENTITY, Resource.QUALIFIER_CLASS, "org.sonar.samples.InnerClass")),
argThat(new IsMeasure(CoreMetrics.LINE_COVERAGE, 37.1)));
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")));
+ 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 {
SensorContext context = mock(SensorContext.class);
when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
verify(context).saveMeasure(
eq(new JavaFile("org.apache.commons.chain.impl.CatalogBase")),
argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA,
- "111=18;121=0;122=0;125=0;126=0;127=0;128=0;131=0;133=0;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;48=117;56=234;66=0;67=0;68=0;84=999;86=999;98=318")));
}
@Test
public void collectFileBranchHitsData() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass"));
- new CoberturaSensor(null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor().parseReport(getCoverageReport(), context);
// no conditions
verify(context, never()).saveMeasure(
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.batch;
+
+import org.sonar.api.batch.Phase.Name;
+import org.sonar.api.resources.Project;
+
+/**
+ * @since 2.6
+ */
+@Phase(name = Name.PRE)
+public abstract class AbstractInitializer implements Sensor {
+
+ public boolean shouldExecuteOnProject(Project project) {
+ return true;
+ }
+
+ public void analyse(Project project, SensorContext context) {
+ prepare(project);
+ }
+
+ public abstract void prepare(Project project);
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
+
+}
/**
* This annotation allows to specify in which environments {@link org.sonar.api.BatchExtension} would be active.
- * Consult to {@link org.sonar.api.platform.Environment} to find possible values, for example - "maven2".
- * We strictly recommend you to not overuse this annotation - most preferable is to design extensions to work in all environments.
+ * For example: "maven", "ant".
+ * Usage of this annotation is discouraged and we strictly recommend you to not overuse it.
+ * Most preferable is to design extensions to work in all environments.
*
* @since 2.6
*/
package org.sonar.api.batch.maven;
import org.sonar.api.BatchExtension;
+import org.sonar.api.batch.SupportedEnvironment;
import org.sonar.api.resources.Project;
/**
* Used for Sensors and PostJobs only.
- *
+ *
* @since 1.10
*/
+@SupportedEnvironment("maven")
public interface DependsUponMavenPlugin extends BatchExtension {
MavenPluginHandler getMavenPluginHandler(Project project);