From: Duarte Meneses Date: Mon, 18 Feb 2019 16:01:41 +0000 (-0600) Subject: Minor fixes X-Git-Tag: 7.7~75 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=579871c5226580deb0cd539fd8d317836046e1ab;p=sonarqube.git Minor fixes --- diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/FillComponentIssuesVisitorRule.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/FillComponentIssuesVisitorRule.java index 77a5775e411..529ca5f54ef 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/FillComponentIssuesVisitorRule.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/FillComponentIssuesVisitorRule.java @@ -65,11 +65,6 @@ public class FillComponentIssuesVisitorRule extends TypeAwareVisitorAdapter impl }; } - public void setIssues(Component component, DefaultIssue... issues) { - checkNotNull(component, "component cannot be null"); - setIssues(component.getReportAttributes().getRef(), issues); - } - public void setIssues(int componentRef, DefaultIssue... issues) { Component component = treeRootHolder.getComponentByRef(componentRef); checkArgument(component != null, String.format("Component '%s' does not exists in the report ", componentRef)); diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index d0dd316830c..042f746c35d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -76,7 +76,7 @@ import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createAddi import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createDeveloperParameters; import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createMetricKeysParameter; import static org.sonar.server.measure.ws.MetricDtoToWsMetric.metricDtoToWsMetric; -import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriods.snapshotToWsPeriods; +import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeriods; 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; @@ -154,10 +154,10 @@ public class ComponentAction implements MeasuresWsAction { checkPermissions(component); SnapshotDto analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, component.projectUuid()).orElse(null); List metrics = searchMetrics(dbSession, request); - List periods = snapshotToWsPeriods(analysis); + Optional period = snapshotToWsPeriods(analysis); List measures = searchMeasures(dbSession, component, metrics); - return buildResponse(request, component, refComponent, measures, metrics, periods); + return buildResponse(request, component, refComponent, measures, metrics, period); } } @@ -183,8 +183,8 @@ public class ComponentAction implements MeasuresWsAction { return dbClient.componentDao().selectByUuid(dbSession, component.getCopyResourceUuid()); } - private static ComponentWsResponse buildResponse(ComponentRequest request, ComponentDto component, Optional refComponent, List measures, - List metrics, List periods) { + private static ComponentWsResponse buildResponse(ComponentRequest request, ComponentDto component, Optional refComponent, + List measures, List metrics, Optional period) { ComponentWsResponse.Builder response = ComponentWsResponse.newBuilder(); Map metricsById = Maps.uniqueIndex(metrics, MetricDto::getId); Map measuresByMetric = new HashMap<>(); @@ -205,8 +205,8 @@ public class ComponentAction implements MeasuresWsAction { response.getMetricsBuilder().addMetrics(metricDtoToWsMetric(metric)); } } - if (additionalFields.contains(ADDITIONAL_PERIODS)) { - response.getPeriodsBuilder().addAllPeriods(periods); + if (additionalFields.contains(ADDITIONAL_PERIODS) && period.isPresent()) { + response.getPeriodsBuilder().addPeriods(period.get()); } } @@ -282,8 +282,6 @@ public class ComponentAction implements MeasuresWsAction { private String pullRequest; private List metricKeys; private List additionalFields; - private String developerId; - private String developerKey; /** * @deprecated since 6.6, please use {@link #getComponent()} instead @@ -351,25 +349,5 @@ public class ComponentAction implements MeasuresWsAction { this.additionalFields = additionalFields; return this; } - - @CheckForNull - private String getDeveloperId() { - return developerId; - } - - private ComponentRequest setDeveloperId(@Nullable String developerId) { - this.developerId = developerId; - return this; - } - - @CheckForNull - private String getDeveloperKey() { - return developerKey; - } - - private ComponentRequest setDeveloperKey(@Nullable String developerKey) { - this.developerKey = developerKey; - return this; - } } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java index 0af53195acd..dd5a447e4c5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java @@ -107,12 +107,12 @@ import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createAddi import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createDeveloperParameters; import static org.sonar.server.measure.ws.MeasuresWsParametersBuilder.createMetricKeysParameter; import static org.sonar.server.measure.ws.MetricDtoToWsMetric.metricDtoToWsMetric; -import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriods.snapshotToWsPeriods; +import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeriods; 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.createQualifiersParameter; import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; +import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; import static org.sonar.server.ws.WsUtils.checkRequest; import static org.sonar.server.ws.WsUtils.writeProtobuf; @@ -121,15 +121,15 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf; * To limit the number of rows in database, a best value algorithm exists in database.

* A measure is not stored in database if: *
    - *
  • the component is a file (production or test)
  • - *
  • optimization algorithm is enabled on the metric
  • - *
  • the measure computed equals the metric best value
  • - *
  • the period values are all equal to 0
  • + *
  • the component is a file (production or test)
  • + *
  • optimization algorithm is enabled on the metric
  • + *
  • the measure computed equals the metric best value
  • + *
  • the period values are all equal to 0
  • *
* To recreate a best value 2 different cases: *
    - *
  • Metric starts with 'new_' (ex: new_violations): the best value measure doesn't have a value and period values are all equal to 0
  • - *
  • Other metrics: the best value measure has a value of 0 and no period value
  • + *
  • Metric starts with 'new_' (ex: new_violations): the best value measure doesn't have a value and period values are all equal to 0
  • + *
  • Other metrics: the best value measure has a value of 0 and no period value
  • *
*/ public class ComponentTreeAction implements MeasuresWsAction { @@ -177,8 +177,8 @@ public class ComponentTreeAction implements MeasuresWsAction { public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION_COMPONENT_TREE) .setDescription(format("Navigate through components based on the chosen strategy with specified measures. The %s or the %s parameter must be provided.
" + - "Requires the following permission: 'Browse' on the specified project.
" + - "When limiting search with the %s parameter, directories are not returned.", + "Requires the following permission: 'Browse' on the specified project.
" + + "When limiting search with the %s parameter, directories are not returned.", DEPRECATED_PARAM_BASE_COMPONENT_ID, PARAM_COMPONENT, Param.TEXT_QUERY)) .setResponseExample(getClass().getResource("component_tree-example.json")) .setSince("5.4") @@ -316,8 +316,8 @@ public class ComponentTreeAction implements MeasuresWsAction { } } - if (arePeriodsInResponse(request)) { - response.getPeriodsBuilder().addAllPeriods(data.getPeriods()); + if (arePeriodsInResponse(request) && data.getPeriod() != null) { + response.getPeriodsBuilder().addPeriods(data.getPeriod()); } return response.build(); @@ -431,7 +431,7 @@ public class ComponentTreeAction implements MeasuresWsAction { .setComponentCount(componentCount) .setMeasuresByComponentUuidAndMetric(measuresByComponentUuidAndMetric) .setMetrics(metrics) - .setPeriods(snapshotToWsPeriods(baseSnapshot.get())) + .setPeriod(snapshotToWsPeriods(baseSnapshot.get()).orElse(null)) .setReferenceComponentsByUuid(searchReferenceComponentsById(dbSession, components)) .build(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java index 4b963673c70..6f01434455a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java @@ -39,7 +39,7 @@ class ComponentTreeData { private final int componentCount; private final Map referenceComponentsByUuid; private final List metrics; - private final List periods; + private final Measures.Period period; private final Table measuresByComponentUuidAndMetric; private ComponentTreeData(Builder builder) { @@ -49,7 +49,7 @@ class ComponentTreeData { this.referenceComponentsByUuid = builder.referenceComponentsByUuid; this.metrics = builder.metrics; this.measuresByComponentUuidAndMetric = builder.measuresByComponentUuidAndMetric; - this.periods = builder.periods; + this.period = builder.period; } public ComponentDto getBaseComponent() { @@ -77,8 +77,8 @@ class ComponentTreeData { } @CheckForNull - List getPeriods() { - return periods; + Measures.Period getPeriod() { + return period; } @CheckForNull @@ -96,7 +96,7 @@ class ComponentTreeData { private Map referenceComponentsByUuid; private int componentCount; private List metrics; - private List periods; + private Measures.Period period; private Table measuresByComponentUuidAndMetric; private Builder() { @@ -123,8 +123,8 @@ class ComponentTreeData { return this; } - public Builder setPeriods(List periods) { - this.periods = periods; + public Builder setPeriod(@Nullable Measures.Period period) { + this.period = period; return this; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriod.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriod.java new file mode 100644 index 00000000000..1143d7dc4a8 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriod.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.measure.ws; + +import java.util.Optional; +import javax.annotation.Nullable; +import org.sonar.db.component.SnapshotDto; +import org.sonarqube.ws.Measures; + +import static org.sonar.api.utils.DateUtils.formatDateTime; + +class SnapshotDtoToWsPeriod { + private SnapshotDtoToWsPeriod() { + // prevent instantiation + } + + static Optional snapshotToWsPeriods(@Nullable SnapshotDto snapshot) { + if (snapshot == null) { + return Optional.empty(); + } + + if (snapshot.getPeriodDate() != null) { + return Optional.of(snapshotDtoToWsPeriod(snapshot)); + } + + return Optional.empty(); + } + + private static Measures.Period snapshotDtoToWsPeriod(SnapshotDto snapshot) { + Measures.Period.Builder period = Measures.Period.newBuilder(); + period.setIndex(1); + String periodMode = snapshot.getPeriodMode(); + if (periodMode != null) { + period.setMode(periodMode); + } + String periodModeParameter = snapshot.getPeriodModeParameter(); + if (periodModeParameter != null) { + period.setParameter(periodModeParameter); + } + Long periodDate = snapshot.getPeriodDate(); + if (periodDate != null) { + period.setDate(formatDateTime(periodDate)); + } + return period.build(); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriods.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriods.java deleted file mode 100644 index 26e5fce0d5b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/SnapshotDtoToWsPeriods.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.measure.ws; - -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Nullable; -import org.sonar.db.component.SnapshotDto; -import org.sonarqube.ws.Measures; - -import static java.util.Collections.emptyList; -import static org.sonar.api.utils.DateUtils.formatDateTime; - -class SnapshotDtoToWsPeriods { - private SnapshotDtoToWsPeriods() { - // prevent instantiation - } - - static List snapshotToWsPeriods(@Nullable SnapshotDto snapshot) { - if (snapshot == null) { - return emptyList(); - } - - List periods = new ArrayList<>(); - if (snapshot.getPeriodDate() != null) { - periods.add(snapshotDtoToWsPeriod(snapshot)); - } - - return periods; - } - - private static Measures.Period snapshotDtoToWsPeriod(SnapshotDto snapshot) { - Measures.Period.Builder period = Measures.Period.newBuilder(); - period.setIndex(1); - String periodMode = snapshot.getPeriodMode(); - if (periodMode != null) { - period.setMode(periodMode); - } - String periodModeParameter = snapshot.getPeriodModeParameter(); - if (periodModeParameter != null) { - period.setParameter(periodModeParameter); - } - Long periodDate = snapshot.getPeriodDate(); - if (periodDate != null) { - period.setDate(formatDateTime(periodDate)); - } - return period.build(); - } -}