@@ -59,7 +59,7 @@ import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; | |||
import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT; | |||
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.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
public class AppAction implements ComponentsWsAction { | |||
@@ -17,7 +17,7 @@ | |||
* 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.sonarqube.ws.client.measure; | |||
package org.sonar.server.component.ws; | |||
import com.google.common.collect.ImmutableSortedSet; | |||
import java.util.Set; |
@@ -49,7 +49,7 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SHOW; | |||
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
public class ShowAction implements ComponentsWsAction { | |||
private final UserSession userSession; |
@@ -74,7 +74,7 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COM | |||
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_QUALIFIERS; | |||
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_STRATEGY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
public class TreeAction implements ComponentsWsAction { | |||
@@ -38,7 +38,7 @@ import static com.google.common.base.Preconditions.checkArgument; | |||
import static org.sonar.server.component.ComponentFinder.ParamNames.UUID_AND_KEY; | |||
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
public class ShowAction implements DuplicationsWsAction { | |||
@@ -69,17 +69,17 @@ 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.WsUtils.checkRequest; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_METRICS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.ACTION_COMPONENT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_METRICS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIODS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_KEY; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
public class ComponentAction implements MeasuresWsAction { | |||
private static final Set<String> QUALIFIERS_ELIGIBLE_FOR_BEST_VALUE = ImmutableSortedSet.of(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE); |
@@ -98,22 +98,22 @@ import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; | |||
import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; | |||
import static org.sonar.server.ws.WsUtils.checkRequest; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT_TREE; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_METRICS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.ACTION_COMPONENT_TREE; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_METRICS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIODS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_KEY; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_SORT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_QUALIFIERS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_STRATEGY; | |||
/** | |||
* <p>Navigate through components based on different strategy with specified measures. | |||
@@ -237,7 +237,7 @@ public class ComponentTreeAction implements MeasuresWsAction { | |||
.setPossibleValues(METRIC_SORT_FILTERS); | |||
createMetricKeysParameter(action) | |||
.setDescription("Metric keys. Types %s are not allowed", COMMA_JOINER.join(FORBIDDEN_METRIC_TYPES)) | |||
.setDescription("Comma-separated list of metric keys. Types %s are not allowed.", COMMA_JOINER.join(FORBIDDEN_METRIC_TYPES)) | |||
.setMaxValuesAllowed(MAX_METRIC_KEYS); | |||
createAdditionalFieldsParameter(action); | |||
createDeveloperParameters(action); |
@@ -20,7 +20,7 @@ | |||
package org.sonar.server.measure.ws; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonarqube.ws.client.measure.MeasuresWsParameters; | |||
import org.sonar.server.component.ws.MeasuresWsParameters; | |||
public class MeasuresWs implements WebService { | |||
private final MeasuresWsAction[] actions; |
@@ -22,11 +22,11 @@ package org.sonar.server.measure.ws; | |||
import org.sonar.api.server.ws.WebService.NewAction; | |||
import org.sonar.api.server.ws.WebService.NewParam; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_FIELDS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_FIELDS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_KEY; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
class MeasuresWsParametersBuilder { | |||
@@ -43,7 +43,7 @@ class MeasuresWsParametersBuilder { | |||
static NewParam createMetricKeysParameter(NewAction action) { | |||
return action.createParam(PARAM_METRIC_KEYS) | |||
.setDescription("Metric keys") | |||
.setDescription("Comma-separated list of metric keys") | |||
.setRequired(true) | |||
.setExampleValue("ncloc,complexity,violations"); | |||
} |
@@ -55,8 +55,8 @@ import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; | |||
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002; | |||
import static org.sonar.server.ws.WsUtils.checkRequest; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_PROJECT_KEYS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PROJECT_KEYS; | |||
public class SearchAction implements MeasuresWsAction { | |||
@@ -56,12 +56,12 @@ import static org.sonar.core.util.Protobuf.setNullable; | |||
import static org.sonar.db.component.SnapshotDto.STATUS_PROCESSED; | |||
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_SEARCH_HISTORY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.ACTION_SEARCH_HISTORY; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_FROM; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRICS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_TO; | |||
public class SearchHistoryAction implements MeasuresWsAction { | |||
@@ -54,12 +54,12 @@ import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
import static org.sonar.db.component.ComponentTesting.newProjectCopy; | |||
import static org.sonar.server.computation.task.projectanalysis.metric.Metric.MetricType.INT; | |||
import static org.sonar.test.JsonAssert.assertJson; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
public class ComponentActionTest { | |||
@@ -79,18 +79,18 @@ import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT; | |||
import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT; | |||
import static org.sonar.server.measure.ws.ComponentTreeAction.WITH_MEASURES_ONLY_METRIC_SORT_FILTER; | |||
import static org.sonar.test.JsonAssert.assertJson; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIODS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_SORT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_QUALIFIERS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_STRATEGY; | |||
public class ComponentTreeActionTest { | |||
@Rule |
@@ -56,8 +56,8 @@ import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
import static org.sonar.db.component.ComponentTesting.newModuleDto; | |||
import static org.sonar.db.component.ComponentTesting.newSubView; | |||
import static org.sonar.test.JsonAssert.assertJson; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_PROJECT_KEYS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PROJECT_KEYS; | |||
public class SearchActionTest { | |||
@@ -69,11 +69,11 @@ import static org.sonar.db.component.SnapshotTesting.newAnalysis; | |||
import static org.sonar.db.measure.MeasureTesting.newMeasureDto; | |||
import static org.sonar.db.metric.MetricTesting.newMetricDto; | |||
import static org.sonar.test.JsonAssert.assertJson; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_FROM; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRICS; | |||
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_TO; | |||
public class SearchHistoryActionTest { | |||
@@ -52,7 +52,7 @@ public abstract class BaseService { | |||
return wsConnector.call(request).failIfNotSuccessful(); | |||
} | |||
public <T extends Message> T convert(WsResponse response, Parser<T> parser) { | |||
public static <T extends Message> T convert(WsResponse response, Parser<T> parser) { | |||
try (InputStream byteStream = response.contentStream()) { | |||
byte[] bytes = IOUtils.toByteArray(byteStream); | |||
// HTTP header "Content-Type" is not verified. It may be different than protobuf. |
@@ -63,7 +63,6 @@ class DefaultWsClient implements WsClient { | |||
private final UserGroupsService userGroupsService; | |||
private final UserTokensService userTokensService; | |||
private final QualitygatesService qualityGatesService; | |||
private final org.sonarqube.ws.client.measure.MeasuresService measuresOld; | |||
private final MeasuresService measures; | |||
private final SystemService systemService; | |||
private final CeService ceService; | |||
@@ -90,7 +89,6 @@ class DefaultWsClient implements WsClient { | |||
this.userGroupsService = new UserGroupsService(wsConnector); | |||
this.userTokensService = new UserTokensService(wsConnector); | |||
this.qualityGatesService = new QualitygatesService(wsConnector); | |||
this.measuresOld = new org.sonarqube.ws.client.measure.MeasuresService(wsConnector); | |||
this.measures = new MeasuresService(wsConnector); | |||
this.systemService = new SystemService(wsConnector); | |||
this.ceService = new CeService(wsConnector); | |||
@@ -165,11 +163,6 @@ class DefaultWsClient implements WsClient { | |||
return qualityGatesService; | |||
} | |||
@Override | |||
public org.sonarqube.ws.client.measure.MeasuresService measuresOld() { | |||
return measuresOld; | |||
} | |||
@Override | |||
public MeasuresService measures() { | |||
return measures; |
@@ -91,12 +91,6 @@ public interface WsClient { | |||
QualitygatesService qualityGates(); | |||
/** | |||
* @deprecated since 7.0 use {@link #measures()} instead | |||
*/ | |||
@Deprecated | |||
org.sonarqube.ws.client.measure.MeasuresService measuresOld(); | |||
MeasuresService measures(); | |||
SystemService system(); |
@@ -1,130 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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.sonarqube.ws.client.measure; | |||
import java.util.List; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
public class ComponentRequest { | |||
private String componentId; | |||
private String componentKey; | |||
private String component; | |||
private String branch; | |||
private List<String> metricKeys; | |||
private List<String> additionalFields; | |||
private String developerId; | |||
private String developerKey; | |||
/** | |||
* @deprecated since 6.6, please use {@link #getComponent()} instead | |||
*/ | |||
@Deprecated | |||
@CheckForNull | |||
public String getComponentId() { | |||
return componentId; | |||
} | |||
/** | |||
* @deprecated since 6.6, please use {@link #setComponent(String)} instead | |||
*/ | |||
@Deprecated | |||
public ComponentRequest setComponentId(@Nullable String componentId) { | |||
this.componentId = componentId; | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 6.6, please use {@link #getComponent()} instead | |||
*/ | |||
@Deprecated | |||
@CheckForNull | |||
public String getComponentKey() { | |||
return componentKey; | |||
} | |||
/** | |||
* @deprecated since 6.6, please use {@link #setComponent(String)} instead | |||
*/ | |||
@Deprecated | |||
public ComponentRequest setComponentKey(@Nullable String componentKey) { | |||
this.componentKey = componentKey; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getComponent() { | |||
return component; | |||
} | |||
public ComponentRequest setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getBranch() { | |||
return branch; | |||
} | |||
public ComponentRequest setBranch(@Nullable String branch) { | |||
this.branch = branch; | |||
return this; | |||
} | |||
public List<String> getMetricKeys() { | |||
return metricKeys; | |||
} | |||
public ComponentRequest setMetricKeys(@Nullable List<String> metricKeys) { | |||
this.metricKeys = metricKeys; | |||
return this; | |||
} | |||
@CheckForNull | |||
public List<String> getAdditionalFields() { | |||
return additionalFields; | |||
} | |||
public ComponentRequest setAdditionalFields(@Nullable List<String> additionalFields) { | |||
this.additionalFields = additionalFields; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getDeveloperId() { | |||
return developerId; | |||
} | |||
public ComponentRequest setDeveloperId(@Nullable String developerId) { | |||
this.developerId = developerId; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getDeveloperKey() { | |||
return developerKey; | |||
} | |||
public ComponentRequest setDeveloperKey(@Nullable String developerKey) { | |||
this.developerKey = developerKey; | |||
return this; | |||
} | |||
} |
@@ -1,242 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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.sonarqube.ws.client.measure; | |||
import java.util.List; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
public class ComponentTreeRequest { | |||
private String baseComponentId; | |||
private String baseComponentKey; | |||
private String component; | |||
private String branch; | |||
private String strategy; | |||
private List<String> qualifiers; | |||
private List<String> additionalFields; | |||
private String query; | |||
private List<String> sort; | |||
private Boolean asc; | |||
private String metricSort; | |||
private Integer metricPeriodSort; | |||
private String metricSortFilter; | |||
private List<String> metricKeys; | |||
private Integer page; | |||
private Integer pageSize; | |||
private String developerId; | |||
private String developerKey; | |||
/** | |||
* @deprecated since 6.6, please use {@link #getComponent()} instead | |||
*/ | |||
@Deprecated | |||
@CheckForNull | |||
public String getBaseComponentId() { | |||
return baseComponentId; | |||
} | |||
/** | |||
* @deprecated since 6.6, please use {@link #setComponent(String)} instead | |||
*/ | |||
@Deprecated | |||
public ComponentTreeRequest setBaseComponentId(@Nullable String baseComponentId) { | |||
this.baseComponentId = baseComponentId; | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 6.6, please use {@link #getComponent()} instead | |||
*/ | |||
@Deprecated | |||
@CheckForNull | |||
public String getBaseComponentKey() { | |||
return baseComponentKey; | |||
} | |||
/** | |||
* @deprecated since 6.6, please use {@link #setComponent(String)} instead | |||
*/ | |||
@Deprecated | |||
public ComponentTreeRequest setBaseComponentKey(@Nullable String baseComponentKey) { | |||
this.baseComponentKey = baseComponentKey; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getComponent() { | |||
return component; | |||
} | |||
public ComponentTreeRequest setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getBranch() { | |||
return branch; | |||
} | |||
public ComponentTreeRequest setBranch(@Nullable String branch) { | |||
this.branch = branch; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getStrategy() { | |||
return strategy; | |||
} | |||
public ComponentTreeRequest setStrategy(String strategy) { | |||
this.strategy = strategy; | |||
return this; | |||
} | |||
@CheckForNull | |||
public List<String> getQualifiers() { | |||
return qualifiers; | |||
} | |||
public ComponentTreeRequest setQualifiers(@Nullable List<String> qualifiers) { | |||
this.qualifiers = qualifiers; | |||
return this; | |||
} | |||
@CheckForNull | |||
public List<String> getAdditionalFields() { | |||
return additionalFields; | |||
} | |||
public ComponentTreeRequest setAdditionalFields(@Nullable List<String> additionalFields) { | |||
this.additionalFields = additionalFields; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getQuery() { | |||
return query; | |||
} | |||
public ComponentTreeRequest setQuery(@Nullable String query) { | |||
this.query = query; | |||
return this; | |||
} | |||
@CheckForNull | |||
public List<String> getSort() { | |||
return sort; | |||
} | |||
public ComponentTreeRequest setSort(@Nullable List<String> sort) { | |||
this.sort = sort; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getMetricSort() { | |||
return metricSort; | |||
} | |||
public ComponentTreeRequest setMetricSort(@Nullable String metricSort) { | |||
this.metricSort = metricSort; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getMetricSortFilter() { | |||
return metricSortFilter; | |||
} | |||
public ComponentTreeRequest setMetricSortFilter(@Nullable String metricSortFilter) { | |||
this.metricSortFilter = metricSortFilter; | |||
return this; | |||
} | |||
@CheckForNull | |||
public List<String> getMetricKeys() { | |||
return metricKeys; | |||
} | |||
public ComponentTreeRequest setMetricKeys(List<String> metricKeys) { | |||
this.metricKeys = metricKeys; | |||
return this; | |||
} | |||
@CheckForNull | |||
public Boolean getAsc() { | |||
return asc; | |||
} | |||
public ComponentTreeRequest setAsc(@Nullable Boolean asc) { | |||
this.asc = asc; | |||
return this; | |||
} | |||
@CheckForNull | |||
public Integer getPage() { | |||
return page; | |||
} | |||
public ComponentTreeRequest setPage(int page) { | |||
this.page = page; | |||
return this; | |||
} | |||
@CheckForNull | |||
public Integer getPageSize() { | |||
return pageSize; | |||
} | |||
public ComponentTreeRequest setPageSize(int pageSize) { | |||
this.pageSize = pageSize; | |||
return this; | |||
} | |||
@CheckForNull | |||
public Integer getMetricPeriodSort() { | |||
return metricPeriodSort; | |||
} | |||
public ComponentTreeRequest setMetricPeriodSort(@Nullable Integer metricPeriodSort) { | |||
this.metricPeriodSort = metricPeriodSort; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getDeveloperId() { | |||
return developerId; | |||
} | |||
public ComponentTreeRequest setDeveloperId(@Nullable String developerId) { | |||
this.developerId = developerId; | |||
return this; | |||
} | |||
@CheckForNull | |||
public String getDeveloperKey() { | |||
return developerKey; | |||
} | |||
public ComponentTreeRequest setDeveloperKey(@Nullable String developerKey) { | |||
this.developerKey = developerKey; | |||
return this; | |||
} | |||
} |
@@ -1,119 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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.sonarqube.ws.client.measure; | |||
import org.sonar.api.server.ws.WebService.Param; | |||
import org.sonarqube.ws.Measures.ComponentTreeWsResponse; | |||
import org.sonarqube.ws.Measures.ComponentWsResponse; | |||
import org.sonarqube.ws.Measures.SearchHistoryResponse; | |||
import org.sonarqube.ws.Measures.SearchWsResponse; | |||
import org.sonarqube.ws.client.BaseService; | |||
import org.sonarqube.ws.client.GetRequest; | |||
import org.sonarqube.ws.client.WsConnector; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT_TREE; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_SEARCH_HISTORY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.CONTROLLER_MEASURES; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_PROJECT_KEYS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO; | |||
/** | |||
* @deprecated since 7.0, use {@link org.sonarqube.ws.client.measures.MeasuresService} instead | |||
*/ | |||
@Deprecated | |||
public class MeasuresService extends BaseService { | |||
public MeasuresService(WsConnector wsConnector) { | |||
super(wsConnector, CONTROLLER_MEASURES); | |||
} | |||
public ComponentTreeWsResponse componentTree(ComponentTreeRequest request) { | |||
GetRequest getRequest = new GetRequest(path(ACTION_COMPONENT_TREE)) | |||
.setParam(DEPRECATED_PARAM_BASE_COMPONENT_ID, request.getBaseComponentId()) | |||
.setParam(DEPRECATED_PARAM_BASE_COMPONENT_KEY, request.getBaseComponentKey()) | |||
.setParam(PARAM_COMPONENT, request.getComponent()) | |||
.setParam(PARAM_BRANCH, request.getBranch()) | |||
.setParam(PARAM_STRATEGY, request.getStrategy()) | |||
.setParam(PARAM_QUALIFIERS, inlineMultipleParamValue(request.getQualifiers())) | |||
.setParam(PARAM_METRIC_KEYS, inlineMultipleParamValue(request.getMetricKeys())) | |||
.setParam(PARAM_ADDITIONAL_FIELDS, inlineMultipleParamValue(request.getAdditionalFields())) | |||
.setParam(PARAM_DEVELOPER_ID, request.getDeveloperId()) | |||
.setParam(PARAM_DEVELOPER_KEY, request.getDeveloperKey()) | |||
.setParam("q", request.getQuery()) | |||
.setParam("p", request.getPage()) | |||
.setParam("ps", request.getPageSize()) | |||
.setParam("s", inlineMultipleParamValue(request.getSort())) | |||
.setParam("asc", request.getAsc()) | |||
.setParam(PARAM_METRIC_SORT, request.getMetricSort()) | |||
.setParam(PARAM_METRIC_SORT_FILTER, request.getMetricSortFilter()); | |||
return call(getRequest, ComponentTreeWsResponse.parser()); | |||
} | |||
public ComponentWsResponse component(ComponentRequest request) { | |||
GetRequest getRequest = new GetRequest(path(ACTION_COMPONENT)) | |||
.setParam(DEPRECATED_PARAM_COMPONENT_ID, request.getComponentId()) | |||
.setParam(DEPRECATED_PARAM_COMPONENT_KEY, request.getComponentKey()) | |||
.setParam(PARAM_COMPONENT, request.getComponent()) | |||
.setParam(PARAM_BRANCH, request.getBranch()) | |||
.setParam(PARAM_ADDITIONAL_FIELDS, inlineMultipleParamValue(request.getAdditionalFields())) | |||
.setParam(PARAM_METRIC_KEYS, inlineMultipleParamValue(request.getMetricKeys())) | |||
.setParam(PARAM_DEVELOPER_ID, request.getDeveloperId()) | |||
.setParam(PARAM_DEVELOPER_KEY, request.getDeveloperKey()); | |||
return call(getRequest, ComponentWsResponse.parser()); | |||
} | |||
public SearchHistoryResponse searchHistory(SearchHistoryRequest request) { | |||
GetRequest getRequest = new GetRequest(path(ACTION_SEARCH_HISTORY)) | |||
.setParam(PARAM_COMPONENT, request.getComponent()) | |||
.setParam(PARAM_BRANCH, request.getBranch()) | |||
.setParam(PARAM_METRICS, inlineMultipleParamValue(request.getMetrics())) | |||
.setParam(PARAM_FROM, request.getFrom()) | |||
.setParam(PARAM_TO, request.getTo()) | |||
.setParam(Param.PAGE, request.getPage()) | |||
.setParam(Param.PAGE_SIZE, request.getPageSize()); | |||
return call(getRequest, SearchHistoryResponse.parser()); | |||
} | |||
public SearchWsResponse search(SearchRequest request) { | |||
GetRequest getRequest = new GetRequest(path(ACTION_SEARCH_HISTORY)) | |||
.setParam(PARAM_PROJECT_KEYS, inlineMultipleParamValue(request.getProjectKeys())) | |||
.setParam(PARAM_METRIC_KEYS, inlineMultipleParamValue(request.getMetricKeys())); | |||
return call(getRequest, SearchWsResponse.parser()); | |||
} | |||
} |
@@ -1,147 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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.sonarqube.ws.client.measure; | |||
import java.util.List; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import static java.lang.String.format; | |||
public class SearchHistoryRequest { | |||
public static final int MAX_PAGE_SIZE = 1_000; | |||
public static final int DEFAULT_PAGE_SIZE = 100; | |||
private final String component; | |||
private final String branch; | |||
private final List<String> metrics; | |||
private final String from; | |||
private final String to; | |||
private final int page; | |||
private final int pageSize; | |||
public SearchHistoryRequest(Builder builder) { | |||
this.component = builder.component; | |||
this.branch = builder.branch; | |||
this.metrics = builder.metrics; | |||
this.from = builder.from; | |||
this.to = builder.to; | |||
this.page = builder.page; | |||
this.pageSize = builder.pageSize; | |||
} | |||
public String getComponent() { | |||
return component; | |||
} | |||
@CheckForNull | |||
public String getBranch() { | |||
return branch; | |||
} | |||
public List<String> getMetrics() { | |||
return metrics; | |||
} | |||
@CheckForNull | |||
public String getFrom() { | |||
return from; | |||
} | |||
@CheckForNull | |||
public String getTo() { | |||
return to; | |||
} | |||
public int getPage() { | |||
return page; | |||
} | |||
public int getPageSize() { | |||
return pageSize; | |||
} | |||
public static Builder builder() { | |||
return new Builder(); | |||
} | |||
public static class Builder { | |||
private String component; | |||
private String branch; | |||
private List<String> metrics; | |||
private String from; | |||
private String to; | |||
private int page = 1; | |||
private int pageSize = DEFAULT_PAGE_SIZE; | |||
private Builder() { | |||
// enforce build factory method | |||
} | |||
public Builder setComponent(String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
public Builder setBranch(@Nullable String branch) { | |||
this.branch = branch; | |||
return this; | |||
} | |||
public Builder setMetrics(List<String> metrics) { | |||
this.metrics = metrics; | |||
return this; | |||
} | |||
public Builder setFrom(@Nullable String from) { | |||
this.from = from; | |||
return this; | |||
} | |||
public Builder setTo(@Nullable String to) { | |||
this.to = to; | |||
return this; | |||
} | |||
public Builder setPage(int page) { | |||
this.page = page; | |||
return this; | |||
} | |||
public Builder setPageSize(int pageSize) { | |||
this.pageSize = pageSize; | |||
return this; | |||
} | |||
public SearchHistoryRequest build() { | |||
checkArgument(component != null && !component.isEmpty(), "Component key is required"); | |||
checkArgument(metrics != null && !metrics.isEmpty(), "Metric keys are required"); | |||
checkArgument(pageSize <= MAX_PAGE_SIZE, "Page size (%d) must be lower than or equal to %d", pageSize, MAX_PAGE_SIZE); | |||
return new SearchHistoryRequest(this); | |||
} | |||
private static void checkArgument(boolean condition, String message, Object... args) { | |||
if (!condition) { | |||
throw new IllegalArgumentException(format(message, args)); | |||
} | |||
} | |||
} | |||
} |
@@ -1,76 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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.sonarqube.ws.client.measure; | |||
import java.util.List; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
public class SearchRequest { | |||
private static final int MAX_NB_PROJECTS = 100; | |||
private final List<String> metricKeys; | |||
private final List<String> projectKeys; | |||
public SearchRequest(Builder builder) { | |||
metricKeys = builder.metricKeys; | |||
projectKeys = builder.projectKeys; | |||
} | |||
public List<String> getMetricKeys() { | |||
return metricKeys; | |||
} | |||
public List<String> getProjectKeys() { | |||
return projectKeys; | |||
} | |||
public static Builder builder() { | |||
return new Builder(); | |||
} | |||
public static class Builder { | |||
private List<String> metricKeys; | |||
private List<String> projectKeys; | |||
private Builder() { | |||
// enforce method constructor | |||
} | |||
public Builder setMetricKeys(List<String> metricKeys) { | |||
this.metricKeys = metricKeys; | |||
return this; | |||
} | |||
public Builder setProjectKeys(List<String> projectKeys) { | |||
this.projectKeys = projectKeys; | |||
return this; | |||
} | |||
public SearchRequest build() { | |||
checkArgument(metricKeys != null && !metricKeys.isEmpty(), "Metric keys must be provided"); | |||
checkArgument(projectKeys != null && !projectKeys.isEmpty(), "Project keys must be provided"); | |||
int nbComponents = projectKeys.size(); | |||
checkArgument(nbComponents <= MAX_NB_PROJECTS, | |||
"%s projects provided, more than maximum authorized (%s)", nbComponents, MAX_NB_PROJECTS); | |||
return new SearchRequest(this); | |||
} | |||
} | |||
} |
@@ -1,24 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonarqube.ws.client.measure; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -37,7 +37,7 @@ public class ComponentRequest { | |||
private String componentId; | |||
private String developerId; | |||
private String developerKey; | |||
private String metricKeys; | |||
private List<String> metricKeys; | |||
/** | |||
* Example value: "periods,metrics" | |||
@@ -125,12 +125,12 @@ public class ComponentRequest { | |||
* This is a mandatory parameter. | |||
* Example value: "ncloc,complexity,violations" | |||
*/ | |||
public ComponentRequest setMetricKeys(String metricKeys) { | |||
public ComponentRequest setMetricKeys(List<String> metricKeys) { | |||
this.metricKeys = metricKeys; | |||
return this; | |||
} | |||
public String getMetricKeys() { | |||
public List<String> getMetricKeys() { | |||
return metricKeys; | |||
} | |||
} |
@@ -38,7 +38,7 @@ public class ComponentTreeRequest { | |||
private String component; | |||
private String developerId; | |||
private String developerKey; | |||
private String metricKeys; | |||
private List<String> metricKeys; | |||
private String metricPeriodSort; | |||
private String metricSort; | |||
private String metricSortFilter; | |||
@@ -153,12 +153,12 @@ public class ComponentTreeRequest { | |||
* This is a mandatory parameter. | |||
* Example value: "ncloc,complexity,violations" | |||
*/ | |||
public ComponentTreeRequest setMetricKeys(String metricKeys) { | |||
public ComponentTreeRequest setMetricKeys(List<String> metricKeys) { | |||
this.metricKeys = metricKeys; | |||
return this; | |||
} | |||
public String getMetricKeys() { | |||
public List<String> getMetricKeys() { | |||
return metricKeys; | |||
} | |||
@@ -57,7 +57,7 @@ public class MeasuresService extends BaseService { | |||
.setParam("componentId", request.getComponentId()) | |||
.setParam("developerId", request.getDeveloperId()) | |||
.setParam("developerKey", request.getDeveloperKey()) | |||
.setParam("metricKeys", request.getMetricKeys()), | |||
.setParam("metricKeys", request.getMetricKeys() == null ? null : request.getMetricKeys().stream().collect(Collectors.joining(","))), | |||
ComponentWsResponse.parser()); | |||
} | |||
@@ -78,7 +78,7 @@ public class MeasuresService extends BaseService { | |||
.setParam("component", request.getComponent()) | |||
.setParam("developerId", request.getDeveloperId()) | |||
.setParam("developerKey", request.getDeveloperKey()) | |||
.setParam("metricKeys", request.getMetricKeys()) | |||
.setParam("metricKeys", request.getMetricKeys() == null ? null : request.getMetricKeys().stream().collect(Collectors.joining(","))) | |||
.setParam("metricPeriodSort", request.getMetricPeriodSort()) | |||
.setParam("metricSort", request.getMetricSort()) | |||
.setParam("metricSortFilter", request.getMetricSortFilter()) | |||
@@ -101,7 +101,7 @@ public class MeasuresService extends BaseService { | |||
public SearchWsResponse search(SearchRequest request) { | |||
return call( | |||
new GetRequest(path("search")) | |||
.setParam("metricKeys", request.getMetricKeys()) | |||
.setParam("metricKeys", request.getMetricKeys() == null ? null : request.getMetricKeys().stream().collect(Collectors.joining(","))) | |||
.setParam("projectKeys", request.getProjectKeys() == null ? null : request.getProjectKeys().stream().collect(Collectors.joining(","))), | |||
SearchWsResponse.parser()); | |||
} |
@@ -31,19 +31,19 @@ import javax.annotation.Generated; | |||
@Generated("sonar-ws-generator") | |||
public class SearchRequest { | |||
private String metricKeys; | |||
private List<String> metricKeys; | |||
private List<String> projectKeys; | |||
/** | |||
* This is a mandatory parameter. | |||
* Example value: "ncloc,complexity,violations" | |||
*/ | |||
public SearchRequest setMetricKeys(String metricKeys) { | |||
public SearchRequest setMetricKeys(List<String> metricKeys) { | |||
this.metricKeys = metricKeys; | |||
return this; | |||
} | |||
public String getMetricKeys() { | |||
public List<String> getMetricKeys() { | |||
return metricKeys; | |||
} | |||
@@ -1,200 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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.sonarqube.ws.client.measure; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonarqube.ws.Measures; | |||
import org.sonarqube.ws.Measures.ComponentTreeWsResponse; | |||
import org.sonarqube.ws.Measures.ComponentWsResponse; | |||
import org.sonarqube.ws.client.GetRequest; | |||
import org.sonarqube.ws.client.ServiceTester; | |||
import org.sonarqube.ws.client.WsConnector; | |||
import static com.google.common.collect.Lists.newArrayList; | |||
import static java.util.Arrays.asList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_PROJECT_KEYS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; | |||
import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO; | |||
public class MeasuresServiceTest { | |||
private static final String VALUE_BASE_COMPONENT_ID = "base-component-id"; | |||
private static final String VALUE_BASE_COMPONENT_KEY = "base-component-key"; | |||
private static final String VALUE_COMPONENT = "component-key"; | |||
private static final List<String> VALUE_METRIC_KEYS = newArrayList("ncloc", "complexity"); | |||
private static final List<String> VALUE_METRICS = newArrayList("ncloc", "complexity"); | |||
private static final String VALUE_STRATEGY = "all"; | |||
private static final List<String> VALUE_QUALIFIERS = newArrayList("FIL", "PRJ"); | |||
private static final ArrayList<String> VALUE_ADDITIONAL_FIELDS = newArrayList("metrics"); | |||
private static final List<String> VALUE_SORT = newArrayList("qualifier", "metric"); | |||
private static final boolean VALUE_ASC = false; | |||
private static final String VALUE_METRIC_SORT = "ncloc"; | |||
private static final String VALUE_METRIC_SORT_FILTER = "all"; | |||
private static final int VALUE_PAGE = 42; | |||
private static final int VALUE_PAGE_SIZE = 1000; | |||
private static final String VALUE_QUERY = "query-sq"; | |||
private static final String VALUE_DEVELOPER_ID = "developer-id"; | |||
private static final String VALUE_DEVELOPER_KEY = "developer-key"; | |||
private static final String VALUE_FROM = "2017-10-01"; | |||
private static final String VALUE_TO = "2017-11-01"; | |||
@Rule | |||
public ServiceTester<MeasuresService> serviceTester = new ServiceTester<>(new MeasuresService(mock(WsConnector.class))); | |||
private MeasuresService underTest = serviceTester.getInstanceUnderTest(); | |||
@Test | |||
public void component() { | |||
ComponentRequest request = new ComponentRequest() | |||
.setComponentId(VALUE_BASE_COMPONENT_ID) | |||
.setComponentKey(VALUE_BASE_COMPONENT_KEY) | |||
.setComponent(VALUE_BASE_COMPONENT_KEY) | |||
.setBranch("my_branch") | |||
.setMetricKeys(VALUE_METRIC_KEYS) | |||
.setAdditionalFields(VALUE_ADDITIONAL_FIELDS) | |||
.setMetricKeys(VALUE_METRICS) | |||
.setDeveloperId(VALUE_DEVELOPER_ID) | |||
.setDeveloperKey(VALUE_DEVELOPER_KEY); | |||
underTest.component(request); | |||
GetRequest getRequest = serviceTester.getGetRequest(); | |||
assertThat(serviceTester.getGetParser()).isSameAs(ComponentWsResponse.parser()); | |||
serviceTester.assertThat(getRequest) | |||
.hasParam(DEPRECATED_PARAM_COMPONENT_ID, VALUE_BASE_COMPONENT_ID) | |||
.hasParam(DEPRECATED_PARAM_COMPONENT_KEY, VALUE_BASE_COMPONENT_KEY) | |||
.hasParam(PARAM_COMPONENT, VALUE_BASE_COMPONENT_KEY) | |||
.hasParam(PARAM_BRANCH, "my_branch") | |||
.hasParam(PARAM_METRIC_KEYS, "ncloc,complexity") | |||
.hasParam(PARAM_ADDITIONAL_FIELDS, "metrics") | |||
.hasParam(PARAM_DEVELOPER_ID, VALUE_DEVELOPER_ID) | |||
.hasParam(PARAM_DEVELOPER_KEY, VALUE_DEVELOPER_KEY) | |||
.andNoOtherParam(); | |||
} | |||
@Test | |||
public void component_tree() { | |||
ComponentTreeRequest componentTreeRequest = new ComponentTreeRequest() | |||
.setBaseComponentId(VALUE_BASE_COMPONENT_ID) | |||
.setBaseComponentKey(VALUE_BASE_COMPONENT_KEY) | |||
.setComponent(VALUE_BASE_COMPONENT_KEY) | |||
.setBranch("my_branch") | |||
.setMetricKeys(VALUE_METRIC_KEYS) | |||
.setStrategy(VALUE_STRATEGY) | |||
.setQualifiers(VALUE_QUALIFIERS) | |||
.setAdditionalFields(VALUE_ADDITIONAL_FIELDS) | |||
.setSort(VALUE_SORT) | |||
.setAsc(VALUE_ASC) | |||
.setMetricSort(VALUE_METRIC_SORT) | |||
.setPage(VALUE_PAGE) | |||
.setPageSize(VALUE_PAGE_SIZE) | |||
.setQuery(VALUE_QUERY) | |||
.setDeveloperId(VALUE_DEVELOPER_ID) | |||
.setDeveloperKey(VALUE_DEVELOPER_KEY) | |||
.setMetricSortFilter(VALUE_METRIC_SORT_FILTER); | |||
underTest.componentTree(componentTreeRequest); | |||
GetRequest getRequest = serviceTester.getGetRequest(); | |||
assertThat(serviceTester.getGetParser()).isSameAs(ComponentTreeWsResponse.parser()); | |||
serviceTester.assertThat(getRequest) | |||
.hasParam(DEPRECATED_PARAM_BASE_COMPONENT_ID, VALUE_BASE_COMPONENT_ID) | |||
.hasParam(DEPRECATED_PARAM_BASE_COMPONENT_KEY, VALUE_BASE_COMPONENT_KEY) | |||
.hasParam(PARAM_COMPONENT, VALUE_BASE_COMPONENT_KEY) | |||
.hasParam(PARAM_BRANCH, "my_branch") | |||
.hasParam(PARAM_METRIC_KEYS, "ncloc,complexity") | |||
.hasParam(PARAM_STRATEGY, VALUE_STRATEGY) | |||
.hasParam(PARAM_QUALIFIERS, "FIL,PRJ") | |||
.hasParam(PARAM_ADDITIONAL_FIELDS, "metrics") | |||
.hasParam("s", "qualifier,metric") | |||
.hasParam("asc", VALUE_ASC) | |||
.hasParam(PARAM_METRIC_SORT, VALUE_METRIC_SORT) | |||
.hasParam("p", VALUE_PAGE) | |||
.hasParam("ps", VALUE_PAGE_SIZE) | |||
.hasParam("q", VALUE_QUERY) | |||
.hasParam(PARAM_DEVELOPER_ID, VALUE_DEVELOPER_ID) | |||
.hasParam(PARAM_DEVELOPER_KEY, VALUE_DEVELOPER_KEY) | |||
.hasParam(PARAM_METRIC_SORT_FILTER, VALUE_METRIC_SORT_FILTER) | |||
.andNoOtherParam(); | |||
} | |||
@Test | |||
public void search_history() { | |||
SearchHistoryRequest request = SearchHistoryRequest.builder() | |||
.setComponent(VALUE_COMPONENT) | |||
.setBranch("my_branch") | |||
.setMetrics(VALUE_METRICS) | |||
.setFrom(VALUE_FROM) | |||
.setTo(VALUE_TO) | |||
.setPage(VALUE_PAGE) | |||
.setPageSize(VALUE_PAGE_SIZE) | |||
.build(); | |||
underTest.searchHistory(request); | |||
GetRequest getRequest = serviceTester.getGetRequest(); | |||
assertThat(serviceTester.getGetParser()).isSameAs(Measures.SearchHistoryResponse.parser()); | |||
serviceTester.assertThat(getRequest) | |||
.hasParam(PARAM_COMPONENT, VALUE_COMPONENT) | |||
.hasParam(PARAM_BRANCH, "my_branch") | |||
.hasParam(PARAM_METRICS, "ncloc,complexity") | |||
.hasParam(PARAM_FROM, VALUE_FROM) | |||
.hasParam(PARAM_TO, VALUE_TO) | |||
.hasParam("p", VALUE_PAGE) | |||
.hasParam("ps", VALUE_PAGE_SIZE) | |||
.andNoOtherParam(); | |||
} | |||
@Test | |||
public void search() { | |||
SearchRequest request = SearchRequest.builder() | |||
.setProjectKeys(asList("P1", "P2")) | |||
.setMetricKeys(asList("ncloc", "complexity")) | |||
.build(); | |||
underTest.search(request); | |||
GetRequest getRequest = serviceTester.getGetRequest(); | |||
assertThat(serviceTester.getGetParser()).isSameAs(Measures.SearchWsResponse.parser()); | |||
serviceTester.assertThat(getRequest) | |||
.hasParam(PARAM_PROJECT_KEYS, "P1,P2") | |||
.hasParam(PARAM_METRIC_KEYS, "ncloc,complexity") | |||
.andNoOtherParam(); | |||
} | |||
} |
@@ -1,103 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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.sonarqube.ws.client.measure; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static java.util.Collections.emptyList; | |||
import static java.util.Collections.singletonList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonarqube.ws.client.measure.SearchHistoryRequest.DEFAULT_PAGE_SIZE; | |||
import static org.sonarqube.ws.client.measure.SearchHistoryRequest.MAX_PAGE_SIZE; | |||
public class SearchHistoryRequestTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private SearchHistoryRequest.Builder underTest = SearchHistoryRequest.builder(); | |||
@Test | |||
public void full_example() { | |||
SearchHistoryRequest result = underTest | |||
.setComponent("C1") | |||
.setBranch("my_branch") | |||
.setMetrics(singletonList("new_lines")) | |||
.setFrom("2017-01-15") | |||
.setTo("2017-01-20") | |||
.setPage(23) | |||
.setPageSize(42) | |||
.build(); | |||
assertThat(result) | |||
.extracting(SearchHistoryRequest::getComponent, SearchHistoryRequest::getBranch, SearchHistoryRequest::getMetrics, SearchHistoryRequest::getFrom, SearchHistoryRequest::getTo, | |||
SearchHistoryRequest::getPage, SearchHistoryRequest::getPageSize) | |||
.containsExactly("C1", "my_branch", singletonList("new_lines"), "2017-01-15", "2017-01-20", 23, 42); | |||
} | |||
@Test | |||
public void default_values() { | |||
SearchHistoryRequest result = underTest.setComponent("C1").setMetrics(singletonList("new_lines")).build(); | |||
assertThat(result.getPage()).isEqualTo(1); | |||
assertThat(result.getPageSize()).isEqualTo(DEFAULT_PAGE_SIZE); | |||
} | |||
@Test | |||
public void fail_if_no_component() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Component key is required"); | |||
underTest.setMetrics(singletonList("new_lines")).build(); | |||
} | |||
@Test | |||
public void fail_if_empty_component() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Component key is required"); | |||
underTest.setComponent("").setMetrics(singletonList("new_lines")).build(); | |||
} | |||
@Test | |||
public void fail_if_no_metric() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Metric keys are required"); | |||
underTest.setComponent("C1").build(); | |||
} | |||
@Test | |||
public void fail_if_empty_metrics() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Metric keys are required"); | |||
underTest.setComponent("C1").setMetrics(emptyList()).build(); | |||
} | |||
@Test | |||
public void fail_if_page_size_greater_than_max_authorized_size() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Page size (1001) must be lower than or equal to 1000"); | |||
underTest.setComponent("C1").setMetrics(singletonList("violations")).setPageSize(MAX_PAGE_SIZE + 1).build(); | |||
} | |||
} |
@@ -1,111 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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.sonarqube.ws.client.measure; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.IntStream; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static java.util.Collections.emptyList; | |||
import static java.util.Collections.singletonList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class SearchRequestTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
SearchRequest.Builder underTest = SearchRequest.builder(); | |||
@Test | |||
public void create_request() { | |||
SearchRequest result = underTest | |||
.setMetricKeys(singletonList("metric")) | |||
.setProjectKeys(singletonList("key")) | |||
.build(); | |||
assertThat(result.getMetricKeys()).containsExactly("metric"); | |||
assertThat(result.getProjectKeys()).containsExactly("key"); | |||
} | |||
@Test | |||
public void create_request_with_100_keys() { | |||
SearchRequest result = underTest | |||
.setMetricKeys(singletonList("metric")) | |||
.setProjectKeys(IntStream.rangeClosed(1, 100).mapToObj(Integer::toString).collect(Collectors.toList())) | |||
.build(); | |||
assertThat(result.getProjectKeys()).hasSize(100); | |||
} | |||
@Test | |||
public void fail_when_non_null_metric_keys() { | |||
expectExceptionOnMetricKeys(); | |||
underTest.setMetricKeys(null).build(); | |||
} | |||
@Test | |||
public void fail_when_non_empty_metric_keys() { | |||
expectExceptionOnMetricKeys(); | |||
underTest.setMetricKeys(emptyList()).build(); | |||
} | |||
@Test | |||
public void fail_when_unset_metric_keys() { | |||
expectExceptionOnMetricKeys(); | |||
underTest.build(); | |||
} | |||
@Test | |||
public void fail_when_component_keys_is_empty() { | |||
expectExceptionOnComponents(); | |||
underTest | |||
.setMetricKeys(singletonList("metric")) | |||
.setProjectKeys(emptyList()) | |||
.build(); | |||
} | |||
@Test | |||
public void fail_when_component_keys_contains_more_than_100_keys() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("101 projects provided, more than maximum authorized (100)"); | |||
underTest | |||
.setMetricKeys(singletonList("metric")) | |||
.setProjectKeys(IntStream.rangeClosed(1, 101).mapToObj(Integer::toString).collect(Collectors.toList())) | |||
.build(); | |||
} | |||
private void expectExceptionOnMetricKeys() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Metric keys must be provided"); | |||
} | |||
private void expectExceptionOnComponents() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Project keys must be provided"); | |||
} | |||
} |
@@ -31,9 +31,9 @@ import org.sonarqube.ws.Measures; | |||
import org.sonarqube.ws.client.components.TreeRequest; | |||
import org.sonarqube.ws.client.issues.IssuesService; | |||
import org.sonarqube.ws.client.issues.SearchRequest; | |||
import org.sonarqube.ws.client.measure.ComponentTreeRequest; | |||
import org.sonarqube.ws.client.measure.ComponentRequest; | |||
import org.sonarqube.ws.client.measure.MeasuresService; | |||
import org.sonarqube.ws.client.measures.ComponentTreeRequest; | |||
import org.sonarqube.ws.client.measures.ComponentRequest; | |||
import org.sonarqube.ws.client.measures.MeasuresService; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.singletonList; | |||
@@ -88,15 +88,15 @@ public class LiteTest { | |||
@Test | |||
public void call_measures_ws() { | |||
// project measures | |||
MeasuresService measuresService = tester.wsClient().measuresOld(); | |||
MeasuresService measuresService = tester.wsClient().measures(); | |||
Measures.ComponentWsResponse component = measuresService.component(new ComponentRequest() | |||
.setComponentKey(PROJECT_KEY) | |||
.setComponent(PROJECT_KEY) | |||
.setMetricKeys(asList("lines", "ncloc", "files"))); | |||
assertThat(component.getComponent().getMeasuresCount()).isEqualTo(3); | |||
// file measures | |||
Measures.ComponentTreeWsResponse tree = measuresService.componentTree(new ComponentTreeRequest() | |||
.setBaseComponentKey(PROJECT_KEY) | |||
.setComponent(PROJECT_KEY) | |||
.setQualifiers(singletonList("FIL")) | |||
.setMetricKeys(asList("lines", "ncloc"))); | |||
assertThat(tree.getComponentsCount()).isEqualTo(4); |
@@ -30,8 +30,8 @@ import org.sonarqube.qa.util.Tester; | |||
import org.sonarqube.ws.Measures; | |||
import org.sonarqube.ws.Measures.ComponentTreeWsResponse; | |||
import org.sonarqube.ws.Measures.ComponentWsResponse; | |||
import org.sonarqube.ws.client.measure.ComponentTreeRequest; | |||
import org.sonarqube.ws.client.measure.ComponentRequest; | |||
import org.sonarqube.ws.client.measures.ComponentTreeRequest; | |||
import org.sonarqube.ws.client.measures.ComponentRequest; | |||
import static com.google.common.collect.Lists.newArrayList; | |||
import static java.util.Arrays.asList; | |||
@@ -59,7 +59,7 @@ public class MeasuresWsTest { | |||
public void component_tree() { | |||
scanXooSample(); | |||
ComponentTreeWsResponse response = tester.wsClient().measuresOld().componentTree(new ComponentTreeRequest() | |||
ComponentTreeWsResponse response = tester.wsClient().measures().componentTree(new ComponentTreeRequest() | |||
.setComponent("sample") | |||
.setMetricKeys(singletonList("ncloc")) | |||
.setAdditionalFields(asList("metrics", "periods"))); | |||
@@ -123,7 +123,7 @@ public class MeasuresWsTest { | |||
} | |||
private void verifyComponentTreeWithChildren(String baseComponentKey, String... childKeys) { | |||
ComponentTreeWsResponse response = tester.wsClient().measuresOld().componentTree(new ComponentTreeRequest() | |||
ComponentTreeWsResponse response = tester.wsClient().measures().componentTree(new ComponentTreeRequest() | |||
.setComponent(baseComponentKey) | |||
.setMetricKeys(singletonList("ncloc")) | |||
.setStrategy("children")); | |||
@@ -137,7 +137,7 @@ public class MeasuresWsTest { | |||
public void component() { | |||
scanXooSample(); | |||
ComponentWsResponse response = tester.wsClient().measuresOld().component(new ComponentRequest() | |||
ComponentWsResponse response = tester.wsClient().measures().component(new ComponentRequest() | |||
.setComponent("sample") | |||
.setMetricKeys(singletonList("ncloc")) | |||
.setAdditionalFields(newArrayList("metrics", "periods"))); |
@@ -21,7 +21,6 @@ package org.sonarqube.tests.measure; | |||
import com.sonar.orchestrator.Orchestrator; | |||
import com.sonar.orchestrator.build.SonarScanner; | |||
import java.util.Arrays; | |||
import java.util.Date; | |||
import java.util.Map; | |||
import org.junit.BeforeClass; | |||
@@ -32,10 +31,11 @@ import org.sonarqube.qa.util.Tester; | |||
import org.sonarqube.ws.Measures.Measure; | |||
import org.sonarqube.ws.Measures.SearchHistoryResponse; | |||
import org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryValue; | |||
import org.sonarqube.ws.client.measure.SearchHistoryRequest; | |||
import org.sonarqube.ws.client.measures.SearchHistoryRequest; | |||
import util.ItUtils; | |||
import util.ItUtils.ComponentNavigation; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.singletonList; | |||
import static org.apache.commons.lang.time.DateUtils.addDays; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -102,12 +102,11 @@ public class TimeMachineTest { | |||
public void noDataForInterval() { | |||
Date now = new Date(); | |||
SearchHistoryResponse response = tester.wsClient().measuresOld().searchHistory(SearchHistoryRequest.builder() | |||
SearchHistoryResponse response = tester.wsClient().measures().searchHistory(new SearchHistoryRequest() | |||
.setComponent(PROJECT_KEY) | |||
.setMetrics(singletonList("lines")) | |||
.setFrom(formatDate(now)) | |||
.setTo(formatDate(now)) | |||
.build()); | |||
.setTo(formatDate(now))); | |||
assertThat(response.getPaging().getTotal()).isEqualTo(0); | |||
assertThat(response.getMeasures(0).getHistoryList()).isEmpty(); | |||
@@ -134,10 +133,9 @@ public class TimeMachineTest { | |||
} | |||
private static SearchHistoryResponse searchHistory(String... metrics) { | |||
return tester.wsClient().measuresOld().searchHistory(SearchHistoryRequest.builder() | |||
return tester.wsClient().measures().searchHistory(new SearchHistoryRequest() | |||
.setComponent(PROJECT_KEY) | |||
.setMetrics(Arrays.asList(metrics)) | |||
.build()); | |||
.setMetrics(asList(metrics))); | |||
} | |||
private static void assertHistory(SearchHistoryResponse response, String metric, String... expectedMeasures) { |
@@ -37,7 +37,7 @@ import org.sonarqube.ws.Measures; | |||
import org.sonarqube.ws.client.HttpConnector; | |||
import org.sonarqube.ws.client.WsClient; | |||
import org.sonarqube.ws.client.WsClientFactories; | |||
import org.sonarqube.ws.client.measure.ComponentRequest; | |||
import org.sonarqube.ws.client.measures.ComponentRequest; | |||
import static java.lang.Double.parseDouble; | |||
import static java.util.Arrays.asList; | |||
@@ -80,8 +80,8 @@ public class DuplicationTest extends AbstractPerfTest { | |||
} | |||
private Map<String, Double> getMeasures(String key) { | |||
return newWsClient().measuresOld().component(new ComponentRequest() | |||
.setComponentKey(key) | |||
return newWsClient().measures().component(new ComponentRequest() | |||
.setComponent(key) | |||
.setMetricKeys(asList("duplicated_lines", "duplicated_blocks", "duplicated_files", "duplicated_lines_density"))) | |||
.getComponent().getMeasuresList() | |||
.stream() |
@@ -31,22 +31,26 @@ import java.io.File; | |||
import java.io.IOException; | |||
import java.net.HttpURLConnection; | |||
import java.net.URL; | |||
import java.util.Collections; | |||
import org.apache.commons.io.IOUtils; | |||
import org.junit.After; | |||
import org.junit.Test; | |||
import org.sonarqube.qa.util.SelenideConfig; | |||
import org.sonarqube.ws.Measures; | |||
import org.sonarqube.ws.Measures.Measure; | |||
import org.sonarqube.ws.MediaTypes; | |||
import org.sonarqube.ws.client.BaseService; | |||
import org.sonarqube.ws.client.GetRequest; | |||
import org.sonarqube.ws.client.HttpConnector; | |||
import org.sonarqube.ws.client.PostRequest; | |||
import org.sonarqube.ws.client.WsClient; | |||
import org.sonarqube.ws.client.WsClientFactories; | |||
import org.sonarqube.ws.client.WsResponse; | |||
import org.sonarqube.ws.client.measure.ComponentRequest; | |||
import org.sonarqube.ws.client.measures.ComponentRequest; | |||
import static com.codeborne.selenide.Condition.hasText; | |||
import static com.codeborne.selenide.Selenide.$; | |||
import static java.lang.Integer.parseInt; | |||
import static java.util.Collections.singletonList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class UpgradeTest { | |||
@@ -73,7 +77,7 @@ public class UpgradeTest { | |||
private void testDatabaseUpgrade(Version fromVersion) { | |||
startOldVersionServer(fromVersion, false); | |||
scanProject(); | |||
int files = countFiles(PROJECT_KEY); | |||
int files = countFilesOld(PROJECT_KEY); | |||
assertThat(files).isGreaterThan(0); | |||
stopServer(); | |||
@@ -83,9 +87,9 @@ public class UpgradeTest { | |||
} | |||
private void verifyAnalysis(int expectedNumberOfFiles) { | |||
assertThat(countFiles(PROJECT_KEY)).isEqualTo(expectedNumberOfFiles); | |||
assertThat(countFilesNew(PROJECT_KEY)).isEqualTo(expectedNumberOfFiles); | |||
scanProject(); | |||
assertThat(countFiles(PROJECT_KEY)).isEqualTo(expectedNumberOfFiles); | |||
assertThat(countFilesNew(PROJECT_KEY)).isEqualTo(expectedNumberOfFiles); | |||
browseWebapp(); | |||
} | |||
@@ -197,8 +201,20 @@ public class UpgradeTest { | |||
orchestrator.executeBuild(build); | |||
} | |||
private int countFiles(String key) { | |||
Measure measure = newWsClient(orchestrator).measuresOld().component(new ComponentRequest().setComponentKey(key).setMetricKeys(Collections.singletonList("files"))) | |||
private int countFilesOld(String key) { | |||
PostRequest httpRequest = new PostRequest("api/measures/component") | |||
.setParam("componentKey", key) | |||
.setParam("metricKeys", singletonList("files")) | |||
.setMediaType(MediaTypes.PROTOBUF); | |||
WsResponse response = HttpConnector.newBuilder() | |||
.url(orchestrator.getServer().getUrl()) | |||
.build().call(httpRequest); | |||
Measure measure = BaseService.convert(response, Measures.ComponentWsResponse.parser()).getComponent().getMeasures(0); | |||
return parseInt(measure.getValue()); | |||
} | |||
private int countFilesNew(String key) { | |||
Measure measure = newWsClient(orchestrator).measures().component(new ComponentRequest().setComponent(key).setMetricKeys(singletonList("files"))) | |||
.getComponent().getMeasures(0); | |||
return parseInt(measure.getValue()); | |||
} |
@@ -71,7 +71,7 @@ import org.sonarqube.ws.client.HttpConnector; | |||
import org.sonarqube.ws.client.WsClient; | |||
import org.sonarqube.ws.client.WsClientFactories; | |||
import org.sonarqube.ws.client.components.ShowRequest; | |||
import org.sonarqube.ws.client.measure.ComponentRequest; | |||
import org.sonarqube.ws.client.measures.ComponentRequest; | |||
import org.sonarqube.ws.client.qualityprofile.RestoreRequest; | |||
import org.sonarqube.ws.client.settings.ResetRequest; | |||
import org.sonarqube.ws.client.settings.SetRequest; | |||
@@ -334,7 +334,7 @@ public class ItUtils { | |||
} | |||
private static Stream<Measure> getStreamMeasures(Orchestrator orchestrator, String componentKey, String... metricKeys) { | |||
return newWsClient(orchestrator).measuresOld().component(new ComponentRequest() | |||
return newWsClient(orchestrator).measures().component(new ComponentRequest() | |||
.setComponent(componentKey) | |||
.setMetricKeys(asList(metricKeys))) | |||
.getComponent().getMeasuresList() | |||
@@ -343,7 +343,7 @@ public class ItUtils { | |||
@CheckForNull | |||
public static Measure getMeasureWithVariation(Orchestrator orchestrator, String componentKey, String metricKey) { | |||
Measures.ComponentWsResponse response = newWsClient(orchestrator).measuresOld().component(new ComponentRequest() | |||
Measures.ComponentWsResponse response = newWsClient(orchestrator).measures().component(new ComponentRequest() | |||
.setComponent(componentKey) | |||
.setMetricKeys(singletonList(metricKey)) | |||
.setAdditionalFields(singletonList("periods"))); | |||
@@ -353,8 +353,8 @@ public class ItUtils { | |||
@CheckForNull | |||
public static Map<String, Measure> getMeasuresWithVariationsByMetricKey(Orchestrator orchestrator, String componentKey, String... metricKeys) { | |||
return newWsClient(orchestrator).measuresOld().component(new ComponentRequest() | |||
.setComponentKey(componentKey) | |||
return newWsClient(orchestrator).measures().component(new ComponentRequest() | |||
.setComponent(componentKey) | |||
.setMetricKeys(asList(metricKeys)) | |||
.setAdditionalFields(singletonList("periods"))).getComponent().getMeasuresList() | |||
.stream() |