Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
d244b6b6
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,发现更多精彩内容 >>
提交
d244b6b6
编写于
10月 07, 2013
作者:
A
Andrew Kiellor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIXES JENKINS-18434 - Added validation error to Parameterized build choice, removed hard error.
上级
ce29cdb3
变更
6
显示空白变更内容
内联
并排
Showing
6 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
+9
-8
core/src/main/java/jenkins/model/Jenkins.java
core/src/main/java/jenkins/model/Jenkins.java
+12
-0
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
+17
-0
test/src/test/java/jenkins/model/JenkinsTest.java
test/src/test/java/jenkins/model/JenkinsTest.java
+12
-0
未找到文件。
core/src/main/java/hudson/model/ChoiceParameterDefinition.java
浏览文件 @
d244b6b6
...
...
@@ -15,25 +15,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
;
}
...
...
core/src/main/java/jenkins/model/Jenkins.java
浏览文件 @
d244b6b6
...
...
@@ -30,6 +30,7 @@ import com.google.common.collect.Lists;
import
com.google.inject.Injector
;
import
hudson.ExtensionComponent
;
import
hudson.ExtensionFinder
;
import
hudson.model.ChoiceParameterDefinition
;
import
hudson.model.LoadStatistics
;
import
hudson.model.Messages
;
import
hudson.model.Node
;
...
...
@@ -3559,6 +3560,17 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro
return
FormValidation
.
error
(
Messages
.
Hudson_ViewAlreadyExists
(
view
));
}
/**
* 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
());
}
}
/**
* Serves static resources placed along with Jelly view files.
* <p>
...
...
core/src/main/resources/hudson/model/ChoiceParameterDefinition/config.jelly
浏览文件 @
d244b6b6
...
...
@@ -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}/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
浏览文件 @
d244b6b6
...
...
@@ -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
浏览文件 @
d244b6b6
package
hudson.model
;
import
org.junit.Test
;
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/src/test/java/jenkins/model/JenkinsTest.java
浏览文件 @
d244b6b6
...
...
@@ -46,9 +46,12 @@ import org.jvnet.hudson.test.ExtractResourceSCM;
import
org.jvnet.hudson.test.HudsonTestCase
;
import
org.jvnet.hudson.test.TestExtension
;
import
org.kohsuke.stapler.HttpResponse
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
/**
* @author kingfai
*
...
...
@@ -307,6 +310,15 @@ public class JenkinsTest extends HudsonTestCase {
assertEquals
(
HttpURLConnection
.
HTTP_FORBIDDEN
,
e
.
getStatusCode
());
}
}
@Test
public
void
testCheckChoices
()
throws
Exception
{
Jenkins
jenkins
=
Jenkins
.
getInstance
();
assertEquals
(
FormValidation
.
Kind
.
OK
,
jenkins
.
doCheckChoices
(
"abc\ndef"
).
kind
);
assertEquals
(
FormValidation
.
Kind
.
ERROR
,
jenkins
.
doCheckChoices
(
""
).
kind
);
}
private
String
eval
(
WebClient
wc
)
throws
Exception
{
WebRequestSettings
req
=
new
WebRequestSettings
(
new
URL
(
wc
.
getContextPath
()
+
"eval"
),
HttpMethod
.
POST
);
req
.
setRequestBody
(
"<j:jelly xmlns:j='jelly:core'>${1+2}</j:jelly>"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录