Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
ef7b9d84
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,发现更多精彩内容 >>
提交
ef7b9d84
编写于
3月 31, 2011
作者:
K
Kohsuke Kawaguchi
提交者:
Stephen Connolly
4月 04, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
generalized the reconfigure concept.
上级
6fc699ff
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
100 addition
and
5 deletion
+100
-5
core/src/main/java/hudson/model/ReconfigurableDescribable.java
...src/main/java/hudson/model/ReconfigurableDescribable.java
+81
-0
core/src/main/java/hudson/model/ViewProperty.java
core/src/main/java/hudson/model/ViewProperty.java
+2
-2
core/src/main/java/hudson/util/DescribableList.java
core/src/main/java/hudson/util/DescribableList.java
+17
-3
未找到文件。
core/src/main/java/hudson/model/ReconfigurableDescribable.java
0 → 100644
浏览文件 @
ef7b9d84
/*
* The MIT License
*
* Copyright (c) 2011, 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
hudson.model.Descriptor.FormException
;
import
hudson.slaves.NodeProperty
;
import
net.sf.json.JSONObject
;
import
org.kohsuke.stapler.StaplerRequest
;
/**
* Marks modern {@link Describable}s that allow the current instances to pass information down to the next
* instance when the configuration is submitted.
*
* <p>
* As the generics signature implies, it isn't up to individual {@link Describable} implementation to
* implement this. Rather, it is up to the designer of an extension point to mark the extension point
* as {@link ReconfigurableDescribable}, as it requires coordination at the owner of the extension point.
*
* <h1>Use Cases</h1>
* <h2>Invisible Property</h2>
* <p>
* This mechanism can be used to create an entirely invisible {@link Describable}, which is handy
* for {@link NodeProperty}, {@link JobProperty}, etc. To do so, define a descriptor with null
* {@linkplain Descriptor#getDisplayName() display name} and empty config.jelly to prevent it from
* showing up in the config UI, then implement {@link #reconfigure(StaplerRequest, JSONObject)}
* and simply return {@code this}.
*
* <h2>Passing some values without going through clients</h2>
* <p>
* Sometimes your {@link Describable} object may have some expensive objects that you might want to
* hand over to the next instance. This hook lets you do that.
*
* @author Kohsuke Kawaguchi
* @since 1.406
*/
public
interface
ReconfigurableDescribable
<
T
extends
ReconfigurableDescribable
<
T
>>
extends
Describable
<
T
>
{
/**
* When a parent/owner object of a Describable gets a config form submission and instances are
* recreated, this method is invoked on the existing instance (meaning the 'this' reference
* points to the existing instance) to create a new instance to be added to the parent/owner object.
*
* <p>
* The default implementation of this should be the following:
* <pre>
* return form==null ? null : getDescriptor().newInstance(req, form);
* </pre>
*
* @param req
* The current HTTP request being processed.
* @param form
* JSON fragment that corresponds to this describable object.
* If the newly submitted form doesn't include a fragment for this describable
* (meaning the user has de-selected your descriptor), then this argument is null.
*
* @return
* The new instance. To not to create an instance of a describable, return null.
*/
T
reconfigure
(
StaplerRequest
req
,
JSONObject
form
)
throws
FormException
;
}
core/src/main/java/hudson/model/ViewProperty.java
浏览文件 @
ef7b9d84
...
...
@@ -50,7 +50,7 @@ import java.util.List;
* @author Stephen Connolly
* @since 1.406
*/
public
class
ViewProperty
implements
Describable
<
ViewProperty
>,
ExtensionPoint
{
public
class
ViewProperty
implements
Reconfigurable
Describable
<
ViewProperty
>,
ExtensionPoint
{
/**
* The view object that owns this property.
* This value will be set by the core code.
...
...
@@ -71,6 +71,6 @@ public class ViewProperty implements Describable<ViewProperty>, ExtensionPoint {
}
public
ViewProperty
reconfigure
(
StaplerRequest
req
,
JSONObject
form
)
throws
Descriptor
.
FormException
{
return
getDescriptor
().
newInstance
(
req
,
form
);
return
form
==
null
?
null
:
getDescriptor
().
newInstance
(
req
,
form
);
}
}
core/src/main/java/hudson/util/DescribableList.java
浏览文件 @
ef7b9d84
...
...
@@ -36,8 +36,10 @@ import hudson.model.DependencyGraph;
import
hudson.model.Describable
;
import
hudson.model.Descriptor
;
import
hudson.model.Descriptor.FormException
;
import
hudson.model.ReconfigurableDescribable
;
import
hudson.model.Saveable
;
import
net.sf.json.JSONObject
;
import
org.apache.avalon.framework.configuration.Reconfigurable
;
import
org.kohsuke.stapler.StaplerRequest
;
import
java.io.IOException
;
...
...
@@ -141,11 +143,23 @@ public class DescribableList<T extends Describable<T>, D extends Descriptor<T>>
List
<
T
>
newList
=
new
ArrayList
<
T
>();
for
(
Descriptor
<
T
>
d
:
descriptors
)
{
T
existing
=
get
((
D
)
d
);
String
name
=
d
.
getJsonSafeClassName
();
if
(
json
.
has
(
name
))
{
T
instance
=
d
.
newInstance
(
req
,
json
.
getJSONObject
(
name
));
newList
.
add
(
instance
);
JSONObject
o
=
json
.
optJSONObject
(
name
);
T
instance
=
null
;
if
(
o
!=
null
)
{
if
(
existing
instanceof
ReconfigurableDescribable
)
instance
=
(
T
)((
ReconfigurableDescribable
)
existing
).
reconfigure
(
req
,
o
);
else
instance
=
d
.
newInstance
(
req
,
o
);
}
else
{
if
(
existing
instanceof
ReconfigurableDescribable
)
instance
=
(
T
)((
ReconfigurableDescribable
)
existing
).
reconfigure
(
req
,
null
);
}
if
(
instance
!=
null
)
newList
.
add
(
instance
);
}
replaceBy
(
newList
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录