Package hudson.model

Class JobPropertyDescriptor

    • Constructor Detail

      • JobPropertyDescriptor

        protected JobPropertyDescriptor​(Class<? extends JobProperty<?>> clazz)
      • JobPropertyDescriptor

        protected JobPropertyDescriptor()
        Infers the type of the corresponding JobProperty from the outer class. This version works when you follow the common convention, where a descriptor is written as the static nested class of the describable class.
        Since:
        1.278
    • Method Detail

      • newInstance

        public JobProperty<?> newInstance​(org.kohsuke.stapler.StaplerRequest req,
                                          net.sf.json.JSONObject formData)
                                   throws Descriptor.FormException
        Description copied from class: Descriptor
        Creates a configured instance from the submitted form.

        Hudson only invokes this method when the user wants an instance of T. So there's no need to check that in the implementation.

        The default implementation of this method uses Descriptor.bindJSON(org.kohsuke.stapler.StaplerRequest, java.lang.Class<T>, net.sf.json.JSONObject) which performs the databinding on the constructor of Descriptor.clazz.

        For some types of Describable, such as ListViewColumn, this method can be invoked with null request object for historical reason. Such design is considered broken, but due to the compatibility reasons we cannot fix it. Because of this, the default implementation gracefully handles null request, but the contract of the method still is "request is always non-null." Extension points that need to define the "default instance" semantics should define a descriptor subtype and add the no-arg newInstance method.

        Overrides:
        newInstance in class Descriptor<JobProperty<?>>
        Parameters:
        req - Always non-null (see note above.) This object includes represents the entire submission.
        formData - The JSON object that captures the configuration data for this Descriptor. See https://www.jenkins.io/doc/developer/forms/structured-form-submission/ Always non-null.
        Returns:
        null to avoid setting an instance of JobProperty to the target project (or just use OptionalJobProperty)
        Throws:
        Descriptor.FormException - Signals a problem in the submitted form.
      • isApplicable

        public boolean isApplicable​(Class<? extends Job> jobType)
        Returns true if this JobProperty type is applicable to the given job type.

        The default implementation of this method checks if the given job type is assignable to J of JobProperty<J>, but subtypes can extend this to change this behavior.

        Returns:
        true to indicate applicable, in which case the property will be displayed in the configuration screen of this job.