1 package org.sonar.plugins.sample;
3 import org.apache.commons.lang.math.RandomUtils;
4 import org.sonar.api.batch.Sensor;
5 import org.sonar.api.batch.SensorContext;
6 import org.sonar.api.measures.Measure;
7 import org.sonar.api.resources.Project;
9 public class SampleSensor implements Sensor {
11 public boolean shouldExecuteOnProject(Project project) {
12 // this sensor is executed on any type of project
16 public void analyse(Project project, SensorContext sensorContext) {
17 saveLabelMeasure(sensorContext);
18 saveNumericMeasure(sensorContext);
21 private void saveNumericMeasure(SensorContext context) {
22 // Sonar API includes many libraries like commons-lang and google-collections
23 context.saveMeasure(SampleMetrics.RANDOM, RandomUtils.nextDouble());
26 private void saveLabelMeasure(SensorContext context) {
27 Measure measure = new Measure(SampleMetrics.MESSAGE, "Hello World!");
28 context.saveMeasure(measure);