aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/pom.xml6
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java108
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java9
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java16
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java193
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/HttpException.java4
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java12
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java34
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/Parameters.java37
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/Tls12Java7SocketFactory.java94
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java12
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsRequest.java9
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java6
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java11
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/ce/TaskWsRequest.java84
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/BulkUpdateWsRequest.java111
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java24
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java17
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/component/UpdateWsRequest.java86
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java4
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesService.java41
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesWsParameters.java32
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentTreeWsRequest.java3
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddProjectCreatorToTemplateWsRequest.java84
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java17
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/permission/OldUsersWsRequest.java104
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsService.java20
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/permission/RemoveProjectCreatorFromTemplateWsRequest.java84
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/permission/UsersWsRequest.java18
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/project/SearchMyProjectsRequest.java82
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/CreateWsRequest.java68
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/DeleteWsRequest.java33
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksService.java64
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksWsParameters.java39
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/SearchWsRequest.java50
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/package-info.java25
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesService.java9
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesWsParameters.java11
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/SelectWsRequest.java57
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/serverid/GenerateRequest.java70
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/serverid/package-info.java27
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ListDefinitionsRequest.java73
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ResetRequest.java93
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SetRequest.java127
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsService.java79
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsWsParameters.java43
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ValuesRequest.java97
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/setting/package-info.java27
-rw-r--r--sonar-ws/src/main/protobuf/ws-ce.proto4
-rw-r--r--sonar-ws/src/main/protobuf/ws-components.proto11
-rw-r--r--sonar-ws/src/main/protobuf/ws-licenses.proto52
-rw-r--r--sonar-ws/src/main/protobuf/ws-permissions.proto31
-rw-r--r--sonar-ws/src/main/protobuf/ws-projectlink.proto23
-rw-r--r--sonar-ws/src/main/protobuf/ws-projects.proto48
-rw-r--r--sonar-ws/src/main/protobuf/ws-qualitygates.proto11
-rw-r--r--sonar-ws/src/main/protobuf/ws-qualityprofiles.proto3
-rw-r--r--sonar-ws/src/main/protobuf/ws-serverid.proto39
-rw-r--r--sonar-ws/src/main/protobuf/ws-settings.proto115
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/BaseRequestTest.java41
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/BaseServiceTest.java2
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java37
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/HttpExceptionTest.java4
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/ServiceTester.java13
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java83
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java33
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/component/UpdateWsRequestTest.java49
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/license/LicensesServiceTest.java49
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/permission/PermissionsServiceTest.java48
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/projectlinks/ProjectLinksServiceTest.java102
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/qualitygate/QualityGatesServiceTest.java63
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/serverid/GenerateRequestTest.java65
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ListDefinitionsRequestTest.java60
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ResetRequestTest.java49
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SetRequestTest.java85
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java111
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java81
76 files changed, 3310 insertions, 356 deletions
diff --git a/sonar-ws/pom.xml b/sonar-ws/pom.xml
index 996f239200b..a38526a8ee6 100644
--- a/sonar-ws/pom.xml
+++ b/sonar-ws/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonarqube</artifactId>
- <version>5.6.2-SNAPSHOT</version>
+ <version>6.1-SNAPSHOT</version>
</parent>
<artifactId>sonar-ws</artifactId>
@@ -27,7 +27,7 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp</groupId>
+ <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
@@ -54,7 +54,7 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp</groupId>
+ <groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java
index 584d9505ae7..5357d581a7d 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseRequest.java
@@ -19,13 +19,23 @@
*/
package org.sonarqube.ws.client;
+import com.google.common.collect.LinkedListMultimap;
+import com.google.common.collect.ListMultimap;
+import java.util.Collection;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonarqube.ws.MediaTypes;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
+import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
abstract class BaseRequest<SELF extends BaseRequest> implements WsRequest {
@@ -34,8 +44,7 @@ abstract class BaseRequest<SELF extends BaseRequest> implements WsRequest {
private String mediaType = MediaTypes.JSON;
- // keep the same order -> do not use HashMap
- private final Map<String, String> params = new LinkedHashMap<>();
+ private final DefaultParameters parameters = new DefaultParameters();
BaseRequest(String path) {
this.path = path;
@@ -60,16 +69,103 @@ abstract class BaseRequest<SELF extends BaseRequest> implements WsRequest {
return (SELF) this;
}
- public SELF setParam(String key, @Nullable Object value) {
+ public SELF setParam(String key, @Nullable String value) {
+ return setSingleValueParam(key, value);
+ }
+
+ public SELF setParam(String key, @Nullable Integer value) {
+ return setSingleValueParam(key, value);
+ }
+
+ public SELF setParam(String key, @Nullable Long value) {
+ return setSingleValueParam(key, value);
+ }
+
+ public SELF setParam(String key, @Nullable Float value) {
+ return setSingleValueParam(key, value);
+ }
+
+ public SELF setParam(String key, @Nullable Boolean value) {
+ return setSingleValueParam(key, value);
+ }
+
+ private SELF setSingleValueParam(String key, @Nullable Object value) {
checkArgument(!isNullOrEmpty(key), "a WS parameter key cannot be null");
- if (value != null) {
- this.params.put(key, value.toString());
+ if (value == null) {
+ return (SELF) this;
}
+ parameters.setValue(key, value.toString());
+
+ return (SELF) this;
+ }
+
+ public SELF setParam(String key, @Nullable Collection<? extends Object> values) {
+ checkArgument(!isNullOrEmpty(key), "a WS parameter key cannot be null");
+ if (values == null || values.isEmpty()) {
+ return (SELF) this;
+ }
+
+ parameters.setValues(key, values.stream()
+ .filter(Objects::nonNull)
+ .map(Object::toString)
+ .filter(value -> !value.isEmpty())
+ .collect(Collectors.toList()));
+
return (SELF) this;
}
@Override
public Map<String, String> getParams() {
- return params;
+ return parameters.keyValues.keySet().stream()
+ .collect(Collectors.toMap(
+ Function.identity(),
+ key -> parameters.keyValues.get(key).get(0),
+ (v1, v2) -> {
+ throw new IllegalStateException(String.format("Duplicate key '%s' in request", v1));
+ },
+ LinkedHashMap::new));
+ }
+
+ @Override
+ public Parameters getParameters() {
+ return parameters;
+ }
+
+ private static class DefaultParameters implements Parameters {
+ // preserve insertion order
+ private final ListMultimap<String, String> keyValues = LinkedListMultimap.create();
+
+ @Override
+ @CheckForNull
+ public String getValue(String key) {
+ return keyValues.containsKey(key) ? keyValues.get(key).get(0) : null;
+ }
+
+ @Override
+ public List<String> getValues(String key) {
+ return keyValues.get(key);
+ }
+
+ @Override
+ public Set<String> getKeys() {
+ return keyValues.keySet();
+ }
+
+ private DefaultParameters setValue(String key, String value) {
+ checkArgument(!isNullOrEmpty(key));
+ checkArgument(!isNullOrEmpty(value));
+
+ keyValues.putAll(key, singletonList(value));
+ return this;
+ }
+
+ private DefaultParameters setValues(String key, Collection<String> values) {
+ checkArgument(!isNullOrEmpty(key));
+ checkArgument(values != null && !values.isEmpty());
+
+ this.keyValues.putAll(key, values.stream().map(Object::toString).collect(Collectors.toList()));
+
+ return this;
+ }
}
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
index 2cfcd7448a5..6949f4fe9a6 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
@@ -31,7 +31,9 @@ abstract class BaseResponse implements WsResponse {
@Override
public WsResponse failIfNotSuccessful() {
if (!isSuccessful()) {
- throw new HttpException(requestUrl(), code());
+ String content = content();
+ close();
+ throw new HttpException(requestUrl(), code(), content);
}
return this;
}
@@ -40,4 +42,9 @@ abstract class BaseResponse implements WsResponse {
public boolean hasContent() {
return code() != HTTP_NO_CONTENT;
}
+
+ @Override
+ public void close() {
+ // override if needed
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
index 110c8d0377a..a5d98cff324 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
@@ -25,9 +25,11 @@ import org.sonarqube.ws.client.issue.IssuesService;
import org.sonarqube.ws.client.measure.MeasuresService;
import org.sonarqube.ws.client.permission.PermissionsService;
import org.sonarqube.ws.client.project.ProjectsService;
+import org.sonarqube.ws.client.projectlinks.ProjectLinksService;
import org.sonarqube.ws.client.qualitygate.QualityGatesService;
import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
import org.sonarqube.ws.client.rule.RulesService;
+import org.sonarqube.ws.client.setting.SettingsService;
import org.sonarqube.ws.client.system.SystemService;
import org.sonarqube.ws.client.usertoken.UserTokensService;
@@ -51,6 +53,8 @@ class DefaultWsClient implements WsClient {
private final CeService ceService;
private final RulesService rulesService;
private final ProjectsService projectsService;
+ private final ProjectLinksService projectLinksService;
+ private final SettingsService settingsService;
DefaultWsClient(WsConnector wsConnector) {
this.wsConnector = wsConnector;
@@ -65,6 +69,8 @@ class DefaultWsClient implements WsClient {
this.ceService = new CeService(wsConnector);
this.rulesService = new RulesService(wsConnector);
this.projectsService = new ProjectsService(wsConnector);
+ this.projectLinksService = new ProjectLinksService(wsConnector);
+ this.settingsService = new SettingsService(wsConnector);
}
@Override
@@ -126,4 +132,14 @@ class DefaultWsClient implements WsClient {
public ProjectsService projects() {
return projectsService;
}
+
+ @Override
+ public ProjectLinksService projectLinks() {
+ return projectLinksService;
+ }
+
+ @Override
+ public SettingsService settingsService() {
+ return settingsService;
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java
index faa1d4e19e3..3091c40faf8 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java
@@ -19,25 +19,34 @@
*/
package org.sonarqube.ws.client;
-import com.google.common.annotations.VisibleForTesting;
-import com.squareup.okhttp.Call;
-import com.squareup.okhttp.ConnectionSpec;
-import com.squareup.okhttp.Credentials;
-import com.squareup.okhttp.Headers;
-import com.squareup.okhttp.HttpUrl;
-import com.squareup.okhttp.MediaType;
-import com.squareup.okhttp.MultipartBuilder;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.RequestBody;
-import com.squareup.okhttp.Response;
+import java.io.FileInputStream;
import java.io.IOException;
import java.net.Proxy;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509TrustManager;
+import okhttp3.Call;
+import okhttp3.ConnectionSpec;
+import okhttp3.Credentials;
+import okhttp3.Headers;
+import okhttp3.HttpUrl;
+import okhttp3.MediaType;
+import okhttp3.MultipartBody;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
@@ -54,6 +63,8 @@ public class HttpConnector implements WsConnector {
public static final int DEFAULT_CONNECT_TIMEOUT_MILLISECONDS = 30_000;
public static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = 60_000;
+ private static final String NONE = "NONE";
+ private static final String P11KEYSTORE = "PKCS11";
/**
* Base URL with trailing slash, for instance "https://localhost/sonarqube/".
@@ -63,11 +74,11 @@ public class HttpConnector implements WsConnector {
private final String userAgent;
private final String credentials;
private final String proxyCredentials;
- private final OkHttpClient okHttpClient = new OkHttpClient();
+ private final OkHttpClient okHttpClient;
- private HttpConnector(Builder builder, JavaVersion javaVersion) {
+ private HttpConnector(Builder builder) {
this.baseUrl = HttpUrl.parse(builder.url.endsWith("/") ? builder.url : format("%s/", builder.url));
- checkArgument(this.baseUrl!=null, "Malformed URL: '%s'", builder.url);
+ checkArgument(this.baseUrl != null, "Malformed URL: '%s'", builder.url);
this.userAgent = builder.userAgent;
if (isNullOrEmpty(builder.login)) {
@@ -78,49 +89,129 @@ public class HttpConnector implements WsConnector {
// the Basic credentials consider an empty password.
this.credentials = Credentials.basic(builder.login, nullToEmpty(builder.password));
}
-
- if (builder.proxy != null) {
- this.okHttpClient.setProxy(builder.proxy);
- }
// proxy credentials can be used on system-wide proxies, so even if builder.proxy is null
if (isNullOrEmpty(builder.proxyLogin)) {
this.proxyCredentials = null;
} else {
this.proxyCredentials = Credentials.basic(builder.proxyLogin, nullToEmpty(builder.proxyPassword));
}
+ this.okHttpClient = buildClient(builder);
+ }
- this.okHttpClient.setConnectTimeout(builder.connectTimeoutMs, TimeUnit.MILLISECONDS);
- this.okHttpClient.setReadTimeout(builder.readTimeoutMs, TimeUnit.MILLISECONDS);
+ private static OkHttpClient buildClient(Builder builder) {
+ OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
+ if (builder.proxy != null) {
+ okHttpClientBuilder.proxy(builder.proxy);
+ }
+
+ okHttpClientBuilder.connectTimeout(builder.connectTimeoutMs, TimeUnit.MILLISECONDS);
+ okHttpClientBuilder.readTimeout(builder.readTimeoutMs, TimeUnit.MILLISECONDS);
ConnectionSpec tls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.allEnabledTlsVersions()
.allEnabledCipherSuites()
.supportsTlsExtensions(true)
.build();
- this.okHttpClient.setConnectionSpecs(asList(tls, ConnectionSpec.CLEARTEXT));
- this.okHttpClient.setSslSocketFactory(createSslSocketFactory(javaVersion));
+ okHttpClientBuilder.connectionSpecs(asList(tls, ConnectionSpec.CLEARTEXT));
+ X509TrustManager systemDefaultTrustManager = systemDefaultTrustManager();
+ okHttpClientBuilder.sslSocketFactory(systemDefaultSslSocketFactory(systemDefaultTrustManager), systemDefaultTrustManager);
+
+ return okHttpClientBuilder.build();
}
- private static SSLSocketFactory createSslSocketFactory(JavaVersion javaVersion) {
+ private static X509TrustManager systemDefaultTrustManager() {
try {
- SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
- return enableTls12InJava7(sslSocketFactory, javaVersion);
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ trustManagerFactory.init((KeyStore) null);
+ TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
+ if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
+ throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
+ }
+ return (X509TrustManager) trustManagers[0];
+ } catch (GeneralSecurityException e) {
+ // The system has no TLS. Just give up.
+ throw new AssertionError(e);
+ }
+ }
+
+ private static SSLSocketFactory systemDefaultSslSocketFactory(X509TrustManager trustManager) {
+ KeyManager[] defaultKeyManager;
+ try {
+ defaultKeyManager = getDefaultKeyManager();
} catch (Exception e) {
- throw new IllegalStateException("Fail to init TLS context", e);
+ throw new IllegalStateException("Unable to get default key manager", e);
+ }
+ try {
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ sslContext.init(defaultKeyManager, new TrustManager[] {trustManager}, null);
+ return sslContext.getSocketFactory();
+ } catch (GeneralSecurityException e) {
+ // The system has no TLS. Just give up.
+ throw new AssertionError(e);
+ }
+ }
+
+ private static void logDebug(String msg) {
+ boolean debugEnabled = "all".equals(System.getProperty("javax.net.debug"));
+ if (debugEnabled) {
+ System.out.println(msg);
}
}
- private static SSLSocketFactory enableTls12InJava7(SSLSocketFactory sslSocketFactory, JavaVersion javaVersion) {
- if (javaVersion.isJava7()) {
- // OkHttp executes SSLContext.getInstance("TLS") by default (see
- // https://github.com/square/okhttp/blob/c358656/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java#L616)
- // As only TLS 1.0 is enabled by default in Java 7, the SSLContextFactory must be changed
- // in order to support all versions from 1.0 to 1.2.
- // Note that this is not overridden for Java 8 as TLS 1.2 is enabled by default.
- // Keeping getInstance("TLS") allows to support potential future versions of TLS on Java 8.
- return new Tls12Java7SocketFactory(sslSocketFactory);
+ /**
+ * Inspired from sun.security.ssl.SSLContextImpl#getDefaultKeyManager()
+ */
+ private static synchronized KeyManager[] getDefaultKeyManager() throws Exception {
+
+ final String defaultKeyStore = System.getProperty("javax.net.ssl.keyStore", "");
+ String defaultKeyStoreType = System.getProperty("javax.net.ssl.keyStoreType", KeyStore.getDefaultType());
+ String defaultKeyStoreProvider = System.getProperty("javax.net.ssl.keyStoreProvider", "");
+
+ logDebug("keyStore is : " + defaultKeyStore);
+ logDebug("keyStore type is : " + defaultKeyStoreType);
+ logDebug("keyStore provider is : " + defaultKeyStoreProvider);
+
+ if (P11KEYSTORE.equals(defaultKeyStoreType) && !NONE.equals(defaultKeyStore)) {
+ throw new IllegalArgumentException("if keyStoreType is " + P11KEYSTORE + ", then keyStore must be " + NONE);
}
- return sslSocketFactory;
+
+ KeyStore ks = null;
+ String defaultKeyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword", "");
+ char[] passwd = defaultKeyStorePassword.isEmpty() ? null : defaultKeyStorePassword.toCharArray();
+
+ /**
+ * Try to initialize key store.
+ */
+ if (!defaultKeyStoreType.isEmpty()) {
+ logDebug("init keystore");
+ if (defaultKeyStoreProvider.isEmpty()) {
+ ks = KeyStore.getInstance(defaultKeyStoreType);
+ } else {
+ ks = KeyStore.getInstance(defaultKeyStoreType, defaultKeyStoreProvider);
+ }
+ if (!defaultKeyStore.isEmpty() && !NONE.equals(defaultKeyStore)) {
+ try (FileInputStream fs = new FileInputStream(defaultKeyStore)) {
+ ks.load(fs, passwd);
+ }
+ } else {
+ ks.load(null, passwd);
+ }
+ }
+
+ /*
+ * Try to initialize key manager.
+ */
+ logDebug("init keymanager of type " + KeyManagerFactory.getDefaultAlgorithm());
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+
+ if (P11KEYSTORE.equals(defaultKeyStoreType)) {
+ // do not pass key passwd if using token
+ kmf.init(ks, null);
+ } else {
+ kmf.init(ks, passwd);
+ }
+
+ return kmf.getKeyManagers();
}
@Override
@@ -162,14 +253,15 @@ public class HttpConnector implements WsConnector {
if (parts.isEmpty()) {
okRequestBuilder.post(RequestBody.create(null, ""));
} else {
- MultipartBuilder body = new MultipartBuilder().type(MultipartBuilder.FORM);
+ MultipartBody.Builder bodyBuilder = new MultipartBody.Builder();
+ bodyBuilder.setType(MultipartBody.FORM);
for (Map.Entry<String, PostRequest.Part> param : parts.entrySet()) {
PostRequest.Part part = param.getValue();
- body.addPart(
+ bodyBuilder.addPart(
Headers.of("Content-Disposition", format("form-data; name=\"%s\"", param.getKey())),
RequestBody.create(MediaType.parse(part.getMediaType()), part.getFile()));
}
- okRequestBuilder.post(body.build());
+ okRequestBuilder.post(bodyBuilder.build());
}
return doCall(okRequestBuilder.build());
@@ -180,9 +272,10 @@ public class HttpConnector implements WsConnector {
HttpUrl.Builder urlBuilder = baseUrl
.resolve(path.startsWith("/") ? path.replaceAll("^(/)+", "") : path)
.newBuilder();
- for (Map.Entry<String, String> param : wsRequest.getParams().entrySet()) {
- urlBuilder.addQueryParameter(param.getKey(), param.getValue());
- }
+ wsRequest.getParameters().getKeys()
+ .forEach(key -> wsRequest.getParameters().getValues(key)
+ .forEach(value -> urlBuilder.addQueryParameter(key, value)));
+
return urlBuilder;
}
@@ -209,7 +302,7 @@ public class HttpConnector implements WsConnector {
Response okResponse = call.execute();
return new OkHttpResponse(okResponse);
} catch (IOException e) {
- throw new IllegalStateException("Fail to request " + okRequest.urlString(), e);
+ throw new IllegalStateException("Fail to request " + okRequest.url(), e);
}
}
@@ -302,19 +395,9 @@ public class HttpConnector implements WsConnector {
}
public HttpConnector build() {
- return build(new JavaVersion());
- }
-
- @VisibleForTesting
- HttpConnector build(JavaVersion javaVersion) {
checkArgument(!isNullOrEmpty(url), "Server URL is not defined");
- return new HttpConnector(this, javaVersion);
+ return new HttpConnector(this);
}
}
- static class JavaVersion {
- boolean isJava7() {
- return System.getProperty("java.version").startsWith("1.7.");
- }
- }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpException.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpException.java
index b69cd482679..462145d6a45 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpException.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpException.java
@@ -27,8 +27,8 @@ public class HttpException extends RuntimeException {
private final String url;
private final int code;
- public HttpException(String url, int code) {
- super(String.format("Error %d on %s", code, url));
+ public HttpException(String url, int code, String content) {
+ super(String.format("Error %d on %s : %s", code, url, content));
this.url = url;
this.code = code;
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java
index ca8947e64e7..52e6392f847 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java
@@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.util.List;
import org.sonar.api.server.ws.LocalConnector;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -55,9 +56,11 @@ class LocalWsConnector implements WsConnector {
private static class DefaultLocalRequest implements LocalConnector.LocalRequest {
private final WsRequest wsRequest;
+ private final Parameters parameters;
public DefaultLocalRequest(WsRequest wsRequest) {
this.wsRequest = wsRequest;
+ this.parameters = wsRequest.getParameters();
}
@Override
@@ -77,12 +80,17 @@ class LocalWsConnector implements WsConnector {
@Override
public boolean hasParam(String key) {
- return wsRequest.getParams().containsKey(key);
+ return !parameters.getValues(key).isEmpty();
}
@Override
public String getParam(String key) {
- return wsRequest.getParams().get(key);
+ return parameters.getValue(key);
+ }
+
+ @Override
+ public List<String> getMultiParam(String key) {
+ return parameters.getValues(key);
}
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
index 30217f16681..0532e9f70f8 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
@@ -19,7 +19,9 @@
*/
package org.sonarqube.ws.client;
-import com.squareup.okhttp.Response;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
@@ -39,7 +41,7 @@ class OkHttpResponse extends BaseResponse {
@Override
public String requestUrl() {
- return okResponse.request().urlString();
+ return okResponse.request().url().toString();
}
@Override
@@ -52,11 +54,7 @@ class OkHttpResponse extends BaseResponse {
*/
@Override
public InputStream contentStream() {
- try {
- return okResponse.body().byteStream();
- } catch (IOException e) {
- throw fail(e);
- }
+ return okResponse.body().byteStream();
}
/**
@@ -66,23 +64,33 @@ class OkHttpResponse extends BaseResponse {
*/
@Override
public Reader contentReader() {
- try {
- return okResponse.body().charStream();
- } catch (IOException e) {
- throw fail(e);
- }
+ return okResponse.body().charStream();
}
+ /**
+ * Get body content as a String. This response will be automatically closed.
+ */
@Override
public String content() {
+ ResponseBody body = okResponse.body();
try {
- return okResponse.body().string();
+ return body.string();
} catch (IOException e) {
throw fail(e);
+ } finally {
+ body.close();
}
}
private RuntimeException fail(Exception e) {
throw new IllegalStateException("Fail to read response of " + requestUrl(), e);
}
+
+ /**
+ * Equivalent to closing contentReader or contentStream.
+ */
+ @Override
+ public void close() {
+ okResponse.close();
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/Parameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/Parameters.java
new file mode 100644
index 00000000000..f2ad75bf960
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/Parameters.java
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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;
+
+import java.util.List;
+import java.util.Set;
+import javax.annotation.CheckForNull;
+
+public interface Parameters {
+ /**
+ * In the case of a multi value parameter, returns the first element
+ */
+ @CheckForNull
+ String getValue(String key);
+
+ List<String> getValues(String key);
+
+ Set<String> getKeys();
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/Tls12Java7SocketFactory.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/Tls12Java7SocketFactory.java
deleted file mode 100644
index f9f472dae06..00000000000
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/Tls12Java7SocketFactory.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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;
-
-import com.google.common.annotations.VisibleForTesting;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
-
-/**
- * {@link SSLSocketFactory} which enables all the versions of TLS. This is required
- * to support TLSv1.2 on Java 7. Note that Java 8 supports TLSv1.2 natively, without
- * any configuration
- */
-public class Tls12Java7SocketFactory extends SSLSocketFactory {
-
- @VisibleForTesting
- static final String[] TLS_PROTOCOLS = new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"};
-
- private final SSLSocketFactory delegate;
-
- public Tls12Java7SocketFactory(SSLSocketFactory delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public String[] getDefaultCipherSuites() {
- return delegate.getDefaultCipherSuites();
- }
-
- @Override
- public String[] getSupportedCipherSuites() {
- return delegate.getSupportedCipherSuites();
- }
-
- @Override
- public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
- Socket underlyingSocket = delegate.createSocket(socket, host, port, autoClose);
- return overrideProtocol(underlyingSocket);
- }
-
- @Override
- public Socket createSocket(String host, int port) throws IOException {
- Socket underlyingSocket = delegate.createSocket(host, port);
- return overrideProtocol(underlyingSocket);
- }
-
- @Override
- public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException {
- Socket underlyingSocket = delegate.createSocket(host, port, localAddress, localPort);
- return overrideProtocol(underlyingSocket);
- }
-
- @Override
- public Socket createSocket(InetAddress host, int port) throws IOException {
- Socket underlyingSocket = delegate.createSocket(host, port);
- return overrideProtocol(underlyingSocket);
- }
-
- @Override
- public Socket createSocket(InetAddress host, int port, InetAddress localAddress, int localPort) throws IOException {
- Socket underlyingSocket = delegate.createSocket(host, port, localAddress, localPort);
- return overrideProtocol(underlyingSocket);
- }
-
- /**
- * Enables TLS v1.0, 1.1 and 1.2 on the socket
- */
- private static Socket overrideProtocol(Socket socket) {
- if (socket instanceof SSLSocket) {
- ((SSLSocket) socket).setEnabledProtocols(TLS_PROTOCOLS);
- }
- return socket;
- }
-}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
index 36369c45e5c..c470bfa4b4c 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java
@@ -25,9 +25,11 @@ import org.sonarqube.ws.client.issue.IssuesService;
import org.sonarqube.ws.client.measure.MeasuresService;
import org.sonarqube.ws.client.permission.PermissionsService;
import org.sonarqube.ws.client.project.ProjectsService;
+import org.sonarqube.ws.client.projectlinks.ProjectLinksService;
import org.sonarqube.ws.client.qualitygate.QualityGatesService;
import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
import org.sonarqube.ws.client.rule.RulesService;
+import org.sonarqube.ws.client.setting.SettingsService;
import org.sonarqube.ws.client.system.SystemService;
import org.sonarqube.ws.client.usertoken.UserTokensService;
@@ -76,4 +78,14 @@ public interface WsClient {
* @since 5.5
*/
ProjectsService projects();
+
+ /**
+ * @since 6.1
+ */
+ ProjectLinksService projectLinks();
+
+ /**
+ * @since 6.1
+ */
+ SettingsService settingsService();
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsRequest.java
index 91db5b8a18e..2c52bc50840 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsRequest.java
@@ -32,8 +32,17 @@ public interface WsRequest {
String getMediaType();
+ /**
+ *
+ * In case of multi value parameters, returns the first value
+ *
+ * @deprecated since 6.1. Use {@link #getParameters()} instead
+ */
+ @Deprecated
Map<String, String> getParams();
+ Parameters getParameters();
+
enum Method {
GET, POST
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java
index 89c8977a46d..fc3d83ff177 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java
@@ -19,13 +19,14 @@
*/
package org.sonarqube.ws.client;
+import java.io.Closeable;
import java.io.InputStream;
import java.io.Reader;
/**
* @since 5.3
*/
-public interface WsResponse {
+public interface WsResponse extends Closeable {
/**
* The absolute requested URL
@@ -57,5 +58,8 @@ public interface WsResponse {
Reader contentReader();
String content();
+
+ @Override
+ void close();
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
index 460ddb53faa..c1d51fded43 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/CeService.java
@@ -70,7 +70,16 @@ public class CeService extends BaseService {
* @since 5.5
*/
public WsCe.TaskResponse task(String id) {
- return call(new GetRequest(path("task")).setParam("id", id), WsCe.TaskResponse.parser());
+ return task(TaskWsRequest.newBuilder(id).build());
+ }
+
+ public WsCe.TaskResponse task(TaskWsRequest taskWsRequest) {
+ GetRequest request = new GetRequest(path("task"))
+ .setParam("id", taskWsRequest.getTaskUuid());
+ if (!taskWsRequest.getAdditionalFields().isEmpty()) {
+ request.setParam("additionalFields", inlineMultipleParamValue(taskWsRequest.getAdditionalFields()));
+ }
+ return call(request, WsCe.TaskResponse.parser());
}
public WsCe.ActivityStatusWsResponse activityStatus(ActivityStatusWsRequest request) {
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/TaskWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/TaskWsRequest.java
new file mode 100644
index 00000000000..314b9dfa949
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/ce/TaskWsRequest.java
@@ -0,0 +1,84 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.ce;
+
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class TaskWsRequest {
+ private final String taskUuid;
+ private final List<String> additionalFields;
+
+ private TaskWsRequest(Builder builder) {
+ this.taskUuid = builder.taskUuid;
+ this.additionalFields = createAdditionalFields(builder);
+ }
+ public static Builder newBuilder(String taskUuid) {
+ return new Builder(taskUuid);
+ }
+
+ private static List<String> createAdditionalFields(Builder builder) {
+ if (!builder.errorStacktrace && !builder.scannerContext) {
+ return Collections.emptyList();
+ }
+ List<String> res = new ArrayList<>(2);
+ if (builder.errorStacktrace) {
+ res.add("stacktrace");
+ }
+ if (builder.scannerContext) {
+ res.add("scannerContext");
+ }
+ return ImmutableList.copyOf(res);
+ }
+
+ public String getTaskUuid() {
+ return taskUuid;
+ }
+
+ public List<String> getAdditionalFields() {
+ return additionalFields;
+ }
+
+ public static final class Builder {
+ private final String taskUuid;
+ private boolean errorStacktrace = false;
+ private boolean scannerContext = false;
+
+ private Builder(String taskUuid) {
+ this.taskUuid = taskUuid;
+ }
+
+ public Builder withErrorStacktrace() {
+ this.errorStacktrace = true;
+ return this;
+ }
+
+ public Builder withScannerContext() {
+ this.scannerContext = true;
+ return this;
+ }
+
+ public TaskWsRequest build() {
+ return new TaskWsRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/BulkUpdateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/BulkUpdateWsRequest.java
new file mode 100644
index 00000000000..881a8d0fe1a
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/BulkUpdateWsRequest.java
@@ -0,0 +1,111 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.component;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class BulkUpdateWsRequest {
+ private final String id;
+ private final String key;
+ private final String from;
+ private final String to;
+ private final boolean dryRun;
+
+ public BulkUpdateWsRequest(Builder builder) {
+ this.id = builder.id;
+ this.key = builder.key;
+ this.from = builder.from;
+ this.to = builder.to;
+ this.dryRun = builder.dryRun;
+ }
+
+ @CheckForNull
+ public String getId() {
+ return id;
+ }
+
+ @CheckForNull
+ public String getKey() {
+ return key;
+ }
+
+ public String getFrom() {
+ return from;
+ }
+
+ public String getTo() {
+ return to;
+ }
+
+ public boolean isDryRun() {
+ return dryRun;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String id;
+ private String key;
+ private String from;
+ private String to;
+ private boolean dryRun;
+
+ private Builder() {
+ // enforce method constructor
+ }
+
+ public Builder setId(@Nullable String id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder setKey(@Nullable String key) {
+ this.key = key;
+ return this;
+ }
+
+ public Builder setFrom(String from) {
+ this.from = from;
+ return this;
+ }
+
+ public Builder setTo(String to) {
+ this.to = to;
+ return this;
+ }
+
+ public Builder setDryRun(boolean dryRun) {
+ this.dryRun = dryRun;
+ return this;
+ }
+
+ public BulkUpdateWsRequest build() {
+ checkArgument(from != null && !from.isEmpty(), "The string to match must not be empty");
+ checkArgument(to != null && !to.isEmpty(), "The string replacement must not be empty");
+ return new BulkUpdateWsRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java
index 24154b93a2e..b7e71d43a3e 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsService.java
@@ -20,21 +20,26 @@
package org.sonarqube.ws.client.component;
import com.google.common.base.Joiner;
+import org.sonarqube.ws.WsComponents.BulkUpdateKeyWsResponse;
import org.sonarqube.ws.WsComponents.SearchWsResponse;
import org.sonarqube.ws.WsComponents.ShowWsResponse;
import org.sonarqube.ws.WsComponents.TreeWsResponse;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SHOW;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BASE_COMPONENT_KEY;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FROM;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ID;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_KEY;
+import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_NEW_KEY;
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.component.ComponentsWsParameters.PARAM_TO;
public class ComponentsService extends BaseService {
@@ -70,4 +75,23 @@ public class ComponentsService extends BaseService {
.setParam(PARAM_KEY, request.getKey());
return call(get, ShowWsResponse.parser());
}
+
+ public void updateKey(UpdateWsRequest request) {
+ PostRequest post = new PostRequest(path("update_key"))
+ .setParam(PARAM_ID, request.getId())
+ .setParam(PARAM_KEY, request.getKey())
+ .setParam(PARAM_NEW_KEY, request.getNewKey());
+
+ call(post);
+ }
+
+ public BulkUpdateKeyWsResponse bulkUpdateKey(BulkUpdateWsRequest request) {
+ PostRequest post = new PostRequest(path("bulk_update_key"))
+ .setParam(PARAM_ID, request.getId())
+ .setParam(PARAM_KEY, request.getKey())
+ .setParam(PARAM_FROM, request.getFrom())
+ .setParam(PARAM_TO, request.getTo());
+
+ return call(post, BulkUpdateKeyWsResponse.parser());
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
index b85fea13bbd..4ae95bf46b0 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/ComponentsWsParameters.java
@@ -20,20 +20,25 @@
package org.sonarqube.ws.client.component;
public class ComponentsWsParameters {
- private ComponentsWsParameters() {
- // static utility class
- }
-
- //actions
+ // actions
public static final String ACTION_TREE = "tree";
- public static final String ACTION_SHOW = "show";
+ public static final String ACTION_SHOW = "show";
// parameters
public static final String PARAM_QUALIFIERS = "qualifiers";
+
public static final String PARAM_LANGUAGE = "language";
public static final String PARAM_BASE_COMPONENT_ID = "baseComponentId";
public static final String PARAM_BASE_COMPONENT_KEY = "baseComponentKey";
public static final String PARAM_STRATEGY = "strategy";
public static final String PARAM_ID = "id";
public static final String PARAM_KEY = "key";
+ public static final String PARAM_NEW_KEY = "newKey";
+ public static final String PARAM_FROM = "from";
+ public static final String PARAM_TO = "to";
+ public static final String PARAM_DRY_RUN = "dryRun";
+
+ private ComponentsWsParameters() {
+ // static utility class
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/UpdateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/UpdateWsRequest.java
new file mode 100644
index 00000000000..b93d4892c93
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/UpdateWsRequest.java
@@ -0,0 +1,86 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.component;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class UpdateWsRequest {
+ private final String id;
+ private final String key;
+ private final String newKey;
+
+ public UpdateWsRequest(Builder builder) {
+ this.id = builder.id;
+ this.key = builder.key;
+ this.newKey = builder.newKey;
+ }
+
+ @CheckForNull
+ public String getId() {
+ return id;
+ }
+
+ @CheckForNull
+ public String getKey() {
+ return key;
+ }
+
+ public String getNewKey() {
+ return newKey;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String id;
+ private String key;
+ private String newKey;
+
+ private Builder() {
+ // enforce method constructor
+ }
+
+ public Builder setId(@Nullable String id) {
+ this.id = id;
+ return this;
+ }
+
+ public Builder setKey(@Nullable String key) {
+ this.key = key;
+ return this;
+ }
+
+ public Builder setNewKey(String newKey) {
+ this.newKey = newKey;
+ return this;
+ }
+
+ public UpdateWsRequest build() {
+ checkArgument(newKey != null && !newKey.isEmpty(), "The new key must not be empty");
+ return new UpdateWsRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java
index 6b2766e4527..080653b08b5 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/issue/IssuesService.java
@@ -56,6 +56,7 @@ import static org.sonarqube.ws.client.issue.IssueFilterParameters.SEVERITIES;
import static org.sonarqube.ws.client.issue.IssueFilterParameters.SINCE_LEAK_PERIOD;
import static org.sonarqube.ws.client.issue.IssueFilterParameters.STATUSES;
import static org.sonarqube.ws.client.issue.IssueFilterParameters.TAGS;
+import static org.sonarqube.ws.client.issue.IssueFilterParameters.TYPES;
public class IssuesService extends BaseService {
@@ -101,7 +102,8 @@ public class IssuesService extends BaseService {
.setParam(SEVERITIES, inlineMultipleParamValue(request.getSeverities()))
.setParam(SINCE_LEAK_PERIOD, request.getSinceLeakPeriod())
.setParam(STATUSES, inlineMultipleParamValue(request.getStatuses()))
- .setParam(TAGS, inlineMultipleParamValue(request.getTags())),
+ .setParam(TAGS, inlineMultipleParamValue(request.getTags()))
+ .setParam(TYPES, inlineMultipleParamValue(request.getTypes())),
SearchWsResponse.parser());
}
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesService.java
new file mode 100644
index 00000000000..93fb452ac0d
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesService.java
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.license;
+
+import org.sonarqube.ws.Licenses.ListWsResponse;
+import org.sonarqube.ws.client.BaseService;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.sonarqube.ws.client.license.LicensesWsParameters.ACTION_LIST;
+import static org.sonarqube.ws.client.license.LicensesWsParameters.CONTROLLER_SETTINGS;
+
+public class LicensesService extends BaseService {
+
+ public LicensesService(WsConnector wsConnector) {
+ super(wsConnector, CONTROLLER_SETTINGS);
+ }
+
+ public ListWsResponse list() {
+ GetRequest getRequest = new GetRequest(path(ACTION_LIST));
+ return call(getRequest, ListWsResponse.parser());
+ }
+
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesWsParameters.java
new file mode 100644
index 00000000000..a035f684519
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/license/LicensesWsParameters.java
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.license;
+
+public class LicensesWsParameters {
+ public static final String CONTROLLER_SETTINGS = "api/licenses";
+
+ public static final String ACTION_LIST = "list";
+
+ private LicensesWsParameters() {
+ // Only static stuff
+ }
+
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentTreeWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentTreeWsRequest.java
index 1d7322a486b..233eae10665 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentTreeWsRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentTreeWsRequest.java
@@ -102,12 +102,11 @@ public class ComponentTreeWsRequest {
return this;
}
- @CheckForNull
public List<String> getSort() {
return sort;
}
- public ComponentTreeWsRequest setSort(@Nullable List<String> sort) {
+ public ComponentTreeWsRequest setSort(List<String> sort) {
this.sort = sort;
return this;
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddProjectCreatorToTemplateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddProjectCreatorToTemplateWsRequest.java
new file mode 100644
index 00000000000..cbec95d29b0
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/AddProjectCreatorToTemplateWsRequest.java
@@ -0,0 +1,84 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.permission;
+
+import javax.annotation.CheckForNull;
+
+import static java.util.Objects.requireNonNull;
+
+public class AddProjectCreatorToTemplateWsRequest {
+ private final String templateId;
+ private final String templateName;
+ private final String permission;
+
+ public AddProjectCreatorToTemplateWsRequest(Builder builder) {
+ this.templateId = builder.templateId;
+ this.templateName = builder.templateName;
+ this.permission = requireNonNull(builder.permission);
+ }
+
+ @CheckForNull
+ public String getTemplateId() {
+ return templateId;
+ }
+
+ @CheckForNull
+ public String getTemplateName() {
+ return templateName;
+ }
+
+ public String getPermission() {
+ return permission;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String templateId;
+ private String templateName;
+ private String permission;
+
+ private Builder() {
+ // enforce method constructor
+ }
+
+ public Builder setTemplateId(String templateId) {
+ this.templateId = templateId;
+ return this;
+ }
+
+ public Builder setTemplateName(String templateName) {
+ this.templateName = templateName;
+ return this;
+ }
+
+ public Builder setPermission(String permission) {
+ this.permission = permission;
+ return this;
+ }
+
+ public AddProjectCreatorToTemplateWsRequest build() {
+ return new AddProjectCreatorToTemplateWsRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java
index 2cf3f674856..fe18bc20155 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/GroupsWsRequest.java
@@ -22,8 +22,6 @@ package org.sonarqube.ws.client.permission;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import static java.util.Objects.requireNonNull;
-
public class GroupsWsRequest {
private String permission;
private String projectId;
@@ -31,14 +29,14 @@ public class GroupsWsRequest {
private Integer page;
private Integer pageSize;
private String query;
- private String selected;
+ @CheckForNull
public String getPermission() {
return permission;
}
- public GroupsWsRequest setPermission(String permission) {
- this.permission = requireNonNull(permission, "permission must not be null");
+ public GroupsWsRequest setPermission(@Nullable String permission) {
+ this.permission = permission;
return this;
}
@@ -91,13 +89,4 @@ public class GroupsWsRequest {
this.query = query;
return this;
}
-
- public String getSelected() {
- return selected;
- }
-
- public GroupsWsRequest setSelected(String selected) {
- this.selected = requireNonNull(selected, "selected must not be null");
- return this;
- }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/OldUsersWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/OldUsersWsRequest.java
new file mode 100644
index 00000000000..d17f32d54e8
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/OldUsersWsRequest.java
@@ -0,0 +1,104 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.permission;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static java.util.Objects.requireNonNull;
+
+public class OldUsersWsRequest {
+ private String permission;
+ private String projectId;
+ private String projectKey;
+ private String selected;
+ private String query;
+ private Integer page;
+ private Integer pageSize;
+
+ public String getPermission() {
+ return permission;
+ }
+
+ public OldUsersWsRequest setPermission(String permission) {
+ this.permission = requireNonNull(permission);
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public OldUsersWsRequest setProjectId(@Nullable String projectId) {
+ this.projectId = projectId;
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectKey() {
+ return projectKey;
+ }
+
+ public OldUsersWsRequest setProjectKey(@Nullable String projectKey) {
+ this.projectKey = projectKey;
+ return this;
+ }
+
+ @CheckForNull
+ public String getSelected() {
+ return selected;
+ }
+
+ public OldUsersWsRequest setSelected(@Nullable String selected) {
+ this.selected = selected;
+ return this;
+ }
+
+ @CheckForNull
+ public String getQuery() {
+ return query;
+ }
+
+ public OldUsersWsRequest setQuery(@Nullable String query) {
+ this.query = query;
+ return this;
+ }
+
+ @CheckForNull
+ public Integer getPage() {
+ return page;
+ }
+
+ public OldUsersWsRequest setPage(int page) {
+ this.page = page;
+ return this;
+ }
+
+ @CheckForNull
+ public Integer getPageSize() {
+ return pageSize;
+ }
+
+ public OldUsersWsRequest setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ return this;
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsService.java
index 76a553792ea..a0a53cf8427 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsService.java
@@ -58,7 +58,6 @@ public class PermissionsService extends BaseService {
.setParam(PARAM_PROJECT_KEY, request.getProjectKey())
.setParam("p", request.getPage())
.setParam("ps", request.getPageSize())
- .setParam("selected", request.getSelected())
.setParam("q", request.getQuery());
return call(get, WsPermissions.WsGroupsResponse.parser());
}
@@ -97,6 +96,13 @@ public class PermissionsService extends BaseService {
.setParam(PARAM_TEMPLATE_NAME, request.getTemplateName()));
}
+ public void addProjectCreatorToTemplate(AddProjectCreatorToTemplateWsRequest request) {
+ call(new PostRequest(path("add_project_creator_to_template"))
+ .setParam(PARAM_PERMISSION, request.getPermission())
+ .setParam(PARAM_TEMPLATE_ID, request.getTemplateId())
+ .setParam(PARAM_TEMPLATE_NAME, request.getTemplateName()));
+ }
+
public void applyTemplate(ApplyTemplateWsRequest request) {
call(new PostRequest(path("apply_template"))
.setParam(PARAM_PROJECT_ID, request.getProjectId())
@@ -110,8 +116,7 @@ public class PermissionsService extends BaseService {
.setParam(PARAM_TEMPLATE_ID, request.getTemplateId())
.setParam(PARAM_TEMPLATE_NAME, request.getTemplateName())
.setParam("q", request.getQuery())
- .setParam(PARAM_QUALIFIER, request.getQualifier())
- );
+ .setParam(PARAM_QUALIFIER, request.getQualifier()));
}
public CreateTemplateWsResponse createTemplate(CreateTemplateWsRequest request) {
@@ -146,6 +151,14 @@ public class PermissionsService extends BaseService {
.setParam(PARAM_TEMPLATE_NAME, request.getTemplateName()));
}
+ public void removeProjectCreatorFromTemplate(RemoveProjectCreatorFromTemplateWsRequest request) {
+ call(
+ new PostRequest(path("remove_project_creator_from_template"))
+ .setParam(PARAM_PERMISSION, request.getPermission())
+ .setParam(PARAM_TEMPLATE_ID, request.getTemplateId())
+ .setParam(PARAM_TEMPLATE_NAME, request.getTemplateName()));
+ }
+
public void removeUser(RemoveUserWsRequest request) {
call(new PostRequest(path("remove_user"))
.setParam(PARAM_PERMISSION, request.getPermission())
@@ -204,7 +217,6 @@ public class PermissionsService extends BaseService {
.setParam(PARAM_PERMISSION, request.getPermission())
.setParam(PARAM_PROJECT_ID, request.getProjectId())
.setParam(PARAM_PROJECT_KEY, request.getProjectKey())
- .setParam("selected", request.getSelected())
.setParam("p", request.getPage())
.setParam("ps", request.getPageSize())
.setParam("q", request.getQuery()), UsersWsResponse.parser());
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/RemoveProjectCreatorFromTemplateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/RemoveProjectCreatorFromTemplateWsRequest.java
new file mode 100644
index 00000000000..7cb87736828
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/RemoveProjectCreatorFromTemplateWsRequest.java
@@ -0,0 +1,84 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.permission;
+
+import javax.annotation.CheckForNull;
+
+import static java.util.Objects.requireNonNull;
+
+public class RemoveProjectCreatorFromTemplateWsRequest {
+ private final String templateId;
+ private final String templateName;
+ private final String permission;
+
+ private RemoveProjectCreatorFromTemplateWsRequest(Builder builder) {
+ this.templateId = builder.templateId;
+ this.templateName = builder.templateName;
+ this.permission = requireNonNull(builder.permission);
+ }
+
+ @CheckForNull
+ public String getTemplateId() {
+ return templateId;
+ }
+
+ @CheckForNull
+ public String getTemplateName() {
+ return templateName;
+ }
+
+ public String getPermission() {
+ return permission;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String templateId;
+ private String templateName;
+ private String permission;
+
+ private Builder() {
+ // enforce method constructor
+ }
+
+ public Builder setTemplateId(String templateId) {
+ this.templateId = templateId;
+ return this;
+ }
+
+ public Builder setTemplateName(String templateName) {
+ this.templateName = templateName;
+ return this;
+ }
+
+ public Builder setPermission(String permission) {
+ this.permission = permission;
+ return this;
+ }
+
+ public RemoveProjectCreatorFromTemplateWsRequest build() {
+ return new RemoveProjectCreatorFromTemplateWsRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/UsersWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/UsersWsRequest.java
index 2abe8177969..390e6c49ee7 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/UsersWsRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/UsersWsRequest.java
@@ -22,23 +22,21 @@ package org.sonarqube.ws.client.permission;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import static java.util.Objects.requireNonNull;
-
public class UsersWsRequest {
private String permission;
private String projectId;
private String projectKey;
- private String selected;
private String query;
private Integer page;
private Integer pageSize;
+ @CheckForNull
public String getPermission() {
return permission;
}
- public UsersWsRequest setPermission(String permission) {
- this.permission = requireNonNull(permission);
+ public UsersWsRequest setPermission(@Nullable String permission) {
+ this.permission = permission;
return this;
}
@@ -63,16 +61,6 @@ public class UsersWsRequest {
}
@CheckForNull
- public String getSelected() {
- return selected;
- }
-
- public UsersWsRequest setSelected(@Nullable String selected) {
- this.selected = selected;
- return this;
- }
-
- @CheckForNull
public String getQuery() {
return query;
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/project/SearchMyProjectsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/SearchMyProjectsRequest.java
new file mode 100644
index 00000000000..b93f940e28a
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/SearchMyProjectsRequest.java
@@ -0,0 +1,82 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.project;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class SearchMyProjectsRequest {
+ private final String query;
+ private final Integer page;
+ private final Integer pageSize;
+
+ public SearchMyProjectsRequest(Builder builder) {
+ this.query = builder.query;
+ this.page = builder.page;
+ this.pageSize = builder.pageSize;
+ }
+
+ @CheckForNull
+ public String getQuery() {
+ return query;
+ }
+
+ public Integer getPage() {
+ return page;
+ }
+
+ public Integer getPageSize() {
+ return pageSize;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String query;
+ private Integer page;
+ private Integer pageSize;
+
+ private Builder() {
+ // enforce method constructor
+ }
+
+ public Builder setQuery(@Nullable String query) {
+ this.query = query;
+ return this;
+ }
+
+ public Builder setPage(Integer page) {
+ this.page = page;
+ return this;
+ }
+
+ public Builder setPageSize(Integer pageSize) {
+ this.pageSize = pageSize;
+ return this;
+ }
+
+ public SearchMyProjectsRequest build() {
+ return new SearchMyProjectsRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/CreateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/CreateWsRequest.java
new file mode 100644
index 00000000000..6d41e08e7a7
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/CreateWsRequest.java
@@ -0,0 +1,68 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.projectlinks;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class CreateWsRequest {
+ private String projectId;
+ private String projectKey;
+ private String name;
+ private String url;
+
+ @CheckForNull
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public CreateWsRequest setProjectId(@Nullable String projectId) {
+ this.projectId = projectId;
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectKey() {
+ return projectKey;
+ }
+
+ public CreateWsRequest setProjectKey(@Nullable String projectKey) {
+ this.projectKey = projectKey;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public CreateWsRequest setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public CreateWsRequest setUrl(String url) {
+ this.url = url;
+ return this;
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/DeleteWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/DeleteWsRequest.java
new file mode 100644
index 00000000000..843a79985cd
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/DeleteWsRequest.java
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.projectlinks;
+
+public class DeleteWsRequest {
+ private Long id;
+
+ public Long getId() {
+ return id;
+ }
+
+ public DeleteWsRequest setId(Long id) {
+ this.id = id;
+ return this;
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksService.java
new file mode 100644
index 00000000000..9e18e85043e
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksService.java
@@ -0,0 +1,64 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.projectlinks;
+
+import org.sonarqube.ws.WsProjectLinks.CreateWsResponse;
+import org.sonarqube.ws.WsProjectLinks.SearchWsResponse;
+import org.sonarqube.ws.client.BaseService;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.ACTION_CREATE;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.ACTION_DELETE;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.ACTION_SEARCH;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_ID;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_NAME;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_PROJECT_ID;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_PROJECT_KEY;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_URL;
+
+public class ProjectLinksService extends BaseService {
+
+ public ProjectLinksService(WsConnector wsConnector) {
+ super(wsConnector, "api/project_links");
+ }
+
+ public SearchWsResponse search(SearchWsRequest request) {
+ return call(new GetRequest(path(ACTION_SEARCH))
+ .setParam(PARAM_PROJECT_KEY, request.getProjectKey())
+ .setParam(PARAM_PROJECT_ID, request.getProjectId()),
+ SearchWsResponse.parser());
+ }
+
+ public CreateWsResponse create(CreateWsRequest request) {
+ return call(new PostRequest(path(ACTION_CREATE))
+ .setParam(PARAM_PROJECT_KEY, request.getProjectKey())
+ .setParam(PARAM_PROJECT_ID, request.getProjectId())
+ .setParam(PARAM_NAME, request.getName())
+ .setParam(PARAM_URL, request.getUrl()),
+ CreateWsResponse.parser());
+ }
+
+ public void delete(DeleteWsRequest request) {
+ call(new PostRequest(path(ACTION_DELETE))
+ .setParam(PARAM_ID, request.getId()));
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksWsParameters.java
new file mode 100644
index 00000000000..dfd2c38e869
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/ProjectLinksWsParameters.java
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.projectlinks;
+
+public class ProjectLinksWsParameters {
+
+ //actions
+ public static final String ACTION_SEARCH = "search";
+ public static final String ACTION_CREATE = "create";
+ public static final String ACTION_DELETE = "delete";
+
+ // parameters
+ public static final String PARAM_PROJECT_ID = "projectId";
+ public static final String PARAM_PROJECT_KEY = "projectKey";
+ public static final String PARAM_ID = "id";
+ public static final String PARAM_NAME = "name";
+ public static final String PARAM_URL = "url";
+
+ private ProjectLinksWsParameters() {
+ // static utility class
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/SearchWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/SearchWsRequest.java
new file mode 100644
index 00000000000..68ec36607d9
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/SearchWsRequest.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.projectlinks;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class SearchWsRequest {
+ @CheckForNull
+ private String projectId;
+ @CheckForNull
+ private String projectKey;
+
+ @CheckForNull
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public SearchWsRequest setProjectId(@Nullable String projectId) {
+ this.projectId = projectId;
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectKey() {
+ return projectKey;
+ }
+
+ public SearchWsRequest setProjectKey(@Nullable String projectKey) {
+ this.projectKey = projectKey;
+ return this;
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/package-info.java
new file mode 100644
index 00000000000..9c27157c46b
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectlinks/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.projectlinks;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesService.java
index bd00874f57a..fa8a57ab4b9 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesService.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesService.java
@@ -22,9 +22,11 @@ package org.sonarqube.ws.client.qualitygate;
import org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse;
import org.sonarqube.ws.client.BaseService;
import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsConnector;
import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_ANALYSIS_ID;
+import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_GATE_ID;
import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_KEY;
@@ -41,4 +43,11 @@ public class QualityGatesService extends BaseService {
.setParam(PARAM_PROJECT_KEY, request.getProjectKey()),
ProjectStatusWsResponse.parser());
}
+
+ public void associateProject(SelectWsRequest request) {
+ call(new PostRequest(path("select"))
+ .setParam(PARAM_GATE_ID, request.getGateId())
+ .setParam(PARAM_PROJECT_ID, request.getProjectId())
+ .setParam(PARAM_PROJECT_KEY, request.getProjectKey()));
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesWsParameters.java
index 5ba885b3dd3..e01d58e7b70 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesWsParameters.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/QualityGatesWsParameters.java
@@ -24,6 +24,17 @@ public class QualityGatesWsParameters {
public static final String PARAM_ANALYSIS_ID = "analysisId";
public static final String PARAM_PROJECT_ID = "projectId";
public static final String PARAM_PROJECT_KEY = "projectKey";
+ public static final String PARAM_PAGE_SIZE = "pageSize";
+ public static final String PARAM_PAGE = "page";
+ public static final String PARAM_QUERY = "query";
+ public static final String PARAM_NAME = "name";
+ public static final String PARAM_ERROR = "error";
+ public static final String PARAM_WARNING = "warning";
+ public static final String PARAM_PERIOD = "period";
+ public static final String PARAM_OPERATOR = "op";
+ public static final String PARAM_METRIC = "metric";
+ public static final String PARAM_GATE_ID = "gateId";
+ public static final String PARAM_ID = "id";
private QualityGatesWsParameters() {
// prevent instantiation
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/SelectWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/SelectWsRequest.java
new file mode 100644
index 00000000000..a81f5e3f253
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygate/SelectWsRequest.java
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.qualitygate;
+
+import javax.annotation.CheckForNull;
+
+public class SelectWsRequest {
+ private long gateId;
+ private String projectId;
+ private String projectKey;
+
+ public long getGateId() {
+ return gateId;
+ }
+
+ public SelectWsRequest setGateId(long gateId) {
+ this.gateId = gateId;
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public SelectWsRequest setProjectId(String projectId) {
+ this.projectId = projectId;
+ return this;
+ }
+
+ @CheckForNull
+ public String getProjectKey() {
+ return projectKey;
+ }
+
+ public SelectWsRequest setProjectKey(String projectKey) {
+ this.projectKey = projectKey;
+ return this;
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/serverid/GenerateRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/serverid/GenerateRequest.java
new file mode 100644
index 00000000000..57b29d62b15
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/serverid/GenerateRequest.java
@@ -0,0 +1,70 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.serverid;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class GenerateRequest {
+ private final String organization;
+ private final String ip;
+
+ public GenerateRequest(Builder builder) {
+ this.organization = builder.organization;
+ this.ip = builder.ip;
+ }
+
+ public String getOrganization() {
+ return organization;
+ }
+
+ public String getIp() {
+ return ip;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String organization;
+ private String ip;
+
+ private Builder() {
+ // enforce static constructor
+ }
+
+ public Builder setOrganization(String organization) {
+ this.organization = organization;
+ return this;
+ }
+
+ public Builder setIp(String ip) {
+ this.ip = ip;
+ return this;
+ }
+
+ public GenerateRequest build() {
+ checkArgument(organization != null && !organization.isEmpty(), "Organization must not be null or empty");
+ checkArgument(ip != null && !ip.isEmpty(), "IP must not be null or empty");
+ return new GenerateRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/serverid/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/serverid/package-info.java
new file mode 100644
index 00000000000..2ea55636428
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/serverid/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.serverid;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ListDefinitionsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ListDefinitionsRequest.java
new file mode 100644
index 00000000000..bace689f91a
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ListDefinitionsRequest.java
@@ -0,0 +1,73 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class ListDefinitionsRequest {
+
+ private final String componentId;
+ private final String componentKey;
+
+ private ListDefinitionsRequest(Builder builder) {
+ this.componentId = builder.componentId;
+ this.componentKey = builder.componentKey;
+ }
+
+ @CheckForNull
+ public String getComponentId() {
+ return componentId;
+ }
+
+ @CheckForNull
+ public String getComponentKey() {
+ return componentKey;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String componentId;
+ private String componentKey;
+
+ private Builder() {
+ // enforce factory method use
+ }
+
+ public Builder setComponentId(@Nullable String componentId) {
+ this.componentId = componentId;
+ return this;
+ }
+
+ public Builder setComponentKey(@Nullable String componentKey) {
+ this.componentKey = componentKey;
+ return this;
+ }
+
+ public ListDefinitionsRequest build() {
+ return new ListDefinitionsRequest(this);
+ }
+ }
+
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ResetRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ResetRequest.java
new file mode 100644
index 00000000000..e999dde79b9
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ResetRequest.java
@@ -0,0 +1,93 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Arrays.asList;
+
+public class ResetRequest {
+ private final List<String> keys;
+ private final String componentId;
+ private final String componentKey;
+
+ public ResetRequest(Builder builder) {
+ this.keys = builder.keys;
+ this.componentId = builder.componentId;
+ this.componentKey = builder.componentKey;
+ }
+
+ public List<String> getKeys() {
+ return keys;
+ }
+
+ @CheckForNull
+ public String getComponentId() {
+ return componentId;
+ }
+
+ @CheckForNull
+ public String getComponentKey() {
+ return componentKey;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private List<String> keys;
+ private String componentId;
+ private String componentKey;
+
+ private Builder() {
+ // enforce factory method use
+ }
+
+ public Builder setKeys(List<String> keys) {
+ this.keys = keys;
+ return this;
+ }
+
+ public Builder setKeys(String... keys) {
+ setKeys(asList(keys));
+ return this;
+ }
+
+ public Builder setComponentId(@Nullable String componentId) {
+ this.componentId = componentId;
+ return this;
+ }
+
+ public Builder setComponentKey(@Nullable String componentKey) {
+ this.componentKey = componentKey;
+ return this;
+ }
+
+ public ResetRequest build() {
+ checkArgument(keys != null && !keys.isEmpty(), "Setting keys is mandatory and must not be empty.");
+ return new ResetRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SetRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SetRequest.java
new file mode 100644
index 00000000000..d427fd0d9e1
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SetRequest.java
@@ -0,0 +1,127 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Collections.emptyList;
+
+public class SetRequest {
+ private final String key;
+ private final String value;
+ private final List<String> values;
+ private final List<String> fieldValues;
+ private final String componentId;
+ private final String componentKey;
+
+ public SetRequest(Builder builder) {
+ this.key = builder.key;
+ this.value = builder.value;
+ this.values = builder.values;
+ this.fieldValues = builder.fieldValues;
+ this.componentId = builder.componentId;
+ this.componentKey = builder.componentKey;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ @CheckForNull
+ public String getValue() {
+ return value;
+ }
+
+ public List<String> getValues() {
+ return values;
+ }
+
+ public List<String> getFieldValues() {
+ return fieldValues;
+ }
+
+ @CheckForNull
+ public String getComponentId() {
+ return componentId;
+ }
+
+ @CheckForNull
+ public String getComponentKey() {
+ return componentKey;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String key;
+ private String value;
+ private List<String> values = emptyList();
+ private List<String> fieldValues = emptyList();
+ private String componentId;
+ private String componentKey;
+
+ private Builder() {
+ // enforce factory method use
+ }
+
+ public Builder setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public Builder setValue(@Nullable String value) {
+ this.value = value;
+ return this;
+ }
+
+ public Builder setValues(List<String> values) {
+ this.values = values;
+ return this;
+ }
+
+ public Builder setFieldValues(List<String> fieldValues) {
+ this.fieldValues = fieldValues;
+ return this;
+ }
+
+ public Builder setComponentId(@Nullable String componentId) {
+ this.componentId = componentId;
+ return this;
+ }
+
+ public Builder setComponentKey(@Nullable String componentKey) {
+ this.componentKey = componentKey;
+ return this;
+ }
+
+ public SetRequest build() {
+ checkArgument(key != null && !key.isEmpty(), "Setting key is mandatory and must not be empty");
+ checkArgument(values != null, "Setting values must not be null");
+ checkArgument(fieldValues != null, "Setting fields values must not be null");
+ return new SetRequest(this);
+ }
+ }
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsService.java
new file mode 100644
index 00000000000..bdc9453aba1
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsService.java
@@ -0,0 +1,79 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import org.sonarqube.ws.Settings.ListDefinitionsWsResponse;
+import org.sonarqube.ws.Settings.ValuesWsResponse;
+import org.sonarqube.ws.client.BaseService;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_ID;
+import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT_KEY;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_LIST_DEFINITIONS;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_RESET;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_SET;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.ACTION_VALUES;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.CONTROLLER_SETTINGS;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_FIELD_VALUES;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEY;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEYS;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_VALUE;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_VALUES;
+
+public class SettingsService extends BaseService {
+ public SettingsService(WsConnector wsConnector) {
+ super(wsConnector, CONTROLLER_SETTINGS);
+ }
+
+ public ListDefinitionsWsResponse listDefinitions(ListDefinitionsRequest request) {
+ GetRequest getRequest = new GetRequest(path(ACTION_LIST_DEFINITIONS))
+ .setParam(PARAM_COMPONENT_ID, request.getComponentId())
+ .setParam(PARAM_COMPONENT_KEY, request.getComponentKey());
+ return call(getRequest, ListDefinitionsWsResponse.parser());
+ }
+
+ public ValuesWsResponse values(ValuesRequest request) {
+ GetRequest getRequest = new GetRequest(path(ACTION_VALUES))
+ .setParam(PARAM_KEYS, inlineMultipleParamValue(request.getKeys()))
+ .setParam(PARAM_COMPONENT_ID, request.getComponentId())
+ .setParam(PARAM_COMPONENT_KEY, request.getComponentKey());
+ return call(getRequest, ValuesWsResponse.parser());
+ }
+
+ public void set(SetRequest request) {
+ call(new PostRequest(path(ACTION_SET))
+ .setParam(PARAM_KEY, request.getKey())
+ .setParam(PARAM_VALUE, request.getValue())
+ .setParam(PARAM_VALUES, request.getValues())
+ .setParam(PARAM_FIELD_VALUES, request.getFieldValues())
+ .setParam(PARAM_COMPONENT_ID, request.getComponentId())
+ .setParam(PARAM_COMPONENT_KEY, request.getComponentKey()));
+ }
+
+ public void reset(ResetRequest request) {
+ call(new PostRequest(path(ACTION_RESET))
+ .setParam(PARAM_KEYS, inlineMultipleParamValue(request.getKeys()))
+ .setParam(PARAM_COMPONENT_ID, request.getComponentId())
+ .setParam(PARAM_COMPONENT_KEY, request.getComponentKey()));
+ }
+
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsWsParameters.java
new file mode 100644
index 00000000000..85e4da4e300
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/SettingsWsParameters.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+public class SettingsWsParameters {
+ public static final String CONTROLLER_SETTINGS = "api/settings";
+
+ public static final String ACTION_LIST_DEFINITIONS = "list_definitions";
+ public static final String ACTION_VALUES = "values";
+ public static final String ACTION_SET = "set";
+ public static final String ACTION_RESET = "reset";
+
+ public static final String PARAM_COMPONENT_ID = "componentId";
+ public static final String PARAM_COMPONENT_KEY = "componentKey";
+ public static final String PARAM_KEYS = "keys";
+ public static final String PARAM_KEY = "key";
+ public static final String PARAM_VALUE = "value";
+ public static final String PARAM_VALUES = "values";
+ public static final String PARAM_FIELD_VALUES = "fieldValues";
+
+ private SettingsWsParameters() {
+ // Only static stuff
+ }
+
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ValuesRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ValuesRequest.java
new file mode 100644
index 00000000000..3c1d8d212a3
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/ValuesRequest.java
@@ -0,0 +1,97 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Arrays.asList;
+import static java.util.Objects.requireNonNull;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEYS;
+
+public class ValuesRequest {
+
+ private final String componentId;
+ private final String componentKey;
+ private final List<String> keys;
+
+ public ValuesRequest(Builder builder) {
+ this.componentId = builder.componentId;
+ this.componentKey = builder.componentKey;
+ this.keys = builder.keys;
+ }
+
+ @CheckForNull
+ public String getComponentId() {
+ return componentId;
+ }
+
+ @CheckForNull
+ public String getComponentKey() {
+ return componentKey;
+ }
+
+ public List<String> getKeys() {
+ return keys;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private String componentId;
+ private String componentKey;
+ private List<String> keys = new ArrayList<>();
+
+ private Builder() {
+ // enforce factory method use
+ }
+
+ public Builder setComponentId(@Nullable String componentId) {
+ this.componentId = componentId;
+ return this;
+ }
+
+ public Builder setComponentKey(@Nullable String componentKey) {
+ this.componentKey = componentKey;
+ return this;
+ }
+
+ public Builder setKeys(List<String> keys) {
+ this.keys = requireNonNull(keys);
+ return this;
+ }
+
+ public Builder setKeys(String... keys) {
+ return setKeys(asList(keys));
+ }
+
+ public ValuesRequest build() {
+ checkArgument(!keys.isEmpty(), "'%s' cannot be empty", PARAM_KEYS);
+ return new ValuesRequest(this);
+ }
+ }
+
+}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/package-info.java
new file mode 100644
index 00000000000..f4575065bee
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/setting/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/sonar-ws/src/main/protobuf/ws-ce.proto b/sonar-ws/src/main/protobuf/ws-ce.proto
index 4440851e45a..36bc39fbaea 100644
--- a/sonar-ws/src/main/protobuf/ws-ce.proto
+++ b/sonar-ws/src/main/protobuf/ws-ce.proto
@@ -77,6 +77,10 @@ message Task {
optional bool isLastExecuted = 13;
optional int64 executionTimeMs = 14;
optional bool logs = 15;
+ optional string errorMessage = 16;
+ optional string errorStacktrace = 17;
+ optional string scannerContext = 18;
+ optional bool hasScannerContext = 19;
}
enum TaskStatus {
diff --git a/sonar-ws/src/main/protobuf/ws-components.proto b/sonar-ws/src/main/protobuf/ws-components.proto
index 128ade44c99..a14966e8acd 100644
--- a/sonar-ws/src/main/protobuf/ws-components.proto
+++ b/sonar-ws/src/main/protobuf/ws-components.proto
@@ -46,6 +46,17 @@ message ShowWsResponse {
repeated Component ancestors = 3;
}
+// WS api/components/prepare_bulk_update_key
+message BulkUpdateKeyWsResponse {
+ repeated Key keys = 1;
+
+ message Key {
+ optional string key = 1;
+ optional string newKey = 2;
+ optional bool duplicate = 3;
+ }
+}
+
message Component {
optional string id = 1;
optional string key = 2;
diff --git a/sonar-ws/src/main/protobuf/ws-licenses.proto b/sonar-ws/src/main/protobuf/ws-licenses.proto
new file mode 100644
index 00000000000..72bf937010c
--- /dev/null
+++ b/sonar-ws/src/main/protobuf/ws-licenses.proto
@@ -0,0 +1,52 @@
+// SonarQube, open source software quality management tool.
+// Copyright (C) 2008-2015 SonarSource
+// mailto:contact AT sonarsource DOT com
+//
+// SonarQube 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.
+//
+// SonarQube 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.
+
+syntax = "proto2";
+
+package sonarqube.ws.licenses;
+
+option java_package = "org.sonarqube.ws";
+option java_outer_classname = "Licenses";
+option optimize_for = SPEED;
+
+// Response of GET api/licenses/list
+message ListWsResponse {
+ repeated License licenses = 1;
+}
+
+message License {
+ optional string key = 1;
+ optional string name = 2;
+ optional string value = 3;
+ optional string product = 4;
+ optional string organization = 5;
+ optional string expiration = 6;
+ optional string serverId = 7;
+ optional string type = 8;
+ optional AdditionalProperties additionalProperties = 9;
+ optional bool invalidProduct = 10;
+ optional bool invalidExpiration = 11;
+ optional bool invalidServerId = 12;
+}
+
+message AdditionalProperties {
+ map<string, string> additionalProperties = 1;
+}
+
+
+
diff --git a/sonar-ws/src/main/protobuf/ws-permissions.proto b/sonar-ws/src/main/protobuf/ws-permissions.proto
index 6c27cc37f0d..3f9a31372ff 100644
--- a/sonar-ws/src/main/protobuf/ws-permissions.proto
+++ b/sonar-ws/src/main/protobuf/ws-permissions.proto
@@ -26,20 +26,30 @@ option java_package = "org.sonarqube.ws";
option java_outer_classname = "WsPermissions";
option optimize_for = SPEED;
+// WS api/permissions/template_users for internal use only
+message OldUsersWsResponse {
+ optional sonarqube.ws.commons.Paging paging = 1;
+ repeated OldUser users = 2;
+}
+
// WS api/permissions/users for internal use only
-// and WS api/permissions/template_users for internal use only
message UsersWsResponse {
optional sonarqube.ws.commons.Paging paging = 1;
repeated User users = 2;
}
// WS api/permissions/groups for internal use only
-// and WS api/permissions/template_groups for internal use only
message WsGroupsResponse {
optional sonarqube.ws.commons.Paging paging = 1;
repeated Group groups = 2;
}
+// WS api/permissions/template_groups for internal use only
+message WsTemplateGroupsResponse {
+ optional sonarqube.ws.commons.Paging paging = 1;
+ repeated OldGroup groups = 2;
+}
+
message WsSearchGlobalPermissionsResponse {
repeated Permission permissions = 1;
}
@@ -83,6 +93,7 @@ message Permission {
optional string description = 3;
optional int32 usersCount = 4;
optional int32 groupsCount = 5;
+ optional bool withProjectCreator = 6;
}
message PermissionTemplate {
@@ -97,10 +108,24 @@ message PermissionTemplate {
repeated Permission permissions = 7;
}
+message OldUser {
+ optional string login = 1;
+ optional string name = 2;
+ optional string email = 3;
+ optional bool selected = 4;
+}
+
message User {
optional string login = 1;
optional string name = 2;
optional string email = 3;
+ repeated string permissions = 4;
+}
+
+message OldGroup {
+ optional string id = 1;
+ optional string name = 2;
+ optional string description = 3;
optional bool selected = 4;
}
@@ -108,5 +133,5 @@ message Group {
optional string id = 1;
optional string name = 2;
optional string description = 3;
- optional bool selected = 4;
+ repeated string permissions = 4;
}
diff --git a/sonar-ws/src/main/protobuf/ws-projectlink.proto b/sonar-ws/src/main/protobuf/ws-projectlink.proto
new file mode 100644
index 00000000000..073b3e498b0
--- /dev/null
+++ b/sonar-ws/src/main/protobuf/ws-projectlink.proto
@@ -0,0 +1,23 @@
+syntax = "proto2";
+
+package sonarqube.ws.projectlink;
+
+option java_package = "org.sonarqube.ws";
+option java_outer_classname = "WsProjectLinks";
+option optimize_for = SPEED;
+
+// WS api/project_links/list
+message SearchWsResponse {
+ repeated Link links = 1;
+}
+
+message CreateWsResponse {
+ optional Link link = 1;
+}
+
+message Link {
+ optional string id = 1;
+ optional string name = 2;
+ optional string type = 3;
+ optional string url = 4;
+} \ No newline at end of file
diff --git a/sonar-ws/src/main/protobuf/ws-projects.proto b/sonar-ws/src/main/protobuf/ws-projects.proto
new file mode 100644
index 00000000000..df62d112ce9
--- /dev/null
+++ b/sonar-ws/src/main/protobuf/ws-projects.proto
@@ -0,0 +1,48 @@
+// SonarQube, open source software quality management tool.
+// Copyright (C) 2008-2015 SonarSource
+// mailto:contact AT sonarsource DOT com
+//
+// SonarQube 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.
+//
+// SonarQube 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.
+
+syntax = "proto2";
+
+package sonarqube.ws.projects;
+
+import "ws-commons.proto";
+
+option java_package = "org.sonarqube.ws";
+option java_outer_classname = "WsProjects";
+option optimize_for = SPEED;
+
+message SearchMyProjectsWsResponse {
+ message Project {
+ optional string id = 1;
+ optional string key = 2;
+ optional string name = 4;
+ optional string description = 5;
+ optional string lastAnalysisDate = 6;
+ optional string qualityGate = 7;
+ repeated Link links = 8;
+ }
+
+ message Link {
+ optional string name = 1;
+ optional string type = 2;
+ optional string href = 3;
+ }
+
+ optional sonarqube.ws.commons.Paging paging = 1;
+ repeated Project projects = 2;
+}
diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto
index 57e867e767d..514a5341a37 100644
--- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto
+++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto
@@ -65,3 +65,14 @@ message ProjectStatusWsResponse {
NE = 4;
}
}
+
+// GET api/qualitygates/get_by_project
+message GetByProjectWsResponse {
+ optional QualityGate qualityGate = 1;
+}
+
+message QualityGate {
+ optional string id = 1;
+ optional string name = 2;
+ optional bool default = 3;
+}
diff --git a/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto b/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto
index 7ec0752759a..0829180d46d 100644
--- a/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto
+++ b/sonar-ws/src/main/protobuf/ws-qualityprofiles.proto
@@ -38,7 +38,10 @@ message SearchWsResponse {
optional string parentName = 7;
optional bool isDefault = 8;
optional int64 activeRuleCount = 9;
+ optional int64 activeDeprecatedRuleCount = 12;
optional int64 projectCount = 10;
optional string rulesUpdatedAt = 11;
+ optional string lastUsed = 13;
+ optional string userUpdatedAt = 14;
}
}
diff --git a/sonar-ws/src/main/protobuf/ws-serverid.proto b/sonar-ws/src/main/protobuf/ws-serverid.proto
new file mode 100644
index 00000000000..855a93889de
--- /dev/null
+++ b/sonar-ws/src/main/protobuf/ws-serverid.proto
@@ -0,0 +1,39 @@
+// SonarQube, open source software quality management tool.
+// Copyright (C) 2008-2015 SonarSource
+// mailto:contact AT sonarsource DOT com
+//
+// SonarQube 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.
+//
+// SonarQube 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.
+
+syntax = "proto2";
+
+package sonarqube.ws.serverid;
+
+option java_package = "org.sonarqube.ws";
+option java_outer_classname = "ServerId";
+option optimize_for = SPEED;
+
+// Response of GET api/server_id/show
+message ShowWsResponse {
+ optional string serverId = 1;
+ optional string organization = 2;
+ optional string ip = 3;
+ repeated string validIpAddresses = 4;
+ optional bool invalidServerId = 5;
+}
+
+// Response of POST api/server_id/generate
+message GenerateWsResponse {
+ optional string serverId = 1;
+}
diff --git a/sonar-ws/src/main/protobuf/ws-settings.proto b/sonar-ws/src/main/protobuf/ws-settings.proto
new file mode 100644
index 00000000000..df8e36059b5
--- /dev/null
+++ b/sonar-ws/src/main/protobuf/ws-settings.proto
@@ -0,0 +1,115 @@
+// SonarQube, open source software quality management tool.
+// Copyright (C) 2008-2015 SonarSource
+// mailto:contact AT sonarsource DOT com
+//
+// SonarQube 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.
+//
+// SonarQube 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.
+
+syntax = "proto2";
+
+package sonarqube.ws.settings;
+
+option java_package = "org.sonarqube.ws";
+option java_outer_classname = "Settings";
+option optimize_for = SPEED;
+
+// Response of GET api/settings/list_definitions
+message ListDefinitionsWsResponse {
+ repeated Definition definitions = 1;
+}
+
+// Response of GET api/settings/encrypt
+message EncryptWsResponse {
+ optional string encryptedValue = 1;
+}
+
+// Response of GET api/settings/generate_secret_key
+message GenerateSecretKeyWsResponse {
+ optional string secretKey = 1;
+}
+
+// Response of GET api/settings/check_secret_key
+message CheckSecretKeyWsResponse {
+ optional bool secretKeyAvailable = 1;
+}
+
+message Definition {
+ optional string key = 1;
+ optional string name = 2;
+ optional string description = 3;
+ optional Type type = 4;
+ optional string category = 5;
+ optional string subCategory = 6;
+ optional string defaultValue = 7;
+ optional bool multiValues = 8;
+ repeated string options = 9;
+ repeated Field fields = 10;
+ optional string deprecatedKey = 11;
+}
+
+message Field {
+ optional string key = 1;
+ optional string name = 2;
+ optional string description = 3;
+ optional Type type = 4;
+ repeated string options = 5;
+}
+
+enum Type {
+ STRING = 0;
+ TEXT = 1;
+ PASSWORD = 2;
+ BOOLEAN = 3;
+ INTEGER = 4;
+ FLOAT = 5;
+ LONG = 6;
+ REGULAR_EXPRESSION = 7;
+ METRIC = 8;
+ USER_LOGIN = 9;
+ METRIC_LEVEL = 10;
+ SINGLE_SELECT_LIST = 11;
+ PROPERTY_SET = 12;
+ LICENSE = 13;
+}
+
+// Response of GET api/settings/values
+message ValuesWsResponse {
+ repeated Setting settings = 1;
+}
+
+message Setting {
+ optional string key = 1;
+ optional string value = 2;
+ optional Values values = 3;
+ optional FieldValues fieldValues = 4;
+ optional bool inherited = 5;
+ optional string parentValue = 6;
+ optional Values parentValues = 7;
+ optional FieldValues parentFieldValues = 8;
+}
+
+message Values {
+ repeated string values = 1;
+}
+
+message FieldValues {
+ repeated Value fieldValues = 1;
+
+ message Value {
+ map<string, string> value = 1;
+ }
+}
+
+
+
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/BaseRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/BaseRequestTest.java
index 50c74985e92..ce2f0ad45f9 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/BaseRequestTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/BaseRequestTest.java
@@ -19,11 +19,17 @@
*/
package org.sonarqube.ws.client;
+import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
+import java.util.List;
+import org.assertj.core.data.MapEntry;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonarqube.ws.MediaTypes;
+import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.MapEntry.entry;
@@ -51,17 +57,36 @@ public class BaseRequestTest {
@Test
public void keep_order_of_params() {
assertThat(underTest.getParams()).isEmpty();
+ assertThat(underTest.getParameters().getKeys()).isEmpty();
underTest.setParam("keyB", "b");
assertThat(underTest.getParams()).containsExactly(entry("keyB", "b"));
+ assertParameters(entry("keyB", "b"));
+ assertMultiValueParameters(entry("keyB", singletonList("b")));
underTest.setParam("keyA", "a");
assertThat(underTest.getParams()).containsExactly(entry("keyB", "b"), entry("keyA", "a"));
+ assertParameters(entry("keyB", "b"), entry("keyA", "a"));
+ assertMultiValueParameters(entry("keyB", singletonList("b")), entry("keyA", singletonList("a")));
+
+ underTest.setParam("keyC", ImmutableList.of("c1", "c2", "c3"));
+ assertParameters(entry("keyB", "b"), entry("keyA", "a"), entry("keyC", "c1"));
+ assertMultiValueParameters(
+ entry("keyB", singletonList("b")),
+ entry("keyA", singletonList("a")),
+ entry("keyC", ImmutableList.of("c1", "c2", "c3")));
+ }
+
+ @Test
+ public void skip_null_value_in_multi_param() {
+ underTest.setParam("key", newArrayList("v1", null, "v3"));
+
}
@Test
public void null_param_value() {
- underTest.setParam("key", null);
+ Boolean nullBool = null;
+ underTest.setParam("key", nullBool);
assertThat(underTest.getParams()).isEmpty();
}
@@ -71,6 +96,20 @@ public class BaseRequestTest {
underTest.setParam(null, "val");
}
+ private void assertParameters(MapEntry<String, String>... values) {
+ Parameters parameters = underTest.getParameters();
+ assertThat(parameters.getKeys()).extracting(key -> MapEntry.entry(key, parameters.getValue(key))).containsExactly(values);
+ }
+
+ private void assertMultiValueParameters(MapEntry<String, List<String>>... expectedParameters) {
+ Parameters parameters = underTest.getParameters();
+ String[] expectedKeys = Arrays.stream(expectedParameters).map(MapEntry::getKey).toArray(String[]::new);
+ assertThat(parameters.getKeys()).containsExactly(expectedKeys);
+ Arrays.stream(expectedParameters).forEach(expectedParameter -> {
+ assertThat(parameters.getValues(expectedParameter.getKey())).containsExactly(expectedParameter.getValue().toArray(new String[0]));
+ });
+ }
+
private static class FakeRequest extends BaseRequest<FakeRequest> {
FakeRequest(String path) {
super(path);
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/BaseServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/BaseServiceTest.java
index e7e0a43dc2d..5b1b8d411ae 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/BaseServiceTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/BaseServiceTest.java
@@ -74,7 +74,7 @@ public class BaseServiceTest {
public void test() {
GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC");
- when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo"));
+ when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo").setContent("error"));
try {
call(get, Testing.Fake.parser());
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java
index 3df29b05672..527fcc5bf27 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java
@@ -19,13 +19,13 @@
*/
package org.sonarqube.ws.client;
-import com.squareup.okhttp.ConnectionSpec;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-import com.squareup.okhttp.mockwebserver.RecordedRequest;
import java.io.File;
import java.util.List;
import javax.net.ssl.SSLSocketFactory;
+import okhttp3.ConnectionSpec;
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import okhttp3.mockwebserver.RecordedRequest;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
@@ -36,11 +36,10 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonarqube.ws.MediaTypes;
-import static com.squareup.okhttp.Credentials.basic;
+import static okhttp3.Credentials.basic;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.sonarqube.ws.client.HttpConnector.newBuilder;
public class HttpConnectorTest {
@@ -50,7 +49,6 @@ public class HttpConnectorTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- HttpConnector.JavaVersion javaVersion = mock(HttpConnector.JavaVersion.class);
MockWebServer server;
String serverUrl;
@@ -72,8 +70,8 @@ public class HttpConnectorTest {
WsResponse response = underTest.call(request);
// verify default timeouts on client
- assertThat(underTest.okHttpClient().getConnectTimeout()).isEqualTo(HttpConnector.DEFAULT_CONNECT_TIMEOUT_MILLISECONDS);
- assertThat(underTest.okHttpClient().getReadTimeout()).isEqualTo(HttpConnector.DEFAULT_READ_TIMEOUT_MILLISECONDS);
+ assertThat(underTest.okHttpClient().connectTimeoutMillis()).isEqualTo(HttpConnector.DEFAULT_CONNECT_TIMEOUT_MILLISECONDS);
+ assertThat(underTest.okHttpClient().readTimeoutMillis()).isEqualTo(HttpConnector.DEFAULT_READ_TIMEOUT_MILLISECONDS);
// verify response
assertThat(response.hasContent()).isTrue();
@@ -162,8 +160,8 @@ public class HttpConnectorTest {
.connectTimeoutMilliseconds(74)
.build();
- assertThat(underTest.okHttpClient().getReadTimeout()).isEqualTo(42);
- assertThat(underTest.okHttpClient().getConnectTimeout()).isEqualTo(74);
+ assertThat(underTest.okHttpClient().readTimeoutMillis()).isEqualTo(42);
+ assertThat(underTest.okHttpClient().connectTimeoutMillis()).isEqualTo(74);
}
@Test
@@ -281,26 +279,15 @@ public class HttpConnectorTest {
}
@Test
- public void support_tls_1_2_on_java7() {
- when(javaVersion.isJava7()).thenReturn(true);
- underTest = HttpConnector.newBuilder().url(serverUrl).build(javaVersion);
-
- assertTlsAndClearTextSpecifications(underTest);
- // enable TLS 1.0, 1.1 and 1.2
- assertThat(underTest.okHttpClient().getSslSocketFactory()).isNotNull().isInstanceOf(Tls12Java7SocketFactory.class);
- }
-
- @Test
public void support_tls_versions_of_java8() {
- when(javaVersion.isJava7()).thenReturn(false);
- underTest = HttpConnector.newBuilder().url(serverUrl).build(javaVersion);
+ underTest = HttpConnector.newBuilder().url(serverUrl).build();
assertTlsAndClearTextSpecifications(underTest);
- assertThat(underTest.okHttpClient().getSslSocketFactory()).isInstanceOf(SSLSocketFactory.getDefault().getClass());
+ assertThat(underTest.okHttpClient().sslSocketFactory()).isInstanceOf(SSLSocketFactory.getDefault().getClass());
}
private void assertTlsAndClearTextSpecifications(HttpConnector underTest) {
- List<ConnectionSpec> connectionSpecs = underTest.okHttpClient().getConnectionSpecs();
+ List<ConnectionSpec> connectionSpecs = underTest.okHttpClient().connectionSpecs();
assertThat(connectionSpecs).hasSize(2);
// TLS. tlsVersions()==null means all TLS versions
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpExceptionTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpExceptionTest.java
index 17ed590f744..c379a4f8851 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpExceptionTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/HttpExceptionTest.java
@@ -26,9 +26,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class HttpExceptionTest {
@Test
public void test_exception() throws Exception {
- HttpException exception = new HttpException("http://localhost:9000/api/search", 500);
+ HttpException exception = new HttpException("http://localhost:9000/api/search", 500, "error");
assertThat(exception.code()).isEqualTo(500);
assertThat(exception.url()).isEqualTo("http://localhost:9000/api/search");
- assertThat(exception.getMessage()).isEqualTo("Error 500 on http://localhost:9000/api/search");
+ assertThat(exception.getMessage()).isEqualTo("Error 500 on http://localhost:9000/api/search : error");
}
}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/ServiceTester.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/ServiceTester.java
index 13d633ec1ec..06f41cd38ac 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/ServiceTester.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/ServiceTester.java
@@ -19,6 +19,7 @@
*/
package org.sonarqube.ws.client;
+import com.google.common.base.Joiner;
import com.google.protobuf.Parser;
import java.util.ArrayList;
import java.util.List;
@@ -88,6 +89,8 @@ import static org.mockito.Mockito.spy;
*
*/
public class ServiceTester<T extends BaseService> extends ExternalResource {
+ private static final Joiner COMMA_JOINER = Joiner.on(",");
+
private final T underTest;
private final List<GetCall> getCalls = new ArrayList<>();
private final List<PostCall> postCalls = new ArrayList<>();
@@ -318,6 +321,16 @@ public class ServiceTester<T extends BaseService> extends ExternalResource {
return this;
}
+ public RequestAssert hasParam(String key, List<String> values) {
+ isNotNull();
+
+ MapEntry<String, String> entry = MapEntry.entry(key, values.toString());
+ Assertions.assertThat(actual.getParameters().getValues(key)).containsExactly(values.toArray(new String[0]));
+ this.assertedParams.add(entry);
+
+ return this;
+ }
+
public RequestAssert andNoOtherParam() {
isNotNull();
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java
deleted file mode 100644
index 183e2114211..00000000000
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class Tls12Java7SocketFactoryTest {
-
- SSLSocketFactory delegate = mock(SSLSocketFactory.class);
- Tls12Java7SocketFactory underTest = new Tls12Java7SocketFactory(delegate);
-
- @Test
- public void createSocket_1() throws IOException {
- InetAddress address = mock(InetAddress.class);
- SSLSocket socket = mock(SSLSocket.class);
- when(delegate.createSocket(address, 80)).thenReturn(socket);
- socket = (SSLSocket) underTest.createSocket(address, 80);
- verify(socket).setEnabledProtocols(Tls12Java7SocketFactory.TLS_PROTOCOLS);
- }
-
- @Test
- public void createSocket_2() throws IOException {
- InetAddress address = mock(InetAddress.class);
- InetAddress address2 = mock(InetAddress.class);
- SSLSocket socket = mock(SSLSocket.class);
- when(delegate.createSocket(address, 80, address2, 443)).thenReturn(socket);
- socket = (SSLSocket) underTest.createSocket(address, 80, address2, 443);
- verify(socket).setEnabledProtocols(Tls12Java7SocketFactory.TLS_PROTOCOLS);
- }
-
- @Test
- public void createSocket_3() throws IOException {
- SSLSocket socket = mock(SSLSocket.class);
- when(delegate.createSocket("", 80)).thenReturn(socket);
- socket = (SSLSocket) underTest.createSocket("", 80);
- verify(socket).setEnabledProtocols(Tls12Java7SocketFactory.TLS_PROTOCOLS);
- }
-
- @Test
- public void support_non_ssl_sockets() throws IOException {
- Socket regularSocket = mock(Socket.class);
- when(delegate.createSocket("", 80)).thenReturn(regularSocket);
- assertThat(underTest.createSocket("", 80)).isNotInstanceOf(SSLSocket.class);
- }
-
- @Test
- public void delegate_getters() {
- String[] defaultCipherSuites = new String[0];
- String[] supportedCipherSuites = new String[0];
- when(delegate.getDefaultCipherSuites()).thenReturn(defaultCipherSuites);
- when(delegate.getSupportedCipherSuites()).thenReturn(supportedCipherSuites);
-
- assertThat(underTest.getDefaultCipherSuites()).isSameAs(defaultCipherSuites);
- assertThat(underTest.getSupportedCipherSuites()).isSameAs(supportedCipherSuites);
- }
-}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java
index 51cc5293bc6..4674d9d184f 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/ce/CeServiceTest.java
@@ -97,10 +97,41 @@ public class CeServiceTest {
}
@Test
- public void task() {
+ public void task_by_id_only() {
underTest.task("task_id");
assertThat(serviceTester.getGetRequest().getPath()).isEqualTo("api/ce/task");
assertThat(serviceTester.getGetRequest().getParams()).containsOnly(entry("id", "task_id"));
}
+
+ @Test
+ public void task_with_stacktrace_and_scanner_context() {
+ underTest.task(TaskWsRequest.newBuilder("task_id")
+ .withErrorStacktrace()
+ .withScannerContext()
+ .build());
+
+ assertThat(serviceTester.getGetRequest().getPath()).isEqualTo("api/ce/task");
+ assertThat(serviceTester.getGetRequest().getParams()).containsOnly(entry("id", "task_id"), entry("additionalFields", "stacktrace,scannerContext"));
+ }
+
+ @Test
+ public void task_with_scanner_context_only() {
+ underTest.task(TaskWsRequest.newBuilder("task_id")
+ .withScannerContext()
+ .build());
+
+ assertThat(serviceTester.getGetRequest().getPath()).isEqualTo("api/ce/task");
+ assertThat(serviceTester.getGetRequest().getParams()).containsOnly(entry("id", "task_id"), entry("additionalFields", "scannerContext"));
+ }
+
+ @Test
+ public void task_with_stacktrace_only() {
+ underTest.task(TaskWsRequest.newBuilder("task_id")
+ .withErrorStacktrace()
+ .build());
+
+ assertThat(serviceTester.getGetRequest().getPath()).isEqualTo("api/ce/task");
+ assertThat(serviceTester.getGetRequest().getParams()).containsOnly(entry("id", "task_id"), entry("additionalFields", "stacktrace"));
+ }
}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/component/UpdateWsRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/UpdateWsRequestTest.java
new file mode 100644
index 00000000000..76d0a307c2f
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/component/UpdateWsRequestTest.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.component;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class UpdateWsRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ UpdateWsRequest.Builder underTest = UpdateWsRequest.builder();
+
+ @Test
+ public void fail_if_new_key_is_null() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("The new key must not be empty");
+
+ underTest.setNewKey(null).build();
+ }
+
+ @Test
+ public void fail_if_new_key_is_empty() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("The new key must not be empty");
+
+ underTest.setNewKey("").build();
+ }
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/license/LicensesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/license/LicensesServiceTest.java
new file mode 100644
index 00000000000..8b305df0514
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/license/LicensesServiceTest.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.license;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.Licenses.ListWsResponse;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.ServiceTester;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class LicensesServiceTest {
+
+ @Rule
+ public ServiceTester<LicensesService> serviceTester = new ServiceTester<>(new LicensesService(mock(WsConnector.class)));
+
+ private LicensesService underTest = serviceTester.getInstanceUnderTest();
+
+ @Test
+ public void list_definitions() {
+ underTest.list();
+ GetRequest getRequest = serviceTester.getGetRequest();
+
+ assertThat(serviceTester.getGetParser()).isSameAs(ListWsResponse.parser());
+ serviceTester.assertThat(getRequest).andNoOtherParam();
+ }
+
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/permission/PermissionsServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/permission/PermissionsServiceTest.java
index 5cdf798fbbd..1b9fcb4ed95 100644
--- a/sonar-ws/src/test/java/org/sonarqube/ws/client/permission/PermissionsServiceTest.java
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/permission/PermissionsServiceTest.java
@@ -84,7 +84,6 @@ public class PermissionsServiceTest {
.setProjectKey(PROJECT_KEY_VALUE)
.setPage(PAGE_VALUE)
.setPageSize(PAGE_SIZE_VALUE)
- .setSelected(SELECTED_VALUE)
.setQuery(QUERY_VALUE));
assertThat(serviceTester.getGetParser()).isSameAs(WsPermissions.WsGroupsResponse.parser());
@@ -96,7 +95,6 @@ public class PermissionsServiceTest {
.hasParam(PARAM_PROJECT_KEY, PROJECT_KEY_VALUE)
.hasParam(PARAM_P, PAGE_VALUE)
.hasParam(PARAM_PS, PAGE_SIZE_VALUE)
- .hasParam(PARAM_SELECTED, SELECTED_VALUE)
.hasParam(PARAM_Q, QUERY_VALUE)
.andNoOtherParam();
}
@@ -430,28 +428,38 @@ public class PermissionsServiceTest {
}
@Test
- public void users_does_GET_on_Ws_users() {
- underTest.users(new UsersWsRequest()
+ public void add_project_creator_to_template() {
+ underTest.addProjectCreatorToTemplate(AddProjectCreatorToTemplateWsRequest.builder()
.setPermission(PERMISSION_VALUE)
- .setProjectId(PROJECT_ID_VALUE)
- .setProjectKey(PROJECT_KEY_VALUE)
- .setSelected(SELECTED_VALUE)
- .setPage(PAGE_VALUE)
- .setPageSize(PAGE_SIZE_VALUE)
- .setQuery(QUERY_VALUE)
- );
+ .setTemplateId(TEMPLATE_ID_VALUE)
+ .setTemplateName(TEMPLATE_NAME_VALUE)
+ .build());
- assertThat(serviceTester.getGetParser()).isSameAs(WsPermissions.UsersWsResponse.parser());
- GetRequest getRequest = serviceTester.getGetRequest();
+ assertThat(serviceTester.getPostParser()).isNull();
+ PostRequest getRequest = serviceTester.getPostRequest();
serviceTester.assertThat(getRequest)
- .hasPath("users")
+ .hasPath("add_project_creator_to_template")
.hasParam(PARAM_PERMISSION, PERMISSION_VALUE)
- .hasParam(PARAM_PROJECT_ID, PROJECT_ID_VALUE)
- .hasParam(PARAM_PROJECT_KEY, PROJECT_KEY_VALUE)
- .hasParam(PARAM_SELECTED, SELECTED_VALUE)
- .hasParam(PARAM_P, PAGE_VALUE)
- .hasParam(PARAM_PS, PAGE_SIZE_VALUE)
- .hasParam(PARAM_Q, QUERY_VALUE)
+ .hasParam(PARAM_TEMPLATE_ID, TEMPLATE_ID_VALUE)
+ .hasParam(PARAM_TEMPLATE_NAME, TEMPLATE_NAME_VALUE)
+ .andNoOtherParam();
+ }
+
+ @Test
+ public void remove_project_creator_from_template() {
+ underTest.removeProjectCreatorFromTemplate(RemoveProjectCreatorFromTemplateWsRequest.builder()
+ .setPermission(PERMISSION_VALUE)
+ .setTemplateId(TEMPLATE_ID_VALUE)
+ .setTemplateName(TEMPLATE_NAME_VALUE)
+ .build());
+
+ assertThat(serviceTester.getPostParser()).isNull();
+ PostRequest getRequest = serviceTester.getPostRequest();
+ serviceTester.assertThat(getRequest)
+ .hasPath("remove_project_creator_from_template")
+ .hasParam(PARAM_PERMISSION, PERMISSION_VALUE)
+ .hasParam(PARAM_TEMPLATE_ID, TEMPLATE_ID_VALUE)
+ .hasParam(PARAM_TEMPLATE_NAME, TEMPLATE_NAME_VALUE)
.andNoOtherParam();
}
}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectlinks/ProjectLinksServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectlinks/ProjectLinksServiceTest.java
new file mode 100644
index 00000000000..4127c8727bf
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectlinks/ProjectLinksServiceTest.java
@@ -0,0 +1,102 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.projectlinks;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.WsProjectLinks.CreateWsResponse;
+import org.sonarqube.ws.WsProjectLinks.SearchWsResponse;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.ServiceTester;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_ID;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_NAME;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_PROJECT_ID;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_PROJECT_KEY;
+import static org.sonarqube.ws.client.projectlinks.ProjectLinksWsParameters.PARAM_URL;
+
+public class ProjectLinksServiceTest {
+ private static final String PROJECT_ID_VALUE = "project_id_value";
+ private static final String PROJECT_KEY_VALUE = "project_key_value";
+ private static final String NAME_VALUE = "name_value";
+ private static final String URL_VALUE = "url_value";
+ private static final long ID_VALUE = 175;
+
+ @Rule
+ public ServiceTester<ProjectLinksService> serviceTester = new ServiceTester<>(new ProjectLinksService(mock(WsConnector.class)));
+
+ private ProjectLinksService underTest = serviceTester.getInstanceUnderTest();
+
+ @Test
+ public void search_does_GET_request() {
+ underTest.search(new SearchWsRequest()
+ .setProjectId(PROJECT_ID_VALUE)
+ .setProjectKey(PROJECT_KEY_VALUE));
+
+ assertThat(serviceTester.getGetParser()).isSameAs(SearchWsResponse.parser());
+
+ GetRequest getRequest = serviceTester.getGetRequest();
+
+ serviceTester.assertThat(getRequest)
+ .hasPath("search")
+ .hasParam(PARAM_PROJECT_ID, PROJECT_ID_VALUE)
+ .hasParam(PARAM_PROJECT_KEY, PROJECT_KEY_VALUE)
+ .andNoOtherParam();
+ }
+
+ @Test
+ public void create_does_POST_request() {
+ underTest.create(new CreateWsRequest()
+ .setProjectId(PROJECT_ID_VALUE)
+ .setProjectKey(PROJECT_KEY_VALUE)
+ .setName(NAME_VALUE)
+ .setUrl(URL_VALUE));
+
+ assertThat(serviceTester.getPostParser()).isSameAs(CreateWsResponse.parser());
+
+ PostRequest postRequest = serviceTester.getPostRequest();
+
+ serviceTester.assertThat(postRequest)
+ .hasPath("create")
+ .hasParam(PARAM_PROJECT_ID, PROJECT_ID_VALUE)
+ .hasParam(PARAM_PROJECT_KEY, PROJECT_KEY_VALUE)
+ .hasParam(PARAM_NAME, NAME_VALUE)
+ .hasParam(PARAM_URL, URL_VALUE)
+ .andNoOtherParam();
+ }
+
+ @Test
+ public void delete_does_POST_request() {
+ underTest.delete(new DeleteWsRequest().setId(ID_VALUE));
+
+ assertThat(serviceTester.getPostParser()).isNull();
+
+ PostRequest postRequest = serviceTester.getPostRequest();
+
+ serviceTester.assertThat(postRequest)
+ .hasPath("delete")
+ .hasParam(PARAM_ID, String.valueOf(ID_VALUE))
+ .andNoOtherParam();
+ }
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/qualitygate/QualityGatesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualitygate/QualityGatesServiceTest.java
new file mode 100644
index 00000000000..38ef7ba77c2
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/qualitygate/QualityGatesServiceTest.java
@@ -0,0 +1,63 @@
+
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.qualitygate;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.ServiceTester;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_ID;
+import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_KEY;
+import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_GATE_ID;
+
+public class QualityGatesServiceTest {
+ private static final String PROJECT_ID_VALUE = "195";
+ private static final String PROJECT_KEY_VALUE = "project_key_value";
+ private static final Long GATE_ID_VALUE = 243L;
+
+ @Rule
+ public ServiceTester<QualityGatesService> serviceTester = new ServiceTester<>(new QualityGatesService(mock(WsConnector.class)));
+
+ private QualityGatesService underTest = serviceTester.getInstanceUnderTest();
+
+ @Test
+ public void associate_project_does_POST_request() {
+ underTest.associateProject(new SelectWsRequest()
+ .setGateId(GATE_ID_VALUE)
+ .setProjectId(PROJECT_ID_VALUE)
+ .setProjectKey(PROJECT_KEY_VALUE));
+
+ assertThat(serviceTester.getPostParser()).isNull();
+
+ PostRequest postRequest = serviceTester.getPostRequest();
+
+ serviceTester.assertThat(postRequest)
+ .hasPath("select")
+ .hasParam(PARAM_GATE_ID, String.valueOf(GATE_ID_VALUE))
+ .hasParam(PARAM_PROJECT_ID, String.valueOf(PROJECT_ID_VALUE))
+ .hasParam(PARAM_PROJECT_KEY, PROJECT_KEY_VALUE)
+ .andNoOtherParam();
+ }
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/serverid/GenerateRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/serverid/GenerateRequestTest.java
new file mode 100644
index 00000000000..ecbf2588ae3
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/serverid/GenerateRequestTest.java
@@ -0,0 +1,65 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.serverid;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class GenerateRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ GenerateRequest.Builder underTest = GenerateRequest.builder();
+
+ @Test
+ public void fail_if_null_organization() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Organization must not be null or empty");
+
+ underTest.setIp("127.0.0.1").setOrganization(null).build();
+ }
+
+ @Test
+ public void fail_if_empty_organization() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Organization must not be null or empty");
+
+ underTest.setIp("127.0.0.1").setOrganization("").build();
+ }
+
+ @Test
+ public void fail_if_null_ip() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("IP must not be null or empty");
+
+ underTest.setOrganization("SonarSource").setIp(null).build();
+ }
+
+ @Test
+ public void fail_if_empty_ip() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("IP must not be null or empty");
+
+ underTest.setOrganization("SonarSource").setIp("").build();
+ }
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ListDefinitionsRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ListDefinitionsRequestTest.java
new file mode 100644
index 00000000000..66eb07952f7
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ListDefinitionsRequestTest.java
@@ -0,0 +1,60 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ListDefinitionsRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ ListDefinitionsRequest.Builder underTest = ListDefinitionsRequest.builder();
+
+ @Test
+ public void create_request_with_no_component() {
+ ListDefinitionsRequest result = underTest.build();
+
+ assertThat(result.getComponentId()).isNull();
+ assertThat(result.getComponentKey()).isNull();
+ }
+
+ @Test
+ public void create_request_with_component_id() {
+ ListDefinitionsRequest result = underTest.setComponentId("projectId").build();
+
+ assertThat(result.getComponentId()).isEqualTo("projectId");
+ assertThat(result.getComponentKey()).isNull();
+ }
+
+ @Test
+ public void create_request_with_component_key() {
+ ListDefinitionsRequest result = underTest.setComponentKey("projectKey").build();
+
+ assertThat(result.getComponentId()).isNull();
+ assertThat(result.getComponentKey()).isEqualTo("projectKey");
+ }
+
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ResetRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ResetRequestTest.java
new file mode 100644
index 00000000000..994af2a0756
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ResetRequestTest.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ResetRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ ResetRequest.Builder underTest = ResetRequest.builder();
+
+ @Test
+ public void create_set_request() {
+ ResetRequest result = underTest.setKeys("my.key").build();
+
+ assertThat(result.getKeys()).containsOnly("my.key");
+ }
+
+ @Test
+ public void fail_when_empty_keys() {
+ expectedException.expect(IllegalArgumentException.class);
+ underTest.setKeys().build();
+ }
+
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SetRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SetRequestTest.java
new file mode 100644
index 00000000000..461daa1d29f
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SetRequestTest.java
@@ -0,0 +1,85 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SetRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ SetRequest.Builder underTest = SetRequest.builder();
+
+ @Test
+ public void create_set_request() {
+ SetRequest result = underTest.setKey("my.key").setValue("my value").build();
+
+ assertThat(result.getKey()).isEqualTo("my.key");
+ assertThat(result.getValue()).isEqualTo("my value");
+ assertThat(result.getValues()).isNotNull().isEmpty();
+ assertThat(result.getComponentKey()).isNull();
+ assertThat(result.getComponentId()).isNull();
+ }
+
+ @Test
+ public void create_request_with_component_id() {
+ SetRequest result = underTest.setKey("my.key").setValue("my value").setComponentId("projectId").build();
+
+ assertThat(result.getKey()).isEqualTo("my.key");
+ assertThat(result.getValue()).isEqualTo("my value");
+ assertThat(result.getComponentId()).isEqualTo("projectId");
+ assertThat(result.getComponentKey()).isNull();
+ }
+
+ @Test
+ public void create_request_with_component_key() {
+ SetRequest result = underTest.setKey("my.key").setValue("my value").setComponentKey("projectKey").build();
+
+ assertThat(result.getKey()).isEqualTo("my.key");
+ assertThat(result.getValue()).isEqualTo("my value");
+ assertThat(result.getComponentId()).isNull();
+ assertThat(result.getComponentKey()).isEqualTo("projectKey");
+ }
+
+ @Test
+ public void fail_when_empty_key() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Setting key is mandatory and must not be empty");
+
+ underTest
+ .setKey("")
+ .setValue("value")
+ .build();
+ }
+
+ @Test
+ public void fail_when_values_is_null() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Setting values must not be null");
+
+ underTest.setKey("my.key").setValues(null).build();
+ }
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java
new file mode 100644
index 00000000000..1faf51ef43d
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/SettingsServiceTest.java
@@ -0,0 +1,111 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.Settings.ListDefinitionsWsResponse;
+import org.sonarqube.ws.Settings.ValuesWsResponse;
+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 org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_ID;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT_KEY;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_FIELD_VALUES;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEY;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEYS;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_VALUE;
+import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_VALUES;
+
+public class SettingsServiceTest {
+
+ @Rule
+ public ServiceTester<SettingsService> serviceTester = new ServiceTester<>(new SettingsService(mock(WsConnector.class)));
+
+ private SettingsService underTest = serviceTester.getInstanceUnderTest();
+
+ @Test
+ public void list_definitions() {
+ underTest.listDefinitions(ListDefinitionsRequest.builder()
+ .setComponentKey("KEY")
+ .build());
+ GetRequest getRequest = serviceTester.getGetRequest();
+
+ assertThat(serviceTester.getGetParser()).isSameAs(ListDefinitionsWsResponse.parser());
+ serviceTester.assertThat(getRequest)
+ .hasParam(PARAM_COMPONENT_KEY, "KEY")
+ .andNoOtherParam();
+ }
+
+ @Test
+ public void values() {
+ underTest.values(ValuesRequest.builder()
+ .setKeys("sonar.debt,sonar.issue")
+ .setComponentKey("KEY")
+ .build());
+ GetRequest getRequest = serviceTester.getGetRequest();
+
+ assertThat(serviceTester.getGetParser()).isSameAs(ValuesWsResponse.parser());
+ serviceTester.assertThat(getRequest)
+ .hasParam(PARAM_KEYS, "sonar.debt,sonar.issue")
+ .hasParam(PARAM_COMPONENT_KEY, "KEY")
+ .andNoOtherParam();
+ }
+
+ @Test
+ public void set() {
+ underTest.set(SetRequest.builder()
+ .setKey("sonar.debt")
+ .setValue("8h")
+ .setValues(newArrayList("v1", "v2", "v3"))
+ .setFieldValues(newArrayList("json1","json2","json3"))
+ .setComponentId("UUID")
+ .setComponentKey("KEY")
+ .build());
+
+ serviceTester.assertThat(serviceTester.getPostRequest())
+ .hasParam(PARAM_KEY, "sonar.debt")
+ .hasParam(PARAM_VALUE, "8h")
+ .hasParam(PARAM_VALUES, newArrayList("v1", "v2", "v3"))
+ .hasParam(PARAM_FIELD_VALUES, newArrayList("json1", "json2", "json3"))
+ .hasParam(PARAM_COMPONENT_ID, "UUID")
+ .hasParam(PARAM_COMPONENT_KEY, "KEY")
+ .andNoOtherParam();
+ }
+
+ @Test
+ public void reset() {
+ underTest.reset(ResetRequest.builder()
+ .setKeys("sonar.debt")
+ .setComponentKey("KEY")
+ .build());
+
+ serviceTester.assertThat(serviceTester.getPostRequest())
+ .hasParam(PARAM_KEYS, "sonar.debt")
+ .hasParam(PARAM_COMPONENT_KEY, "KEY")
+ .andNoOtherParam();
+ }
+
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java
new file mode 100644
index 00000000000..1ee0d1763bd
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/setting/ValuesRequestTest.java
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.setting;
+
+import java.util.List;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ValuesRequestTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ ValuesRequest.Builder underTest = ValuesRequest.builder();
+
+ @Test
+ public void create_request_with_no_component() {
+ ValuesRequest result = underTest.setKeys("sonar.debt").build();
+
+ assertThat(result.getComponentId()).isNull();
+ assertThat(result.getComponentKey()).isNull();
+ assertThat(result.getKeys()).containsOnly("sonar.debt");
+ }
+
+ @Test
+ public void create_request_with_component_id() {
+ ValuesRequest result = underTest.setKeys("sonar.debt").setComponentId("projectId").build();
+
+ assertThat(result.getComponentId()).isEqualTo("projectId");
+ assertThat(result.getComponentKey()).isNull();
+ assertThat(result.getKeys()).containsOnly("sonar.debt");
+ }
+
+ @Test
+ public void create_request_with_component_key() {
+ ValuesRequest result = underTest.setKeys("sonar.debt").setComponentKey("projectKey").build();
+
+ assertThat(result.getComponentId()).isNull();
+ assertThat(result.getComponentKey()).isEqualTo("projectKey");
+ assertThat(result.getKeys()).containsOnly("sonar.debt");
+ }
+
+ @Test
+ public void fail_when_keys_is_null() throws Exception {
+ expectedException.expect(NullPointerException.class);
+ underTest
+ .setKeys((List<String>) null)
+ .setComponentId("projectId")
+ .build();
+ }
+
+ @Test
+ public void fail_when_keys_is_empty() throws Exception {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("'keys' cannot be empty");
+
+ underTest.setComponentId("projectId").build();
+ }
+
+}