Is it possible to change the order of parameters generated by the Snippitizer?

27 views
Skip to first unread message

Michael Fowler

unread,
Aug 3, 2018, 1:35:09 PM8/3/18
to Jenkins Developers
Hi,
 I have a plugin that outputs a pipeline snippet like this from the snippitizer: "mycommand parameter2: value2, parameter1: value 1" . For readability, I would like to have parameter1 be written first. Is there something I can do in the plugin code to change the order? Thanks,
-Michael

Jesse Glick

unread,
Aug 6, 2018, 10:56:21 AM8/6/18
to Jenkins Dev
On Fri, Aug 3, 2018 at 1:35 PM Michael Fowler <michael...@gmail.com> wrote:
> I have a plugin that outputs a pipeline snippet like this from the snippitizer: "mycommand parameter2: value2, parameter1: value 1" . For readability, I would like to have parameter1 be written first. Is there something I can do in the plugin code to change the order?

Not currently; parameters are alphabetized. It would be ideal if any
mandatory parameters (`@DataBoundConstructor`) preceded any optional
ones (`@DataBoundSetter`), but I do not think `Snippetizer` or its
underlying `DescribableModel` utility does this yet. As far as further
ordering of parameters, there is no API defined which would allow
that.

Martin Weber

unread,
Aug 11, 2018, 5:53:16 AM8/11/18
to jenkin...@googlegroups.com
Could the snippetizer be changed to derive the parameter order from the UI
(jelly file)? Most plugins already have a sensible parameter order in their UI
already.

Martin

--
E-Mails sollten Text sein, Text und nur Text.
Wenn Gott gewollt hätte, dass E-Mails in HTML geschrieben würden,
endeten Gebete traditionell mit </amen>.

Jesse Glick

unread,
Aug 11, 2018, 9:57:18 AM8/11/18
to Jenkins Dev
On Sat, Aug 11, 2018 at 5:53 AM Martin Weber <enten...@gmx.de> wrote:
> Could the snippetizer be changed to derive the parameter order from the UI (jelly file)?

Uh, this would be quite hacky as you would have to not just parse that
XML but hard-code knowledge of how various databinding controls encode
the name of a parameter—sometimes a `field` on a `section`, sometimes
directly on a control. And then there are config forms which for
various reasons directly refer to `${instance.fieldName}` or similar.
And it would not work at all for Groovy views.

I did track down a possible mistake in the current code:
https://issues.jenkins-ci.org/browse/JENKINS-52996

Oleg Nenashev

unread,
Aug 11, 2018, 10:04:37 AM8/11/18
to Jenkins Developers
There could be optional ordinal field for DataBoundSetter and annotation for constructor parameters to support ordering, but it would require a patch in a foundation Jenkins libs like structs.

BR, Oleg

Jesse Glick

unread,
Aug 11, 2018, 10:10:15 AM8/11/18
to Jenkins Dev
On Sat, Aug 11, 2018 at 10:04 AM Oleg Nenashev <o.v.ne...@gmail.com> wrote:
> There could be optional ordinal field for DataBoundSetter

Yes, if anyone really needs it, though I think putting the (usually
one) mandatory parameter first typically suffices.

> annotation for constructor parameters to support ordering

Unnecessary. You can simply reorder the parameters in the constructor
in Java source.

What you _cannot_ do is reorder setters in Java source. In Java 6 and
below, the `Method`s would usually appear in source order, at least if
you used javac. In Java 7 and above, they appear in essentially random
order on each startup.

James Nord

unread,
Aug 11, 2018, 1:03:28 PM8/11/18
to Jenkins Developers
I presume you are meaning the reflection order which is now no longer sorted when running on newer jvms.

It is possible if the code is compiled with debugging (the default) to order them (yourself) so someone could, if they felt like it, add some code (somewhere which I do not know the location) to sort the setters based on source code order.

Reply all
Reply to author
Forward
0 new messages