Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
a1c30c7b
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
提交
a1c30c7b
编写于
5月 12, 2014
作者:
O
Oliver Gondža
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIXED JENKINS-23361] Add CLI commands to add jobs to and remove jobs from views.
上级
c95777e4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
257 addition
and
0 deletion
+257
-0
core/src/main/java/hudson/cli/AddJobToViewCommand.java
core/src/main/java/hudson/cli/AddJobToViewCommand.java
+68
-0
core/src/main/java/hudson/cli/RemoveJobFromViewCommand.java
core/src/main/java/hudson/cli/RemoveJobFromViewCommand.java
+68
-0
core/src/main/resources/hudson/cli/Messages.properties
core/src/main/resources/hudson/cli/Messages.properties
+4
-0
test/src/test/java/hudson/cli/ViewManipulationTest.java
test/src/test/java/hudson/cli/ViewManipulationTest.java
+117
-0
未找到文件。
core/src/main/java/hudson/cli/AddJobToViewCommand.java
0 → 100644
浏览文件 @
a1c30c7b
/*
* The MIT License
*
* Copyright (c) 2014 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
hudson.cli
;
import
java.util.List
;
import
hudson.Extension
;
import
hudson.model.TopLevelItem
;
import
hudson.model.DirectlyModifiableView
;
import
hudson.model.View
;
import
org.kohsuke.args4j.Argument
;
import
org.kohsuke.args4j.CmdLineException
;
/**
* @author ogondza
* @since TODO
*/
@Extension
public
class
AddJobToViewCommand
extends
CLICommand
{
@Argument
(
usage
=
"Name of the view"
,
required
=
true
,
index
=
0
)
private
View
view
;
@Argument
(
usage
=
"Job names"
,
required
=
true
,
index
=
1
)
private
List
<
TopLevelItem
>
jobs
;
@Override
public
String
getShortDescription
()
{
return
Messages
.
AddJobToViewCommand_ShortDescription
();
}
@Override
protected
int
run
()
throws
Exception
{
view
.
checkPermission
(
View
.
CONFIGURE
);
if
(!(
view
instanceof
DirectlyModifiableView
))
throw
new
CmdLineException
(
null
,
"'"
+
view
.
getDisplayName
()
+
"' view can not be modified directly"
);
for
(
TopLevelItem
job:
jobs
)
{
((
DirectlyModifiableView
)
view
).
add
(
job
);
}
return
0
;
}
}
core/src/main/java/hudson/cli/RemoveJobFromViewCommand.java
0 → 100644
浏览文件 @
a1c30c7b
/*
* The MIT License
*
* Copyright (c) 2014 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
hudson.cli
;
import
java.util.List
;
import
hudson.Extension
;
import
hudson.model.TopLevelItem
;
import
hudson.model.DirectlyModifiableView
;
import
hudson.model.View
;
import
org.kohsuke.args4j.Argument
;
import
org.kohsuke.args4j.CmdLineException
;
/**
* @author ogondza
* @since TODO
*/
@Extension
public
class
RemoveJobFromViewCommand
extends
CLICommand
{
@Argument
(
usage
=
"Name of the view"
,
required
=
true
,
index
=
0
)
private
View
view
;
@Argument
(
usage
=
"Job names"
,
required
=
true
,
index
=
1
)
private
List
<
TopLevelItem
>
jobs
;
@Override
public
String
getShortDescription
()
{
return
Messages
.
RemoveJobFromViewCommand_ShortDescription
();
}
@Override
protected
int
run
()
throws
Exception
{
view
.
checkPermission
(
View
.
CONFIGURE
);
if
(!(
view
instanceof
DirectlyModifiableView
))
throw
new
CmdLineException
(
null
,
"'"
+
view
.
getDisplayName
()
+
"' view can not be modified directly"
);
for
(
TopLevelItem
job:
jobs
)
{
((
DirectlyModifiableView
)
view
).
remove
(
job
);
}
return
0
;
}
}
core/src/main/resources/hudson/cli/Messages.properties
浏览文件 @
a1c30c7b
...
...
@@ -6,6 +6,8 @@ InstallPluginCommand.NoUpdateCenterDefined=Note that no update center is defined
InstallPluginCommand.NoUpdateDataRetrieved
=
No update center data is retrieved yet from: {0}
InstallPluginCommand.NotAValidSourceName
=
{0} is neither a valid file, URL, nor a plugin artifact name in the update center
AddJobToViewCommand.ShortDescription
=
\
Adds jobs to view.
BuildCommand.ShortDescription
=
\
Builds a job, and optionally waits until its completion.
ConsoleCommand.ShortDescription
=
Retrieves console output of a build.
...
...
@@ -47,6 +49,8 @@ SetBuildDescriptionCommand.ShortDescription=\
SetBuildParameterCommand.ShortDescription
=
Update/set the build parameter of the current build in progress.
SetBuildResultCommand.ShortDescription
=
\
Sets the result of the current build. Works only if invoked from within a build.
RemoveJobFromViewCommand.ShortDescription
=
\
Removes jobs from view.
VersionCommand.ShortDescription
=
\
Outputs the current version.
GetJobCommand.ShortDescription
=
\
...
...
test/src/test/java/hudson/cli/ViewManipulationTest.java
0 → 100644
浏览文件 @
a1c30c7b
/*
* The MIT License
*
* Copyright (c) 2014 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
hudson.cli
;
import
static
org
.
junit
.
Assert
.*;
import
static
hudson
.
cli
.
CLICommandInvoker
.
Matcher
.*;
import
static
org
.
hamcrest
.
Matchers
.*;
import
jenkins.model.Jenkins
;
import
hudson.cli.CLICommandInvoker.Result
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Job
;
import
hudson.model.ListView
;
import
hudson.model.View
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.JenkinsRule
;
public
class
ViewManipulationTest
{
@Rule
public
final
JenkinsRule
j
=
new
JenkinsRule
();
private
Result
res
;
@Test
public
void
addJobToView
()
throws
Exception
{
ListView
view
=
new
ListView
(
"a_view"
);
j
.
jenkins
.
addView
(
view
);
FreeStyleProject
inView
=
j
.
createFreeStyleProject
(
"in_view"
);
FreeStyleProject
inView2
=
j
.
createFreeStyleProject
(
"in_view2"
);
FreeStyleProject
notInView
=
j
.
createFreeStyleProject
(
"not_in_view"
);
res
=
add
().
invokeWithArgs
(
"a_view"
,
"in_view"
,
"in_view2"
);
assertThat
(
res
,
succeededSilently
());
assertTrue
(
view
.
contains
(
inView
));
assertTrue
(
view
.
contains
(
inView2
));
assertFalse
(
view
.
contains
(
notInView
));
}
@Test
public
void
removeJobFromView
()
throws
Exception
{
ListView
view
=
new
ListView
(
"a_view"
);
j
.
jenkins
.
addView
(
view
);
FreeStyleProject
inView
=
j
.
createFreeStyleProject
(
"in_view"
);
FreeStyleProject
removed
=
j
.
createFreeStyleProject
(
"removed"
);
FreeStyleProject
removed2
=
j
.
createFreeStyleProject
(
"removed2"
);
view
.
add
(
inView
);
view
.
add
(
removed
);
view
.
add
(
removed2
);
res
=
remove
().
invokeWithArgs
(
"a_view"
,
"removed"
,
"removed2"
);
assertThat
(
res
,
succeededSilently
());
assertTrue
(
view
.
contains
(
inView
));
assertFalse
(
view
.
contains
(
removed
));
assertFalse
(
view
.
contains
(
removed2
));
}
@Test
public
void
failIfTheViewIsNotDirectlyModifiable
()
throws
Exception
{
j
.
createFreeStyleProject
(
"a_project"
);
res
=
add
().
invokeWithArgs
(
"All"
,
"a_project"
);
assertThat
(
res
,
failedWith
(-
1
));
assertThat
(
res
.
stderr
(),
containsString
(
"'All' view can not be modified directly"
));
res
=
remove
().
invokeWithArgs
(
"All"
,
"a_project"
);
assertThat
(
res
,
failedWith
(-
1
));
assertThat
(
res
.
stderr
(),
containsString
(
"'All' view can not be modified directly"
));
}
@Test
public
void
failIfUserNotAuthorizedToConfigure
()
throws
Exception
{
ListView
view
=
new
ListView
(
"a_view"
);
j
.
jenkins
.
addView
(
view
);
j
.
createFreeStyleProject
(
"a_project"
);
res
=
add
().
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
View
.
READ
).
invokeWithArgs
(
"a_view"
,
"a_project"
);
assertThat
(
res
,
failedWith
(-
1
));
assertThat
(
res
.
stderr
(),
containsString
(
"user is missing the View/Configure permission"
));
res
=
remove
().
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
View
.
READ
).
invokeWithArgs
(
"a_view"
,
"a_project"
);
assertThat
(
res
,
failedWith
(-
1
));
assertThat
(
res
.
stderr
(),
containsString
(
"user is missing the View/Configure permission"
));
}
private
CLICommandInvoker
add
()
{
return
new
CLICommandInvoker
(
j
,
new
AddJobToViewCommand
());
}
private
CLICommandInvoker
remove
()
{
return
new
CLICommandInvoker
(
j
,
new
RemoveJobFromViewCommand
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录