Skip to content

Commit

Permalink
JENKINS-20271 : Added script arg labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ganncamp committed Oct 25, 2013
1 parent ced7636 commit 6f7b3ce
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 165 deletions.
Expand Up @@ -44,7 +44,7 @@
* A project that uses this builder can choose a build step from a list of predefined config files that are uses as command line scripts. The hash-bang sequence at the beginning of each file is used * A project that uses this builder can choose a build step from a list of predefined config files that are uses as command line scripts. The hash-bang sequence at the beginning of each file is used
* to determine the interpreter. * to determine the interpreter.
* <p> * <p>
* *
* @author Norman Baumann * @author Norman Baumann
* @author Dominik Bartholdi (imod) * @author Dominik Bartholdi (imod)
*/ */
Expand All @@ -64,23 +64,35 @@ public ArgValue(String arg) {
} }
} }


public static class ScriptBuildStepArgs {
public final boolean defineArgs;
public final ArgValue[] buildStepArgs;

@DataBoundConstructor
public ScriptBuildStepArgs(boolean defineArgs, ArgValue[] buildStepArgs)
{
this.defineArgs = defineArgs;
this.buildStepArgs = buildStepArgs;
}
}

/** /**
* The constructor used at form submission * The constructor used at form submission
* *
* @param buildStepId * @param buildStepId
* the Id of the config file * the Id of the config file
* @param defineArgs * @param scriptBuildStepArgs
* if the passed arguments should be saved (required because of html form submission, which also sends hidden values) * whether to save the args and arg values (the boolean is required because of html form submission, which also sends hidden values)
* @param buildStepArgs
* list of arguments specified as buildStepargs
*/ */
@DataBoundConstructor @DataBoundConstructor
public ScriptBuildStep(String buildStepId, boolean defineArgs, ArgValue[] buildStepArgs) { public ScriptBuildStep(String buildStepId, ScriptBuildStepArgs scriptBuildStepArgs)
{
this.buildStepId = buildStepId; this.buildStepId = buildStepId;
List<String> l = null; List<String> l = null;
if (defineArgs && buildStepArgs != null) { if (scriptBuildStepArgs != null && scriptBuildStepArgs.defineArgs
&& scriptBuildStepArgs.buildStepArgs != null) {
l = new ArrayList<String>(); l = new ArrayList<String>();
for (ArgValue arg : buildStepArgs) { for (ArgValue arg : scriptBuildStepArgs.buildStepArgs) {
l.add(arg.arg); l.add(arg.arg);
} }
} }
Expand Down Expand Up @@ -217,7 +229,7 @@ public String getDisplayName() {


/** /**
* Return all config files (templates) that the user can choose from when creating a build step. Ordered by name. * Return all config files (templates) that the user can choose from when creating a build step. Ordered by name.
* *
* @return A collection of config files of type {@link ScriptConfig}. * @return A collection of config files of type {@link ScriptConfig}.
*/ */
public Collection<Config> getAvailableBuildTemplates() { public Collection<Config> getAvailableBuildTemplates() {
Expand All @@ -232,7 +244,7 @@ public int compare(Config o1, Config o2) {


/** /**
* Returns a Config object for a given config file Id. * Returns a Config object for a given config file Id.
* *
* @param id * @param id
* The Id of a config file. * The Id of a config file.
* @return If Id can be found a Config object that represents the given Id is returned. Otherwise null. * @return If Id can be found a Config object that represents the given Id is returned. Otherwise null.
Expand All @@ -243,7 +255,7 @@ public ScriptConfig getBuildStepConfigById(String id) {


/** /**
* gets the argument description to be displayed on the screen when selecting a config in the dropdown * gets the argument description to be displayed on the screen when selecting a config in the dropdown
* *
* @param configId * @param configId
* the config id to get the arguments description for * the config id to get the arguments description for
* @return the description * @return the description
Expand All @@ -270,9 +282,15 @@ public String getArgsDescription(String configId) {
return "please select a script!"; return "please select a script!";
} }


@JavaScriptMethod
public List<Arg> getArgs(String configId) {
final ScriptConfig config = getBuildStepConfigById(configId);
return config.args;
}

/** /**
* validate that an existing config was chosen * validate that an existing config was chosen
* *
* @param value * @param value
* the configId * the configId
* @return * @return
Expand Down
Expand Up @@ -27,7 +27,7 @@
/** /**
* A project that uses this builder can choose a build step from a list of predefined windows batch files that are used as command line scripts. * A project that uses this builder can choose a build step from a list of predefined windows batch files that are used as command line scripts.
* <p> * <p>
* *
* @author Dominik Bartholdi (imod) * @author Dominik Bartholdi (imod)
* @see hudson.tasks.BatchFile * @see hudson.tasks.BatchFile
*/ */
Expand All @@ -44,23 +44,33 @@ public ArgValue(String arg) {
} }
} }


public static class ScriptBuildStepArgs {
public final boolean defineArgs;
public final ArgValue[] buildStepArgs;

@DataBoundConstructor
public ScriptBuildStepArgs(boolean defineArgs, ArgValue[] buildStepArgs)
{
this.defineArgs = defineArgs;
this.buildStepArgs = buildStepArgs;
}
}
/** /**
* The constructor used at form submission * The constructor used at form submission
* *
* @param buildStepId * @param buildStepId
* the Id of the config file * the Id of the config file
* @param defineArgs * @param scriptBuildStepArgs
* if the passed arguments should be saved (required because of html form submission, which also sends hidden values) * whether to save the args and arg values (the boolean is required because of html form submission, which also sends hidden values)
* @param buildStepArgs
* list of arguments specified as buildStepargs
*/ */
@DataBoundConstructor @DataBoundConstructor
public WinBatchBuildStep(String buildStepId, boolean defineArgs, ArgValue[] buildStepArgs) { public WinBatchBuildStep(String buildStepId, ScriptBuildStepArgs scriptBuildStepArgs) {
super(buildStepId); super(buildStepId);
List<String> l = null; List<String> l = null;
if (defineArgs && buildStepArgs != null) { if (scriptBuildStepArgs != null && scriptBuildStepArgs.defineArgs
&& scriptBuildStepArgs.buildStepArgs != null) {
l = new ArrayList<String>(); l = new ArrayList<String>();
for (ArgValue arg : buildStepArgs) { for (ArgValue arg : scriptBuildStepArgs.buildStepArgs) {
l.add(arg.arg); l.add(arg.arg);
} }
} }
Expand All @@ -69,7 +79,7 @@ public WinBatchBuildStep(String buildStepId, boolean defineArgs, ArgValue[] buil


/** /**
* The constructor * The constructor
* *
* @param buildStepId * @param buildStepId
* the Id of the config file * the Id of the config file
* @param buildStepArgs * @param buildStepArgs
Expand Down Expand Up @@ -153,7 +163,7 @@ public String getDisplayName() {


/** /**
* Return all batch files (templates) that the user can choose from when creating a build step. Ordered by name. * Return all batch files (templates) that the user can choose from when creating a build step. Ordered by name.
* *
* @return A collection of batch files of type {@link WinBatchConfig}. * @return A collection of batch files of type {@link WinBatchConfig}.
*/ */
public Collection<Config> getAvailableBuildTemplates() { public Collection<Config> getAvailableBuildTemplates() {
Expand All @@ -168,7 +178,7 @@ public int compare(Config o1, Config o2) {


/** /**
* Returns a Config object for a given config file Id. * Returns a Config object for a given config file Id.
* *
* @param id * @param id
* The Id of a config file. * The Id of a config file.
* @return If Id can be found a Config object that represents the given Id is returned. Otherwise null. * @return If Id can be found a Config object that represents the given Id is returned. Otherwise null.
Expand All @@ -179,7 +189,7 @@ public WinBatchConfig getBuildStepConfigById(String id) {


/** /**
* gets the argument description to be displayed on the screen when selecting a config in the dropdown * gets the argument description to be displayed on the screen when selecting a config in the dropdown
* *
* @param configId * @param configId
* the config id to get the arguments description for * the config id to get the arguments description for
* @return the description * @return the description
Expand All @@ -206,9 +216,15 @@ public String getArgsDescription(String configId) {
return "please select a script!"; return "please select a script!";
} }


@JavaScriptMethod
public List<Arg> getArgs(String configId) {
final WinBatchConfig config = getBuildStepConfigById(configId);
return config.args;
}

/** /**
* validate that an existing config was chosen * validate that an existing config was chosen
* *
* @param value * @param value
* the configId * the configId
* @return * @return
Expand Down
@@ -1,67 +1,69 @@
<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"> <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:adjunct assumes="org.kohsuke.stapler.framework.prototype.prototype" includes="org.kohsuke.stapler.bind"/>


<st:once> <st:once>
<script type="text/javascript" src="${rootURL}/plugin/managed-scripts/js/managed-scripts.js" /> <script type="text/javascript" src="${rootURL}/plugin/managed-scripts/js/managed-scripts.js" />
</st:once> </st:once>
<j:choose> <j:choose>
<j:when test="${empty(descriptor.availableBuildTemplates)}"> <j:when test="${empty(descriptor.availableBuildTemplates)}">
<f:entry title=""> <f:entry title="">
<div> <div>
No build templates are defined. Please define one No build templates are defined. Please define one
<a href="/configfiles">here</a>. <a href="/configfiles">here</a>.
</div> </div>
</f:entry> </f:entry>
</j:when> </j:when>
<j:otherwise> <j:otherwise>
<f:entry title="${%Script}" field="buildStepContent"> <f:entry title="${%Script}" field="buildStepContent">
<select name="buildStepId" onChange="ms_initDetailLink('${rootURL}', this);ms_showParams(this, this.value);"> <select name="buildStepId" onChange="ms_initDetailLink('${rootURL}', this);ms_showParams(this, this.value);">
<option value="">(Default)</option> <option value="">(Default)</option>
<j:forEach var="inst" items="${descriptor.availableBuildTemplates}" varStatus="loop"> <j:forEach var="inst" items="${descriptor.availableBuildTemplates}" varStatus="loop">
<j:choose> <j:choose>
<j:when test="${inst.id == instance.buildStepId}"> <j:when test="${inst.id == instance.buildStepId}">
<option value="${inst.id}" selected="selected">${inst.name} - ${inst.comment}</option> <option value="${inst.id}" selected="selected">${inst.name} - ${inst.comment}</option>
</j:when> </j:when>
<j:otherwise> <j:otherwise>
<option value="${inst.id}">${inst.name} - ${inst.comment}</option> <option value="${inst.id}">${inst.name} - ${inst.comment}</option>
</j:otherwise> </j:otherwise>
</j:choose> </j:choose>
</j:forEach> </j:forEach>
</select> </select>
<a target="_blank" name="showDetailLink" href="" style="display:none;" onclick="window.open(this.href,'window','width=900,height=640,resizable,scrollbars,toolbar,menubar') ;return false;"> view selected script</a> <a target="_blank" name="showDetailLink" href="" style="display:none;" onclick="window.open(this.href,'window','width=900,height=640,resizable,scrollbars,toolbar,menubar') ;return false;"> view selected script</a>
<div name="argumentDescription" /> <div name="argumentDescription" id="argumentDescription"/>
<f:block> <f:block>
<table> <table name="scriptBuildStepArgs" id="scriptBuildStepArgs">
<f:optionalBlock name="defineArgs" inline="true" title="${%Define arguments}" checked="${!empty(instance.buildStepArgs)}" help="/plugin/managed-scripts/help-defineArgs.html"> <f:optionalBlock name="defineArgs" inline="true" title="${%Define arguments}" checked="${!empty(instance.buildStepArgs)}" help="/plugin/managed-scripts/help-defineArgs.html">
<f:entry> <f:entry>
<f:repeatable var="arg" items="${instance.buildStepArgs}" name="buildStepArgs" noAddButton="true" minimum="1"> <f:repeatable var="arg" items="${instance.buildStepArgs}" name="buildStepArgs" noAddButton="true" minimum="1">
<table width="100%"> <table width="100%">
<f:entry> <f:entry>
<input type="text" name="arg" value="${arg}" size="80"/> <div name="argName"><st:nbsp/></div>
<input type="button" name="delete_button" value="${%Delete}" class="repeatable-delete show-if-not-only" style="margin-left: 1em;" /> <input type="text" name="arg" value="${arg}" size="80"/>
<input type="button" name="add_button" value="${%Add argument}" class="repeatable-add show-if-last" /> <input type="button" name="delete_button" value="${%Delete}" class="repeatable-delete show-if-not-only" style="margin-left: 1em;" />
</f:entry> <input type="button" name="add_button" onClick="ms_labelArgs()" value="${%Add argument}" class="repeatable-add show-if-last" />
</table> </f:entry>
</f:repeatable> </table>
</f:entry> </f:repeatable>
</f:optionalBlock> </f:entry>
</table> </f:optionalBlock>
</f:block> </table>
</f:entry> </f:block>
</j:otherwise> </f:entry>
</j:choose> </j:otherwise>
<st:bind var="desc" value="${descriptor}"/> </j:choose>
<st:once> <st:bind var="desc" value="${descriptor}"/>
<script type="text/javascript"> <st:once>
Event.observe(window, 'load', function() { <script type="text/javascript">
var all = new Array(); Event.observe(window, 'load', function() {
all = document.getElementsByName('buildStepId'); var all = new Array();
for(var i = 0; i &lt; all.length; i++) { all = document.getElementsByName('buildStepId');
ms_initDetailLink('<j:out value="${rootURL}" />', all.item(i)); for(var i = 0; i &lt; all.length; i++) {
ms_showParams(all.item(i), all.item(i).value); ms_initDetailLink('<j:out value="${rootURL}" />', all.item(i));
} ms_showParams(all.item(i), all.item(i).value);
}); ms_getArgs(all.item(i), all.item(i).value);
</script> }
</st:once> });
</j:jelly> </script>
</st:once>
</j:jelly>

0 comments on commit 6f7b3ce

Please sign in to comment.