Search in sources :

Example 1 with JSONObject

use of org.sonar.wsclient.jsonsimple.JSONObject in project sonarqube by SonarSource.

the class WsCallAndWait method call.

@Nonnull
public RESPONSE call() {
    String response = orchestrator.getServer().wsClient().post(targetRelativeUrl);
    JSONObject jsonObject = toJsonObject(response);
    try {
        return parse(jsonObject);
    } catch (Exception e) {
        throw new IllegalStateException("Failed to parse JSON response", e);
    }
}
Also used : JSONObject(org.sonar.wsclient.jsonsimple.JSONObject) Nonnull(javax.annotation.Nonnull)

Example 2 with JSONObject

use of org.sonar.wsclient.jsonsimple.JSONObject in project sonarqube by SonarSource.

the class ScmTest method getScmData.

private Map<Integer, LineData> getScmData(String fileKey) throws ParseException {
    Map<Integer, LineData> result = new HashMap<>();
    String json = orchestrator.getServer().adminWsClient().get("api/sources/scm", "key", fileKey);
    JSONObject obj = (JSONObject) JSONValue.parse(json);
    JSONArray array = (JSONArray) obj.get("scm");
    for (Object anArray : array) {
        JSONArray item = (JSONArray) anArray;
        String datetime = (String) item.get(2);
        result.put(((Long) item.get(0)).intValue(), new LineData((String) item.get(3), datetime, (String) item.get(1)));
    }
    return result;
}
Also used : JSONObject(org.sonar.wsclient.jsonsimple.JSONObject) HashMap(java.util.HashMap) JSONArray(org.sonar.wsclient.jsonsimple.JSONArray) JSONObject(org.sonar.wsclient.jsonsimple.JSONObject)

Example 3 with JSONObject

use of org.sonar.wsclient.jsonsimple.JSONObject in project sonarqube by SonarSource.

the class WsCallAndWait method toJsonObject.

private JSONObject toJsonObject(String s) {
    try {
        JSONParser parser = new JSONParser();
        Object o = parser.parse(s);
        if (o instanceof JSONObject) {
            return (JSONObject) o;
        }
        throw new RuntimeException("Can not parse response from server migration WS (not a JSON object)");
    } catch (Exception e) {
        throw new IllegalStateException("Invalid JSON: " + s, e);
    }
}
Also used : JSONObject(org.sonar.wsclient.jsonsimple.JSONObject) JSONParser(org.sonar.wsclient.jsonsimple.parser.JSONParser) JSONObject(org.sonar.wsclient.jsonsimple.JSONObject)

Aggregations

JSONObject (org.sonar.wsclient.jsonsimple.JSONObject)3 HashMap (java.util.HashMap)1 Nonnull (javax.annotation.Nonnull)1 JSONArray (org.sonar.wsclient.jsonsimple.JSONArray)1 JSONParser (org.sonar.wsclient.jsonsimple.parser.JSONParser)1