提交 48e80102 编写于 作者: S Stephen Connolly

[JENKINS-18381] Provide a mechanism to differentiate between node

properties that are applicable to the master node only and node properties
that can be applied to all nodes
上级 2c8da0b8
......@@ -90,6 +90,10 @@ Upcoming changes</a>
<li class=rfe>
CLI list-jobs command should list all nested jobs.
(<a href="https://github.com/jenkinsci/jenkins/pull/793">pull request 793</a>)
<li class=rfe>
Provide a mechanism to differentiate between node properties that are applicable
to the master node only and node properties that can be applied to all nodes
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18381">issue 18381</a>)
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -796,6 +796,22 @@ public class Functions {
return result;
}
/**
* Returns those node properties which can be configured as global node properties.
*
* @since 1.520
*/
public static List<NodePropertyDescriptor> getGlobalNodePropertyDescriptors() {
List<NodePropertyDescriptor> result = new ArrayList<NodePropertyDescriptor>();
Collection<NodePropertyDescriptor> list = (Collection) Jenkins.getInstance().getDescriptorList(NodeProperty.class);
for (NodePropertyDescriptor npd : list) {
if (npd.isApplicableAsGlobal()) {
result.add(npd);
}
}
return result;
}
/**
* Gets all the descriptors sorted by their inheritance tree of {@link Describable}
* so that descriptors of similar types come nearby.
......
......@@ -26,6 +26,7 @@ package hudson.slaves;
import hudson.Extension;
import hudson.model.Node;
import hudson.tools.PropertyDescriptor;
import jenkins.model.Jenkins;
/**
* Descriptor for {@link NodeProperty}.
......@@ -43,4 +44,17 @@ public abstract class NodePropertyDescriptor extends PropertyDescriptor<NodeProp
protected NodePropertyDescriptor() {
}
/**
* Is this node property one where it makes sense to permit it as a global node property.
*
* @return {@code true} if and only if the node property can be listed as a global node property.
* @since 1.520
*/
public boolean isApplicableAsGlobal() {
// preserve legacy behaviour, even if brain-dead stupid, where applying to Jenkins was the discriminator
// note that it would be a mistake to assume Jenkins.getInstance().getClass() == Jenkins.class
// the groovy code tested against app.class, so we replicate that exact logic.
return isApplicable(Jenkins.getInstance().getClass());
}
}
......@@ -5,4 +5,4 @@ import hudson.Functions
def f=namespace(lib.FormTagLib)
f.descriptorList(title:_("Global properties"), name:"globalNodeProperties",
instances: app.globalNodeProperties, descriptors: Functions.getNodePropertyDescriptors(app.getClass()));
instances: app.globalNodeProperties, descriptors: Functions.getGlobalNodePropertyDescriptors());
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册