}
private Optional<RefComponent> getReference(DbSession dbSession, ComponentDto component) {
- if (component.getCopyComponentUuid() == null) {
+ String copyComponentUuid = component.getCopyComponentUuid();
+ if (copyComponentUuid == null) {
return Optional.empty();
}
- Optional<ComponentDto> refComponent = dbClient.componentDao().selectByUuid(dbSession, component.getCopyComponentUuid());
+ Optional<ComponentDto> refComponent = dbClient.componentDao().selectByUuid(dbSession, copyComponentUuid);
if (refComponent.isEmpty()) {
return Optional.empty();
}
response.setComponent(componentDtoToWsComponent(component, measuresByMetric, emptyMap(), isMainBranch ? null : request.getBranch(), request.getPullRequest()));
}
+ setAdditionalFields(request, metrics, period, response);
+
+ return response.build();
+ }
+
+ private static void setAdditionalFields(ComponentRequest request, Collection<MetricDto> metrics, Optional<Measures.Period> period, ComponentWsResponse.Builder response) {
List<String> additionalFields = request.getAdditionalFields();
if (additionalFields != null) {
if (additionalFields.contains(ADDITIONAL_METRICS)) {
response.setPeriod(period.get());
}
}
-
- return response.build();
}
private static ComponentRequest toComponentWsRequest(Request request) {
}
private static class RefComponent {
- public RefComponent(BranchDto refBranch, ComponentDto refComponent) {
+
+ private final BranchDto refBranch;
+ private final ComponentDto component;
+
+ public RefComponent(BranchDto refBranch, ComponentDto component) {
this.refBranch = refBranch;
- this.refComponent = refComponent;
+ this.component = component;
}
- private BranchDto refBranch;
- private ComponentDto refComponent;
-
public BranchDto getRefBranch() {
return refBranch;
}
public ComponentDto getComponent() {
- return refComponent;
+ return component;
}
}
}
import com.google.common.base.Joiner;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
-import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
+import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
/**
static final String ALL_STRATEGY = "all";
static final String CHILDREN_STRATEGY = "children";
static final String LEAVES_STRATEGY = "leaves";
- static final Map<String, Strategy> STRATEGIES = ImmutableMap.of(
+ static final Map<String, Strategy> STRATEGIES = Map.of(
ALL_STRATEGY, LEAVES,
CHILDREN_STRATEGY, CHILDREN,
LEAVES_STRATEGY, LEAVES);
static final String ALL_METRIC_SORT_FILTER = "all";
static final String WITH_MEASURES_ONLY_METRIC_SORT_FILTER = "withMeasuresOnly";
static final Set<String> METRIC_SORT_FILTERS = ImmutableSortedSet.of(ALL_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER);
- static final Set<String> FORBIDDEN_METRIC_TYPES = ImmutableSet.of(DISTRIB.name(), DATA.name());
+ static final Set<String> FORBIDDEN_METRIC_TYPES = Set.of(DISTRIB.name(), DATA.name());
private static final int MAX_METRIC_KEYS = 15;
private static final Joiner COMMA_JOINER = Joiner.on(", ");
- private static final Set<String> QUALIFIERS_ELIGIBLE_FOR_BEST_VALUE = ImmutableSet.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE);
+ private static final Set<String> QUALIFIERS_ELIGIBLE_FOR_BEST_VALUE = Set.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE);
private final DbClient dbClient;
private final ComponentFinder componentFinder;
.containsExactlyInAnyOrder(file.getKey(), "");
}
+ @Test
+ public void show_branch_on_empty_response_if_not_main_branch() {
+ ComponentDto mainProjectBranch = db.components().insertPrivateProject();
+ ComponentDto project = db.components().insertProjectBranch(mainProjectBranch, b -> b.setKey("develop"));
+ userSession.addProjectPermission(USER, mainProjectBranch);
+ ComponentDto file = db.components().insertComponent(newFileDto(project));
+ MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
+
+ ComponentTreeWsResponse response = ws.newRequest()
+ .setParam(PARAM_COMPONENT, file.getKey())
+ .setParam(PARAM_BRANCH, "develop")
+ .setParam(PARAM_METRIC_KEYS, complexity.getKey())
+ .executeProtobuf(ComponentTreeWsResponse.class);
+
+ assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getBranch)
+ .containsExactlyInAnyOrder(file.getKey(), "develop");
+ }
+
@Test
public void pull_request() {
ComponentDto project = db.components().insertPrivateProject();