Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
8a2849b4
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,发现更多精彩内容 >>
提交
8a2849b4
编写于
11月 13, 2015
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIXED JENKINS-31518] Translate Job.logRotator to BuildDiscarderProperty more seamlessly.
上级
2200711b
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
40 addition
and
3 deletion
+40
-3
core/src/main/java/hudson/model/Job.java
core/src/main/java/hudson/model/Job.java
+16
-3
test/src/test/java/jenkins/model/BuildDiscarderPropertyTest.java
...c/test/java/jenkins/model/BuildDiscarderPropertyTest.java
+24
-0
test/src/test/resources/jenkins/model/BuildDiscarderPropertyTest/buildDiscarderField.zip
.../model/BuildDiscarderPropertyTest/buildDiscarderField.zip
+0
-0
未找到文件。
core/src/main/java/hudson/model/Job.java
浏览文件 @
8a2849b4
...
@@ -430,7 +430,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
...
@@ -430,7 +430,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
* Returns the configured build discarder for this job, via {@link BuildDiscarderProperty}, or null if none.
* Returns the configured build discarder for this job, via {@link BuildDiscarderProperty}, or null if none.
*/
*/
public
synchronized
BuildDiscarder
getBuildDiscarder
()
{
public
synchronized
BuildDiscarder
getBuildDiscarder
()
{
BuildDiscarderProperty
prop
=
getProperty
(
BuildDiscarderProperty
.
class
);
BuildDiscarderProperty
prop
=
_
getProperty
(
BuildDiscarderProperty
.
class
);
return
prop
!=
null
?
prop
.
getStrategy
()
:
/* settings compatibility */
logRotator
;
return
prop
!=
null
?
prop
.
getStrategy
()
:
/* settings compatibility */
logRotator
;
}
}
...
@@ -553,9 +553,13 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
...
@@ -553,9 +553,13 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
/**
/**
* Gets all the job properties configured for this job.
* Gets all the job properties configured for this job.
*/
*/
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
{
"unchecked"
,
"rawtypes"
}
)
public
Map
<
JobPropertyDescriptor
,
JobProperty
<?
super
JobT
>>
getProperties
()
{
public
Map
<
JobPropertyDescriptor
,
JobProperty
<?
super
JobT
>>
getProperties
()
{
return
Descriptor
.
toMap
((
Iterable
)
properties
);
Map
result
=
Descriptor
.
toMap
((
Iterable
)
properties
);
if
(
logRotator
!=
null
)
{
result
.
put
(
Jenkins
.
getActiveInstance
().
getDescriptorByType
(
BuildDiscarderProperty
.
DescriptorImpl
.
class
),
new
BuildDiscarderProperty
(
logRotator
));
}
return
result
;
}
}
/**
/**
...
@@ -572,6 +576,13 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
...
@@ -572,6 +576,13 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
* this job.
* this job.
*/
*/
public
<
T
extends
JobProperty
>
T
getProperty
(
Class
<
T
>
clazz
)
{
public
<
T
extends
JobProperty
>
T
getProperty
(
Class
<
T
>
clazz
)
{
if
(
clazz
==
BuildDiscarderProperty
.
class
&&
logRotator
!=
null
)
{
return
clazz
.
cast
(
new
BuildDiscarderProperty
(
logRotator
));
}
return
_getProperty
(
clazz
);
}
private
<
T
extends
JobProperty
>
T
_getProperty
(
Class
<
T
>
clazz
)
{
for
(
JobProperty
p
:
properties
)
{
for
(
JobProperty
p
:
properties
)
{
if
(
clazz
.
isInstance
(
p
))
if
(
clazz
.
isInstance
(
p
))
return
clazz
.
cast
(
p
);
return
clazz
.
cast
(
p
);
...
@@ -1196,6 +1207,8 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
...
@@ -1196,6 +1207,8 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
try
{
try
{
setDisplayName
(
json
.
optString
(
"displayNameOrNull"
));
setDisplayName
(
json
.
optString
(
"displayNameOrNull"
));
logRotator
=
null
;
DescribableList
<
JobProperty
<?>,
JobPropertyDescriptor
>
t
=
new
DescribableList
<
JobProperty
<?>,
JobPropertyDescriptor
>(
NOOP
,
getAllProperties
());
DescribableList
<
JobProperty
<?>,
JobPropertyDescriptor
>
t
=
new
DescribableList
<
JobProperty
<?>,
JobPropertyDescriptor
>(
NOOP
,
getAllProperties
());
JSONObject
jsonProperties
=
json
.
optJSONObject
(
"properties"
);
JSONObject
jsonProperties
=
json
.
optJSONObject
(
"properties"
);
if
(
jsonProperties
!=
null
)
{
if
(
jsonProperties
!=
null
)
{
...
...
test/src/test/java/jenkins/model/BuildDiscarderPropertyTest.java
浏览文件 @
8a2849b4
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
package
jenkins.model
;
package
jenkins.model
;
import
hudson.model.AbstractProject
;
import
hudson.model.AbstractProject
;
import
hudson.model.FreeStyleProject
;
import
hudson.tasks.LogRotator
;
import
hudson.tasks.LogRotator
;
import
java.io.StringReader
;
import
java.io.StringReader
;
import
javax.xml.transform.Source
;
import
javax.xml.transform.Source
;
...
@@ -41,6 +42,29 @@ public class BuildDiscarderPropertyTest {
...
@@ -41,6 +42,29 @@ public class BuildDiscarderPropertyTest {
@Rule
@Rule
public
JenkinsRule
r
=
new
JenkinsRule
();
public
JenkinsRule
r
=
new
JenkinsRule
();
@Issue
(
"JENKINS-31518"
)
@LocalData
@Test
public
void
buildDiscarderField
()
throws
Exception
{
FreeStyleProject
p
=
r
.
jenkins
.
getItemByFullName
(
"p"
,
FreeStyleProject
.
class
);
verifyBuildDiscarder
(
p
);
r
.
configRoundtrip
(
p
);
verifyBuildDiscarder
(
p
);
String
xml
=
p
.
getConfigFile
().
asString
();
assertFalse
(
xml
,
xml
.
contains
(
"<logRotator class="
));
assertTrue
(
xml
,
xml
.
contains
(
"<"
+
BuildDiscarderProperty
.
class
.
getName
()
+
">"
));
}
private
void
verifyBuildDiscarder
(
FreeStyleProject
p
)
{
BuildDiscarder
bd
=
p
.
getBuildDiscarder
();
assertNotNull
(
bd
);
LogRotator
lr
=
(
LogRotator
)
bd
;
assertEquals
(
7
,
lr
.
getDaysToKeep
());
assertEquals
(
10
,
lr
.
getNumToKeep
());
assertNotNull
(
p
.
getProperty
(
BuildDiscarderProperty
.
class
));
assertEquals
(
1
,
p
.
getProperties
().
size
());
}
@Issue
(
"JENKINS-16979"
)
@Issue
(
"JENKINS-16979"
)
@LocalData
@LocalData
@Test
@Test
...
...
test/src/test/resources/jenkins/model/BuildDiscarderPropertyTest/buildDiscarderField.zip
0 → 100644
浏览文件 @
8a2849b4
此差异由.gitattributes 抑制。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录