use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.
the class JenkinsJSExtensions method getExtensionsData.
/**
* Return the actual data, from /js-extensions
*/
public static JSONArray getExtensionsData() {
Object jsExtensionData = getJenkinsJSExtensionData();
JSONArray jsExtensionDataJson = JSONArray.fromObject(jsExtensionData);
return jsExtensionDataJson;
}
use of net.sf.json.JSONArray in project promoted-builds-plugin by jenkinsci.
the class Status method doBuild.
/**
* Schedules a new build.
* @param req Request
* @param rsp Response
* @throws IOException Functional error
* @throws ServletException Request handling error
*/
public void doBuild(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
final PromotionProcess process = getProcess();
if (process == null) {
throw new AbortException("Cannot retrieve the promotion process");
}
AbstractBuild<?, ?> target = getTarget();
if (target == null) {
throw new AbortException("Cannot get the target build to be promoted");
}
ManualCondition manualCondition = (ManualCondition) process.getPromotionCondition(ManualCondition.class.getName());
if (!target.hasPermission(Promotion.PROMOTE)) {
if (manualCondition == null || (!manualCondition.getUsersAsSet().isEmpty() && !manualCondition.isInUsersList() && !manualCondition.isInGroupList()))
return;
}
JSONObject formData = req.getSubmittedForm();
List<ParameterValue> paramValues = null;
if (formData != null) {
paramValues = new ArrayList<ParameterValue>();
if (manualCondition != null) {
List<ParameterDefinition> parameterDefinitions = manualCondition.getParameterDefinitions();
if (parameterDefinitions != null && !parameterDefinitions.isEmpty()) {
JSONArray a = JSONArray.fromObject(formData.get("parameter"));
for (Object o : a) {
JSONObject jo = (JSONObject) o;
String name = jo.getString("name");
ParameterDefinition d = manualCondition.getParameterDefinition(name);
if (d == null)
throw new IllegalArgumentException("No such parameter definition: " + name);
paramValues.add(d.createValue(req, jo));
}
}
}
}
if (paramValues == null) {
paramValues = new ArrayList<ParameterValue>();
}
Future<Promotion> f = process.scheduleBuild2(target, new UserCause(), paramValues);
if (f == null)
LOGGER.warning("Failing to schedule the promotion of " + target);
// TODO: we need better visual feed back so that the user knows that the build happened.
rsp.forwardToPreviousPage(req);
}
use of net.sf.json.JSONArray in project hudson-2.x by hudson.
the class JSONTest method testCanonicalWriter.
public void testCanonicalWriter() throws IOException {
JSONArray jsonArray = new JSONArray();
jsonArray.add(true);
jsonArray.add(1);
jsonArray.add(5.3);
JSONObject jsonObject = new JSONObject();
jsonObject.put("key1", "1");
jsonObject.put("key2", "2");
jsonObject.put("key3", "3");
jsonObject.put("string", "123\r\n\b\t\f\\\\u65E5\\u672C\\u8A9E");
jsonArray.add(jsonObject);
Writer writer = new StringWriter();
JSONCanonicalUtils.write(jsonArray, writer);
assertEquals(writer.toString(), "[true,1,5.3,{\"key1\":\"1\",\"key2\":\"2\",\"key3\":\"3\",\"string\":\"123\\u000d\\u000a\\u0008\\u0009\\u000c\\\\\\\\u65E5\\\\u672C\\\\u8A9E\"}]");
}
use of net.sf.json.JSONArray in project head by mifos.
the class DatabaseConfiguration method readVCAPConfiguration.
private void readVCAPConfiguration() throws ConfigurationException {
final String vcapServicesVar = System.getenv(VCAP_SERVICES_VAR);
if (vcapServicesVar != null) {
// use database configuration from the system variable to replace the default config
final JSONObject json = (JSONObject) JSONSerializer.toJSON(vcapServicesVar);
String mysqlKey = null;
@SuppressWarnings("rawtypes") final Iterator iterator = json.keys();
while (iterator.hasNext()) {
final String key = (String) iterator.next();
if (key.startsWith("mysql")) {
mysqlKey = key;
break;
}
}
if (mysqlKey == null) {
throw new ConfigurationException(INVALID_STRUCTURE);
}
final JSON mysqlJson = (JSON) json.get(mysqlKey);
JSONObject dbJson;
if (mysqlJson.isArray()) {
final JSONArray mysqlJsonArray = (JSONArray) mysqlJson;
if (mysqlJsonArray.size() < 1) {
throw new ConfigurationException(INVALID_STRUCTURE);
}
dbJson = (JSONObject) mysqlJsonArray.get(0);
} else {
dbJson = (JSONObject) mysqlJson;
}
final JSONObject credentialsJson = (JSONObject) dbJson.get("credentials");
this.dbName = credentialsJson.getString("name");
this.host = credentialsJson.getString("host");
this.port = credentialsJson.getString("port");
this.user = credentialsJson.getString("user");
this.password = credentialsJson.getString("password");
this.dbPentahoDW = credentialsJson.getString("dbPentahoDW");
}
}
use of net.sf.json.JSONArray in project pinpoint by naver.
the class JsonLibJSONArrayIT method jsonToArrayTest.
@SuppressWarnings("deprecation")
@Test
public void jsonToArrayTest() throws Exception {
Method fromObject = JSONArray.class.getMethod("fromObject", Object.class);
Method toArray = JSONArray.class.getMethod("toArray", JSONArray.class);
Method toList = JSONArray.class.getMethod("toList", JSONArray.class);
// JSONArray.toCollection() is added in json-lib 2.2. so check toCollection in JSONArray
Method toCollection = null;
try {
toCollection = JSONArray.class.getMethod("toCollection", JSONArray.class);
} catch (NoSuchMethodException ignored) {
}
String json = "[{'string':'JSON'}]";
JSONArray jsonArray = JSONArray.fromObject(json);
// JSONArray.toArray() of json-lib 2.0 and below have different return type. so we invoke it by reflection to avoid NoSuchMethodError
toArray.invoke(null, jsonArray);
JSONArray.toList(jsonArray);
if (toCollection != null) {
JSONArray.toCollection(jsonArray);
}
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTrace(event(SERVICE_TYPE, fromObject, annotation(ANNOTATION_KEY, json.length())));
verifier.verifyTrace(event(SERVICE_TYPE, toArray));
verifier.verifyTrace(event(SERVICE_TYPE, toList));
if (toCollection != null) {
verifier.verifyTrace(event(SERVICE_TYPE, toCollection));
}
verifier.verifyTraceCount(0);
}
Aggregations