Search in sources :

Example 1 with JSONNull

use of net.sf.json.JSONNull in project phabricator-jenkins-plugin by uber.

the class SendHarbormasterResultTask method sendMessage.

/**
 * Try to send a message to harbormaster
 * @param unitResults the unit testing results to send
 * @param coverage the coverage data to send
 * @return false if an error was encountered
 */
private boolean sendMessage(UnitResults unitResults, Map<String, String> coverage, LintResults lintResults) throws IOException, ConduitAPIException {
    JSONObject result = diffClient.sendHarbormasterMessage(phid, harbormasterSuccess, unitResults, coverage, lintResults);
    if (result.containsKey("error_info") && !(result.get("error_info") instanceof JSONNull)) {
        info(String.format("Error from Harbormaster: %s", result.getString("error_info")));
        failTask();
        return false;
    } else {
        this.result = Result.SUCCESS;
    }
    return true;
}
Also used : JSONObject(net.sf.json.JSONObject) JSONNull(net.sf.json.JSONNull)

Example 2 with JSONNull

use of net.sf.json.JSONNull in project phabricator-jenkins-plugin by uber.

the class SendHarbormasterUriTask method execute.

@Override
protected void execute() {
    try {
        JSONObject result = diffClient.sendHarbormasterUri(phid, buildUri);
        if (result.containsKey("error_info") && !(result.get("error_info") instanceof JSONNull)) {
            info(String.format("Harbormaster declined URI artifact: %s", result.getString("error_info")));
            this.result = Result.FAILURE;
        } else {
            this.result = Result.SUCCESS;
        }
    } catch (ConduitAPIException e) {
        e.printStackTrace();
        this.result = Result.FAILURE;
    } catch (IOException e) {
        e.printStackTrace();
        this.result = Result.FAILURE;
    }
}
Also used : JSONObject(net.sf.json.JSONObject) JSONNull(net.sf.json.JSONNull) ConduitAPIException(com.uber.jenkins.phabricator.conduit.ConduitAPIException) IOException(java.io.IOException)

Example 3 with JSONNull

use of net.sf.json.JSONNull in project jmeter-plugins-manager by undera.

the class Plugin method fromJSON.

public static Plugin fromJSON(JSONObject elm) {
    Plugin inst = new Plugin(elm.getString("id"));
    if (!(elm.get("markerClass") instanceof JSONNull)) {
        inst.markerClass = elm.getString("markerClass");
    }
    inst.componentClasses = new ArrayList<>();
    if (inst.markerClass != null) {
        inst.componentClasses.add(inst.markerClass);
    }
    if (elm.containsKey("componentClasses")) {
        JSONArray componentsJSON = elm.getJSONArray("componentClasses");
        if (componentsJSON.size() > 0) {
            for (int i = 0; i < componentsJSON.size(); i++) {
                inst.componentClasses.add(componentsJSON.getString(i));
            }
        }
    }
    if (elm.get("versions") instanceof JSONObject) {
        inst.versions = elm.getJSONObject("versions");
    }
    inst.name = elm.getString("name");
    inst.description = elm.getString("description");
    if (elm.containsKey("screenshotUrl")) {
        inst.screenshot = elm.getString("screenshotUrl");
    }
    inst.helpLink = elm.getString("helpUrl");
    inst.vendor = elm.getString("vendor");
    if (elm.containsKey("canUninstall")) {
        inst.canUninstall = elm.getBoolean("canUninstall");
    }
    if (elm.containsKey("installerClass")) {
        inst.installerClass = elm.getString("installerClass");
    }
    return inst;
}
Also used : JSONNull(net.sf.json.JSONNull) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray)

Example 4 with JSONNull

use of net.sf.json.JSONNull in project phabricator-jenkins-plugin by uber.

the class UberallsClient method getParentCoverage.

public CodeCoverageMetrics getParentCoverage(String sha) {
    if (sha == null) {
        return null;
    }
    try {
        String coverageJSON = getCoverage(sha);
        JsonSlurper jsonParser = new JsonSlurper();
        JSON responseJSON = jsonParser.parseText(coverageJSON);
        if (responseJSON instanceof JSONNull) {
            return null;
        }
        JSONObject coverage = (JSONObject) responseJSON;
        return new CodeCoverageMetrics(((Double) coverage.getDouble(PACKAGE_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(FILES_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(CLASSES_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(METHOD_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(LINE_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(CONDITIONAL_COVERAGE_KEY)).floatValue());
    } catch (Exception e) {
        e.printStackTrace(logger.getStream());
    }
    return null;
}
Also used : CodeCoverageMetrics(com.uber.jenkins.phabricator.coverage.CodeCoverageMetrics) JsonSlurper(net.sf.json.groovy.JsonSlurper) JSONNull(net.sf.json.JSONNull) JSONObject(net.sf.json.JSONObject) JSON(net.sf.json.JSON) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException)

Example 5 with JSONNull

use of net.sf.json.JSONNull in project phabricator-jenkins-plugin by uber.

the class PostCommentTask method execute.

/**
 * {@inheritDoc}
 */
@Override
protected void execute() {
    JSONObject postDifferentialCommentResult = postDifferentialComment(comment, SILENT, commentAction);
    if (postDifferentialCommentResult == null || !(postDifferentialCommentResult.get("error_info") instanceof JSONNull)) {
        if (postDifferentialCommentResult != null) {
            info(String.format("Got error %s with action %s", postDifferentialCommentResult.get("error_info"), commentAction));
        }
        info("Re-trying with action 'none'");
        postDifferentialComment(comment, SILENT, DEFAULT_COMMENT_ACTION);
    }
}
Also used : JSONObject(net.sf.json.JSONObject) JSONNull(net.sf.json.JSONNull)

Aggregations

JSONNull (net.sf.json.JSONNull)5 JSONObject (net.sf.json.JSONObject)5 IOException (java.io.IOException)2 ConduitAPIException (com.uber.jenkins.phabricator.conduit.ConduitAPIException)1 CodeCoverageMetrics (com.uber.jenkins.phabricator.coverage.CodeCoverageMetrics)1 URISyntaxException (java.net.URISyntaxException)1 JSON (net.sf.json.JSON)1 JSONArray (net.sf.json.JSONArray)1 JsonSlurper (net.sf.json.groovy.JsonSlurper)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 HttpResponseException (org.apache.http.client.HttpResponseException)1