]> source.dussan.org Git - sonarqube.git/commitdiff
VIEWS-223 description is not report specific
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 14 Sep 2015 14:06:00 +0000 (16:06 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 16 Sep 2015 09:00:08 +0000 (11:00 +0200)
move it back from ReportAttributes to Component

server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java
server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/component/ReportAttributes.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistComponentsStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/component/ReportComponent.java
server/sonar-server/src/test/java/org/sonar/server/computation/component/ViewsComponent.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java

index 436af6540313ad49e1e5e82798ef9cf88d77dd0f..d9b992c546599e846b4491dd991095fe5ca9c17c 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.computation.component;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Set;
+import javax.annotation.CheckForNull;
 import org.sonar.server.computation.step.FillComponentsStep;
 
 public interface Component {
@@ -75,6 +76,12 @@ public interface Component {
    */
   String getName();
 
+  /**
+   * The optional description of the component.
+   */
+  @CheckForNull
+  String getDescription();
+
   List<Component> getChildren();
 
   /**
index 5b1febb475d98b655386d69e9146b5b0a0880cdb..3e4f4a6a160cc8e09d8bdb9bdf5b1514f3a15ec6 100644 (file)
@@ -35,6 +35,8 @@ import static com.google.common.collect.Iterables.filter;
 public class ComponentImpl implements Component {
   private final Type type;
   private final String name;
+  @CheckForNull
+  private final String description;
   private final List<Component> children;
   @CheckForNull
   private final ReportAttributes reportAttributes;
@@ -48,6 +50,7 @@ public class ComponentImpl implements Component {
   public ComponentImpl(BatchReport.Component component, @Nullable Iterable<Component> children) {
     this.type = convertType(component.getType());
     this.name = checkNotNull(component.getName());
+    this.description = component.hasDescription() ? component.getDescription() : null;
     this.reportAttributes = createBatchAttributes(component);
     this.fileAttributes = createFileAttributes(component);
     this.children = children == null ? Collections.<Component>emptyList() : copyOf(filter(children, notNull()));
@@ -56,7 +59,6 @@ public class ComponentImpl implements Component {
   private static ReportAttributes createBatchAttributes(BatchReport.Component component) {
     return ReportAttributes.newBuilder(component.getRef())
       .setVersion(component.hasVersion() ? component.getVersion() : null)
-      .setDescription(component.hasDescription() ? component.getDescription() : null)
       .setPath(component.hasPath() ? component.getPath() : null)
       .build();
   }
@@ -123,6 +125,12 @@ public class ComponentImpl implements Component {
     return this.name;
   }
 
+  @Override
+  @CheckForNull
+  public String getDescription() {
+    return this.description;
+  }
+
   @Override
   public List<Component> getChildren() {
     return children;
@@ -150,8 +158,9 @@ public class ComponentImpl implements Component {
       "key='" + key + '\'' +
       ", type=" + type +
       ", uuid='" + uuid + '\'' +
-      ", fileAttributes=" + fileAttributes +
       ", name='" + name + '\'' +
+      ", description='" + description + '\'' +
+      ", fileAttributes=" + fileAttributes +
       ", reportAttributes=" + reportAttributes +
       '}';
   }
index 7bc1642eecc8f4c0a35651e0ee9990ca792a019d..79d82279639062bace68bb7d04c7a7ebea03d2d3 100644 (file)
@@ -32,14 +32,11 @@ public class ReportAttributes {
   @CheckForNull
   private final String version;
   @CheckForNull
-  private final String description;
-  @CheckForNull
   private final String path;
 
   private ReportAttributes(Builder builder) {
     this.ref = builder.ref;
     this.version = builder.version;
-    this.description = builder.description;
     this.path = builder.path;
   }
 
@@ -52,8 +49,6 @@ public class ReportAttributes {
     @CheckForNull
     private String version;
     @CheckForNull
-    private String description;
-    @CheckForNull
     private String path;
 
     private Builder(int ref) {
@@ -65,11 +60,6 @@ public class ReportAttributes {
       return this;
     }
 
-    public Builder setDescription(@Nullable String description) {
-      this.description = description;
-      return this;
-    }
-
     public Builder setPath(@Nullable String path) {
       this.path = path;
       return this;
@@ -95,14 +85,6 @@ public class ReportAttributes {
     return this.version;
   }
 
-  /**
-   * The description of the report component, if available.
-   */
-  @CheckForNull
-  public String getDescription() {
-    return description;
-  }
-
   /**
    * The path of the report component, must be non null for module, directories and files.
    */
@@ -116,7 +98,6 @@ public class ReportAttributes {
     return "ReportAttributes{" +
       "ref=" + ref +
       ", version='" + version + '\'' +
-      ", description='" + description + '\'' +
       ", path='" + path + '\'' +
       '}';
   }
index a6f797b07a78b19a7d7d3d15617a0c0567e3191f..7db14c85b7b6d4bbc22d2ffcb0a933fd4dfdd54f 100644 (file)
@@ -187,7 +187,7 @@ public class PersistComponentsStep implements ComputationStep {
     res.setQualifier(Qualifiers.PROJECT);
     res.setName(project.getName());
     res.setLongName(res.name());
-    res.setDescription(project.getReportAttributes().getDescription());
+    res.setDescription(project.getDescription());
     res.setProjectUuid(res.uuid());
     res.setModuleUuidPath(MODULE_UUID_PATH_SEP + res.uuid() + MODULE_UUID_PATH_SEP);
 
@@ -202,7 +202,7 @@ public class PersistComponentsStep implements ComputationStep {
     res.setName(module.getName());
     res.setLongName(res.name());
     res.setPath(module.getReportAttributes().getPath());
-    res.setDescription(module.getReportAttributes().getDescription());
+    res.setDescription(module.getDescription());
 
     setRootAndParentModule(res, path);
 
@@ -244,6 +244,7 @@ public class PersistComponentsStep implements ComputationStep {
     res.setScope(Scopes.PROJECT);
     res.setQualifier(Qualifiers.VIEW);
     res.setName(view.getName());
+    res.setDescription(view.getDescription());
     res.setLongName(res.name());
     res.setProjectUuid(res.uuid());
     res.setModuleUuidPath(MODULE_UUID_PATH_SEP + res.uuid() + MODULE_UUID_PATH_SEP);
@@ -257,6 +258,7 @@ public class PersistComponentsStep implements ComputationStep {
     res.setScope(Scopes.PROJECT);
     res.setQualifier(Qualifiers.SUBVIEW);
     res.setName(subView.getName());
+    res.setDescription(subView.getDescription());
     res.setLongName(res.name());
 
     setRootAndParentModule(res, path);
index 8d63604e245626de635e9b879917e01bbf0f67fb..4f16dbf4c6fb96aabe7785392aaa2bce03145ae7 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.computation.component;
 import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.List;
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -39,6 +40,8 @@ public class ReportComponent implements Component {
 
   private final Type type;
   private final String name;
+  @CheckForNull
+  private final String description;
   private final String key;
   private final String uuid;
   private final ReportAttributes reportAttributes;
@@ -49,12 +52,12 @@ public class ReportComponent implements Component {
     this.type = builder.type;
     this.key = builder.key;
     this.name = builder.name == null ? String.valueOf(builder.key) : builder.name;
+    this.description = builder.description;
     this.uuid = builder.uuid;
     this.reportAttributes = ReportAttributes.newBuilder(builder.ref)
-        .setVersion(builder.version)
-        .setDescription(builder.description)
-        .setPath(builder.path)
-        .build();
+      .setVersion(builder.version)
+      .setPath(builder.path)
+      .build();
     this.fileAttributes = builder.fileAttributes == null ? DEFAULT_FILE_ATTRIBUTES : builder.fileAttributes;
     this.children = ImmutableList.copyOf(builder.children);
   }
@@ -85,6 +88,12 @@ public class ReportComponent implements Component {
     return this.name;
   }
 
+  @Override
+  @CheckForNull
+  public String getDescription() {
+    return this.description;
+  }
+
   @Override
   public List<Component> getChildren() {
     return children;
@@ -174,7 +183,7 @@ public class ReportComponent implements Component {
       return this;
     }
 
-    public Builder setFileAttributes(FileAttributes fileAttributes){
+    public Builder setFileAttributes(FileAttributes fileAttributes) {
       checkState(type == Type.FILE, "Only Component of type File can have File attributes");
       this.fileAttributes = fileAttributes;
       return this;
index 326b13ff2790d304f1016ee4c99503823cb9ded6..91c9610a5c02cf79a09c58f5d580830dcd8817b9 100644 (file)
@@ -41,11 +41,13 @@ public class ViewsComponent implements Component {
   private final String uuid;
   @CheckForNull
   private final String name;
+  @CheckForNull
+  private final String description;
   private final List<Component> children;
   @CheckForNull
   private final ProjectViewAttributes projectViewAttributes;
 
-  private ViewsComponent(Type type, String key, @Nullable String uuid, @Nullable String name,
+  private ViewsComponent(Type type, String key, @Nullable String uuid, @Nullable String name, @Nullable String description,
     List<Component> children,
     @Nullable ProjectViewAttributes projectViewAttributes) {
     checkArgument(type.isViewsType(), "Component type must be a Views type");
@@ -53,6 +55,7 @@ public class ViewsComponent implements Component {
     this.key = requireNonNull(key);
     this.uuid = uuid;
     this.name = name;
+    this.description = description;
     this.children = ImmutableList.copyOf(children);
     this.projectViewAttributes = projectViewAttributes;
   }
@@ -72,6 +75,8 @@ public class ViewsComponent implements Component {
     private String uuid;
     @CheckForNull
     private String name;
+    @CheckForNull
+    private String description;
     private List<Component> children = new ArrayList<>();
     @CheckForNull
     private ProjectViewAttributes projectViewAttributes;
@@ -91,6 +96,16 @@ public class ViewsComponent implements Component {
       return this;
     }
 
+    public Builder setDescription(String description) {
+      this.description = description;
+      return this;
+    }
+
+    public Builder setChildren(List<Component> children) {
+      this.children = children;
+      return this;
+    }
+
     public Builder setProjectViewAttributes(@Nullable ProjectViewAttributes projectViewAttributes) {
       this.projectViewAttributes = projectViewAttributes;
       return this;
@@ -105,7 +120,7 @@ public class ViewsComponent implements Component {
     }
 
     public ViewsComponent build() {
-      return new ViewsComponent(type, key, uuid, name, children, projectViewAttributes);
+      return new ViewsComponent(type, key, uuid, name, description, children, projectViewAttributes);
     }
   }
 
@@ -130,6 +145,12 @@ public class ViewsComponent implements Component {
     return this.name;
   }
 
+  @Override
+  @CheckForNull
+  public String getDescription() {
+    return this.description;
+  }
+
   @Override
   public List<Component> getChildren() {
     return children;
index ab6d41fd314b72f7d541a504f751f46f061aed48..9d6c038915b97dee90f71c18025c6d81e89911fd 100644 (file)
@@ -54,9 +54,11 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
 
   private static final String VIEW_KEY = "VIEW_KEY";
   private static final String VIEW_NAME = "VIEW_NAME";
+  private static final String VIEW_DESCRIPTION = "view description";
   private static final String VIEW_UUID = "VIEW_UUID";
   private static final String SUBVIEW_1_KEY = "SUBVIEW_1_KEY";
   private static final String SUBVIEW_1_NAME = "SUBVIEW_1_NAME";
+  private static final String SUBVIEW_1_DESCRIPTION = "subview 1 description";
   private static final String SUBVIEW_1_UUID = "SUBVIEW_1_UUID";
   private static final String PROJECT_VIEW_1_KEY = "PV1_KEY";
   private static final String PROJECT_VIEW_1_NAME = "PV1_NAME";
@@ -218,17 +220,18 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
   }
 
   private static ViewsComponent.Builder createViewBuilder() {
-    return builder(VIEW, VIEW_KEY).setUuid(VIEW_UUID).setName(VIEW_NAME);
+    return builder(VIEW, VIEW_KEY).setUuid(VIEW_UUID).setName(VIEW_NAME).setDescription(VIEW_DESCRIPTION);
   }
 
   private ViewsComponent.Builder createSubView1Builder() {
-    return builder(SUBVIEW, SUBVIEW_1_KEY).setUuid(SUBVIEW_1_UUID).setName(SUBVIEW_1_NAME);
+    return builder(SUBVIEW, SUBVIEW_1_KEY).setUuid(SUBVIEW_1_UUID).setName(SUBVIEW_1_NAME).setDescription(SUBVIEW_1_DESCRIPTION);
   }
 
   private static ViewsComponent.Builder createProjectView1Builder() {
     return builder(PROJECT_VIEW, PROJECT_VIEW_1_KEY)
       .setUuid(PROJECT_VIEW_1_UUID)
       .setName(PROJECT_VIEW_1_NAME)
+      .setDescription("project view description is not persisted")
       .setProjectViewAttributes(new ProjectViewAttributes(PROJECT_1_ID));
   }
 
@@ -259,7 +262,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
   private void assertDtoIsView(ComponentDto projectDto) {
     assertThat(projectDto.name()).isEqualTo(VIEW_NAME);
     assertThat(projectDto.longName()).isEqualTo(VIEW_NAME);
-    assertThat(projectDto.description()).isNull();
+    assertThat(projectDto.description()).isEqualTo(VIEW_DESCRIPTION);
     assertThat(projectDto.path()).isNull();
     assertThat(projectDto.uuid()).isEqualTo(VIEW_UUID);
     assertThat(projectDto.projectUuid()).isEqualTo(projectDto.uuid());
@@ -278,7 +281,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
   private void assertDtoIsSubView1(ComponentDto viewDto, ComponentDto sv1Dto) {
     assertThat(sv1Dto.name()).isEqualTo(SUBVIEW_1_NAME);
     assertThat(sv1Dto.longName()).isEqualTo(SUBVIEW_1_NAME);
-    assertThat(sv1Dto.description()).isNull();
+    assertThat(sv1Dto.description()).isEqualTo(SUBVIEW_1_DESCRIPTION);
     assertThat(sv1Dto.path()).isNull();
     assertThat(sv1Dto.uuid()).isEqualTo(SUBVIEW_1_UUID);
     assertThat(sv1Dto.projectUuid()).isEqualTo(viewDto.uuid());