Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
67827c7e
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,发现更多精彩内容 >>
提交
67827c7e
编写于
6月 15, 2013
作者:
O
Oliver Gondža
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce View.getAllItems()
上级
bdea18f5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
79 addition
and
27 deletion
+79
-27
core/src/main/java/hudson/cli/ListJobsCommand.java
core/src/main/java/hudson/cli/ListJobsCommand.java
+1
-17
core/src/main/java/hudson/model/View.java
core/src/main/java/hudson/model/View.java
+22
-0
core/src/test/java/hudson/cli/ListJobsCommandTest.java
core/src/test/java/hudson/cli/ListJobsCommandTest.java
+14
-10
core/src/test/java/hudson/model/ViewTest.java
core/src/test/java/hudson/model/ViewTest.java
+42
-0
未找到文件。
core/src/main/java/hudson/cli/ListJobsCommand.java
浏览文件 @
67827c7e
...
...
@@ -61,7 +61,7 @@ public class ListJobsCommand extends CLICommand {
View
view
=
h
.
getView
(
name
);
if
(
view
!=
null
)
{
jobs
=
getViewItems
(
view
);
jobs
=
view
.
getAllItems
(
);
}
// If no view was found, try with an item group.
else
{
...
...
@@ -91,20 +91,4 @@ 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/main/java/hudson/model/View.java
浏览文件 @
67827c7e
...
...
@@ -93,6 +93,7 @@ import java.util.Comparator;
import
java.util.GregorianCalendar
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -176,6 +177,27 @@ public abstract class View extends AbstractModelObject implements AccessControll
@Exported
(
name
=
"jobs"
)
public
abstract
Collection
<
TopLevelItem
>
getItems
();
/**
* Gets all the items recursively contained in this collection in a read-only view.
* @since 1.520
*/
public
Collection
<
TopLevelItem
>
getAllItems
()
{
final
Collection
<
TopLevelItem
>
items
=
new
LinkedHashSet
<
TopLevelItem
>(
getItems
()
);
if
(
this
instanceof
ViewGroup
)
{
for
(
final
View
view:
((
ViewGroup
)
this
).
getViews
())
{
items
.
addAll
(
view
.
getAllItems
());
}
}
return
Collections
.
unmodifiableCollection
(
items
);
}
/**
* Gets the {@link TopLevelItem} of the given name.
*/
...
...
core/src/test/java/hudson/cli/ListJobsCommandTest.java
浏览文件 @
67827c7e
...
...
@@ -9,6 +9,7 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic;
import
static
org
.
powermock
.
api
.
mockito
.
PowerMockito
.
when
;
import
hudson.model.TopLevelItem
;
import
hudson.model.ViewGroup
;
import
hudson.model.ViewTest.CompositeView
;
import
hudson.model.View
;
import
java.io.ByteArrayOutputStream
;
...
...
@@ -84,7 +85,7 @@ public class ListJobsCommandTest {
job
(
"some-job"
),
job
(
"some-other-job"
)
);
final
View
customView
=
mock
(
View
.
class
);
final
View
customView
=
view
(
);
when
(
customView
.
getItems
()).
thenReturn
(
viewJobs
);
when
(
jenkins
.
getView
(
"CustomView"
)).
thenReturn
(
customView
);
...
...
@@ -98,8 +99,9 @@ public class ListJobsCommandTest {
public
void
getJobsRecursivelyFromViewGroup
()
throws
Exception
{
final
CompositeView
rootView
=
mock
(
CompositeView
.
class
);
final
View
leftView
=
mock
(
View
.
class
);
final
View
rightView
=
mock
(
View
.
class
);
when
(
rootView
.
getAllItems
()).
thenCallRealMethod
();
final
View
leftView
=
view
();
final
View
rightView
=
view
();
final
TopLevelItem
rootJob
=
job
(
"rootJob"
);
final
TopLevelItem
leftJob
=
job
(
"leftJob"
);
...
...
@@ -118,6 +120,15 @@ public class ListJobsCommandTest {
assertThat
(
stdout
,
listsJobs
(
"rootJob"
,
"leftJob"
,
"rightJob"
,
"sharedJob"
));
}
private
View
view
()
{
final
View
view
=
mock
(
View
.
class
);
when
(
view
.
getAllItems
()).
thenCallRealMethod
();
return
view
;
}
private
TopLevelItem
job
(
final
String
name
)
{
final
TopLevelItem
item
=
mock
(
TopLevelItem
.
class
);
...
...
@@ -173,11 +184,4 @@ public class ListJobsCommandTest {
}
};
}
private
abstract
static
class
CompositeView
extends
View
implements
ViewGroup
{
protected
CompositeView
(
String
name
)
{
super
(
name
);
}
}
}
core/src/test/java/hudson/model/ViewTest.java
浏览文件 @
67827c7e
...
...
@@ -5,6 +5,7 @@ import hudson.search.SearchIndexBuilder;
import
hudson.search.SearchItem
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.List
;
...
...
@@ -65,4 +66,45 @@ public class ViewTest {
Assert
.
assertEquals
(
actual
.
getSearchName
(),
item2
.
getDisplayName
());
Assert
.
assertEquals
(
actual
.
getSearchUrl
(),
item2
.
getSearchUrl
());
}
/*
* Get all items recursively when View implements ViewGroup at the same time
*/
@Test
public
void
getAllItems
()
throws
Exception
{
final
CompositeView
rootView
=
Mockito
.
mock
(
CompositeView
.
class
);
final
View
leftView
=
Mockito
.
mock
(
View
.
class
);
final
View
rightView
=
Mockito
.
mock
(
View
.
class
);
Mockito
.
when
(
rootView
.
getAllItems
()).
thenCallRealMethod
();
Mockito
.
when
(
leftView
.
getAllItems
()).
thenCallRealMethod
();
Mockito
.
when
(
rightView
.
getAllItems
()).
thenCallRealMethod
();
final
TopLevelItem
rootJob
=
Mockito
.
mock
(
TopLevelItem
.
class
);
final
TopLevelItem
leftJob
=
Mockito
.
mock
(
TopLevelItem
.
class
);
final
TopLevelItem
rightJob
=
Mockito
.
mock
(
TopLevelItem
.
class
);
final
TopLevelItem
sharedJob
=
Mockito
.
mock
(
TopLevelItem
.
class
);
Mockito
.
when
(
rootJob
.
getDisplayName
()).
thenReturn
(
"rootJob"
);
Mockito
.
when
(
leftJob
.
getDisplayName
()).
thenReturn
(
"leftJob"
);
Mockito
.
when
(
rightJob
.
getDisplayName
()).
thenReturn
(
"rightJob"
);
Mockito
.
when
(
sharedJob
.
getDisplayName
()).
thenReturn
(
"sharedJob"
);
Mockito
.
when
(
rootView
.
getViews
()).
thenReturn
(
Arrays
.
asList
(
leftView
,
rightView
));
Mockito
.
when
(
rootView
.
getItems
()).
thenReturn
(
Arrays
.
asList
(
rootJob
,
sharedJob
));
Mockito
.
when
(
leftView
.
getItems
()).
thenReturn
(
Arrays
.
asList
(
leftJob
,
sharedJob
));
Mockito
.
when
(
rightView
.
getItems
()).
thenReturn
(
Arrays
.
asList
(
rightJob
));
final
TopLevelItem
[]
expected
=
new
TopLevelItem
[]
{
rootJob
,
sharedJob
,
leftJob
,
rightJob
};
Assert
.
assertArrayEquals
(
expected
,
rootView
.
getAllItems
().
toArray
());
}
public
static
abstract
class
CompositeView
extends
View
implements
ViewGroup
{
protected
CompositeView
(
final
String
name
)
{
super
(
name
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录