aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main/java/org/sonar
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch/src/main/java/org/sonar')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java56
3 files changed, 64 insertions, 3 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
index 8d0f2bfb00d..a531afc577a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
@@ -32,6 +32,7 @@ import org.sonar.batch.maven.MavenProjectBuilder;
import org.sonar.batch.maven.MavenProjectConverter;
import org.sonar.batch.scm.ScmConfiguration;
import org.sonar.batch.scm.ScmSensor;
+import org.sonar.batch.source.LinesSensor;
import org.sonar.core.computation.dbcleaner.DefaultPurgeTask;
import org.sonar.core.computation.dbcleaner.period.DefaultPeriodCleaner;
import org.sonar.core.config.CorePropertyDefinitions;
@@ -61,6 +62,8 @@ public class BatchComponents {
ScmConfiguration.class,
ScmSensor.class,
+ LinesSensor.class,
+
// dbcleaner
DefaultPeriodCleaner.class,
DefaultPurgeTask.class
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
index 64886cc1529..eeb37de63ed 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -87,7 +87,7 @@ public class DefaultIndex extends SonarIndex {
CoreMetrics.FILE_FEEDBACK_EDGES,
CoreMetrics.FILE_TANGLE_INDEX,
CoreMetrics.FILE_TANGLES,
- // Computed by ScmActivitySensor
+ // Computed by ScmSensor
CoreMetrics.SCM_AUTHORS_BY_LINE,
CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE,
CoreMetrics.SCM_REVISIONS_BY_LINE,
@@ -96,7 +96,9 @@ public class DefaultIndex extends SonarIndex {
CoreMetrics.DUPLICATION_LINES_DATA,
CoreMetrics.DUPLICATED_FILES,
CoreMetrics.DUPLICATED_LINES,
- CoreMetrics.DUPLICATED_BLOCKS
+ CoreMetrics.DUPLICATED_BLOCKS,
+ // Computed by LinesSensor
+ CoreMetrics.LINES
);
private final ResourceCache resourceCache;
@@ -256,7 +258,7 @@ public class DefaultIndex extends SonarIndex {
throw new SonarException("Unknown metric: " + measure.getMetricKey());
}
if (!isTechnicalProjectCopy(resource) && !measure.isFromCore() && INTERNAL_METRICS.contains(metric)) {
- LOG.debug("Metric " + metric.key() + " is an internal metric computed by SonarQube. Please update your plugin.");
+ LOG.debug("Metric " + metric.key() + " is an internal metric computed by SonarQube. Provided value is ignored.");
return measure;
}
if (measureCache.contains(resource, measure)) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java b/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java
new file mode 100644
index 00000000000..3272825fd1f
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java
@@ -0,0 +1,56 @@
+/*
+ * 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.batch.source;
+
+import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputFile.Type;
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
+import org.sonar.api.measures.CoreMetrics;
+
+public final class LinesSensor implements Sensor {
+
+ private final FileSystem fs;
+
+ public LinesSensor(FileSystem fs) {
+ this.fs = fs;
+ }
+
+ @Override
+ public void describe(SensorDescriptor descriptor) {
+ descriptor.name("Lines Sensor");
+ }
+
+ @Override
+ public void execute(final SensorContext context) {
+ for (InputFile f : fs.inputFiles(fs.predicates().hasType(Type.MAIN))) {
+ ((DefaultMeasure<Integer>) context.<Integer>newMeasure()
+ .onFile(f)
+ .forMetric(CoreMetrics.LINES)
+ .withValue(f.lines()))
+ .setFromCore()
+ .save();
+ }
+ }
+
+}