Skip to content
Permalink
Browse files

JENKINS-20271 : Added script arg labels

  • Loading branch information
ganncamp
ganncamp committed Oct 25, 2013
1 parent ced7636 commit 6f7b3cea02a32d381c65c259964b39a069173439
@@ -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
* to determine the interpreter.
* <p>
*
*
* @author Norman Baumann
* @author Dominik Bartholdi (imod)
*/
@@ -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
*
*
* @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
* @param scriptBuildStepArgs
* whether to save the args and arg values (the boolean is required because of html form submission, which also sends hidden values)
*/
@DataBoundConstructor
public ScriptBuildStep(String buildStepId, boolean defineArgs, ArgValue[] buildStepArgs) {
public ScriptBuildStep(String buildStepId, ScriptBuildStepArgs scriptBuildStepArgs)
{
this.buildStepId = buildStepId;
List<String> l = null;
if (defineArgs && buildStepArgs != null) {
if (scriptBuildStepArgs != null && scriptBuildStepArgs.defineArgs
&& scriptBuildStepArgs.buildStepArgs != null) {
l = new ArrayList<String>();
for (ArgValue arg : buildStepArgs) {
for (ArgValue arg : scriptBuildStepArgs.buildStepArgs) {
l.add(arg.arg);
}
}
@@ -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 A collection of config files of type {@link ScriptConfig}.
*/
public Collection<Config> getAvailableBuildTemplates() {
@@ -232,7 +244,7 @@ public int compare(Config o1, Config o2) {

/**
* Returns a Config object for a given config file Id.
*
*
* @param id
* The Id of a config file.
* @return If Id can be found a Config object that represents the given Id is returned. Otherwise null.
@@ -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
*
*
* @param configId
* the config id to get the arguments description for
* @return the description
@@ -270,9 +282,15 @@ public String getArgsDescription(String configId) {
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
*
*
* @param value
* the configId
* @return
@@ -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.
* <p>
*
*
* @author Dominik Bartholdi (imod)
* @see hudson.tasks.BatchFile
*/
@@ -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
*
*
* @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
* @param scriptBuildStepArgs
* whether to save the args and arg values (the boolean is required because of html form submission, which also sends hidden values)
*/
@DataBoundConstructor
public WinBatchBuildStep(String buildStepId, boolean defineArgs, ArgValue[] buildStepArgs) {
public WinBatchBuildStep(String buildStepId, ScriptBuildStepArgs scriptBuildStepArgs) {
super(buildStepId);
List<String> l = null;
if (defineArgs && buildStepArgs != null) {
if (scriptBuildStepArgs != null && scriptBuildStepArgs.defineArgs
&& scriptBuildStepArgs.buildStepArgs != null) {
l = new ArrayList<String>();
for (ArgValue arg : buildStepArgs) {
for (ArgValue arg : scriptBuildStepArgs.buildStepArgs) {
l.add(arg.arg);
}
}
@@ -69,7 +79,7 @@ public WinBatchBuildStep(String buildStepId, boolean defineArgs, ArgValue[] buil

/**
* The constructor
*
*
* @param buildStepId
* the Id of the config file
* @param buildStepArgs
@@ -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 A collection of batch files of type {@link WinBatchConfig}.
*/
public Collection<Config> getAvailableBuildTemplates() {
@@ -168,7 +178,7 @@ public int compare(Config o1, Config o2) {

/**
* Returns a Config object for a given config file Id.
*
*
* @param id
* The Id of a config file.
* @return If Id can be found a Config object that represents the given Id is returned. Otherwise null.
@@ -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
*
*
* @param configId
* the config id to get the arguments description for
* @return the description
@@ -206,9 +216,15 @@ public String getArgsDescription(String configId) {
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
*
*
* @param value
* the configId
* @return
@@ -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">

<st:adjunct assumes="org.kohsuke.stapler.framework.prototype.prototype" includes="org.kohsuke.stapler.bind"/>

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

0 comments on commit 6f7b3ce

Please sign in to comment.
You can’t perform that action at this time.