Skip to content

Commit

Permalink
[JENKINS-18381] Provide a mechanism to differentiate between node
Browse files Browse the repository at this point in the history
properties that are applicable to the master node only and node properties
that can be applied to all nodes
  • Loading branch information
stephenc committed Jun 18, 2013
1 parent 2c8da0b commit 48e8010
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog.html
Expand Up @@ -90,6 +90,10 @@
<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=-->

Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/hudson/Functions.java
Expand Up @@ -796,6 +796,22 @@ public static List<NodePropertyDescriptor> getNodePropertyDescriptors(Class<? ex
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.
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/hudson/slaves/NodePropertyDescriptor.java
Expand Up @@ -26,6 +26,7 @@
import hudson.Extension;
import hudson.model.Node;
import hudson.tools.PropertyDescriptor;
import jenkins.model.Jenkins;

/**
* Descriptor for {@link NodeProperty}.
Expand All @@ -43,4 +44,17 @@ protected NodePropertyDescriptor(Class<? extends NodeProperty<?>> clazz) {

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());
}
}
Expand Up @@ -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());

0 comments on commit 48e8010

Please sign in to comment.