Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-13518] Wrong JSON syntax
  • Loading branch information
imod committed Apr 27, 2012
1 parent 738d306 commit f754210
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 5 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Expand Up @@ -4,6 +4,7 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.430</version>
<!-- <version>1.460</version> version caused JENKINS-13518 -->
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -24,15 +25,13 @@
<repositories>
<repository>
<id>m.g.o-public</id>
<!-- <url>http://maven.glassfish.org/content/groups/public/</url> -->
<url>http://maven.jenkins-ci.org/content/groups/artifacts/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>m.g.o-public</id>
<!-- <url>http://maven.glassfish.org/content/groups/public/</url> -->
<url>http://maven.jenkins-ci.org/content/groups/artifacts/</url>
<url>http://maven.jenkins-ci.org/content/groups/artifacts/</url>
</pluginRepository>
</pluginRepositories>
<properties>
Expand Down
Expand Up @@ -19,8 +19,8 @@ public class UIHelper {
*/
public static Parameter[] extractParameters(JSONObject json) throws ServletException {
Parameter[] parameters = new Parameter[0];
final JSONObject defineParams = json.getJSONObject("defineParams");
if (!defineParams.isNullObject()) {
final JSONObject defineParams = json.optJSONObject("defineParams");
if (defineParams != null && !defineParams.isNullObject()) {
JSONObject argsObj = defineParams.optJSONObject("parameters");
if (argsObj == null) {
JSONArray argsArrayObj = defineParams.optJSONArray("parameters");
Expand Down
@@ -1,5 +1,6 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<st:adjunct assumes="org.kohsuke.stapler.framework.prototype.prototype" includes="org.kohsuke.stapler.bind"/>
<st:once>
<script type="text/javascript" src="${rootURL}/plugin/scriptler/lib/scriptler.js" />
</st:once>
Expand Down
@@ -0,0 +1,44 @@
package org.jenkinsci.plugins.scriptler.share.scriptlerweb;

import java.io.IOException;
import java.io.InputStream;

import junit.framework.TestCase;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;

import org.apache.commons.io.IOUtils;
import org.jenkinsci.plugins.scriptler.config.Parameter;
import org.jenkinsci.plugins.scriptler.util.UIHelper;

public class UIHelperTest extends TestCase {

public void testExtractParameters1() throws Exception {
JSONObject json = getJsonFromFile("/simple1.json");
final Parameter[] extractParameters = UIHelper.extractParameters(json);
assertNotNull("no parameters extracted", extractParameters);
assertEquals("not all params extracted", 2, extractParameters.length);
}

public void testExtractParameters2() throws Exception {
JSONObject json = getJsonFromFile("/simple2.json");
final Parameter[] extractParameters = UIHelper.extractParameters(json);
assertNotNull("no parameters extracted", extractParameters);
assertEquals("not all params extracted", 2, extractParameters.length);
}

public void testExtractParameters_JENKINS_13518() throws Exception {
JSONObject json = getJsonFromFile("/JENKINS-13518.json");
final Parameter[] extractParameters = UIHelper.extractParameters(json);
assertNotNull("no parameters extracted", extractParameters);
assertEquals("not all params extracted", 0, extractParameters.length);
}

private JSONObject getJsonFromFile(String resource) throws IOException {
InputStream is = UIHelperTest.class.getResourceAsStream(resource);
String jsonTxt = IOUtils.toString(is);
JSONObject json = (JSONObject) JSONSerializer.toJSON(jsonTxt);
return json;
}

}
1 change: 1 addition & 0 deletions src/test/resources/JENKINS-13518.json
@@ -0,0 +1 @@
{"":"","builder":{"backupJobName":"","builderId":"","defineParams":false,"kind":"org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder","parameters":[{"name":"","value":""},{"name":"","value":""}],"scriptlerScriptId":"testOutput.groovy","stapler-class":"org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder"},"core:apply":"","description":"","displayNameOrNull":"","name":"test","properties":{"hudson-model-ParametersDefinitionProperty":{},"org-jenkinsci-plugins-envinject-EnvInjectJobProperty":{},"stapler-class-bag":"true"},"scm":{"value":"0"}}
1 change: 1 addition & 0 deletions src/test/resources/simple1.json
@@ -0,0 +1 @@
{"backupJobName":"new","builderId":"1331321162149_1","defineParams":{"parameters":[{"name":"jobName","value":"${JOB}"},{"name":"buildRange","value":"1-10"}]},"kind":"org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder$DescriptorImpl","scriptlerScriptId":"bulkDeleteBuilds.groovy","stapler-class":"org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder"}
1 change: 1 addition & 0 deletions src/test/resources/simple2.json
@@ -0,0 +1 @@
{"backupJobName":"","builderId":"","defineParams":{"parameters":[{"name":"param1","value":"value1"},{"name":"param2","value":"value2"}]},"kind":"org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder$DescriptorImpl","scriptlerScriptId":"bulkDeleteBuilds.groovy","stapler-class":"org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder"}

0 comments on commit f754210

Please sign in to comment.