@DataBoundSetter

849 views
Skip to first unread message

Kohsuke Kawaguchi

unread,
Oct 3, 2013, 7:46:28 PM10/3/13
to jenkin...@googlegroups.com
Today, many complex plugins suffer from a massive constructor annotated with @DataBoundConstructor.

This is because the form data-binding requires that all the parameters passed in through the constructor. See xcode plugin [1] for an example of this. The situation was worse with plugins that are used by other plugins, which needed to preserve ever-increasing list of constructors to remain backward compatible.

Starting Jenkins 1.535, this problem is no more. Stapler can not only look for @DataBoundConstructor, but it'll also perform setter injection on methods annotated with @DataBoundSetter.

So whereas you had to write:

    class Foo {
      int a,b,c,d;
      
      @DataBoundConstructor
      public Foo(int a, int b, int c, int d) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
      }
    }

You can now write:

    class Foo {
      int a,b,c,d;
      
      @DataBoundConstructor
      public Foo(int a, int b) {
        this.a = a;
        this.b = b;
      }
      
      @DataBoundSetter
      public void setC(int c) { this.c = c; }
      
      @DataBoundSetter
      public void setD(int d) { this.d = d; }
    }

Or even:

    class Foo {
      int a,b,c,d;
      
      @DataBoundConstructor
      public Foo() {}

      @DataBoundSetter
      public void setA(int a) { this.a = a; }
      
      @DataBoundSetter
      public void setC(int b) { this.b = b; }
      
      @DataBoundSetter
      public void setC(int c) { this.c = c; }
      
      @DataBoundSetter
      public void setD(int d) { this.d = d; }
    }

This will make it easier to evolve plugins that have a large number of configuration options.




--
Kohsuke Kawaguchi

Arnaud Héritier

unread,
Oct 3, 2013, 7:58:32 PM10/3/13
to jenkin...@googlegroups.com, jenkin...@googlegroups.com
Yeah !!! +1000. Thx for this improvement.  

Sent from Mailbox for iPhone


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Slide

unread,
Oct 3, 2013, 10:51:31 PM10/3/13
to Jenkins Dev
This is great, I was just lamenting this! Now I just need it to be in an LTS ;-)

nicolas de loof

unread,
Oct 4, 2013, 12:38:27 AM10/4/13
to jenkin...@googlegroups.com
great,

so next step is to be able to directly annotate fields à la hibernate :)


 class Foo {

     @DataBound
      int a,b,c,d;

}


2013/10/4 Kohsuke Kawaguchi <k...@kohsuke.org>

--

Kevin Fleming (BLOOMBERG/ 731 LEXIN)

unread,
Oct 4, 2013, 9:54:50 AM10/4/13
to jenkin...@googlegroups.com
How will the object know that Stapler has completed calling DataBoundSetters (that all configuration data has been applied)?

nicolas de loof

unread,
Oct 4, 2013, 10:00:42 AM10/4/13
to jenkin...@googlegroups.com
maybe using @PostConstruct ? 


2013/10/4 Kevin Fleming (BLOOMBERG/ 731 LEXIN) <kpfl...@bloomberg.net>

Kohsuke Kawaguchi

unread,
Oct 4, 2013, 2:15:22 PM10/4/13
to jenkin...@googlegroups.com
On 10/03/2013 09:38 PM, nicolas de loof wrote:
> great,
>
> so next step is to be able to directly annotate fields � la hibernate :)
>
>
> class Foo {
>
> @DataBound
> int a,b,c,d;
>
> }

Good idea. I should support that.

> 2013/10/4 Kohsuke Kawaguchi <k...@kohsuke.org <mailto:k...@kohsuke.org>>
> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to jenkinsci-de...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>


--
Kohsuke Kawaguchi | CloudBees, Inc. | http://cloudbees.com/
Try Jenkins Enterprise, our professional version of Jenkins

Kohsuke Kawaguchi

unread,
Oct 4, 2013, 2:15:49 PM10/4/13
to jenkin...@googlegroups.com
On 10/04/2013 07:00 AM, nicolas de loof wrote:
> maybe using @PostConstruct ?
>
>
> 2013/10/4 Kevin Fleming (BLOOMBERG/ 731 LEXIN) <kpfl...@bloomberg.net
> <mailto:kpfl...@bloomberg.net>>
>
> How will the object know that Stapler has completed calling DataBoundSetters
> (that all configuration data has been applied)?

Another great idea. Will implement this.


>
> ----- Original Message -----
> From: jenkin...@googlegroups.com <mailto:jenkin...@googlegroups.com>
> To: jenkin...@googlegroups.com <mailto:jenkin...@googlegroups.com>
> At: Oct 4 2013 00:38:55
>
> great,
>
> so next step is to be able to directly annotate fields � la hibernate :)
>
>
> class Foo {
>
> @DataBound
> int a,b,c,d;
>
> }
>
>
> 2013/10/4 Kohsuke Kawaguchi <k...@kohsuke.org <mailto:k...@kohsuke.org>>
> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-de...@googlegroups.com
> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-de...@googlegroups.com
> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to jenkinsci-de...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>


--

Kevin Fleming (BLOOMBERG/ 731 LEXIN)

unread,
Oct 4, 2013, 2:33:01 PM10/4/13
to jenkin...@googlegroups.com
Great, let us know when this will appear in a Jenkins release and I'll start using it :-)


----- Original Message -----
From: jenkin...@googlegroups.com
To: jenkin...@googlegroups.com
At: Oct 4 2013 14:16:01
On 10/04/2013 07:00 AM, nicolas de loof wrote:
> maybe using @PostConstruct ?
>
>
> 2013/10/4 Kevin Fleming (BLOOMBERG/ 731 LEXIN) <kpfl...@bloomberg.net
> <mailto:kpfl...@bloomberg.net>>
>
> How will the object know that Stapler has completed calling DataBoundSetters
> (that all configuration data has been applied)?

Another great idea. Will implement this.


>
> ----- Original Message -----
> From: jenkin...@googlegroups.com <mailto:jenkin...@googlegroups.com>
> To: jenkin...@googlegroups.com <mailto:jenkin...@googlegroups.com>
> At: Oct 4 2013 00:38:55
>
> great,
>
> so next step is to be able to directly annotate fields à la hibernate :)

domi

unread,
Oct 5, 2013, 3:17:27 AM10/5/13
to jenkin...@googlegroups.com
Kohsuke,
while you'r at it, there are more issues around this topic. e.g.
Plugins still using newInstance() are not usable everywhere: https://issues.jenkins-ci.org/browse/JENKINS-15445
Even worse, when a plugin provides newInstance() and @DBC: https://issues.jenkins-ci.org/browse/JENKINS-18629
/Domi


On 04.10.2013, at 20:15, Kohsuke Kawaguchi <kkawa...@cloudbees.com> wrote:

> On 10/04/2013 07:00 AM, nicolas de loof wrote:
>> maybe using @PostConstruct ?
>>
>>
>> 2013/10/4 Kevin Fleming (BLOOMBERG/ 731 LEXIN) <kpfl...@bloomberg.net
>> <mailto:kpfl...@bloomberg.net>>
>>
>> How will the object know that Stapler has completed calling DataBoundSetters
>> (that all configuration data has been applied)?
>
> Another great idea. Will implement this.
>
>
>>
>> ----- Original Message -----
>> From: jenkin...@googlegroups.com <mailto:jenkin...@googlegroups.com>
>> To: jenkin...@googlegroups.com <mailto:jenkin...@googlegroups.com>
>> At: Oct 4 2013 00:38:55
>>
>> great,
>>
>> so next step is to be able to directly annotate fields à la hibernate :)

Kohsuke Kawaguchi

unread,
Oct 7, 2013, 11:11:54 AM10/7/13
to jenkin...@googlegroups.com
@PostConstruct, @DataBoundSetter on fiels, and Descriptor.newInstance() all fixed in 1.535.


2013/10/5 domi <do...@fortysix.ch>



--
Kohsuke Kawaguchi

Kevin Fleming (BLOOMBERG/ 731 LEXIN)

unread,
Oct 7, 2013, 11:16:48 AM10/7/13
to jenkin...@googlegroups.com
Great! I'll experiment with it in a few weeks after a long overdue vacation :-)

Domi

unread,
Oct 7, 2013, 3:59:19 PM10/7/13
to jenkin...@googlegroups.com
This might be a dummy question, but would it make sense to extract stapler into a separate plugin - like we do with other libs already? Is this even possible?

Kohsuke Kawaguchi

unread,
Oct 7, 2013, 4:12:37 PM10/7/13
to jenkin...@googlegroups.com
Most of the things in core depends on it one way or another, so I don't think it's feasible.


2013/10/7 Domi <do...@fortysix.ch>



--
Kohsuke Kawaguchi

Domi

unread,
Oct 7, 2013, 11:35:43 PM10/7/13
to jenkin...@googlegroups.com
Its not that I think it should not be shipped in the core, but it would make it easter to backport/fix stuff in older versions too.
Regards Domi 

Kohsuke Kawaguchi

unread,
Oct 8, 2013, 12:01:38 AM10/8/13
to jenkin...@googlegroups.com
The problem still remains that the code in core needs to statically link to stapler, so it is just not technically possible to move stapler into a separate plugin.


2013/10/7 Domi <do...@fortysix.ch>



--
Kohsuke Kawaguchi

Dean Yu

unread,
Oct 8, 2013, 12:59:24 PM10/8/13
to jenkin...@googlegroups.com
I'm guessing the desired value is to be able to drop a new version of stapler into an older version of Jenkins. Providing this value as a plugin is sort of an implementation detail. If I exploded an older jenkins.war, dropped in new stapler jars, and repackaged the war, would that work?

  -- Dean

Kohsuke Kawaguchi

unread,
Oct 8, 2013, 1:18:27 PM10/8/13
to jenkin...@googlegroups.com

Yes, it should. In the past, several times we have updated Stapler in LTS.


On 10/08/2013 09:59 AM, Dean Yu wrote:
> I'm guessing the desired value is to be able to drop a new version of stapler
> into an older version of Jenkins. Providing this value as a plugin is sort of an
> implementation detail. If I exploded an older jenkins.war, dropped in new
> stapler jars, and repackaged the war, would that work?
>
> -- Dean
>
> From: Kohsuke Kawaguchi <k...@kohsuke.org <mailto:k...@kohsuke.org>>
> Reply-To: "jenkin...@googlegroups.com
> <mailto:jenkin...@googlegroups.com>" <jenkin...@googlegroups.com
> <mailto:jenkin...@googlegroups.com>>
> Date: Monday, October 7, 2013 9:01 PM
> To: "jenkin...@googlegroups.com <mailto:jenkin...@googlegroups.com>"
> <jenkin...@googlegroups.com <mailto:jenkin...@googlegroups.com>>
> Subject: Re: @DataBoundSetter
>
> The problem still remains that the code in core needs to statically link to
> stapler, so it is just not technically possible to move stapler into a
> separate plugin.
>
>
> 2013/10/7 Domi <do...@fortysix.ch <mailto:do...@fortysix.ch>>
>
> Its not that I think it should not be shipped in the core, but it would
> make it easter to backport/fix stuff in older versions too.
> Regards Domi
>
> Am 07.10.2013 um 22:12 schrieb Kohsuke Kawaguchi <k...@kohsuke.org
> <mailto:k...@kohsuke.org>>:
>
>> Most of the things in core depends on it one way or another, so I
>> don't think it's feasible.
>>
>>
>> 2013/10/7 Domi <do...@fortysix.ch <mailto:do...@fortysix.ch>>
>>
>> This might be a dummy question, but would it make sense to extract
>> stapler into a separate plugin - like we do with other libs
>> already? Is this even possible?
>>
>> Am 07.10.2013 um 17:16 schrieb "Kevin Fleming (BLOOMBERG/ 731
>> LEXIN)" <kpfl...@bloomberg.net <mailto:kpfl...@bloomberg.net>>:
>>
>>> Great! I'll experiment with it in a few weeks after a long
>>> overdue vacation :-)
>>>
>>> ----- Original Message -----
>>> From: jenkin...@googlegroups.com
>>> <mailto:jenkin...@googlegroups.com>
>>> To: jenkin...@googlegroups.com
>>> <mailto:jenkin...@googlegroups.com>
>>> At: Oct 7 2013 11:12:13
>>>
>>> @PostConstruct, @DataBoundSetter on fiels, and
>>> Descriptor.newInstance() all fixed in 1.535.
>>>
>>>
>>> 2013/10/5 domi <do...@fortysix.ch <mailto:do...@fortysix.ch>>
>>>
>>> Kohsuke,
>>> while you'r at it, there are more issues around this
>>> topic. e.g.
>>> Plugins still using newInstance() are not usable
>>> everywhere:
>>> https://issues.jenkins-ci.org/browse/JENKINS-15445
>>> Even worse, when a plugin provides newInstance() and
>>> @DBC: https://issues.jenkins-ci.org/browse/JENKINS-18629
>>> /Domi
>>>
>>>
>>> On 04.10.2013, at 20:15, Kohsuke Kawaguchi
>>> <kkawa...@cloudbees.com
>>> <mailto:kkawa...@cloudbees.com>> wrote:
>>>
>>> > On 10/04/2013 07:00 AM, nicolas de loof wrote:
>>> >> maybe using @PostConstruct ?
>>> >>
>>> >>
>>> >> 2013/10/4 Kevin Fleming (BLOOMBERG/ 731 LEXIN) <kpfl...@bloomberg.net <mailto:kpfl...@bloomberg.net>
>>> >> <mailto:kpfl...@bloomberg.net <mailto:kpfl...@bloomberg.net>>>
>>> >>
>>> >> How will the object know that Stapler has completed calling DataBoundSetters
>>> >> (that all configuration data has been applied)?
>>> >
>>> > Another great idea. Will implement this.
>>> >
>>> >
>>> >>
>>> >> ----- Original Message -----
>>> >> From:jenkin...@googlegroups.com
>>> <mailto:jenkin...@googlegroups.com>
>>> <mailto:jenkin...@googlegroups.com
>>> <mailto:jenkin...@googlegroups.com>>
>>> >> To:jenkin...@googlegroups.com
>>> <mailto:jenkin...@googlegroups.com>
>>> <mailto:jenkin...@googlegroups.com
>>> <mailto:jenkin...@googlegroups.com>>
>>> >> At: Oct 4 2013 00:38:55
>>> >>
>>> >> great,
>>> >>
>>> >> so next step is to be able to directly annotate fields � la hibernate :)
>>> >>
>>> >>
>>> >> class Foo {
>>> >>
>>> >> @DataBound
>>> >> int a,b,c,d;
>>> >>
>>> >> }
>>> >>
>>> >>
>>> >> 2013/10/4 Kohsuke Kawaguchi <k...@kohsuke.org <mailto:k...@kohsuke.org>
>>> <mailto:k...@kohsuke.org <mailto:k...@kohsuke.org>>>
>>> >> send an email tojenkinsci-d...@googlegroups.com
>>> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>
>>> >> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com
>>> <mailto:jenkinsci-dev%252Buns...@googlegroups.com>>.
>>> >> For more options, visithttps://groups.google.com/groups/opt_out.
>>> >>
>>> >>
>>> >> --
>>> >> You received this message because you are subscribed to the Google
>>> >> Groups "Jenkins Developers" group.
>>> >> To unsubscribe from this group and stop receiving emails from it, send
>>> >> an email tojenkinsci-d...@googlegroups.com
>>> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>
>>> >> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com
>>> <mailto:jenkinsci-dev%252Buns...@googlegroups.com>>.
>>> >> For more options, visithttps://groups.google.com/groups/opt_out.
>>> >>
>>> >> --
>>> >> You received this message because you are subscribed to the Google Groups
>>> >> "Jenkins Developers" group.
>>> >> To unsubscribe from this group and stop receiving emails from it, send an
>>> >> email tojenkinsci-d...@googlegroups.com
>>> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>
>>> >> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com
>>> <mailto:jenkinsci-dev%252Buns...@googlegroups.com>>.
>>> >> For more options, visithttps://groups.google.com/groups/opt_out.
>>> >>
>>> >>
>>> >> --
>>> >> You received this message because you are subscribed to the Google Groups
>>> >> "Jenkins Developers" group.
>>> >> To unsubscribe from this group and stop receiving emails from it, send an email
>>> >> tojenkinsci-d...@googlegroups.com
>>> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>.
>>> >> For more options, visithttps://groups.google.com/groups/opt_out.
>>> >>
>>> >
>>> >
>>> > --
>>> > Kohsuke Kawaguchi | CloudBees, Inc. |http://cloudbees.com/
>>> > Try Jenkins Enterprise, our professional version of Jenkins
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
>>> > To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com
>>> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>.
>>> > For more options, visithttps://groups.google.com/groups/opt_out.
>>>
>>> --
>>> You received this message because you are subscribed to
>>> the Google Groups "Jenkins Developers" group.
>>> To unsubscribe from this group and stop receiving emails
>>> from it, send an email to
>>> jenkinsci-de...@googlegroups.com
>>> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>.
>>> For more options, visit
>>> https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>>
>>> --
>>> Kohsuke Kawaguchi
>>> --
>>> You received this message because you are subscribed to the
>>> Google Groups "Jenkins Developers" group.
>>> To unsubscribe from this group and stop receiving emails from
>>> it, send an email to
>>> jenkinsci-de...@googlegroups.com
>>> <mailto:jenkinsci-de...@googlegroups.com>.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>> --
>>> You received this message because you are subscribed to the
>>> Google Groups "Jenkins Developers" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send an email to jenkinsci-de...@googlegroups.com
>>> <mailto:jenkinsci-de...@googlegroups.com>.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Jenkins Developers" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to jenkinsci-de...@googlegroups.com
>> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>>
>> --
>> Kohsuke Kawaguchi
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Jenkins Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to jenkinsci-de...@googlegroups.com
>> <mailto:jenkinsci-de...@googlegroups.com>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-de...@googlegroups.com
> <mailto:jenkinsci-dev%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> --
> Kohsuke Kawaguchi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-de...@googlegroups.com
> <mailto:jenkinsci-de...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages