private JSONArray collectProblems(Map<Source, String> issues, String severity) { final JSONArray problems = new JSONArray(); issues.entrySet().stream().map(e -> new JSONObject().accumulate("line", e.getKey().line).accumulate(severity, e.getValue())) .forEach(problems::add); return problems; }
@SuppressWarnings("unchecked") private JSONObject copyAndSanitizeObject(JSONObject jsonObject) { Set<String> redactedKeySet = retrieveRedactedKeys(jsonObject); JSONObject result = new JSONObject(); jsonObject.keySet().forEach(keyObject -> { String key = keyObject.toString(); if (redactedKeySet.contains(key)) { result.accumulate(key, REDACT_VALUE); } else { Object value = jsonObject.get(keyObject); result.accumulate(key, copyAndSanitize(value)); } }); return result; }
@Override protected synchronized JSON data() { JSONArray r = new JSONArray(); for (User u : modified) { UserInfo i = users.get(u); JSONObject entry = new JSONObject(). accumulate("id", u.getId()). accumulate("fullName", u.getFullName()). accumulate("url", u.getUrl()). accumulate("avatar", i.avatar != null ? i.avatar : Stapler.getCurrentRequest().getContextPath() + Functions.getResourcePath() + "/images/" + iconSize + "/user.png"). accumulate("timeSortKey", i.getTimeSortKey()). accumulate("lastChangeTimeString", i.getLastChangeTimeString()); Job<?,?> p = i.getJob(); if (p != null) { entry.accumulate("projectUrl", p.getUrl()).accumulate("projectFullDisplayName", p.getFullDisplayName()); } r.add(entry); } modified.clear(); return r; }
/** * Like {@link #doInstallNecessaryPlugins(StaplerRequest)} but only checks if everything is installed * or if some plugins need updates or installation. * * This method runs without side-effect. I'm still requiring the ADMINISTER permission since * XML file can contain various external references and we don't configure parsers properly against * that. * * @since 1.483 */ @RequirePOST public JSONArray doPrevalidateConfig(StaplerRequest req) throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); JSONArray response = new JSONArray(); for (Map.Entry<String,VersionNumber> p : parseRequestedPlugins(req.getInputStream()).entrySet()) { PluginWrapper pw = getPlugin(p.getKey()); JSONObject j = new JSONObject() .accumulate("name", p.getKey()) .accumulate("version", p.getValue().toString()); if (pw == null) { // install new response.add(j.accumulate("mode", "missing")); } else if (pw.isOlderThan(p.getValue())) { // upgrade response.add(j.accumulate("mode", "old")); } // else already good } return response; }
@RequirePOST public void doCheck(StaplerRequest req, StaplerResponse res) throws Exception { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { res.sendError(HttpServletResponse.SC_FORBIDDEN); return; } final Map<Source, String> issues = checkWith(new YamlSource<HttpServletRequest>(req, YamlSource.READ_FROM_REQUEST)); res.setContentType("application/json"); final JSONArray warnings = new JSONArray(); issues.entrySet().stream().map(e -> new JSONObject().accumulate("line", e.getKey().line).accumulate("warning", e.getValue())) .forEach(warnings::add); warnings.write(res.getWriter()); }
@RequirePOST @Restricted(NoExternalUse.class) public HttpResponse doConfigureInstance(StaplerRequest req, @QueryParameter String rootUrl) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); Map<String, String> errors = new HashMap<>(); // pre-check data checkRootUrl(errors, rootUrl); if(!errors.isEmpty()){ return HttpResponses.errorJSON(Messages.SetupWizard_ConfigureInstance_ValidationErrors(), errors); } // use the parameters to configure the instance useRootUrl(errors, rootUrl); if(!errors.isEmpty()){ return HttpResponses.errorJSON(Messages.SetupWizard_ConfigureInstance_ValidationErrors(), errors); } InstallUtil.proceedToNextStateFrom(InstallState.CONFIGURE_INSTANCE); CrumbIssuer crumbIssuer = Jenkins.get().getCrumbIssuer(); JSONObject data = new JSONObject(); if (crumbIssuer != null) { data.accumulate("crumbRequestField", crumbIssuer.getCrumbRequestField()).accumulate("crumb", crumbIssuer.getCrumb(req)); } return HttpResponses.okJSON(data); }
json.accumulate("name", p.shortname); json.accumulate("version", p.version); json.accumulate("url", url); json.accumulate("dependencies", new JSONArray());
JSONObject data = new JSONObject(); if (crumbIssuer != null) { data.accumulate("crumbRequestField", crumbIssuer.getCrumbRequestField()).accumulate("crumb", crumbIssuer.getCrumb(req));
/** * Report result to be a failure message due to the given error messages. * * @param result the result to mutate * @param errors the errors */ private void reportFailure(JSONObject result, JSONArray errors) { result.accumulate("result", "failure"); result.accumulate("errors", errors); }
private JSONArray collectProblems(Map<Source, String> issues, String severity) { final JSONArray problems = new JSONArray(); issues.entrySet().stream().map(e -> new JSONObject().accumulate("line", e.getKey().line).accumulate(severity, e.getValue())) .forEach(problems::add); return problems; }
@Override public JSONObject toJSON(JsonSerializeType jsonSerializeType) { JSONObject result = super.toJSON(jsonSerializeType); result.accumulate("serialPort", portName); return result; }
@Override public JSONObject toJSON() { return new JSONObject() .accumulate("isLiteral", isLiteral()) .accumulate("value", getValue()); }
@Override public JSONArray toJSON() { final JSONArray a = new JSONArray(); for (Map.Entry<ModelASTKey, ModelASTValue> entry: arguments.entrySet()) { JSONObject o = new JSONObject(); o.accumulate("key", entry.getKey().toJSON()); o.accumulate("value", entry.getValue().toJSON()); a.add(o); } return a; }
@Override public JSONArray toJSON() { final JSONArray a = new JSONArray(); for (Map.Entry<ModelASTKey, ModelASTMethodArg> entry: variables.entrySet()) { JSONObject o = new JSONObject(); o.accumulate("key", entry.getKey().toJSON()); o.accumulate("value", entry.getValue().toJSON()); a.add(o); } return a; }
@Override public JSONObject toJSON() { final JSONArray a = new JSONArray(); for (ModelASTValue arg: args) { a.add(arg.toJSON()); } return new JSONObject().accumulate("name", name).accumulate("arguments", a); }
@Override public JSONObject toJSON() { final JSONArray a = new JSONArray(); for (ModelASTStep child:children) { a.add(child.toJSON()); } return super.toJSON().accumulate("children", a); }
@Override public JSONObject toJSON() { final JSONArray a = new JSONArray(); for (ModelASTOption option : options) { a.add(option.toJSON()); } return new JSONObject().accumulate("options", a); }
@Override public JSONObject toJSON() { final JSONArray a = new JSONArray(); for (ModelASTBuildCondition condition: conditions) { a.add(condition.toJSON()); } return new JSONObject().accumulate("conditions", a); }
@Override public JSONObject toJSON() { final JSONArray a = new JSONArray(); for (ModelASTTrigger trigger: triggers) { a.add(trigger.toJSON()); } return new JSONObject().accumulate("triggers", a); }
@Override public JSONObject toJSON() { final JSONArray a = new JSONArray(); for (ModelASTBuildParameter parameter : parameters) { a.add(parameter.toJSON()); } return new JSONObject().accumulate("parameters", a); }