Skip to content

Commit

Permalink
[JENKINS-40365] add Node#getNodeProperty methods (#2663)
Browse files Browse the repository at this point in the history
* [JENKINS-40365] add getNodeProperty methods

* implement getNodeProperty in DummySlave

* implement getNodeProperty in Node

avoid binary imcompatible change
dded javadoc

* revert Slave.jar to original

* fix formatting

* more formatting
  • Loading branch information
mwinter69 authored and oleg-nenashev committed Dec 16, 2016
1 parent ef8ddd8 commit a1258c0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions core/src/main/java/hudson/model/Node.java
Expand Up @@ -451,6 +451,47 @@ public FileSystemProvisioner getFileSystemProvisioner() {
*/
public abstract @Nonnull DescribableList<NodeProperty<?>, NodePropertyDescriptor> getNodeProperties();

/**
* Gets the specified property or null if the property is not configured for this Node.
*
* @param clazz the type of the property
*
* @return null if the property is not configured
*
* @since TODO
*/
@CheckForNull
public <T extends NodeProperty> T getNodeProperty(Class<T> clazz)
{
for (NodeProperty p: getNodeProperties()) {
if (clazz.isInstance(p)) {
return clazz.cast(p);
}
}
return null;
}

/**
* Gets the property from the given classname or null if the property
* is not configured for this Node.
*
* @param className The classname of the property
*
* @return null if the property is not configured
*
* @since TODO
*/
@CheckForNull
public NodeProperty getNodeProperty(String className)
{
for (NodeProperty p: getNodeProperties()) {
if (p.getClass().getName().equals(className)) {
return p;
}
}
return null;
}

// used in the Jelly script to expose descriptors
public List<NodePropertyDescriptor> getNodePropertyDescriptors() {
return NodeProperty.for_(this);
Expand Down

0 comments on commit a1258c0

Please sign in to comment.