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; }
private JSONArray copyAndSanitizeArray(JSONArray jsonArray) { JSONArray result = new JSONArray(); jsonArray.forEach(value -> result.add(copyAndSanitize(value)) ); return result; } }
JSONArray dependencies = new JSONArray(); try { Manifest m = new JarFile(t).getManifest();
@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()); }
/** * 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; }
/** * @param list the list of auth urls to serialize * @return {@code null} if {@code list} is null, empty, or contains only null objects; the JSON * array representation of {@code list} otherwise, with any null element stripped off. */ public static String toString(List<LayerIdentifierInfo> list) { if (list == null || list.isEmpty()) { return null; } JSONArray array = new JSONArray(); for (LayerIdentifierInfo id : list) { if (id == null) { continue; } JSONObject jsonId = new JSONObject(); jsonId.put(AUTHORITY, id.getAuthority()); jsonId.put(IDENTIFIER, id.getIdentifier()); array.add(jsonId); } if (array.size() == 0) { // list was made of only null objects? return null; } String serialized = array.toString(); return serialized; } }
/** * @param list the list of layer identifiers to serialize * @return {@code null} if {@code list} is null, empty or contains only null objects; the JSON * array representation of {@code list} otherwise, with any null element stripped off. */ public static String toString(List<AuthorityURLInfo> obj) { if (obj == null || obj.isEmpty()) { return null; } JSONArray array = new JSONArray(); for (AuthorityURLInfo auth : obj) { if (auth == null) { continue; } JSONObject jsonAuth = new JSONObject(); jsonAuth.put(NAME, auth.getName()); jsonAuth.put(HREF, auth.getHref()); array.add(jsonAuth); } if (array.size() == 0) { // list was made of only null objects? return null; } String serialized = array.toString(); return serialized; } }
@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; }
public HttpResponse doPlugins() { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); JSONArray response = new JSONArray(); Map<String,JSONObject> allPlugins = new HashMap<>(); for (PluginWrapper plugin : plugins) {
json.accumulate("version", p.version); json.accumulate("url", url); json.accumulate("dependencies", new JSONArray());
@Override public JSONArray toJSON() { final JSONArray a = new JSONArray(); for (ModelASTValue argument: arguments) { a.add(argument.toJSON()); } return a; }
@Override public JSONArray toJSON() { final JSONArray a = new JSONArray(); for (Map.Entry<ModelASTKey, ModelASTValue> entry: tools.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, ModelASTEnvironmentValue> 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 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 v : libs) { a.add(v.toJSON()); } return new JSONObject().accumulate("libraries", a); }
@Override public JSONObject toJSON() { final JSONArray a = new JSONArray(); for (ModelASTBuildParameter parameter : parameters) { a.add(parameter.toJSON()); } return new JSONObject().accumulate("parameters", 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 (ModelASTStep step: steps) { a.add(step.toJSON()); } return new JSONObject().accumulate("name", name).accumulate("steps", 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); }