All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.model.ParameterDefinition Maven / Gradle / Ivy

package hudson.model;

import net.sf.json.JSONObject;

import org.kohsuke.stapler.StaplerRequest;

import hudson.util.DescriptorList;
import hudson.ExtensionPoint;

/**
 * Defines a parameter for a build.
 *
 * 

* In Hudson, a user can configure a job to require parameters for a build. * For example, imagine a test job that takes the bits to be tested as a parameter. * *

* The actual meaning and the purpose of parameters are entirely up to users, so * what the concrete parameter implmentation is pluggable. Write subclasses * in a plugin and hook it up to {@link #LIST} to register it. * *

* Three classes are used to model build parameters. First is the * {@link ParameterDescriptor}, which tells Hudson what kind of implementations are * available. From {@link ParameterDescriptor#newInstance(StaplerRequest, JSONObject)}, * Hudson creates {@link ParameterDefinition}s based on the job configuration. * For example, if the user defines two string parameters "database-type" and * "appserver-type", we'll get two {@link StringParameterDefinition} instances * with their respective names. * *

* When a job is configured with {@link ParameterDefinition} (or more precisely, * {@link ParametersDefinitionProperty}, which in turns retains {@link ParameterDefinition}s), * user would have to enter the values for the defined build parameters. * The {@link #createValue(StaplerRequest, JSONObject)} method is used to convert this * form submission into {@link ParameterValue} objects, which are then accessible * during a build. * * * *

Persistence

*

* Instances of {@link ParameterDefinition}s are persisted into job config.xml * through XStream. * * *

Assocaited Views

*

config.jelly

*

* {@link ParameterDefinition} class uses config.jelly to provide contribute a form * fragment in the job configuration screen. Values entered there is fed back to * {@link ParameterDescriptor#newInstance(StaplerRequest, JSONObject)} to create {@link ParameterDefinition}s. * *

index.jelly

* The index.jelly view contributes a form fragment in the page where the user * enters actual values of parameters for a build. The result of this form submission * is then fed to {@link ParameterDefinition#createValue(StaplerRequest, JSONObject)} to * create {@link ParameterValue}s. * * TODO: what Jelly pages does this object need for rendering UI? * TODO: {@link ParameterValue} needs to have some mechanism to expose values to the build * @see StringParameterDefinition */ public abstract class ParameterDefinition implements Describable, ExtensionPoint { private final String name; public String getName() { return name; } public ParameterDefinition(String name) { super(); this.name = name; } /** * {@inheritDoc} */ public abstract ParameterDescriptor getDescriptor(); public abstract ParameterValue createValue(StaplerRequest req, JSONObject jo); /** * Returns default parameter value for this definition. * * @return default parameter value or null if no defaults are available * @since 1.253 */ public ParameterValue getDefaultParameterValue() { return null; } /** * A list of available parameter definition types */ public static final DescriptorList LIST = new DescriptorList(); public abstract static class ParameterDescriptor extends Descriptor { protected ParameterDescriptor(Class klazz) { super(klazz); } public String getValuePage() { return getViewPage(clazz, "index.jelly"); } @Override public String getDisplayName() { return "Parameter"; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy