Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
bd2a4c85
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bd2a4c85
编写于
10月 08, 2013
作者:
O
Oliver Gondža
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #968 from akiellor/JENKINS-18434
上级
8a556798
c4e2e597
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
52 addition
and
9 deletion
+52
-9
core/src/main/java/hudson/model/ChoiceParameterDefinition.java
...src/main/java/hudson/model/ChoiceParameterDefinition.java
+22
-8
core/src/main/resources/hudson/model/ChoiceParameterDefinition/config.jelly
...urces/hudson/model/ChoiceParameterDefinition/config.jelly
+1
-1
core/src/main/resources/hudson/model/Messages.properties
core/src/main/resources/hudson/model/Messages.properties
+1
-0
core/src/test/java/hudson/model/ChoiceParameterDefinitionTest.java
...test/java/hudson/model/ChoiceParameterDefinitionTest.java
+28
-0
未找到文件。
core/src/main/java/hudson/model/ChoiceParameterDefinition.java
浏览文件 @
bd2a4c85
package
hudson.model
;
import
hudson.util.FormValidation
;
import
org.kohsuke.stapler.QueryParameter
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.DataBoundConstructor
;
import
org.kohsuke.stapler.export.Exported
;
...
...
@@ -15,25 +17,26 @@ import java.util.Arrays;
* @author huybrechts
*/
public
class
ChoiceParameterDefinition
extends
SimpleParameterDefinition
{
public
static
final
String
CHOICES_DELIMETER
=
"\\r?\\n"
;
private
final
List
<
String
>
choices
;
private
final
String
defaultValue
;
public
static
boolean
areValidChoices
(
String
choices
)
{
String
strippedChoices
=
choices
.
trim
();
return
!
StringUtils
.
isEmpty
(
strippedChoices
)
&&
strippedChoices
.
split
(
CHOICES_DELIMETER
).
length
>
0
;
}
@DataBoundConstructor
public
ChoiceParameterDefinition
(
String
name
,
String
choices
,
String
description
)
{
super
(
name
,
description
);
this
.
choices
=
Arrays
.
asList
(
choices
.
split
(
"\\r?\\n"
));
if
(
choices
.
length
()==
0
)
{
throw
new
IllegalArgumentException
(
"No choices found"
);
}
this
.
choices
=
Arrays
.
asList
(
choices
.
split
(
CHOICES_DELIMETER
));
defaultValue
=
null
;
}
public
ChoiceParameterDefinition
(
String
name
,
String
[]
choices
,
String
description
)
{
super
(
name
,
description
);
this
.
choices
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
choices
));
if
(
this
.
choices
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"No choices found"
);
}
defaultValue
=
null
;
}
...
...
@@ -52,7 +55,7 @@ public class ChoiceParameterDefinition extends SimpleParameterDefinition {
return
this
;
}
}
@Exported
public
List
<
String
>
getChoices
()
{
return
choices
;
...
...
@@ -95,6 +98,17 @@ public class ChoiceParameterDefinition extends SimpleParameterDefinition {
public
String
getHelpFile
()
{
return
"/help/parameter/choice.html"
;
}
/**
* Checks if parameterised build choices are valid.
*/
public
FormValidation
doCheckChoices
(
@QueryParameter
String
value
)
{
if
(
ChoiceParameterDefinition
.
areValidChoices
(
value
))
{
return
FormValidation
.
ok
();
}
else
{
return
FormValidation
.
error
(
Messages
.
ChoiceParameterDefinition_MissingChoices
());
}
}
}
}
\ No newline at end of file
core/src/main/resources/hudson/model/ChoiceParameterDefinition/config.jelly
浏览文件 @
bd2a4c85
...
...
@@ -30,7 +30,7 @@ THE SOFTWARE.
<f:textbox name="parameter.name" value="${instance.name}" />
</f:entry>
<f:entry title="${%Choices}" help="/help/parameter/choice-choices.html">
<f:textarea name="parameter.choices" value="${instance.choicesText}" />
<f:textarea
checkUrl="'${rootURL}/descriptorByName/hudson.model.ChoiceParameterDefinition/checkChoices?value='+encodeURIComponent(this.value)"
name="parameter.choices" value="${instance.choicesText}" />
</f:entry>
<f:entry title="${%Description}" help="/help/parameter/description.html">
<f:textarea name="parameter.description" value="${instance.description}" />
...
...
core/src/main/resources/hudson/model/Messages.properties
浏览文件 @
bd2a4c85
...
...
@@ -308,6 +308,7 @@ TextParameterDefinition.DisplayName=Text Parameter
FileParameterDefinition.DisplayName
=
File Parameter
BooleanParameterDefinition.DisplayName
=
Boolean Value
ChoiceParameterDefinition.DisplayName
=
Choice
ChoiceParameterDefinition.MissingChoices
=
Requires Choices.
RunParameterDefinition.DisplayName
=
Run Parameter
PasswordParameterDefinition.DisplayName
=
Password Parameter
...
...
core/src/test/java/hudson/model/ChoiceParameterDefinitionTest.java
0 → 100644
浏览文件 @
bd2a4c85
package
hudson.model
;
import
hudson.util.FormValidation
;
import
jenkins.model.Jenkins
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
ChoiceParameterDefinitionTest
{
@Test
public
void
shouldValidateChoices
(){
assertFalse
(
ChoiceParameterDefinition
.
areValidChoices
(
""
));
assertFalse
(
ChoiceParameterDefinition
.
areValidChoices
(
" "
));
assertTrue
(
ChoiceParameterDefinition
.
areValidChoices
(
"abc"
));
assertTrue
(
ChoiceParameterDefinition
.
areValidChoices
(
"abc\ndef"
));
assertTrue
(
ChoiceParameterDefinition
.
areValidChoices
(
"abc\r\ndef"
));
}
@Test
public
void
testCheckChoices
()
throws
Exception
{
ChoiceParameterDefinition
.
DescriptorImpl
descriptorImpl
=
new
ChoiceParameterDefinition
.
DescriptorImpl
();
assertEquals
(
FormValidation
.
Kind
.
OK
,
descriptorImpl
.
doCheckChoices
(
"abc\ndef"
).
kind
);
assertEquals
(
FormValidation
.
Kind
.
ERROR
,
descriptorImpl
.
doCheckChoices
(
""
).
kind
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录