aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-04-07 14:56:25 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-04-07 14:57:04 +0200
commitfa3100e005c2fc3884ae6cce708129b71830fe91 (patch)
treecc063979da9cf26c6df99e920dcce937e075d117 /sonar-batch
parent3dbfee3fe1e9d2d5f2f25135e8633377b09dd541 (diff)
downloadsonarqube-fa3100e005c2fc3884ae6cce708129b71830fe91.tar.gz
sonarqube-fa3100e005c2fc3884ae6cce708129b71830fe91.zip
SONAR-6253 Add lines count in report
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java13
3 files changed, 12 insertions, 12 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java
index 7bed3e9db12..fb20efee128 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
@@ -83,6 +84,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
}
if (ResourceUtils.isFile(r)) {
builder.setIsTest(ResourceUtils.isUnitTestClass(r));
+ builder.setLines(((InputFile) batchResource.inputPath()).lines());
}
String name = getName(r);
if (name != null) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
index 54fd33a6f40..941f7d42f61 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
@@ -26,7 +26,6 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Status;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
@@ -95,19 +94,19 @@ public final class ScmSensor implements Sensor {
List<InputFile> filesToBlame = new LinkedList<InputFile>();
for (InputFile f : fs.inputFiles(fs.predicates().all())) {
if (configuration.forceReloadAll()) {
- addIfNotEmpty(filesToBlame, (DefaultInputFile) f);
+ addIfNotEmpty(filesToBlame, f);
} else {
FileData fileData = projectReferentials.fileData(projectDefinition.getKeyWithBranch(), f.relativePath());
if (f.status() != Status.SAME || fileData == null || fileData.needBlame()) {
- addIfNotEmpty(filesToBlame, (DefaultInputFile) f);
+ addIfNotEmpty(filesToBlame, f);
}
}
}
return filesToBlame;
}
- private void addIfNotEmpty(List<InputFile> filesToBlame, DefaultInputFile f) {
- if (!f.isEmpty()) {
+ private void addIfNotEmpty(List<InputFile> filesToBlame, InputFile f) {
+ if (f.lines() > 0) {
filesToBlame.add(f);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
index 812d8110339..5e806339a89 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
@@ -26,6 +26,7 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.Java;
@@ -36,9 +37,7 @@ import org.sonar.batch.protocol.Constants.ComponentLinkType;
import org.sonar.batch.protocol.Constants.EventCategory;
import org.sonar.batch.protocol.output.BatchReport.Component;
import org.sonar.batch.protocol.output.BatchReport.Event;
-import org.sonar.batch.protocol.output.BatchReportReader;
-import org.sonar.batch.protocol.output.BatchReportWriter;
-import org.sonar.batch.protocol.output.FileStructure;
+import org.sonar.batch.protocol.output.*;
import java.io.File;
import java.util.Arrays;
@@ -88,17 +87,17 @@ public class ComponentsPublisherTest {
org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false);
file.setEffectiveKey("module1:src/Foo.java");
file.setId(4).setUuid("FILE_UUID");
- resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14));
+ resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14)).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
org.sonar.api.resources.File fileWithoutLang = org.sonar.api.resources.File.create("src/make", null, false);
fileWithoutLang.setEffectiveKey("module1:src/make");
fileWithoutLang.setId(5).setUuid("FILE_WITHOUT_LANG_UUID");
- resourceCache.add(fileWithoutLang, dir).setSnapshot(new Snapshot().setId(15));
+ resourceCache.add(fileWithoutLang, dir).setSnapshot(new Snapshot().setId(15)).setInputPath(new DefaultInputFile("module1", "src/make").setLines(10));
org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", Java.INSTANCE, true);
testFile.setEffectiveKey("module1:test/FooTest.java");
testFile.setId(6).setUuid("TEST_FILE_UUID");
- resourceCache.add(testFile, dir).setSnapshot(new Snapshot().setId(16));
+ resourceCache.add(testFile, dir).setSnapshot(new Snapshot().setId(16)).setInputPath(new DefaultInputFile("module1", "test/FooTest.java").setLines(4));
File outputDir = temp.newFolder();
BatchReportWriter writer = new BatchReportWriter(outputDir);
@@ -151,7 +150,7 @@ public class ComponentsPublisherTest {
org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false);
file.setEffectiveKey("module1:my_branch:my_branch:src/Foo.java");
file.setId(4).setUuid("FILE_UUID");
- resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14));
+ resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14)).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
File outputDir = temp.newFolder();
BatchReportWriter writer = new BatchReportWriter(outputDir);