Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
bdea18f5
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,发现更多精彩内容 >>
提交
bdea18f5
编写于
5月 27, 2013
作者:
O
Oliver Gondža
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
List Jobs recursively in hudson.cli.ListJobsCommand
上级
5457d1e8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
16 deletion
+52
-16
core/src/main/java/hudson/cli/ListJobsCommand.java
core/src/main/java/hudson/cli/ListJobsCommand.java
+19
-1
core/src/test/java/hudson/cli/ListJobsCommandTest.java
core/src/test/java/hudson/cli/ListJobsCommandTest.java
+33
-15
未找到文件。
core/src/main/java/hudson/cli/ListJobsCommand.java
浏览文件 @
bdea18f5
...
...
@@ -24,12 +24,14 @@
package
hudson.cli
;
import
java.util.Collection
;
import
java.util.LinkedHashSet
;
import
java.util.Collections
;
import
hudson.model.Item
;
import
hudson.model.ItemGroup
;
import
hudson.model.TopLevelItem
;
import
hudson.model.ViewGroup
;
import
hudson.model.View
;
import
hudson.Extension
;
import
jenkins.model.Jenkins
;
...
...
@@ -59,7 +61,7 @@ public class ListJobsCommand extends CLICommand {
View
view
=
h
.
getView
(
name
);
if
(
view
!=
null
)
{
jobs
=
view
.
getItems
(
);
jobs
=
getViewItems
(
view
);
}
// If no view was found, try with an item group.
else
{
...
...
@@ -89,4 +91,20 @@ public class ListJobsCommand extends CLICommand {
return
0
;
}
private
Collection
<
TopLevelItem
>
getViewItems
(
View
view
)
{
final
Collection
<
TopLevelItem
>
jobs
=
new
LinkedHashSet
<
TopLevelItem
>(
view
.
getItems
()
);
if
(
view
instanceof
ViewGroup
)
{
for
(
View
subview:
((
ViewGroup
)
view
).
getViews
())
{
jobs
.
addAll
(
getViewItems
(
subview
));
}
}
return
jobs
;
}
}
core/src/test/java/hudson/cli/ListJobsCommandTest.java
浏览文件 @
bdea18f5
...
...
@@ -20,8 +20,8 @@ import java.util.List;
import
jenkins.model.Jenkins
;
import
org.hamcrest.BaseMatcher
;
import
org.hamcrest.Description
;
import
org.hamcrest.TypeSafeMatcher
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -94,6 +94,30 @@ public class ListJobsCommandTest {
assertThat
(
stdout
,
listsJobs
(
"some-job"
,
"some-other-job"
));
}
@Test
public
void
getJobsRecursivelyFromViewGroup
()
throws
Exception
{
final
CompositeView
rootView
=
mock
(
CompositeView
.
class
);
final
View
leftView
=
mock
(
View
.
class
);
final
View
rightView
=
mock
(
View
.
class
);
final
TopLevelItem
rootJob
=
job
(
"rootJob"
);
final
TopLevelItem
leftJob
=
job
(
"leftJob"
);
final
TopLevelItem
rightJob
=
job
(
"rightJob"
);
final
TopLevelItem
sharedJob
=
job
(
"sharedJob"
);
when
(
rootView
.
getViews
()).
thenReturn
(
Arrays
.
asList
(
leftView
,
rightView
));
when
(
rootView
.
getItems
()).
thenReturn
(
Arrays
.
asList
(
rootJob
,
sharedJob
));
when
(
leftView
.
getItems
()).
thenReturn
(
Arrays
.
asList
(
leftJob
,
sharedJob
));
when
(
rightView
.
getItems
()).
thenReturn
(
Arrays
.
asList
(
rightJob
));
when
(
jenkins
.
getView
(
"Root"
)).
thenReturn
(
rootView
);
assertThat
(
runWith
(
"Root"
),
equalTo
(
0
));
assertThat
(
stderr
,
is
(
empty
()));
assertThat
(
stdout
,
listsJobs
(
"rootJob"
,
"leftJob"
,
"rightJob"
,
"sharedJob"
));
}
private
TopLevelItem
job
(
final
String
name
)
{
final
TopLevelItem
item
=
mock
(
TopLevelItem
.
class
);
...
...
@@ -110,16 +134,14 @@ public class ListJobsCommandTest {
return
command
.
run
();
}
private
<
T
>
Bas
eMatcher
<
ByteArrayOutputStream
>
empty
()
{
private
TypeSaf
eMatcher
<
ByteArrayOutputStream
>
empty
()
{
return
new
Bas
eMatcher
<
ByteArrayOutputStream
>()
{
return
new
TypeSaf
eMatcher
<
ByteArrayOutputStream
>()
{
@Override
p
ublic
boolean
matches
(
Object
item
)
{
p
rotected
boolean
matchesSafely
(
ByteArrayOutputStream
item
)
{
if
(!(
item
instanceof
ByteArrayOutputStream
))
throw
new
IllegalArgumentException
();
return
((
ByteArrayOutputStream
)
item
).
toString
().
isEmpty
();
return
item
.
toString
().
isEmpty
();
}
@Override
...
...
@@ -130,19 +152,15 @@ public class ListJobsCommandTest {
};
}
private
Bas
eMatcher
<
ByteArrayOutputStream
>
listsJobs
(
final
String
...
expected
)
{
private
TypeSaf
eMatcher
<
ByteArrayOutputStream
>
listsJobs
(
final
String
...
expected
)
{
return
new
Bas
eMatcher
<
ByteArrayOutputStream
>()
{
return
new
TypeSaf
eMatcher
<
ByteArrayOutputStream
>()
{
@Override
public
boolean
matches
(
Object
item
)
{
if
(!(
item
instanceof
ByteArrayOutputStream
))
return
false
;
final
ByteArrayOutputStream
actual
=
(
ByteArrayOutputStream
)
item
;
protected
boolean
matchesSafely
(
ByteArrayOutputStream
item
)
{
final
HashSet
<
String
>
jobs
=
new
HashSet
<
String
>(
Arrays
.
asList
(
actual
.
toString
().
split
(
"\n"
))
Arrays
.
asList
(
item
.
toString
().
split
(
"\n"
))
);
return
new
HashSet
<
String
>(
Arrays
.
asList
(
expected
)).
equals
(
jobs
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录