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 {
*/
String getName();
+ /**
+ * The optional description of the component.
+ */
+ @CheckForNull
+ String getDescription();
+
List<Component> getChildren();
/**
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;
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()));
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();
}
return this.name;
}
+ @Override
+ @CheckForNull
+ public String getDescription() {
+ return this.description;
+ }
+
@Override
public List<Component> getChildren() {
return children;
"key='" + key + '\'' +
", type=" + type +
", uuid='" + uuid + '\'' +
- ", fileAttributes=" + fileAttributes +
", name='" + name + '\'' +
+ ", description='" + description + '\'' +
+ ", fileAttributes=" + fileAttributes +
", reportAttributes=" + 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;
}
@CheckForNull
private String version;
@CheckForNull
- private String description;
- @CheckForNull
private String path;
private Builder(int ref) {
return this;
}
- public Builder setDescription(@Nullable String description) {
- this.description = description;
- return this;
- }
-
public Builder setPath(@Nullable String path) {
this.path = path;
return this;
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.
*/
return "ReportAttributes{" +
"ref=" + ref +
", version='" + version + '\'' +
- ", description='" + description + '\'' +
", path='" + path + '\'' +
'}';
}
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);
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);
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);
res.setScope(Scopes.PROJECT);
res.setQualifier(Qualifiers.SUBVIEW);
res.setName(subView.getName());
+ res.setDescription(subView.getDescription());
res.setLongName(res.name());
setRootAndParentModule(res, path);
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;
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;
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);
}
return this.name;
}
+ @Override
+ @CheckForNull
+ public String getDescription() {
+ return this.description;
+ }
+
@Override
public List<Component> getChildren() {
return children;
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;
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");
this.key = requireNonNull(key);
this.uuid = uuid;
this.name = name;
+ this.description = description;
this.children = ImmutableList.copyOf(children);
this.projectViewAttributes = projectViewAttributes;
}
private String uuid;
@CheckForNull
private String name;
+ @CheckForNull
+ private String description;
private List<Component> children = new ArrayList<>();
@CheckForNull
private ProjectViewAttributes projectViewAttributes;
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;
}
public ViewsComponent build() {
- return new ViewsComponent(type, key, uuid, name, children, projectViewAttributes);
+ return new ViewsComponent(type, key, uuid, name, description, children, projectViewAttributes);
}
}
return this.name;
}
+ @Override
+ @CheckForNull
+ public String getDescription() {
+ return this.description;
+ }
+
@Override
public List<Component> getChildren() {
return children;
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";
}
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));
}
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());
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());