diff --git a/core/src/main/java/hudson/model/Environment.java b/core/src/main/java/hudson/model/Environment.java index 284949a7e59f9fa9736d0ded05e4512be3ca569d..b61f258c865d1b8631966e99b221db4ac2901599 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 b1554cdc359dac53ad2f1134f221fcce6a1ec9c9..08de0e5460ab75b7f5abfab176699ce7aafee9c6 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 be128b055b7ed1eed736d0bc875a7add3c3db464..fbd44d29a36d0234af3047a31bc54d93b0530167 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 53cd385ba2f7c6c95dcdb3b665e13c24171e8292..cb900209a158737d2fb2c964f98915c196bc02e7 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 16f796a92323d0269c3fc0bf758b208de5d1a185..71c33b107261f8b6aa169398356e1278d6a50800 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 13785f88d4ef19252fa84740d53e2ee8be14a461..0000000000000000000000000000000000000000 --- 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 c91036a033048833b71e8eeb6f94868035e59ba7..f71486173732a81138947408da113dddf02013b3 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 ae387d0a6270fc1665136fec230e603c65a477f5..61a7567807bfc7e84e5c7b621d9c27ddb2bfed60 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.