From d2612725bd14e5046627823ad6eef00a51dcca79 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Wed, 25 Feb 2009 01:26:50 +0000 Subject: [PATCH] - adding documentation and copyright headers - supporting auto-discovery. Since this is the first release of this feature, I removed the LIST field. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15705 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/java/hudson/model/Environment.java | 48 +++++++++--- .../hudson/model/EnvironmentSpecific.java | 26 ++++++- core/src/main/java/hudson/model/Hudson.java | 2 +- core/src/main/java/hudson/model/Node.java | 19 +---- .../EnvironmentVariablesNodeProperty.java | 8 +- .../java/hudson/slaves/NodeProperties.java | 27 ------- .../main/java/hudson/slaves/NodeProperty.java | 75 ++++++++++++++++++- .../hudson/slaves/NodePropertyDescriptor.java | 36 ++++++++- 8 files changed, 170 insertions(+), 71 deletions(-) delete mode 100644 core/src/main/java/hudson/slaves/NodeProperties.java diff --git a/core/src/main/java/hudson/model/Environment.java b/core/src/main/java/hudson/model/Environment.java index 284949a7e5..b61f258c86 100644 --- a/core/src/main/java/hudson/model/Environment.java +++ b/core/src/main/java/hudson/model/Environment.java @@ -1,22 +1,48 @@ +/* + * The MIT License + * + * Copyright (c) 2004-2009, Sun Microsystems, Inc., Tom Huybrechts + * + * 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.Launcher; -import hudson.Util; -import hudson.model.AbstractBuild; -import hudson.model.Build; -import hudson.model.BuildListener; -import hudson.slaves.NodeProperty; +import hudson.tasks.Builder; import java.io.IOException; import java.util.Map; /** - * Represents the environment set up by - * {@link NodeProperty#setUp(Build,Launcher,BuildListener)}. - * + * Represents some resources that are set up for the duration of a build + * to be torn down when the build is over. + * + *

+ * This is often used to run a parallel server necessary during a build, + * such as an application server, a database reserved for the build, + * X server for performing UI tests, etc. + * *

- * It is expected that the subclasses of {@link NodeProperty} extends this class - * and implements its own semantics. + * By having a plugin that does this, instead of asking each build script to do this, + * we can simplify the build script. {@link Environment} abstraction also gives + * you guaranteed "tear down" phase, so that such resource won't keep running forever. + * + * @since 1.286 */ public abstract class Environment { /** diff --git a/core/src/main/java/hudson/model/EnvironmentSpecific.java b/core/src/main/java/hudson/model/EnvironmentSpecific.java index b1554cdc35..08de0e5460 100644 --- a/core/src/main/java/hudson/model/EnvironmentSpecific.java +++ b/core/src/main/java/hudson/model/EnvironmentSpecific.java @@ -1,3 +1,26 @@ +/* + * The MIT License + * + * Copyright (c) 2004-2009, Sun Microsystems, Inc., Tom Huybrechts + * + * 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.Map; @@ -7,13 +30,12 @@ import java.util.Map; * * Mainly for documentation purposes. * + * @since 1.286 * @param */ public interface EnvironmentSpecific { - /** * Returns a specialized copy of T for functioning in the given environment. */ T forEnvironment(Map environment); - } diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index be128b055b..fbd44d29a3 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -2057,7 +2057,7 @@ public final class Hudson extends Node implements ItemGroup, Stapl clouds.rebuildHetero(req,json, Cloud.all(), "cloud"); - nodeProperties.rebuild(req, json.getJSONObject("nodeProperties"), getNodePropertyDescriptors()); + nodeProperties.rebuild(req, json.getJSONObject("nodeProperties"), NodeProperty.for_(this)); save(); if(result) diff --git a/core/src/main/java/hudson/model/Node.java b/core/src/main/java/hudson/model/Node.java index 53cd385ba2..cb900209a1 100644 --- a/core/src/main/java/hudson/model/Node.java +++ b/core/src/main/java/hudson/model/Node.java @@ -32,7 +32,6 @@ import hudson.remoting.VirtualChannel; import hudson.security.ACL; import hudson.security.AccessControlled; import hudson.security.Permission; -import hudson.slaves.EnvironmentVariablesNodeProperty; import hudson.slaves.NodeDescriptor; import hudson.slaves.NodeProperty; import hudson.slaves.NodePropertyDescriptor; @@ -41,9 +40,7 @@ import hudson.util.DescribableList; import hudson.util.EnumConverter; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; import java.util.Set; import org.kohsuke.stapler.Stapler; @@ -59,10 +56,6 @@ import org.kohsuke.stapler.Stapler; * @see NodeDescriptor */ public abstract class Node extends AbstractModelObject implements Describable, ExtensionPoint, AccessControlled { - - public static final List PROPERTIES = Descriptor - .toList((NodePropertyDescriptor) EnvironmentVariablesNodeProperty.DESCRIPTOR); - public String getDisplayName() { return getNodeName(); // default implementation } @@ -197,17 +190,7 @@ public abstract class Node extends AbstractModelObject implements Describable, NodePropertyDescriptor> getNodeProperties(); public abstract void setNodeProperties(Collection> nodeProperties) throws IOException; - - public List getNodePropertyDescriptors() { - List result = new ArrayList(); - for (NodePropertyDescriptor npd : PROPERTIES) { - if (npd.isApplicable(getClass())) { - result.add(npd); - } - } - return result; - } - + public > N getNodeProperty(Class clazz) { for (NodeProperty p: getNodeProperties()) { if (clazz.isInstance(p)) { diff --git a/core/src/main/java/hudson/slaves/EnvironmentVariablesNodeProperty.java b/core/src/main/java/hudson/slaves/EnvironmentVariablesNodeProperty.java index 16f796a923..71c33b1072 100644 --- a/core/src/main/java/hudson/slaves/EnvironmentVariablesNodeProperty.java +++ b/core/src/main/java/hudson/slaves/EnvironmentVariablesNodeProperty.java @@ -1,6 +1,7 @@ package hudson.slaves; import hudson.Launcher; +import hudson.Extension; import hudson.model.*; import java.io.IOException; @@ -38,12 +39,7 @@ public class EnvironmentVariablesNodeProperty extends NodeProperty { return Environment.create(envVars); } - public NodePropertyDescriptor getDescriptor() { - return DESCRIPTOR; - } - - public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); - + @Extension public static class DescriptorImpl extends NodePropertyDescriptor { @Override diff --git a/core/src/main/java/hudson/slaves/NodeProperties.java b/core/src/main/java/hudson/slaves/NodeProperties.java deleted file mode 100644 index 13785f88d4..0000000000 --- a/core/src/main/java/hudson/slaves/NodeProperties.java +++ /dev/null @@ -1,27 +0,0 @@ -package hudson.slaves; - -import hudson.model.Descriptor; -import hudson.model.Node; - -import java.util.ArrayList; -import java.util.List; - -public class NodeProperties { - public static final List PROPERTIES = Descriptor - .toList((NodePropertyDescriptor) EnvironmentVariablesNodeProperty.DESCRIPTOR); - - /** - * List up all {@link NodePropertyDescriptor}s that are applicable for the - * given project. - */ - public static List getFor(Node node) { - List result = new ArrayList(); - for (NodePropertyDescriptor npd : PROPERTIES) { - if (npd.isApplicable(node.getClass())) { - result.add(npd); - } - } - return result; - } - -} diff --git a/core/src/main/java/hudson/slaves/NodeProperty.java b/core/src/main/java/hudson/slaves/NodeProperty.java index c91036a033..f714861737 100644 --- a/core/src/main/java/hudson/slaves/NodeProperty.java +++ b/core/src/main/java/hudson/slaves/NodeProperty.java @@ -1,7 +1,31 @@ +/* + * The MIT License + * + * Copyright (c) 2004-2009, Sun Microsystems, Inc., Tom Huybrechts + * + * 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.slaves; import hudson.ExtensionPoint; import hudson.Launcher; +import hudson.DescriptorExtensionList; import hudson.model.AbstractBuild; import hudson.model.BuildListener; import hudson.model.Describable; @@ -12,15 +36,40 @@ import hudson.tasks.Builder; import java.io.IOException; import java.util.List; +import java.util.ArrayList; +/** + * Extensible property of {@link Node}. + * + *

+ * Plugins can contribute this extension point to add additional data or UI actions to {@link Node}. + * {@link NodeProperty}s show up in the configuration screen of a node, and they are persisted with the {@link Node} object. + * + * + *

Views

+ *
+ *
config.jelly
+ *
Added to the configuration page of the node. + *
global.jelly
+ *
Added to the system configuration page. + *
+ * + * @param + * {@link NodeProperty} can choose to only work with a certain subtype of {@link Node}, and this 'N' + * represents that type. Also see {@link NodePropertyDescriptor#isApplicable(Class)}. + * + * @since 1.286 + */ public abstract class NodeProperty implements Describable>, ExtensionPoint { - public abstract NodePropertyDescriptor getDescriptor(); - protected transient N node; protected void setNode(N node) { this.node = node; } + public NodePropertyDescriptor getDescriptor() { + return (NodePropertyDescriptor)Hudson.getInstance().getDescriptor(getClass()); + } + /** * Runs before the {@link Builder} runs, and performs a set up. Can contribute additional properties * to the environment. @@ -63,5 +112,25 @@ public abstract class NodeProperty implements Describable,NodePropertyDescriptor> all() { + return (DescriptorExtensionList)Hudson.getInstance().getDescriptorList(NodeProperty.class); + } + + /** + * List up all {@link NodePropertyDescriptor}s that are applicable for the + * given project. + */ + public static List for_(Node node) { + List result = new ArrayList(); + for (NodePropertyDescriptor npd : all()) { + if (npd.isApplicable(node.getClass())) { + result.add(npd); + } + } + return result; + } } diff --git a/core/src/main/java/hudson/slaves/NodePropertyDescriptor.java b/core/src/main/java/hudson/slaves/NodePropertyDescriptor.java index ae387d0a62..61a7567807 100644 --- a/core/src/main/java/hudson/slaves/NodePropertyDescriptor.java +++ b/core/src/main/java/hudson/slaves/NodePropertyDescriptor.java @@ -1,17 +1,47 @@ +/* + * The MIT License + * + * Copyright (c) 2004-2009, Sun Microsystems, Inc., Tom Huybrechts + * + * 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.slaves; import hudson.model.Descriptor; import hudson.model.Node; +import hudson.Extension; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import org.jvnet.tiger_types.Types; +/** + * Descriptor for {@link NodeProperty}. + * + *

+ * Put {@link Extension} on your descriptor implementation to have it auto-registered. + * + * @since 1.286 + * @see NodeProperty + */ public abstract class NodePropertyDescriptor extends Descriptor> { - - protected NodePropertyDescriptor() {} - /** * Returns true if this {@link NodeProperty} type is applicable to the * given job type. -- GitLab