Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
b8d4d2b4
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,发现更多精彩内容 >>
提交
b8d4d2b4
编写于
12月 04, 2015
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
差异文件
[JENKINS-31458] Noting merge of #1936.
上级
7c9ba701
a1542702
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
280 addition
and
9 deletion
+280
-9
changelog.html
changelog.html
+3
-0
core/src/main/java/hudson/model/Descriptor.java
core/src/main/java/hudson/model/Descriptor.java
+88
-2
core/src/main/java/hudson/model/Node.java
core/src/main/java/hudson/model/Node.java
+8
-4
test/src/test/java/hudson/model/JobPropertyTest.java
test/src/test/java/hudson/model/JobPropertyTest.java
+27
-3
test/src/test/java/hudson/model/ParametersDefinitionPropertyTest.java
...t/java/hudson/model/ParametersDefinitionPropertyTest.java
+102
-0
test/src/test/java/hudson/slaves/NodePropertyTest.java
test/src/test/java/hudson/slaves/NodePropertyTest.java
+15
-0
test/src/test/resources/hudson/model/ParametersDefinitionPropertyTest/KrazyParameterDefinition/config.jelly
...initionPropertyTest/KrazyParameterDefinition/config.jelly
+37
-0
未找到文件。
changelog.html
浏览文件 @
b8d4d2b4
...
...
@@ -62,6 +62,9 @@ Upcoming changes</a>
Bytecode Compatibility Transformer computes the common super class without loading classes.
Fixes the
<code>
ClassCircularityError
</code>
exception in Ruby Runtime Plugin.
(
<a
href=
"https://issues.jenkins-ci.org/browse/JENKINS-31019"
>
issue 31019
</a>
)
<li
class=
"major bug"
>
Extended Choice parameter definitions could not be saved since 1.637.
(
<a
href=
"https://issues.jenkins-ci.org/browse/JENKINS-31458"
>
issue 31458
</a>
)
</ul>
</div>
<!--=TRUNK-END=-->
<h3><a
name=
v1.639
>
What's new in 1.639
</a>
(2015/11/29)
</h3>
...
...
core/src/main/java/hudson/model/Descriptor.java
浏览文件 @
b8d4d2b4
...
...
@@ -72,6 +72,7 @@ import java.lang.reflect.Type;
import
java.lang.reflect.Field
;
import
java.lang.reflect.ParameterizedType
;
import
java.beans.Introspector
;
import
java.util.IdentityHashMap
;
import
javax.annotation.CheckForNull
;
import
javax.annotation.Nonnull
;
...
...
@@ -559,7 +560,7 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
* Signals a problem in the submitted form.
* @since 1.145
*/
public
T
newInstance
(
StaplerRequest
req
,
JSONObject
formData
)
throws
FormException
{
public
T
newInstance
(
@CheckForNull
StaplerRequest
req
,
@Nonnull
JSONObject
formData
)
throws
FormException
{
try
{
Method
m
=
getClass
().
getMethod
(
"newInstance"
,
StaplerRequest
.
class
);
...
...
@@ -574,7 +575,20 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
}
// new behavior as of 1.206
return
verifyNewInstance
(
req
.
bindJSON
(
clazz
,
formData
));
BindInterceptor
oldInterceptor
=
req
.
getBindInterceptor
();
try
{
NewInstanceBindInterceptor
interceptor
;
if
((
oldInterceptor
instanceof
NewInstanceBindInterceptor
))
{
interceptor
=
(
NewInstanceBindInterceptor
)
oldInterceptor
;
}
else
{
interceptor
=
new
NewInstanceBindInterceptor
(
oldInterceptor
);
req
.
setBindInterceptor
(
interceptor
);
}
interceptor
.
processed
.
put
(
formData
,
null
);
return
verifyNewInstance
(
req
.
bindJSON
(
clazz
,
formData
));
}
finally
{
req
.
setBindInterceptor
(
oldInterceptor
);
}
}
}
catch
(
NoSuchMethodException
e
)
{
throw
new
AssertionError
(
e
);
// impossible
...
...
@@ -587,6 +601,78 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
}
}
/**
* Ensures that calls to {@link StaplerRequest#bindJSON(Class, JSONObject)} from {@link #newInstance(StaplerRequest, JSONObject)} recurse properly.
* {@code doConfigSubmit}-like methods will wind up calling {@code newInstance} directly
* or via {@link #newInstancesFromHeteroList(StaplerRequest, Object, Collection)},
* which consult any custom {@code newInstance} overrides for top-level {@link Describable} objects.
* But for nested describable objects Stapler would know nothing about {@code newInstance} without this trick.
*/
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
private
static
class
NewInstanceBindInterceptor
extends
BindInterceptor
{
private
final
BindInterceptor
oldInterceptor
;
private
final
Map
<
JSONObject
,
Void
>
processed
=
new
IdentityHashMap
<>();
NewInstanceBindInterceptor
(
BindInterceptor
oldInterceptor
)
{
LOGGER
.
log
(
Level
.
FINER
,
"new interceptor delegating to {0}"
,
oldInterceptor
);
this
.
oldInterceptor
=
oldInterceptor
;
}
private
boolean
isApplicable
(
Class
type
,
JSONObject
json
)
{
if
(
Modifier
.
isAbstract
(
type
.
getModifiers
()))
{
LOGGER
.
log
(
Level
.
FINER
,
"ignoring abstract {0} {1}"
,
new
Object
[]
{
type
.
getName
(),
json
});
return
false
;
}
if
(!
Describable
.
class
.
isAssignableFrom
(
type
))
{
LOGGER
.
log
(
Level
.
FINER
,
"ignoring non-Describable {0} {1}"
,
new
Object
[]
{
type
.
getName
(),
json
});
return
false
;
}
if
(
processed
.
containsKey
(
json
))
{
LOGGER
.
log
(
Level
.
FINER
,
"already processed {0} {1}"
,
new
Object
[]
{
type
.
getName
(),
json
});
return
false
;
}
return
true
;
}
@Override
public
Object
instantiate
(
Class
actualType
,
JSONObject
json
)
{
if
(
isApplicable
(
actualType
,
json
))
{
LOGGER
.
log
(
Level
.
FINE
,
"switching to newInstance {0} {1}"
,
new
Object
[]
{
actualType
.
getName
(),
json
});
try
{
return
Jenkins
.
getActiveInstance
().
getDescriptor
(
actualType
).
newInstance
(
Stapler
.
getCurrentRequest
(),
json
);
}
catch
(
Exception
x
)
{
LOGGER
.
log
(
Level
.
WARNING
,
"falling back to default instantiation "
+
actualType
.
getName
()
+
" "
+
json
,
x
);
// If nested objects are not using newInstance, bindJSON will wind up throwing the same exception anyway,
// so logging above will result in a duplicated stack trace.
// However if they *are* then this is the only way to find errors in that newInstance.
// Normally oldInterceptor.instantiate will just return DEFAULT, not actually do anything,
// so we cannot try calling the default instantiation and then decide which problem to report.
}
}
return
oldInterceptor
.
instantiate
(
actualType
,
json
);
}
@Override
public
Object
onConvert
(
Type
targetType
,
Class
targetTypeErasure
,
Object
jsonSource
)
{
if
(
jsonSource
instanceof
JSONObject
)
{
JSONObject
json
=
(
JSONObject
)
jsonSource
;
if
(
isApplicable
(
targetTypeErasure
,
json
))
{
LOGGER
.
log
(
Level
.
FINE
,
"switching to newInstance {0} {1}"
,
new
Object
[]
{
targetTypeErasure
.
getName
(),
json
});
try
{
return
Jenkins
.
getActiveInstance
().
getDescriptor
(
targetTypeErasure
).
newInstance
(
Stapler
.
getCurrentRequest
(),
json
);
}
catch
(
Exception
x
)
{
LOGGER
.
log
(
Level
.
WARNING
,
"falling back to default instantiation "
+
targetTypeErasure
.
getName
()
+
" "
+
json
,
x
);
}
}
}
else
{
LOGGER
.
log
(
Level
.
FINER
,
"ignoring non-object {0}"
,
jsonSource
);
}
return
oldInterceptor
.
onConvert
(
targetType
,
targetTypeErasure
,
jsonSource
);
}
}
/**
* Look out for a typical error a plugin developer makes.
* See http://hudson.361315.n4.nabble.com/Help-Hint-needed-Post-build-action-doesn-t-stay-activated-td2308833.html
...
...
core/src/main/java/hudson/model/Node.java
浏览文件 @
b8d4d2b4
...
...
@@ -57,6 +57,7 @@ import java.util.Collections;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.logging.Logger
;
import
javax.annotation.CheckForNull
;
import
javax.annotation.Nonnull
;
...
...
@@ -470,10 +471,13 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable
if
(
form
==
null
)
return
null
;
final
JSONObject
jsonForProperties
=
form
.
optJSONObject
(
"nodeProperties"
);
BindInterceptor
old
=
req
.
setBindListener
(
new
BindInterceptor
()
{
final
AtomicReference
<
BindInterceptor
>
old
=
new
AtomicReference
<>();
old
.
set
(
req
.
setBindListener
(
new
BindInterceptor
()
{
@Override
public
Object
onConvert
(
Type
targetType
,
Class
targetTypeErasure
,
Object
jsonSource
)
{
if
(
jsonForProperties
!=
jsonSource
)
return
DEFAULT
;
if
(
jsonForProperties
!=
jsonSource
)
{
return
old
.
get
().
onConvert
(
targetType
,
targetTypeErasure
,
jsonSource
);
}
try
{
DescribableList
<
NodeProperty
<?>,
NodePropertyDescriptor
>
tmp
=
new
DescribableList
<
NodeProperty
<?>,
NodePropertyDescriptor
>(
Saveable
.
NOOP
,
getNodeProperties
().
toList
());
...
...
@@ -485,12 +489,12 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable
throw
new
IllegalArgumentException
(
e
);
}
}
});
})
)
;
try
{
return
getDescriptor
().
newInstance
(
req
,
form
);
}
finally
{
req
.
setBindListener
(
old
);
req
.
setBindListener
(
old
.
get
()
);
}
}
...
...
test/src/test/java/hudson/model/JobPropertyTest.java
浏览文件 @
b8d4d2b4
...
...
@@ -23,15 +23,19 @@
*/
package
hudson.model
;
import
static
org
.
junit
.
Assert
.
assertNotSame
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.*;
import
com.gargoylesoftware.htmlunit.WebAssert
;
import
com.gargoylesoftware.htmlunit.html.HtmlPage
;
import
hudson.matrix.MatrixProject
;
import
hudson.maven.MavenModuleSet
;
import
hudson.model.Descriptor.FormException
;
import
java.util.logging.ConsoleHandler
;
import
java.util.logging.Handler
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
net.sf.json.JSONObject
;
import
org.junit.BeforeClass
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.Issue
;
...
...
@@ -42,6 +46,15 @@ import org.kohsuke.stapler.StaplerRequest;
public
class
JobPropertyTest
{
private
static
final
Logger
logger
=
Logger
.
getLogger
(
Descriptor
.
class
.
getName
());
@BeforeClass
public
static
void
logging
()
{
logger
.
setLevel
(
Level
.
ALL
);
Handler
handler
=
new
ConsoleHandler
();
handler
.
setLevel
(
Level
.
ALL
);
logger
.
addHandler
(
handler
);
}
@Rule
public
JenkinsRule
j
=
new
JenkinsRule
();
...
...
@@ -104,6 +117,11 @@ public class JobPropertyTest {
JobPropertyWithConfigImpl
after
=
p
.
getProperty
(
JobPropertyWithConfigImpl
.
class
);
assertNotSame
(
after
,
before
);
j
.
assertEqualDataBoundBeans
(
before
,
after
);
p
.
removeProperty
(
after
);
JobPropertyWithConfigImpl
empty
=
new
JobPropertyWithConfigImpl
(
""
);
p
.
addProperty
(
empty
);
j
.
configRoundtrip
((
Item
)
p
);
assertNull
(
p
.
getProperty
(
JobPropertyWithConfigImpl
.
class
));
}
public
static
class
JobPropertyWithConfigImpl
extends
JobProperty
<
Job
<?,?>>
{
...
...
@@ -115,7 +133,13 @@ public class JobPropertyTest {
}
@TestExtension
(
"configRoundtrip"
)
public
static
class
DescriptorImpl
extends
JobPropertyDescriptor
{}
public
static
class
DescriptorImpl
extends
JobPropertyDescriptor
{
@Override
public
JobProperty
<?>
newInstance
(
StaplerRequest
req
,
JSONObject
formData
)
throws
FormException
{
JobPropertyWithConfigImpl
prop
=
(
JobPropertyWithConfigImpl
)
super
.
newInstance
(
req
,
formData
);
return
prop
.
name
.
isEmpty
()
?
null
:
prop
;
}
}
}
@Test
...
...
test/src/test/java/hudson/model/ParametersDefinitionPropertyTest.java
0 → 100644
浏览文件 @
b8d4d2b4
/*
* The MIT License
*
* Copyright 2015 CloudBees, 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.model
;
import
java.util.Locale
;
import
java.util.logging.ConsoleHandler
;
import
java.util.logging.Handler
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
net.sf.json.JSONObject
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.BeforeClass
;
import
org.junit.Rule
;
import
org.jvnet.hudson.test.Issue
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
org.jvnet.hudson.test.TestExtension
;
import
org.kohsuke.stapler.StaplerRequest
;
public
class
ParametersDefinitionPropertyTest
{
private
static
final
Logger
logger
=
Logger
.
getLogger
(
Descriptor
.
class
.
getName
());
@BeforeClass
public
static
void
logging
()
{
logger
.
setLevel
(
Level
.
ALL
);
Handler
handler
=
new
ConsoleHandler
();
handler
.
setLevel
(
Level
.
ALL
);
logger
.
addHandler
(
handler
);
}
@Rule
public
JenkinsRule
r
=
new
JenkinsRule
();
@Issue
(
"JENKINS-31458"
)
@Test
public
void
customNewInstance
()
throws
Exception
{
KrazyParameterDefinition
kpd
=
new
KrazyParameterDefinition
(
"kpd"
,
"desc"
,
"KrAzY"
);
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
ParametersDefinitionProperty
pdp
=
new
ParametersDefinitionProperty
(
kpd
);
p
.
addProperty
(
pdp
);
r
.
configRoundtrip
(
p
);
pdp
=
p
.
getProperty
(
ParametersDefinitionProperty
.
class
);
kpd
=
(
KrazyParameterDefinition
)
pdp
.
getParameterDefinition
(
"kpd"
);
assertEquals
(
"desc"
,
kpd
.
getDescription
());
assertEquals
(
"krazy"
,
kpd
.
field
);
}
public
static
class
KrazyParameterDefinition
extends
ParameterDefinition
{
public
final
String
field
;
// not @DataBoundConstructor
public
KrazyParameterDefinition
(
String
name
,
String
description
,
String
field
)
{
super
(
name
,
description
);
this
.
field
=
field
;
}
@Override
public
ParameterValue
createValue
(
StaplerRequest
req
,
JSONObject
jo
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
ParameterValue
createValue
(
StaplerRequest
req
)
{
throw
new
UnsupportedOperationException
();
}
@TestExtension
(
"customNewInstance"
)
public
static
class
DescriptorImpl
extends
ParameterDescriptor
{
@Override
public
ParameterDefinition
newInstance
(
StaplerRequest
req
,
JSONObject
formData
)
throws
FormException
{
return
new
KrazyParameterDefinition
(
formData
.
getString
(
"name"
),
formData
.
getString
(
"description"
),
formData
.
getString
(
"field"
).
toLowerCase
(
Locale
.
ENGLISH
));
}
}
}
}
test/src/test/java/hudson/slaves/NodePropertyTest.java
浏览文件 @
b8d4d2b4
...
...
@@ -9,9 +9,15 @@ import static org.junit.Assert.assertTrue;
import
com.gargoylesoftware.htmlunit.html.DomNodeUtil
;
import
com.gargoylesoftware.htmlunit.html.HtmlForm
;
import
com.gargoylesoftware.htmlunit.html.HtmlLabel
;
import
hudson.model.Descriptor
;
import
hudson.model.Descriptor.FormException
;
import
hudson.model.Slave
;
import
java.util.logging.ConsoleHandler
;
import
java.util.logging.Handler
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
net.sf.json.JSONObject
;
import
org.junit.BeforeClass
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.JenkinsRule
;
...
...
@@ -24,6 +30,15 @@ import org.kohsuke.stapler.StaplerRequest;
*/
public
class
NodePropertyTest
{
private
static
final
Logger
logger
=
Logger
.
getLogger
(
Descriptor
.
class
.
getName
());
@BeforeClass
public
static
void
logging
()
{
logger
.
setLevel
(
Level
.
ALL
);
Handler
handler
=
new
ConsoleHandler
();
handler
.
setLevel
(
Level
.
ALL
);
logger
.
addHandler
(
handler
);
}
@Rule
public
JenkinsRule
j
=
new
JenkinsRule
();
...
...
test/src/test/resources/hudson/model/ParametersDefinitionPropertyTest/KrazyParameterDefinition/config.jelly
0 → 100644
浏览文件 @
b8d4d2b4
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright 2015 CloudBees, 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.
-->
<?jelly escape-by-default='true'?>
<j:jelly
xmlns:j=
"jelly:core"
xmlns:f=
"/lib/form"
>
<f:entry
field=
"name"
title=
"name"
>
<f:textbox/>
</f:entry>
<f:entry
field=
"description"
title=
"description"
>
<f:textarea/>
</f:entry>
<f:entry
title=
"field"
>
<f:textbox
name=
"field"
value=
"${instance.field.toUpperCase()}"
/>
</f:entry>
</j:jelly>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录