]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6281 Add description of components in report
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 25 May 2015 08:09:40 +0000 (10:09 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 25 May 2015 08:09:40 +0000 (10:09 +0200)
sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java
sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java

index 8e4dc077f48e9e5419eeaf8eed94c521356a0683..adbff2ffaaa60d52425c224c3351d1f679c3ebb2 100644 (file)
@@ -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;
index ead29534e983f2eb97cc8106293ff46ab799c7f5..9d60874d175d364c2b346b516703b2c47ebf75d8 100644 (file)
@@ -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");
   }