Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-44892

Ability to override reflective metadata in DescribableModel

    Details

    • Similar Issues:
    • Released As:
      structs 1.18

      Description

      Following up an old semi-suggestion on the dev list with Daniel Spilker and in discussion with Stephen Connolly, I propose a new API in symbol-annotation (so that it could be used from core, not just plugins) that would allow a Describable author to completely customize how instantiate and uninstantiate work, if the POJO-style reflective metadata is not quite right. DescribableModel would then delegate to the custom implementation, which would in turn be able to partly delegate back to the standard implementations where desired.

      Rough  API sketch:

      @Retention(RUNTIME)
      @Target({TYPE}) // TBD: on Descriptor, or its clazz?
      @Documented
      public @interface CustomDescription {
          Class<CustomDescribableModel> value();
      }
      public interface CustomDescribableModel<T> {
          Class<T> getType();
          T instantiate(Map<String, Object> arguments, StandardInstantiator standard);
          Map<String, Object> uninstantiate(T object, StandardUninstantiator standard);
      }
      public interface StandardInstantiator {
          <T> T instantiate(Class<T> type, Map<String, Object> arguments);
      }
      public interface StandardUninstantiator {
          Map<String, Object> uninstantiate(Object object);
      }
      

      TBD:

      • How to deal with UninstantiatedDescribable, defined in the plugin not the annotation library, and which is necessary to support symbols?
      • Is it necessary to be able to override other behaviors of DescribableModel that are currently hard-coded to use reflection, such as the soleRequiredParameter?
      • Can a CustomDescribableModel implementation really be used from, say, job-dsl, given that the implementation would reside in a plugin and might link to any classes in Jenkins? Currently job-dsl runs in-process in the master JVM, but other similar tools run out of process. This is the downside of a procedural override as opposed to annotations.

      Use cases:

      • GerritTrigger could call the standard implementations but rename map entries with keys like gerritBuildFailedCodeReviewValue to something more concise.
      • ChoiceParameterDefinition could correct the type of choices from the PoV of scripts.
      • SCMSourceRetriever in workflow-cps-global-lib could delete .scm.id from uninstantiation results, so that Pipeline Syntax would not offer a random UUID for this form of the library step. (In this use case the SCMSource is never given an owner or otherwise persisted, so its id is irrelevant.) Note that StandardUninstantiator may be called on any object, not necessarily the root object passed into CustomDescribableModel.
      • When refactoring describables into new structures, existing fields, getters, and setters could be retained at the Java level, while providing only the new, recommended form to Pipeline Syntax and similar tools.

        Attachments

          Issue Links

            Activity

            jglick Jesse Glick created issue -
            jglick Jesse Glick made changes -
            Field Original Value New Value
            Link This issue relates to JENKINS-44864 [ JENKINS-44864 ]
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-37227 [ JENKINS-37227 ]
            jglick Jesse Glick made changes -
            Assignee Kohsuke Kawaguchi [ kohsuke ]
            jglick Jesse Glick made changes -
            Link This issue is blocking JENKINS-51638 [ JENKINS-51638 ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "data-api (pre-JEP prototype) (Web Link)" [ 22543 ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "JEP-205 (Web Link)" [ 22544 ]
            jglick Jesse Glick made changes -
            Assignee Jesse Glick [ jglick ]
            jglick Jesse Glick made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-51395 [ JENKINS-51395 ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "structs #43 (Web Link)" [ 22567 ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "workflow-step-api #43 (Web Link)" [ 22569 ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "git #699 (Web Link)" [ 22570 ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "workflow-cps-global-lib #65 (Web Link)" [ 22571 ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "docker-workflow #170 (Web Link)" [ 22574 ]
            jglick Jesse Glick made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-33217 [ JENKINS-33217 ]
            dnusbaum Devin Nusbaum made changes -
            Status In Review [ 10005 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            Released As structs 1.18

              People

              • Assignee:
                jglick Jesse Glick
                Reporter:
                jglick Jesse Glick
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: