aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-05-25 10:09:40 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-05-25 10:09:40 +0200
commitb83f68c27b1bab902ce54da312ecfe77b89148e5 (patch)
treeafb02c03602d4e5ab8c588ba4ececec17b2e6364 /sonar-batch
parentabb3b3611c0fb9fb092847b69052a8f7e2635362 (diff)
downloadsonarqube-b83f68c27b1bab902ce54da312ecfe77b89148e5.tar.gz
sonarqube-b83f68c27b1bab902ce54da312ecfe77b89148e5.zip
SONAR-6281 Add description of components in report
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java13
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java11
2 files changed, 17 insertions, 7 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 8e4dc077f48..adbff2ffaaa 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
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.report;
+import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
@@ -37,8 +38,6 @@ import org.sonar.batch.protocol.output.BatchReport.ComponentLink;
import org.sonar.batch.protocol.output.BatchReport.Event;
import org.sonar.batch.protocol.output.BatchReportWriter;
-import javax.annotation.CheckForNull;
-
/**
* Adds components and analysis metadata to output report
*/
@@ -87,6 +86,10 @@ public class ComponentsPublisher implements ReportPublisherStep {
if (name != null) {
builder.setName(name);
}
+ String description = getDescription(r);
+ if (description != null) {
+ builder.setDescription(description);
+ }
String path = r.getPath();
if (path != null) {
builder.setPath(path);
@@ -174,6 +177,12 @@ public class ComponentsPublisher implements ReportPublisherStep {
return (ResourceUtils.isFile(r) || ResourceUtils.isDirectory(r)) ? null : r.getName();
}
+ @CheckForNull
+ private String getDescription(Resource r) {
+ // Only for projets and modules
+ return ResourceUtils.isProject(r) ? r.getDescription() : null;
+ }
+
private Constants.ComponentType getType(Resource r) {
if (ResourceUtils.isFile(r)) {
return Constants.ComponentType.FILE;
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 ead29534e98..9d60874d175 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
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.report;
+import java.io.File;
+import java.util.Arrays;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -41,9 +43,6 @@ import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.protocol.output.FileStructure;
-import java.io.File;
-import java.util.Arrays;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -70,12 +69,12 @@ public class ComponentsPublisherTest {
@Test
public void add_components_to_report() throws Exception {
// inputs
- Project root = new Project("foo").setName("Root project")
+ Project root = new Project("foo").setName("Root project").setDescription("Root description")
.setAnalysisDate(DateUtils.parseDate(("2012-12-12")));
root.setId(1).setUuid("PROJECT_UUID");
resourceCache.add(root, null).setSnapshot(new Snapshot().setId(11));
- Project module1 = new Project("module1").setName("Module1");
+ Project module1 = new Project("module1").setName("Module1").setDescription("Module description");
module1.setParent(root);
module1.setId(2).setUuid("MODULE_UUID");
resourceCache.add(module1, root).setSnapshot(new Snapshot().setId(12));
@@ -118,11 +117,13 @@ public class ComponentsPublisherTest {
BatchReportReader reader = new BatchReportReader(outputDir);
Component rootProtobuf = reader.readComponent(1);
assertThat(rootProtobuf.getKey()).isEqualTo("foo");
+ assertThat(rootProtobuf.getDescription()).isEqualTo("Root description");
assertThat(rootProtobuf.getVersion()).isEqualTo("1.0");
assertThat(rootProtobuf.getLinkCount()).isEqualTo(0);
Component module1Protobuf = reader.readComponent(2);
assertThat(module1Protobuf.getKey()).isEqualTo("module1");
+ assertThat(module1Protobuf.getDescription()).isEqualTo("Module description");
assertThat(module1Protobuf.getVersion()).isEqualTo("1.0");
}