Skip to content

Commit

Permalink
[FIXED JENKINS-15995] fix form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
imod committed Mar 10, 2013
1 parent f7cf9e4 commit 3b1fc4d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 85 deletions.
Expand Up @@ -28,16 +28,13 @@
import java.util.logging.Logger;

import jenkins.model.Jenkins;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.managedscripts.ScriptConfig.Arg;
import org.jenkinsci.plugins.managedscripts.ScriptConfig.ScriptConfigProvider;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.bind.JavaScriptMethod;

/**
Expand All @@ -57,15 +54,38 @@ public class ScriptBuildStep extends Builder {
private final String buildStepId;
private final String[] buildStepArgs;

public static class ArgValue {
public final String arg;

@DataBoundConstructor
public ArgValue(String arg) {
this.arg = arg;
}
}

/**
* The constructor
* The constructor used at form submission
*
* @param buildStepId
* the Id of the config file
* @param defineArgs
* if the passed arguments should be saved (required because of html form submission, which also sends hidden values)
* @param buildStepArgs
* list of arguments specified as buildStepargs
*/
@DataBoundConstructor
public ScriptBuildStep(String buildStepId, boolean defineArgs, ArgValue[] buildStepArgs) {
this.buildStepId = buildStepId;
List<String> l = null;
if (defineArgs && buildStepArgs != null) {
l = new ArrayList<String>();
for (ArgValue arg : buildStepArgs) {
l.add(arg.arg);
}
}
this.buildStepArgs = l == null ? null : l.toArray(new String[l.size()]);
}

public ScriptBuildStep(String buildStepId, String[] buildStepArgs) {
this.buildStepId = buildStepId;
this.buildStepArgs = buildStepArgs;
Expand Down Expand Up @@ -271,42 +291,6 @@ private ConfigProvider getBuildStepConfigProvider() {
return providers.get(ScriptConfigProvider.class);
}

/**
* Creates a new instance of LibraryBuildStep.
*
* @param req
* The web request as initialized by the user.
* @param json
* A JSON object representing the users input.
* @return A LibraryBuildStep instance.
*/
@Override
public ScriptBuildStep newInstance(StaplerRequest req, JSONObject json) {
String id = json.getString("buildStepId");
final JSONObject definedArgs = json.optJSONObject("defineArgs");
if (definedArgs != null && !definedArgs.isNullObject()) {
JSONObject argsObj = definedArgs.optJSONObject("buildStepArgs");
if (argsObj == null) {
JSONArray argsArrayObj = definedArgs.optJSONArray("buildStepArgs");
String[] args = null;
if (argsArrayObj != null) {
Iterator<JSONObject> arguments = argsArrayObj.iterator();
args = new String[argsArrayObj.size()];
int i = 0;
while (arguments.hasNext()) {
args[i++] = arguments.next().getString("arg");
}
}
return new ScriptBuildStep(id, args);
} else {
String[] args = new String[1];
args[0] = argsObj.getString("arg");
return new ScriptBuildStep(id, args);
}
} else {
return new ScriptBuildStep(id, null);
}
}
}

/**
Expand Down
Expand Up @@ -17,15 +17,11 @@
import java.util.List;
import java.util.logging.Logger;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.managedscripts.WinBatchConfig.Arg;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.bind.JavaScriptMethod;

/**
Expand All @@ -39,15 +35,46 @@ public class WinBatchBuildStep extends CommandInterpreter {

private final String[] buildStepArgs;

public static class ArgValue {
public final String arg;

@DataBoundConstructor
public ArgValue(String arg) {
this.arg = arg;
}
}

/**
* The constructor
* The constructor used at form submission
*
* @param buildStepId
* the Id of the config file
* @param defineArgs
* if the passed arguments should be saved (required because of html form submission, which also sends hidden values)
* @param buildStepArgs
* list of arguments specified as buildStepargs
*/
@DataBoundConstructor
public WinBatchBuildStep(String buildStepId, boolean defineArgs, ArgValue[] buildStepArgs) {
super(buildStepId);
List<String> l = null;
if (defineArgs && buildStepArgs != null) {
l = new ArrayList<String>();
for (ArgValue arg : buildStepArgs) {
l.add(arg.arg);
}
}
this.buildStepArgs = l == null ? null : l.toArray(new String[l.size()]);
}

/**
* The constructor
*
* @param buildStepId
* the Id of the config file
* @param buildStepArgs
* list of arguments specified as buildStepargs
*/
public WinBatchBuildStep(String buildStepId, String[] buildStepArgs) {
super(buildStepId); // save buildStepId as command
this.buildStepArgs = buildStepArgs;
Expand Down Expand Up @@ -200,42 +227,6 @@ private ConfigProvider getBuildStepConfigProvider() {
return providers.get(WinBatchConfig.WinBatchConfigProvider.class);
}

/**
* Creates a new instance of LibraryBuildStep.
*
* @param req
* The web request as initialized by the user.
* @param json
* A JSON object representing the users input.
* @return A LibraryBuildStep instance.
*/
@Override
public WinBatchBuildStep newInstance(StaplerRequest req, JSONObject json) {
String id = json.getString("buildStepId");
final JSONObject definedArgs = json.optJSONObject("defineArgs");
if (definedArgs != null && !definedArgs.isNullObject()) {
JSONObject argsObj = definedArgs.optJSONObject("buildStepArgs");
if (argsObj == null) {
JSONArray argsArrayObj = definedArgs.optJSONArray("buildStepArgs");
String[] args = null;
if (argsArrayObj != null) {
Iterator<JSONObject> arguments = argsArrayObj.iterator();
args = new String[argsArrayObj.size()];
int i = 0;
while (arguments.hasNext()) {
args[i++] = arguments.next().getString("arg");
}
}
return new WinBatchBuildStep(id, args);
} else {
String[] args = new String[1];
args[0] = argsObj.getString("arg");
return new WinBatchBuildStep(id, args);
}
} else {
return new WinBatchBuildStep(id, null);
}
}
}

}
Expand Up @@ -33,8 +33,8 @@
<div name="argumentDescription" />
<f:block>
<table>
<f:optionalBlock name="defineArgs" title="${%Define arguments}" checked="${!empty(instance.buildStepArgs)}" help="/plugin/managed-scripts/help-defineArgs.html">
<f:entry title="${%Argument list}" field="buildStepArgs">
<f:optionalBlock name="defineArgs" inline="true" title="${%Define arguments}" checked="${!empty(instance.buildStepArgs)}" help="/plugin/managed-scripts/help-defineArgs.html">
<f:entry>
<f:repeatable var="arg" items="${instance.buildStepArgs}" name="buildStepArgs" noAddButton="true" minimum="1">
<table width="100%">
<f:entry>
Expand Down
Expand Up @@ -34,8 +34,8 @@
<div name="argumentDescription" />
<f:block>
<table>
<f:optionalBlock name="defineArgs" title="${%Define arguments}" checked="${!empty(instance.buildStepArgs)}" help="/plugin/managed-scripts/help-defineArgs_win.html">
<f:entry title="${%Argument list}" field="buildStepArgs">
<f:optionalBlock name="defineArgs" inline="true" title="${%Define arguments}" checked="${!empty(instance.buildStepArgs)}" help="/plugin/managed-scripts/help-defineArgs_win.html">
<f:entry>
<f:repeatable var="arg" items="${instance.buildStepArgs}" name="buildStepArgs" noAddButton="true" minimum="1">
<table width="100%">
<f:entry>
Expand Down

0 comments on commit 3b1fc4d

Please sign in to comment.