@@ -29,8 +29,9 @@ | |||
<module>sonar-markdown</module> | |||
<module>sonar-plugin-api</module> | |||
<module>server</module> | |||
<module>sonar-ws-generated</module> | |||
<module>sonar-ws</module> | |||
<module>sonar-ws-generated</module> | |||
<module>sonar-ws-generator</module> | |||
<module>sonar-testing-harness</module> | |||
<module>plugins/sonar-xoo-plugin</module> | |||
</modules> | |||
@@ -467,6 +468,11 @@ | |||
<artifactId>sonar-update-center-common</artifactId> | |||
<version>${sonarUpdateCenter.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.sonarsource.orchestrator</groupId> | |||
<artifactId>sonar-orchestrator</artifactId> | |||
<version>${orchestrator.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-squid</artifactId> |
@@ -0,0 +1,4 @@ | |||
package org.sonar.server.setting.ws; | |||
public class SettingsWsParameters { | |||
} |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonarqube.ws.client.settings; | |||
import java.util.List; | |||
import javax.annotation.Generated; | |||
/** |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonarqube.ws.client.settings; | |||
import java.util.List; | |||
import javax.annotation.Generated; | |||
/** |
@@ -35,7 +35,7 @@ public class ResetRequest { | |||
private String branch; | |||
private String component; | |||
private String keys; | |||
private List<String> keys; | |||
/** | |||
* Branch key | |||
@@ -67,17 +67,17 @@ public class ResetRequest { | |||
} | |||
/** | |||
* Setting keys | |||
* Comma-separated list of keys | |||
* | |||
* This is a mandatory parameter. | |||
* Example value: "sonar.links.scm,sonar.debt.hoursInDay" | |||
*/ | |||
public ResetRequest setKeys(String keys) { | |||
public ResetRequest setKeys(List<String> keys) { | |||
this.keys = keys; | |||
return this; | |||
} | |||
public String getKeys() { | |||
public List<String> getKeys() { | |||
return keys; | |||
} | |||
} |
@@ -35,10 +35,10 @@ public class SetRequest { | |||
private String branch; | |||
private String component; | |||
private String fieldValues; | |||
private List<String> fieldValues; | |||
private String key; | |||
private String value; | |||
private String values; | |||
private List<String> values; | |||
/** | |||
* Branch key. Only available on following settings : sonar.leak.period | |||
@@ -74,12 +74,12 @@ public class SetRequest { | |||
* | |||
* Example value: "fieldValues={\"firstField\":\"first value\", \"secondField\":\"second value\", \"thirdField\":\"third value\"}" | |||
*/ | |||
public SetRequest setFieldValues(String fieldValues) { | |||
public SetRequest setFieldValues(List<String> fieldValues) { | |||
this.fieldValues = fieldValues; | |||
return this; | |||
} | |||
public String getFieldValues() { | |||
public List<String> getFieldValues() { | |||
return fieldValues; | |||
} | |||
@@ -117,12 +117,12 @@ public class SetRequest { | |||
* | |||
* Example value: "values=firstValue&values=secondValue&values=thirdValue" | |||
*/ | |||
public SetRequest setValues(String values) { | |||
public SetRequest setValues(List<String> values) { | |||
this.values = values; | |||
return this; | |||
} | |||
public String getValues() { | |||
public List<String> getValues() { | |||
return values; | |||
} | |||
} |
@@ -22,15 +22,15 @@ package org.sonarqube.ws.client.settings; | |||
import java.util.stream.Collectors; | |||
import javax.annotation.Generated; | |||
import org.sonarqube.ws.MediaTypes; | |||
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 org.sonarqube.ws.Settings.CheckSecretKeyWsResponse; | |||
import org.sonarqube.ws.Settings.EncryptWsResponse; | |||
import org.sonarqube.ws.Settings.GenerateSecretKeyWsResponse; | |||
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; | |||
/** | |||
* Manage settings. | |||
@@ -115,7 +115,7 @@ public class SettingsService extends BaseService { | |||
new PostRequest(path("reset")) | |||
.setParam("branch", request.getBranch()) | |||
.setParam("component", request.getComponent()) | |||
.setParam("keys", request.getKeys()) | |||
.setParam("keys", request.getKeys() == null ? null : request.getKeys().stream().collect(Collectors.joining(","))) | |||
.setMediaType(MediaTypes.JSON) | |||
).content(); | |||
} | |||
@@ -133,10 +133,10 @@ public class SettingsService extends BaseService { | |||
new PostRequest(path("set")) | |||
.setParam("branch", request.getBranch()) | |||
.setParam("component", request.getComponent()) | |||
.setParam("fieldValues", request.getFieldValues()) | |||
.setParam("fieldValues", request.getFieldValues() == null ? null : request.getFieldValues().stream().collect(Collectors.joining(","))) | |||
.setParam("key", request.getKey()) | |||
.setParam("value", request.getValue()) | |||
.setParam("values", request.getValues()) | |||
.setParam("values", request.getValues() == null ? null : request.getValues().stream().collect(Collectors.joining(","))) | |||
.setMediaType(MediaTypes.JSON) | |||
).content(); | |||
} | |||
@@ -154,7 +154,7 @@ public class SettingsService extends BaseService { | |||
new GetRequest(path("values")) | |||
.setParam("branch", request.getBranch()) | |||
.setParam("component", request.getComponent()) | |||
.setParam("keys", request.getKeys()), | |||
.setParam("keys", request.getKeys() == null ? null : request.getKeys().stream().collect(Collectors.joining(","))), | |||
ValuesWsResponse.parser()); | |||
} | |||
} |
@@ -35,7 +35,7 @@ public class ValuesRequest { | |||
private String branch; | |||
private String component; | |||
private String keys; | |||
private List<String> keys; | |||
/** | |||
* Branch key | |||
@@ -71,12 +71,12 @@ public class ValuesRequest { | |||
* | |||
* Example value: "sonar.test.inclusions,sonar.dbcleaner.cleanDirectory" | |||
*/ | |||
public ValuesRequest setKeys(String keys) { | |||
public ValuesRequest setKeys(List<String> keys) { | |||
this.keys = keys; | |||
return this; | |||
} | |||
public String getKeys() { | |||
public List<String> getKeys() { | |||
return keys; | |||
} | |||
} |
@@ -0,0 +1,101 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
<modelVersion>4.0.0</modelVersion> | |||
<parent> | |||
<groupId>org.sonarsource.sonarqube</groupId> | |||
<artifactId>sonarqube</artifactId> | |||
<version>7.0-SNAPSHOT</version> | |||
</parent> | |||
<artifactId>sonar-ws-generator</artifactId> | |||
<name>SonarQube :: Web Service :: Generator</name> | |||
<description>Generate source files of sonar-ws</description> | |||
<properties> | |||
<sonar.exclusions>src/**/*</sonar.exclusions> | |||
</properties> | |||
<dependencies> | |||
<dependency> | |||
<groupId>org.apache.velocity</groupId> | |||
<artifactId>velocity</artifactId> | |||
<version>1.7</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.slf4j</groupId> | |||
<artifactId>log4j-over-slf4j</artifactId> | |||
<version>1.7.25</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.sonarsource.orchestrator</groupId> | |||
<artifactId>sonar-orchestrator</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>${project.groupId}</groupId> | |||
<artifactId>sonar-ws</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.google.code.gson</groupId> | |||
<artifactId>gson</artifactId> | |||
<version>2.8.2</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.google.guava</groupId> | |||
<artifactId>guava</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.google.code.findbugs</groupId> | |||
<artifactId>jsr305</artifactId> | |||
<scope>provided</scope> | |||
</dependency> | |||
</dependencies> | |||
<build> | |||
<plugins> | |||
<plugin> | |||
<groupId>org.codehaus.mojo</groupId> | |||
<artifactId>build-helper-maven-plugin</artifactId> | |||
<executions> | |||
<execution> | |||
<id>add-source</id> | |||
<phase>generate-sources</phase> | |||
<goals> | |||
<goal>add-source</goal> | |||
</goals> | |||
<configuration> | |||
<sources> | |||
<source>target/generated-sources/results</source> | |||
</sources> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
<plugin> | |||
<groupId>org.apache.maven.plugins</groupId> | |||
<artifactId>maven-assembly-plugin</artifactId> | |||
<executions> | |||
<execution> | |||
<id>assemble-all</id> | |||
<phase>package</phase> | |||
<goals> | |||
<goal>single</goal> | |||
</goals> | |||
<configuration> | |||
<descriptorRefs> | |||
<descriptorRef>jar-with-dependencies</descriptorRef> | |||
</descriptorRefs> | |||
<archive> | |||
<manifest> | |||
<mainClass>org.sonarqube.wsgenerator.Generator</mainClass> | |||
</manifest> | |||
</archive> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
</plugins> | |||
</build> | |||
</project> |
@@ -0,0 +1,9 @@ | |||
#!/bin/bash | |||
# Example: | |||
# run.sh /path/to/orchestrator.properties | |||
set -euo pipefail | |||
mvn clean package -Prun-ws-generator | |||
java -Dorchestrator.configUrl=file://$* -jar target/sonar-ws-generator-*-SNAPSHOT-jar-with-dependencies.jar |
@@ -0,0 +1,51 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.wsgenerator; | |||
import com.sonar.orchestrator.Orchestrator; | |||
import com.sonar.orchestrator.http.HttpCall; | |||
import com.sonar.orchestrator.http.HttpResponse; | |||
public class ApiDefinitionDownloader { | |||
public static void main(String[] args) { | |||
System.out.println(downloadApiDefinition()); | |||
} | |||
public static String downloadApiDefinition() { | |||
String orchestratorUrl = System.getProperty("orchestrator.configUrl"); | |||
if (orchestratorUrl == null) { | |||
throw new IllegalStateException("Please run with -Dorchestrator.configUrl=file:///path/to/your/orchestrator.properties"); | |||
} | |||
Orchestrator orchestrator = Orchestrator | |||
.builderEnv() | |||
.setSonarVersion("DEV") | |||
.build(); | |||
orchestrator.start(); | |||
try { | |||
HttpCall httpCall = orchestrator.getServer().newHttpCall("api/webservices/list").setParam("include_internals", "true"); | |||
HttpResponse response = httpCall.execute(); | |||
return response.getBodyAsString(); | |||
} finally { | |||
orchestrator.stop(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,124 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.wsgenerator; | |||
import com.google.gson.Gson; | |||
import com.google.gson.JsonArray; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import java.io.BufferedReader; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.InputStreamReader; | |||
import java.io.StringWriter; | |||
import java.io.Writer; | |||
import java.util.Properties; | |||
import org.apache.commons.io.FileUtils; | |||
import org.apache.velocity.VelocityContext; | |||
import org.apache.velocity.app.VelocityEngine; | |||
import static java.nio.charset.StandardCharsets.UTF_8; | |||
public class CodeFormatter { | |||
public static void format(String json) { | |||
JsonObject jsonElement = new Gson().fromJson(json, JsonObject.class); | |||
JsonArray webServices = (JsonArray) jsonElement.get("webServices"); | |||
Helper helper = new Helper(); | |||
for (JsonElement webServiceElement : webServices) { | |||
JsonObject webService = (JsonObject) webServiceElement; | |||
VelocityContext webServiceContext = new VelocityContext(); | |||
webServiceContext.put("webService", webServiceElement); | |||
webServiceContext.put("helper", helper); | |||
String webServiceCode = applyTemplate("webService.vm", webServiceContext); | |||
String webServicePath = webService.get("path").getAsString(); | |||
writeSourceFile(helper.file(webServicePath), webServiceCode); | |||
writeSourceFile(helper.packageInfoFile(webServicePath), applyTemplate("package-info.vm", webServiceContext)); | |||
for (JsonElement actionElement : (JsonArray) webService.get("actions")) { | |||
JsonObject action = (JsonObject) actionElement; | |||
JsonArray params = (JsonArray) action.get("params"); | |||
if (params == null || params.size() < 1) { | |||
continue; | |||
} | |||
VelocityContext actionContext = new VelocityContext(); | |||
actionContext.put("webService", webServiceElement); | |||
actionContext.put("action", actionElement); | |||
actionContext.put("helper", helper); | |||
String requestCode = applyTemplate("request.vm", actionContext); | |||
writeSourceFile(helper.requestFile(webServicePath, action.get("key").getAsString()), requestCode); | |||
} | |||
} | |||
} | |||
private static void writeSourceFile(String file, String code) { | |||
try { | |||
FileUtils.writeStringToFile(new File(file), code, UTF_8); | |||
} catch (IOException e) { | |||
throw new IllegalStateException(e); | |||
} | |||
} | |||
private static String applyTemplate(String templateName, VelocityContext context) { | |||
VelocityEngine velocity = new VelocityEngine(); | |||
Properties properties = new Properties(); | |||
properties.setProperty("resource.loader", "class"); | |||
properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); | |||
velocity.init(properties); | |||
Writer writer = new StringWriter(); | |||
velocity.mergeTemplate(templateName, "UTF-8", context, writer); | |||
try { | |||
writer.flush(); | |||
} catch (IOException e) { | |||
throw new IllegalStateException(e); | |||
} | |||
return writer.toString(); | |||
} | |||
public static void main(String[] args) { | |||
String json = readFromInputStream(Generator.class.getResourceAsStream("/snapshot-of-api.json")); | |||
format(json); | |||
} | |||
private static String readFromInputStream(InputStream inputStream) { | |||
StringBuilder resultStringBuilder = new StringBuilder(); | |||
try { | |||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { | |||
String line; | |||
while ((line = br.readLine()) != null) { | |||
resultStringBuilder.append(line).append("\n"); | |||
} | |||
} | |||
} catch (IOException e) { | |||
throw new IllegalStateException(e); | |||
} | |||
return resultStringBuilder.toString(); | |||
} | |||
} |
@@ -17,26 +17,12 @@ | |||
* 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; | |||
package org.sonarqube.wsgenerator; | |||
public class SettingsWsParameters { | |||
public static final String CONTROLLER_SETTINGS = "api/settings"; | |||
public class Generator { | |||
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 = "component"; | |||
public static final String PARAM_BRANCH = "branch"; | |||
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 | |||
public static void main(String[] args) { | |||
String json = ApiDefinitionDownloader.downloadApiDefinition(); | |||
CodeFormatter.format(json); | |||
} | |||
} |
@@ -0,0 +1,177 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.wsgenerator; | |||
import com.google.common.base.CaseFormat; | |||
import com.google.gson.JsonPrimitive; | |||
import java.io.BufferedReader; | |||
import java.io.InputStream; | |||
import java.io.InputStreamReader; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
public class Helper { | |||
private static final String OUTPUT_DIR = "target/generated-sources/results"; | |||
private final Map<String, List<String[]>> responseTypes; | |||
public Helper() { | |||
InputStream inputStream = Helper.class.getResourceAsStream("/responseClasses.config"); | |||
responseTypes = new BufferedReader(new InputStreamReader(inputStream)) | |||
.lines() | |||
.map(line -> line.split("\\s+")) | |||
.collect(Collectors.groupingBy(arr -> arr[0])); | |||
} | |||
public String packageName(String path) { | |||
return "org.sonarqube.ws.client." + rawName(path).toLowerCase(); | |||
} | |||
private String rawName(String path) { | |||
String x = path.replaceFirst("^api\\/", ""); | |||
if (x.contains("_")) { | |||
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, x.toLowerCase()); | |||
} | |||
return capitalizeFirstLetter(x); | |||
} | |||
public String className(String path) { | |||
String name = rawName(path); | |||
return capitalizeFirstLetter(name) + "Service"; | |||
} | |||
private String capitalizeFirstLetter(String name) { | |||
return name.substring(0, 1).toUpperCase() + name.substring(1); | |||
} | |||
private String lowercaseFirstLetter(String name) { | |||
return name.substring(0, 1).toLowerCase() + name.substring(1); | |||
} | |||
public String responseType(String path, String action) { | |||
return responseTypeFullyQualified(path, action).replaceFirst("^.*\\.", ""); | |||
} | |||
private String responseTypeFullyQualified(String path, String action) { | |||
String fullPath = path + "/" + action; | |||
List<String[]> responseTypesConfig = responseTypes.get(fullPath); | |||
String fullyQualified; | |||
if (responseTypesConfig == null) { | |||
fullyQualified = guessResponseType(path, action); | |||
responseTypes.put(fullPath, Collections.singletonList(new String[] {fullPath, fullyQualified})); | |||
} else { | |||
fullyQualified = responseTypesConfig.get(0)[1]; | |||
} | |||
return fullyQualified; | |||
} | |||
private String guessResponseType(String path, String action) { | |||
return guessResponseOuterClassName(path).flatMap( | |||
potentialClassName -> guessResponseInnerClassName(action).flatMap(potentialInnerClassName -> { | |||
try { | |||
String guess = "org.sonarqube.ws." + potentialClassName + "$" + potentialInnerClassName; | |||
Helper.class.forName(guess); | |||
return Stream.of(guess.replaceFirst("\\$", ".")); | |||
} catch (ClassNotFoundException e) { | |||
} | |||
return Stream.empty(); | |||
})).findFirst().orElseGet(() -> { | |||
return "String"; | |||
}); | |||
} | |||
private Stream<String> guessResponseInnerClassName(String action) { | |||
return Stream.of( | |||
rawName(action) + "Response", | |||
rawName(action) + "WsResponse", | |||
"Ws" + rawName(action) + "Response"); | |||
} | |||
private Stream<String> guessResponseOuterClassName(String path) { | |||
return Stream.of( | |||
rawName(path), | |||
rawName(path).replaceFirst("Qualityprofiles", "QualityProfiles"), | |||
"Ws" + rawName(path), | |||
"Ws" + rawName(path).replaceFirst("Qualitygates", "QualityGates"), | |||
"Ws" + rawName(path).replaceFirst("ProjectBranches", "Branches"), | |||
rawName(path) + "Ws"); | |||
} | |||
public String responseTypeImport(String path, String action) { | |||
String fullyQualified = responseTypeFullyQualified(path, action); | |||
if ("String".equals(fullyQualified)) { | |||
return null; | |||
} | |||
return "import " + fullyQualified + ";"; | |||
} | |||
public String methodName(String path, String action) { | |||
return lowercaseFirstLetter(rawName(action)); | |||
} | |||
public String requestType(String path, String action) { | |||
return rawName(action) + "Request"; | |||
} | |||
public String parameterGetter(String parameter) { | |||
return "get" + rawName(parameter); | |||
} | |||
public String parameterSetter(String parameter) { | |||
return "set" + rawName(parameter); | |||
} | |||
public String setterParameter(String parameter) { | |||
return lowercaseFirstLetter(rawName(parameter)); | |||
} | |||
public String setterParameterType(String parameter, JsonPrimitive parameterDescription) { | |||
if (parameter.equals("values") || parameter.equals("fieldValues") || parameter.equals("keys")) { | |||
return "List<String>"; | |||
} | |||
if (parameterDescription != null && parameterDescription.getAsString().matches(".*[Cc]omma.?separated.*|.*[Ll]ist of.*")) { | |||
return "List<String>"; | |||
} | |||
return "String"; | |||
} | |||
public String apiDocUrl(String path) { | |||
return "https://next.sonarqube.com/sonarqube/web_api/" + path; | |||
} | |||
public String apiDocUrl(String path, String action) { | |||
return apiDocUrl(path) + "/" + action; | |||
} | |||
public String file(String path) { | |||
return OUTPUT_DIR + "/org/sonarqube/ws/client/" + rawName(path).toLowerCase() + "/" + className(path) + ".java"; | |||
} | |||
public String packageInfoFile(String path) { | |||
return OUTPUT_DIR + "/org/sonarqube/ws/client/" + rawName(path).toLowerCase() + "/package-info.java"; | |||
} | |||
public String requestFile(String path, String action) { | |||
return OUTPUT_DIR + "/org/sonarqube/ws/client/" + rawName(path).toLowerCase() + "/" + requestType(path, action) + ".java"; | |||
} | |||
} |
@@ -17,10 +17,8 @@ | |||
* 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; | |||
package org.sonarqube.wsgenerator; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -0,0 +1,24 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package $helper.packageName($webService.path.asString); | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -0,0 +1,91 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package $helper.packageName($webService.path.asString); | |||
import java.util.List; | |||
import javax.annotation.Generated; | |||
/** | |||
* $action.description.asString | |||
* | |||
#if ($action.internal) | |||
* This is part of the internal API. | |||
#end | |||
#if ($action.post) | |||
* This is a POST request. | |||
#else | |||
* This is a GET request. | |||
#end | |||
#if ($action.hasResponseExample) | |||
* @see <a href="$helper.apiDocUrl($webService.path.asString, $action.key.asString)">Further information about this action online (including a response example)</a> | |||
#else | |||
* @see <a href="$helper.apiDocUrl($webService.path.asString, $action.key.asString)">Further information about this action online</a> | |||
#end | |||
#if ($action.since.asString) | |||
* @since $action.since.asString | |||
#end | |||
*/ | |||
@Generated("sonar-ws-generator") | |||
public class $helper.requestType($webService.path.asString, $action.key.asString) { | |||
#foreach($param in $action.params) | |||
private $helper.setterParameterType($param.key.asString, $param.description) ${helper.setterParameter($param.key.asString)}; | |||
#end | |||
#foreach($param in $action.params) | |||
/** | |||
#if ($param.description.asString) | |||
* $param.description.asString | |||
* | |||
#end | |||
#if ($param.required.asBoolean) | |||
* This is a mandatory parameter. | |||
#end | |||
#if ($param.internal.asBoolean) | |||
* This is part of the internal API. | |||
#end | |||
#if ($param.exampleValue) | |||
* Example value: $param.exampleValue | |||
#end | |||
#if ($param.possibleValues) | |||
* Possible values: | |||
* <ul> | |||
#foreach($possibleValue in $param.possibleValues) | |||
* <li>$possibleValue</li> | |||
#end | |||
* </ul> | |||
#end | |||
#if ($param.deprecatedSince.asString) | |||
* @deprecated since $param.deprecatedSince.asString | |||
#end | |||
*/ | |||
#if ($param.deprecatedSince.asString) | |||
@Deprecated | |||
#end | |||
public $helper.requestType($webService.path.asString, $action.key.asString) ${helper.parameterSetter($param.key.asString)}($helper.setterParameterType($param.key.asString, $param.description) ${helper.setterParameter($param.key.asString)}) { | |||
this.${helper.setterParameter($param.key.asString)} = ${helper.setterParameter($param.key.asString)}; | |||
return this; | |||
} | |||
public $helper.setterParameterType($param.key.asString, $param.description) ${helper.parameterGetter($param.key.asString)}() { | |||
return ${helper.setterParameter($param.key.asString)}; | |||
} | |||
#end | |||
} |
@@ -0,0 +1,94 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package $helper.packageName($webService.path.asString); | |||
import java.util.stream.Collectors; | |||
import javax.annotation.Generated; | |||
import org.sonarqube.ws.MediaTypes; | |||
import org.sonarqube.ws.client.BaseService; | |||
import org.sonarqube.ws.client.GetRequest; | |||
import org.sonarqube.ws.client.PostRequest; | |||
import org.sonarqube.ws.client.WsConnector; | |||
#foreach($action in $webService.actions) | |||
#if ($helper.responseTypeImport($webService.path.asString, $action.key.asString)) | |||
$helper.responseTypeImport($webService.path.asString, $action.key.asString) | |||
#end | |||
#end | |||
/** | |||
* $webService.description.asString | |||
* @see <a href="$helper.apiDocUrl($webService.path.asString)">Further information about this web service online</a> | |||
*/ | |||
@Generated("sonar-ws-generator") | |||
public class $helper.className($webService.path.asString) extends BaseService { | |||
public $helper.className($webService.path.asString)(WsConnector wsConnector) { | |||
super(wsConnector, "$webService.path.asString"); | |||
} | |||
#foreach($action in $webService.actions) | |||
/** | |||
* $action.description.asString | |||
* | |||
#if ($action.internal) | |||
* This is part of the internal API. | |||
#end | |||
#if ($action.post.asBoolean) | |||
* This is a POST request. | |||
#else | |||
* This is a GET request. | |||
#end | |||
#if ($action.hasResponseExample) | |||
* @see <a href="$helper.apiDocUrl($webService.path.asString, $action.key.asString)">Further information about this action online (including a response example)</a> | |||
#else | |||
* @see <a href="$helper.apiDocUrl($webService.path.asString, $action.key.asString)">Further information about this action online</a> | |||
#end | |||
#if ($action.since.asString) | |||
* @since $action.since.asString | |||
#end | |||
#if ($action.deprecatedSince) | |||
* @deprecated since $action.deprecatedSince.asString | |||
#end | |||
*/ | |||
#if ($action.deprecatedSince) | |||
@Deprecated | |||
#end | |||
public#if ($action.hasResponseExample.asBoolean) $helper.responseType($webService.path.asString, $action.key.asString)#else void#end $helper.methodName($webService.path.asString, $action.key.asString)(#if ($action.params && $action.params.size() > 0)$helper.requestType($webService.path.asString, $action.key.asString) request#end) { | |||
#if ($action.hasResponseExample.asBoolean) return#end call( | |||
#if ($action.post.asBoolean) | |||
new PostRequest(path("$action.key.asString"))#else | |||
new GetRequest(path("$action.key.asString"))#end | |||
#foreach($param in $action.params) | |||
#if ($helper.setterParameterType($param.key.asString, $param.description) == "List<String>") | |||
.setParam("$param.key.asString", request.${helper.parameterGetter($param.key.asString)}() == null ? null : request.${helper.parameterGetter($param.key.asString)}().stream().collect(Collectors.joining(",")))#else | |||
.setParam("$param.key.asString", request.${helper.parameterGetter($param.key.asString)}())#end | |||
#end | |||
#if ($helper.responseType($webService.path.asString, $action.key.asString) == "String") | |||
.setMediaType(MediaTypes.JSON) | |||
).content(); | |||
#else, | |||
${helper.responseType($webService.path.asString, $action.key.asString)}.parser()); | |||
#end | |||
} | |||
#end | |||
} |
@@ -1,74 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.setting; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import javax.annotation.concurrent.Immutable; | |||
@Immutable | |||
public class ListDefinitionsRequest { | |||
private final String component; | |||
private final String branch; | |||
private ListDefinitionsRequest(Builder builder) { | |||
this.component = builder.component; | |||
this.branch = builder.branch; | |||
} | |||
@CheckForNull | |||
public String getComponent() { | |||
return component; | |||
} | |||
@CheckForNull | |||
public String getBranch() { | |||
return branch; | |||
} | |||
public static Builder builder() { | |||
return new Builder(); | |||
} | |||
public static class Builder { | |||
private String component; | |||
private String branch; | |||
private Builder() { | |||
// enforce factory method use | |||
} | |||
public Builder setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
public Builder setBranch(@Nullable String branch) { | |||
this.branch = branch; | |||
return this; | |||
} | |||
public ListDefinitionsRequest build() { | |||
return new ListDefinitionsRequest(this); | |||
} | |||
} | |||
} |
@@ -1,92 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.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 component; | |||
private final String branch; | |||
private ResetRequest(Builder builder) { | |||
this.keys = builder.keys; | |||
this.component = builder.component; | |||
this.branch = builder.branch; | |||
} | |||
public List<String> getKeys() { | |||
return keys; | |||
} | |||
@CheckForNull | |||
public String getComponent() { | |||
return component; | |||
} | |||
@CheckForNull | |||
public String getBranch() { | |||
return branch; | |||
} | |||
public static Builder builder() { | |||
return new Builder(); | |||
} | |||
public static class Builder { | |||
private List<String> keys; | |||
private String component; | |||
private String branch; | |||
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 setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
public Builder setBranch(@Nullable String branch) { | |||
this.branch = branch; | |||
return this; | |||
} | |||
public ResetRequest build() { | |||
checkArgument(keys != null && !keys.isEmpty(), "Setting keys is mandatory and must not be empty."); | |||
return new ResetRequest(this); | |||
} | |||
} | |||
} |
@@ -1,126 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.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 component; | |||
private final String branch; | |||
private SetRequest(Builder builder) { | |||
this.key = builder.key; | |||
this.value = builder.value; | |||
this.values = builder.values; | |||
this.fieldValues = builder.fieldValues; | |||
this.component = builder.component; | |||
this.branch = builder.branch; | |||
} | |||
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 getComponent() { | |||
return component; | |||
} | |||
@CheckForNull | |||
public String getBranch() { | |||
return branch; | |||
} | |||
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 component; | |||
private String branch; | |||
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 setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
public Builder setBranch(@Nullable String branch) { | |||
this.branch = branch; | |||
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); | |||
} | |||
} | |||
} |
@@ -1,79 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.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.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_BRANCH; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT; | |||
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, request.getComponent()) | |||
.setParam(PARAM_BRANCH, request.getBranch()); | |||
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, request.getComponent()) | |||
.setParam(PARAM_BRANCH, request.getBranch()); | |||
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, request.getComponent()) | |||
.setParam(PARAM_BRANCH, request.getBranch())); | |||
} | |||
public void reset(ResetRequest request) { | |||
call(new PostRequest(path(ACTION_RESET)) | |||
.setParam(PARAM_KEYS, inlineMultipleParamValue(request.getKeys())) | |||
.setParam(PARAM_COMPONENT, request.getComponent()) | |||
.setParam(PARAM_BRANCH, request.getBranch())); | |||
} | |||
} |
@@ -1,93 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.setting; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Objects.requireNonNull; | |||
public class ValuesRequest { | |||
private final List<String> keys; | |||
private final String component; | |||
private final String branch; | |||
private ValuesRequest(Builder builder) { | |||
this.keys = builder.keys; | |||
this.component = builder.component; | |||
this.branch = builder.branch; | |||
} | |||
public List<String> getKeys() { | |||
return keys; | |||
} | |||
@CheckForNull | |||
public String getComponent() { | |||
return component; | |||
} | |||
@CheckForNull | |||
public String getBranch() { | |||
return branch; | |||
} | |||
public static Builder builder() { | |||
return new Builder(); | |||
} | |||
public static class Builder { | |||
private List<String> keys = new ArrayList<>(); | |||
private String component; | |||
private String branch; | |||
private Builder() { | |||
// enforce factory method use | |||
} | |||
public Builder setKeys(List<String> keys) { | |||
this.keys = requireNonNull(keys); | |||
return this; | |||
} | |||
public Builder setKeys(String... keys) { | |||
return setKeys(asList(keys)); | |||
} | |||
public Builder setComponent(@Nullable String component) { | |||
this.component = component; | |||
return this; | |||
} | |||
public Builder setBranch(@Nullable String branch) { | |||
this.branch = branch; | |||
return this; | |||
} | |||
public ValuesRequest build() { | |||
return new ValuesRequest(this); | |||
} | |||
} | |||
} |
@@ -1,59 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.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_nothing() { | |||
ListDefinitionsRequest result = underTest.build(); | |||
assertThat(result.getComponent()).isNull(); | |||
assertThat(result.getBranch()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component() { | |||
ListDefinitionsRequest result = underTest.setComponent("projectKey").build(); | |||
assertThat(result.getComponent()).isEqualTo("projectKey"); | |||
assertThat(result.getBranch()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component_and_branch() { | |||
ListDefinitionsRequest result = underTest.setComponent("projectKey").setBranch("branch").build(); | |||
assertThat(result.getComponent()).isEqualTo("projectKey"); | |||
assertThat(result.getBranch()).isEqualTo("branch"); | |||
} | |||
} |
@@ -1,68 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.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"); | |||
assertThat(result.getComponent()).isNull(); | |||
assertThat(result.getBranch()).isNull(); | |||
} | |||
@Test | |||
public void component() { | |||
ResetRequest result = underTest.setKeys("my.key").setComponent("project").build(); | |||
assertThat(result.getKeys()).containsOnly("my.key"); | |||
assertThat(result.getComponent()).isEqualTo("project"); | |||
assertThat(result.getBranch()).isNull(); | |||
} | |||
@Test | |||
public void component_and_branch() { | |||
ResetRequest result = underTest.setKeys("my.key").setComponent("project").setBranch("branch").build(); | |||
assertThat(result.getKeys()).containsOnly("my.key"); | |||
assertThat(result.getComponent()).isEqualTo("project"); | |||
assertThat(result.getBranch()).isEqualTo("branch"); | |||
} | |||
@Test | |||
public void fail_when_empty_keys() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
underTest.setKeys().build(); | |||
} | |||
} |
@@ -1,84 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.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.getComponent()).isNull(); | |||
assertThat(result.getBranch()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component_key() { | |||
SetRequest result = underTest.setKey("my.key").setValue("my value").setComponent("projectKey").build(); | |||
assertThat(result.getKey()).isEqualTo("my.key"); | |||
assertThat(result.getValue()).isEqualTo("my value"); | |||
assertThat(result.getComponent()).isEqualTo("projectKey"); | |||
assertThat(result.getBranch()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component_and_branch() { | |||
SetRequest result = underTest.setKey("my.key").setValue("my value").setComponent("projectKey").setBranch("my_branch").build(); | |||
assertThat(result.getKey()).isEqualTo("my.key"); | |||
assertThat(result.getValue()).isEqualTo("my value"); | |||
assertThat(result.getComponent()).isEqualTo("projectKey"); | |||
assertThat(result.getBranch()).isEqualTo("my_branch"); | |||
} | |||
@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(); | |||
} | |||
} |
@@ -1,116 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.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_BRANCH; | |||
import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_COMPONENT; | |||
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() | |||
.setComponent("KEY") | |||
.setBranch("BRANCH") | |||
.build()); | |||
GetRequest getRequest = serviceTester.getGetRequest(); | |||
assertThat(serviceTester.getGetParser()).isSameAs(ListDefinitionsWsResponse.parser()); | |||
serviceTester.assertThat(getRequest) | |||
.hasParam(PARAM_COMPONENT, "KEY") | |||
.hasParam(PARAM_BRANCH, "BRANCH") | |||
.andNoOtherParam(); | |||
} | |||
@Test | |||
public void values() { | |||
underTest.values(ValuesRequest.builder() | |||
.setKeys("sonar.debt,sonar.issue") | |||
.setComponent("KEY") | |||
.setBranch("BRANCH") | |||
.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") | |||
.hasParam(PARAM_BRANCH, "BRANCH") | |||
.andNoOtherParam(); | |||
} | |||
@Test | |||
public void set() { | |||
underTest.set(SetRequest.builder() | |||
.setKey("sonar.debt") | |||
.setValue("8h") | |||
.setValues(newArrayList("v1", "v2", "v3")) | |||
.setFieldValues(newArrayList("json1", "json2", "json3")) | |||
.setComponent("KEY") | |||
.setBranch("BRANCH") | |||
.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, "KEY") | |||
.hasParam(PARAM_BRANCH, "BRANCH") | |||
.andNoOtherParam(); | |||
} | |||
@Test | |||
public void reset() { | |||
underTest.reset(ResetRequest.builder() | |||
.setKeys("sonar.debt") | |||
.setComponent("KEY") | |||
.setBranch("BRANCH") | |||
.build()); | |||
serviceTester.assertThat(serviceTester.getPostRequest()) | |||
.hasParam(PARAM_KEYS, "sonar.debt") | |||
.hasParam(PARAM_COMPONENT, "KEY") | |||
.hasParam(PARAM_BRANCH, "BRANCH") | |||
.andNoOtherParam(); | |||
} | |||
} |
@@ -1,71 +0,0 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonarqube.ws.client.setting; | |||
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.getKeys()).containsOnly("sonar.debt"); | |||
assertThat(result.getComponent()).isNull(); | |||
assertThat(result.getBranch()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_no_keys() { | |||
ValuesRequest result = underTest.build(); | |||
assertThat(result.getKeys()).isEmpty(); | |||
assertThat(result.getComponent()).isNull(); | |||
assertThat(result.getBranch()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component() { | |||
ValuesRequest result = underTest.setKeys("sonar.debt").setComponent("projectKey").build(); | |||
assertThat(result.getKeys()).containsOnly("sonar.debt"); | |||
assertThat(result.getComponent()).isEqualTo("projectKey"); | |||
assertThat(result.getBranch()).isNull(); | |||
} | |||
@Test | |||
public void create_request_with_component_and_branch() { | |||
ValuesRequest result = underTest.setKeys("sonar.debt").setComponent("projectKey").setBranch("branch").build(); | |||
assertThat(result.getKeys()).containsOnly("sonar.debt"); | |||
assertThat(result.getComponent()).isEqualTo("projectKey"); | |||
assertThat(result.getBranch()).isEqualTo("branch"); | |||
} | |||
} |
@@ -39,7 +39,6 @@ | |||
<dependency> | |||
<groupId>org.sonarsource.orchestrator</groupId> | |||
<artifactId>sonar-orchestrator</artifactId> | |||
<version>${orchestrator.version}</version> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> |