Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-20271 : Added script arg labels #2

Merged
merged 5 commits into from
Nov 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
* to determine the interpreter.
* <p>
*
*
* @author Norman Baumann
* @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
*
*
* @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);
}
}
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 A collection of config files of type {@link ScriptConfig}.
*/
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.
*
*
* @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.
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
*
*
* @param configId
* the config id to get the arguments description for
* @return the description
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
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.
* <p>
*
*
* @author Dominik Bartholdi (imod)
* @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
*
*
* @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);
}
}
Expand All @@ -69,7 +79,7 @@ public WinBatchBuildStep(String buildStepId, boolean defineArgs, ArgValue[] buil

/**
* The constructor
*
*
* @param buildStepId
* the Id of the config file
* @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 A collection of batch files of type {@link WinBatchConfig}.
*/
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.
*
*
* @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.
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
*
*
* @param configId
* the config id to get the arguments description for
* @return the description
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@
</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" />
<div name="argumentDescription" id="argumentDescription"/>
<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: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" value="${%Add argument}" class="repeatable-add show-if-last" />
<input type="button" name="add_button" onClick="ms_labelArgs()" value="${%Add argument}" class="repeatable-add show-if-last" />
</f:entry>
</table>
</f:repeatable>
Expand All @@ -60,6 +61,7 @@
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<f:entry title="">
<div>
No build templates are defined. Please define one
<a href="/configfiles">here</a>
.
<a href="/configfiles">here</a>.
</div>
</f:entry>
</j:when>
Expand All @@ -31,17 +30,18 @@
</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" />
<div name="argumentDescription" id="argumentDescription"/>
<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_win.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" value="${%Add argument}" class="repeatable-add show-if-last" />
<input type="button" name="add_button" onClick="ms_labelArgs()" value="${%Add argument}" class="repeatable-add show-if-last" />
</f:entry>
</table>
</f:repeatable>
Expand All @@ -61,6 +61,7 @@
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>
Expand Down
32 changes: 29 additions & 3 deletions src/main/webapp/js/managed-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,39 @@ function ms_descArguments(referenceTag, desc){
var descriptionTag = document.getElementsByName('argumentDescription').item(i);
descriptionTag.innerHTML = desc;
}
}
}
}

function ms_showParams(referenceTag, scriptId){
desc.getArgsDescription(scriptId, function(t) {
ms_descArguments(referenceTag, t.responseObject());
desc.getArgsDescription(scriptId, function(t) {
ms_descArguments(referenceTag, t.responseObject());
});
ms_getArgs(referenceTag,scriptId);
}

function ms_getArgs(referenceTag, scriptId){
desc.getArgs(scriptId,function(t){
referenceTag.args = JSON.parse(t.responseText);
ms_labelArgs(referenceTag);
});
}

function ms_labelArgs(referenceTag)
{
var all = new Array();
all = document.getElementsByName('buildStepId');
for(var i = 0; i < all.length; i++)
{
if(!referenceTag || referenceTag === all.item(i))
{
var args = all.item(i).args;
var parent = document.getElementsByName('scriptBuildStepArgs').item(i);
var argNameDivs = parent.querySelectorAll('[name=argName]');
for (var j=0; j < argNameDivs.length; j++)
{
argNameDivs[j].innerHTML = args[j].name;
}
}
}
}