aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverSensor.java4
-rw-r--r--plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverSensorTest.java6
-rw-r--r--plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaSensor.java29
-rw-r--r--plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java75
4 files changed, 51 insertions, 63 deletions
diff --git a/plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverSensor.java b/plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverSensor.java
index da6ca3930ae..0fdc76999bd 100644
--- a/plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverSensor.java
+++ b/plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverSensor.java
@@ -20,7 +20,6 @@
package org.sonar.plugins.clover;
import org.slf4j.LoggerFactory;
-import org.sonar.api.Plugins;
import org.sonar.api.batch.AbstractCoverageExtension;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
@@ -35,8 +34,7 @@ public class CloverSensor extends AbstractCoverageExtension implements Sensor, D
private CloverMavenPluginHandler handler;
- public CloverSensor(Plugins plugins, CloverMavenPluginHandler handler) {
- super(plugins);
+ public CloverSensor(CloverMavenPluginHandler handler) {
this.handler = handler;
}
diff --git a/plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverSensorTest.java b/plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverSensorTest.java
index 917499f0b4d..6b9b2744be8 100644
--- a/plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverSensorTest.java
+++ b/plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverSensorTest.java
@@ -35,20 +35,20 @@ public class CloverSensorTest {
public void doNotExecuteMavenPluginIfReuseReports() {
Project project = mock(Project.class);
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS);
- assertThat(new CloverSensor(null, new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), nullValue());
+ 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(null, new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), nullValue());
+ 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(null, new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), not(nullValue()));
+ assertThat(new CloverSensor(new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), not(nullValue()));
}
}
diff --git a/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaSensor.java b/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaSensor.java
index bf649c7f249..9443de91b15 100644
--- a/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaSensor.java
+++ b/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaSensor.java
@@ -19,26 +19,12 @@
*/
package org.sonar.plugins.cobertura;
-import static java.util.Locale.ENGLISH;
-import static org.sonar.api.utils.ParsingUtils.parseNumber;
-import static org.sonar.api.utils.ParsingUtils.scaleValue;
-
-import java.io.File;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.stream.XMLStreamException;
-
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.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
-import org.sonar.api.Plugins;
import org.sonar.api.batch.AbstractCoverageExtension;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
@@ -54,12 +40,23 @@ import org.sonar.api.resources.Project;
import org.sonar.api.utils.StaxParser;
import org.sonar.api.utils.XmlParserException;
+import javax.xml.stream.XMLStreamException;
+import java.io.File;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Locale.ENGLISH;
+import static org.sonar.api.utils.ParsingUtils.parseNumber;
+import static org.sonar.api.utils.ParsingUtils.scaleValue;
+
public class CoberturaSensor extends AbstractCoverageExtension implements Sensor, DependsUponMavenPlugin {
private CoberturaMavenPluginHandler handler;
- public CoberturaSensor(Plugins plugins, CoberturaMavenPluginHandler handler) {
- super(plugins);
+ public CoberturaSensor(CoberturaMavenPluginHandler handler) {
this.handler = handler;
}
diff --git a/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java b/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
index 2a6ce140a64..6935be5706d 100644
--- a/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
+++ b/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
@@ -19,38 +19,31 @@
*/
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.assertNotNull;
-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 java.io.File;
-import java.net.URISyntaxException;
-
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.DefaultProjectFileSystem;
-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.resources.*;
import org.sonar.api.test.IsMeasure;
import org.sonar.api.test.IsResource;
import org.sonar.api.test.MavenTestUtils;
+import java.io.File;
+import java.net.URISyntaxException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertNotNull;
+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.*;
+
public class CoberturaSensorTest {
@Test
@@ -62,7 +55,7 @@ public class CoberturaSensorTest {
when(project.getFileSystem()).thenReturn(fileSystem);
when(project.getProperty(CoreProperties.COBERTURA_REPORT_PATH_PROPERTY)).thenReturn("foo");
- File report = new CoberturaSensor(null, null).getReport(project);
+ File report = new CoberturaSensor(null).getReport(project);
verify(fileSystem).resolvePath("foo");
assertNotNull(report);
}
@@ -71,22 +64,22 @@ public class CoberturaSensorTest {
public void doNotExecuteMavenPluginIfReuseReports() {
Project project = mock(Project.class);
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS);
- assertThat(new CoberturaSensor(null, new CoberturaMavenPluginHandler()).getMavenPluginHandler(project), nullValue());
+ 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(null, new CoberturaMavenPluginHandler()).getMavenPluginHandler(project), nullValue());
+ assertThat(new CoberturaSensor(new CoberturaMavenPluginHandler()).getMavenPluginHandler(project), nullValue());
}
@Test
public void executeMavenPluginIfDynamicAnalysis() {
Project project = mock(Project.class);
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
- assertThat(new CoberturaSensor(null, new CoberturaMavenPluginHandler()).getMavenPluginHandler(project), not(nullValue()));
- assertThat(new CoberturaSensor(null, new CoberturaMavenPluginHandler()).getMavenPluginHandler(project).getArtifactId(),
+ assertThat(new CoberturaSensor(new CoberturaMavenPluginHandler()).getMavenPluginHandler(project), not(nullValue()));
+ assertThat(new CoberturaSensor(new CoberturaMavenPluginHandler()).getMavenPluginHandler(project).getArtifactId(),
is("cobertura-maven-plugin"));
}
@@ -100,7 +93,7 @@ public class CoberturaSensorTest {
when(project.getPom()).thenReturn(pom);
when(project.getFileSystem()).thenReturn(fileSystem);
- new CoberturaSensor(null, null).getReport(project);
+ new CoberturaSensor(null).getReport(project);
verify(fileSystem).resolvePath("overridden/dir");
}
@@ -108,7 +101,7 @@ public class CoberturaSensorTest {
@Test
public void doNotCollectProjectCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).parseReport(getCoverageReport(), context);
verify(context, never()).saveMeasure(eq(CoreMetrics.COVERAGE), anyDouble());
}
@@ -116,7 +109,7 @@ public class CoberturaSensorTest {
@Test
public void doNotCollectProjectLineCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).parseReport(getCoverageReport(), context);
verify(context, never()).saveMeasure(eq(CoreMetrics.LINE_COVERAGE), anyDouble());
verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA)));
@@ -125,7 +118,7 @@ public class CoberturaSensorTest {
@Test
public void doNotCollectProjectBranchCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).parseReport(getCoverageReport(), context);
verify(context, never()).saveMeasure(eq(CoreMetrics.BRANCH_COVERAGE), anyDouble());
verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.BRANCH_COVERAGE_HITS_DATA)));
@@ -134,7 +127,7 @@ public class CoberturaSensorTest {
@Test
public void collectPackageLineCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).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());
@@ -143,7 +136,7 @@ public class CoberturaSensorTest {
@Test
public void collectPackageBranchCoverage() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).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());
@@ -152,7 +145,7 @@ public class CoberturaSensorTest {
@Test
public void packageCoverageIsCalculatedLaterByDecorator() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
- new CoberturaSensor(null, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).parseReport(getCoverageReport(), context);
verify(context, never()).saveMeasure((Resource) argThat(is(JavaPackage.class)), eq(CoreMetrics.COVERAGE), anyDouble());
}
@@ -161,7 +154,7 @@ public class CoberturaSensorTest {
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, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).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)));
@@ -173,7 +166,7 @@ public class CoberturaSensorTest {
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, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).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)));
@@ -185,14 +178,14 @@ public class CoberturaSensorTest {
public void testDoNotSaveMeasureOnResourceWhichDoesntExistInTheContext() throws URISyntaxException {
SensorContext context = mock(SensorContext.class);
when(context.getResource(any(Resource.class))).thenReturn(null);
- new CoberturaSensor(null, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).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, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).parseReport(getCoverageReport(), context);
final JavaFile interfaze = new JavaFile("org.apache.commons.chain.Chain");
verify(context, never()).saveMeasure(eq(interfaze), argThat(new IsMeasure(CoreMetrics.COVERAGE)));
@@ -212,7 +205,7 @@ public class CoberturaSensorTest {
"/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, null).parseReport(coverage, context);
+ new CoberturaSensor(null).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)));
@@ -278,7 +271,7 @@ public class CoberturaSensorTest {
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, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).parseReport(getCoverageReport(), context);
verify(context).saveMeasure(
eq(new JavaFile("org.apache.commons.chain.impl.CatalogBase")),
argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA,
@@ -289,7 +282,7 @@ public class CoberturaSensorTest {
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, null).parseReport(getCoverageReport(), context);
+ new CoberturaSensor(null).parseReport(getCoverageReport(), context);
// no conditions
verify(context, never()).saveMeasure(