Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dream21st
jenkins
提交
5e999233
J
jenkins
项目概览
dream21st
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
5e999233
编写于
10月 19, 2012
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding auto-completion method
上级
18561d5f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
121 addition
and
0 deletion
+121
-0
core/src/main/java/hudson/model/AutoCompletionCandidates.java
.../src/main/java/hudson/model/AutoCompletionCandidates.java
+68
-0
test/src/test/java/hudson/model/AutoCompletionCandidatesTest.java
.../test/java/hudson/model/AutoCompletionCandidatesTest.java
+53
-0
未找到文件。
core/src/main/java/hudson/model/AutoCompletionCandidates.java
浏览文件 @
5e999233
...
...
@@ -25,6 +25,7 @@
package
hudson.model
;
import
hudson.search.Search
;
import
jenkins.model.Jenkins
;
import
org.kohsuke.stapler.HttpResponse
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.StaplerResponse
;
...
...
@@ -71,4 +72,71 @@ public class AutoCompletionCandidates implements HttpResponse {
}
rsp
.
serveExposedBean
(
req
,
r
,
Flavor
.
JSON
);
}
/**
* Auto-completes possible job names.
*
* @param type
* Limit the auto-completion to the subtype of this type.
* @param value
* The value the user has typed in. Matched as a prefix.
* @param self
* The contextual item for which the auto-completion is provided to.
* For example, if you are configuring a job, this is the job being configured.
* @param container
* The nearby contextual {@link ItemGroup} to resolve relative job names from.
*/
public
static
<
T
extends
Item
>
AutoCompletionCandidates
ofJobNames
(
final
Class
<
T
>
type
,
final
String
value
,
Item
self
,
ItemGroup
container
)
{
if
(
self
==
container
)
container
=
self
.
getParent
();
final
AutoCompletionCandidates
candidates
=
new
AutoCompletionCandidates
();
class
Visitor
extends
ItemVisitor
{
String
prefix
;
Visitor
(
String
prefix
)
{
this
.
prefix
=
prefix
;
}
@Override
public
void
onItem
(
Item
i
)
{
String
n
=
contextualNameOf
(
i
);
if
((
n
.
startsWith
(
value
)
||
value
.
startsWith
(
n
))
// 'foobar' is a valid candidate if the current value is 'foo'.
// Also, we need to visit 'foo' if the current value is 'foo/bar'
&&
(
value
.
length
()>
n
.
length
()
||
!
n
.
substring
(
value
.
length
()).
contains
(
"/"
))
// but 'foobar/zot' isn't if the current value is 'foo'
// we'll first show 'foobar' and then wait for the user to type '/' to show the rest
&&
i
.
hasPermission
(
Item
.
READ
)
// and read permission required
)
{
if
(
type
.
isInstance
(
i
)
&&
n
.
startsWith
(
value
))
candidates
.
add
(
n
);
// recurse
String
oldPrefix
=
prefix
;
prefix
=
n
;
super
.
onItem
(
i
);
prefix
=
oldPrefix
;
}
}
private
String
contextualNameOf
(
Item
i
)
{
if
(
prefix
.
endsWith
(
"/"
)
||
prefix
.
length
()==
0
)
return
prefix
+
i
.
getName
();
else
return
prefix
+
'/'
+
i
.
getName
();
}
}
if
(
container
==
null
||
container
==
Jenkins
.
getInstance
())
{
new
Visitor
(
""
).
onItemGroup
(
Jenkins
.
getInstance
());
}
else
{
new
Visitor
(
""
).
onItemGroup
(
container
);
if
(
value
.
startsWith
(
"/"
))
new
Visitor
(
"/"
).
onItemGroup
(
Jenkins
.
getInstance
());
}
return
candidates
;
}
}
test/src/test/java/hudson/model/AutoCompletionCandidatesTest.java
0 → 100644
浏览文件 @
5e999233
package
hudson.model
;
import
hudson.matrix.AxisList
;
import
hudson.matrix.MatrixConfiguration
;
import
hudson.matrix.MatrixProject
;
import
hudson.matrix.TextAxis
;
import
org.jvnet.hudson.test.HudsonTestCase
;
import
java.util.Arrays
;
import
java.util.TreeSet
;
/**
* @author Kohsuke Kawaguchi
*/
public
class
AutoCompletionCandidatesTest
extends
HudsonTestCase
{
public
void
testCompletion
()
throws
Exception
{
FreeStyleProject
foo
=
jenkins
.
createProject
(
FreeStyleProject
.
class
,
"foo"
);
MatrixProject
bar
=
jenkins
.
createProject
(
MatrixProject
.
class
,
"bar"
);
bar
.
setAxes
(
new
AxisList
(
new
TextAxis
(
"x"
,
"1"
,
"2"
,
"3"
)));
MatrixConfiguration
x3
=
bar
.
getItem
(
"x=3"
);
AutoCompletionCandidates
c
;
c
=
AutoCompletionCandidates
.
ofJobNames
(
Item
.
class
,
""
,
foo
,
jenkins
);
assertContains
(
c
,
"foo"
,
"bar"
);
c
=
AutoCompletionCandidates
.
ofJobNames
(
Item
.
class
,
"ba"
,
foo
,
jenkins
);
assertContains
(
c
,
"bar"
);
c
=
AutoCompletionCandidates
.
ofJobNames
(
Item
.
class
,
"bar/"
,
foo
,
jenkins
);
assertContains
(
c
,
"bar/x=1"
,
"bar/x=2"
,
"bar/x=3"
);
c
=
AutoCompletionCandidates
.
ofJobNames
(
FreeStyleProject
.
class
,
""
,
foo
,
jenkins
);
assertContains
(
c
,
"foo"
);
c
=
AutoCompletionCandidates
.
ofJobNames
(
MatrixConfiguration
.
class
,
"bar/"
,
foo
,
jenkins
);
assertContains
(
c
,
"bar/x=1"
,
"bar/x=2"
,
"bar/x=3"
);
c
=
AutoCompletionCandidates
.
ofJobNames
(
Item
.
class
,
""
,
x3
,
x3
.
getParent
());
assertContains
(
c
,
"x=1"
,
"x=2"
,
"x=3"
);
c
=
AutoCompletionCandidates
.
ofJobNames
(
Item
.
class
,
"/"
,
x3
,
x3
.
getParent
());
assertContains
(
c
,
"/foo"
,
"/bar"
);
c
=
AutoCompletionCandidates
.
ofJobNames
(
Item
.
class
,
"/bar/"
,
x3
,
x3
.
getParent
());
assertContains
(
c
,
"/bar/x=1"
,
"/bar/x=2"
,
"/bar/x=3"
);
}
private
void
assertContains
(
AutoCompletionCandidates
c
,
String
...
values
)
{
assertEquals
(
new
TreeSet
<
String
>(
Arrays
.
asList
(
values
)),
new
TreeSet
<
String
>(
c
.
getValues
()));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录