From: Sébastien Lesaint Date: Mon, 14 Sep 2015 14:06:00 +0000 (+0200) Subject: VIEWS-223 description is not report specific X-Git-Tag: 5.2-RC1~380 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5fbc4e133ece92f997e6dbe139c6524f7f109cbf;p=sonarqube.git VIEWS-223 description is not report specific move it back from ReportAttributes to Component --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java index 436af654031..d9b992c5465 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java @@ -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 getChildren(); /** diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java index 5b1febb475d..3e4f4a6a160 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java @@ -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 children; @CheckForNull private final ReportAttributes reportAttributes; @@ -48,6 +50,7 @@ public class ComponentImpl implements Component { public ComponentImpl(BatchReport.Component component, @Nullable Iterable 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.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 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 + '}'; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ReportAttributes.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ReportAttributes.java index 7bc1642eecc..79d82279639 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ReportAttributes.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ReportAttributes.java @@ -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 + '\'' + '}'; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistComponentsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistComponentsStep.java index a6f797b07a7..7db14c85b7b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistComponentsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistComponentsStep.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ReportComponent.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ReportComponent.java index 8d63604e245..4f16dbf4c6f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ReportComponent.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ReportComponent.java @@ -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 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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ViewsComponent.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ViewsComponent.java index 326b13ff279..91c9610a5c0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ViewsComponent.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ViewsComponent.java @@ -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 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 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 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 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 getChildren() { return children; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java index ab6d41fd314..9d6c038915b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistComponentsStepTest.java @@ -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());