I have been developing Jenkins plugins and changes to Jenkins core for more than 10 years now. As such, I have internalized a lot of the knowledge about how to develop against Jenkins and more specifically against Stapler.
When I talk to people trying to start out development against Jenkins, the magic of Stapler seems to be a big source of confusion - at least to the people I have talked to.
Prospective developers get confused:
@SuppressWarnings("unused") // staplerpublic FormValidation doCheckWidgetValue(@QueryParameter String value) {...}
@WebMethod(name="checkWidgetValue")public FormValidation doCheckWidgetValue(@QueryParameter String value) {...}
@GET // staplerpublic FormValidation doCheckWidgetValue(@QueryParameter String value) {...}
@StaplerObject@StaplerFacets({@StaplerFacet("index"),@StaplerFacet("config")})@StaplerFragments({@StaplerFragment("main"),@StaplerFragment("side-panel"),@StaplerFragment(value="tasks",optional=true)})public class Widget { ... }
@StaplerObject@StaplerFacet("index")@StaplerFacet("config")@StaplerFragment("main")@StaplerFragment("side-panel")@StaplerFragment(value="tasks",optional=true)public class Widget { ... }
public class Widget {@StaplerPathpublic Manchu manchu;@StaplerPaths({@StaplerPath,@StaplerPath("fu")})public Foo foo;@StaplerPathpublic Bar getBar() { ... }@StaplerPath(StaplerPath.DYNAMIC)public Object getDynamic(StaplerRequest req) { ... }@StaplerPOSTpublic HttpResponse doActivate(StaplerRequest req) { ... }@StaplerPath(StaplerPath.DYNAMIC)@StaplerPUTpublic HttpResponse doDynamic(StaplerRequest req) { ... }}
public class Widget {@StaplerPathpublic Manchu manchu;@StaplerPath@StaplerPath("fu")public Foo foo;@StaplerPathpublic Bar getBar() { ... }@StaplerPath(StaplerPath.DYNAMIC)public Object getDynamic(StaplerRequest req) { ... }@StaplerPOSTpublic HttpResponse doActivate(StaplerRequest req) { ... }@StaplerPath(StaplerPath.DYNAMIC)@StaplerPUTpublic HttpResponse doDynamic(StaplerRequest req) { ... }}
@Staple @POSTpublic HttpResponse doActivate(StaplerRequest req) { ... }
rather than
@StaplerPOSTpublic HttpResponse doActivate(StaplerRequest req) { ... }
One of the issues I found with that is class conflicts when back-porting the @GET / @POST / etc annotations, so we could only use those if we were prepared to mark 2.7 as the oldest core that could use the annotations, whereas we can make new annotations in a separate package available as far back as Stapler 1.180 == Jenkins 1.455 (or worst case Stapler 1.237 == Jenkins 1.651)
Now we could introduce new annotations without the @Stapler prefix, but then your code complete would confuse you between @org.kohsuke.stapler.annotations.GET and @org.kohsuke.stapler.verbs.GET plus we still need something to give a hint that the annotation is implying Stapler's involvement (at least from my perspective)
NOTE: In this context I see this change as being entirely opt-in. Plugin developers should not have to go adding the annotations - though we would probably apply them in Jenkins core to assist new developers.
--
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-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2BnPnMz-m49TK7Em%2BxBNb%2BV98dBCz9CrrPXg3uW6%2B_x3KX5gOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Am 04.07.2017 um 18:44 schrieb Stephen Connolly <stephen.alan.connolly@gmail.com>:Ulli,What do you think on this proposal, given that you have contact with a lot of students who have been trying to get to grips with the Jenkins code base.Would it make their task easier?
Up to now most students work in the area of testing (ATH), so this will not help them (they would love to see IDs for all entry fields, but that is a totally different topic).
-Stephen
On 3 July 2017 at 05:21, Stephen Connolly <stephen.alan.connolly@gmail.com> wrote:I have been developing Jenkins plugins and changes to Jenkins core for more than 10 years now. As such, I have internalized a lot of the knowledge about how to develop against Jenkins and more specifically against Stapler.
When I talk to people trying to start out development against Jenkins, the magic of Stapler seems to be a big source of confusion - at least to the people I have talked to.
Prospective developers get confused:
- between primary facets and facet fragments.
- where to put facets and facet fragments.
- which facet fragments are optional and which ones are mandatory
This indeed is one of the most confusing things when developing plug-ins. It cost a lot of time to get these things right (mostly by copying and pasting code from another plugin).I'm not sure if annotations are the correct way of dealing with these problems. I think you then need to know where to put an annotation and where not, this will also result in searching for other plugins that do it right.
(Did you even know that those jelly / groovy views are called facets and that there are two kinds?)Some of those concerns affect me too... but I am a seasoned Jenkins developer CMD+SHIFT+P, *, ENTER and IntelliJ is showing me a full list of facets and facet fragments from the class hierarchy and I can search each one looking for the <st:include page="fragment" optional="true"> to discover that there is an optional facet fragment... and then try and dig through the Jelly / Groovy logic to determine when and why that fragment should be included.
It doesn't just stop there... There are those methods that we expect Stapler to invoke for us... typically they are the doFillXYZItems() or doCheckXYZ() methods. I find myself having to mark them up like:@SuppressWarnings("unused") // staplerpublic FormValidation doCheckWidgetValue(@QueryParameter String value) {...}So that my IDE stops complaining about the dead code. It's not a big deal in the grand scheme of things, but I'd much rather have an annotation on the method to signify that we expect the method to be used by stapler... Right now I could do that using@WebMethod(name="checkWidgetValue")public FormValidation doCheckWidgetValue(@QueryParameter String value) {...}If I don't like that, I guess I could use the newer HTTP verb annotations in stapler:@GET // staplerpublic FormValidation doCheckWidgetValue(@QueryParameter String value) {...}
But do these annotations help to get rid of the unused code warnings? I think you still need to add a @SuppressWarnings.
Would there be some checks, that check for the correct path for the corresponding index.jelly, config.jelly, global.jelly and so on?
Now there are some open questions:
- Does it make sense to start all these annotations with Stapler? My initial stab at this was to use @Staple in place of @StaplerPath and to re-use the @GET / @POST / @PUT / @DELETE verbs but mandating the @Staple annotation so that you would have:
@Staple @POSTpublic HttpResponse doActivate(StaplerRequest req) { ... }rather than@StaplerPOSTpublic HttpResponse doActivate(StaplerRequest req) { ... }One of the issues I found with that is class conflicts when back-porting the @GET / @POST / etc annotations, so we could only use those if we were prepared to mark 2.7 as the oldest core that could use the annotations, whereas we can make new annotations in a separate package available as far back as Stapler 1.180 == Jenkins 1.455 (or worst case Stapler 1.237 == Jenkins 1.651)Now we could introduce new annotations without the @Stapler prefix, but then your code complete would confuse you between @org.kohsuke.stapler.annotations.GET and @org.kohsuke.stapler.verbs.GET plus we still need something to give a hint that the annotation is implying Stapler's involvement (at least from my perspective)
- I had thought about saying that the class level @StaplerObject should be enough of a flag that you should expect the other annotations... but the class annotation will be inherited, so you may not see it until you look at the super-class... and @Path will conflict with java.nio.file.Path... that might work with @Staple (and @Staples as the container) but while cute they do not scream to the new developers that these are involved in url binding.
NOTE: In this context I see this change as being entirely opt-in. Plugin developers should not have to go adding the annotations - though we would probably apply them in Jenkins core to assist new developers.
- If we go with the Stapler prefix, would it make sense to consolidate all the annotations with that prefix?
- I am not convinced for the case of @ExportedBean and @Exported, these reflect a different cross-cutting concern and as such the pair seem named well from my PoV
- The @JavaScriptMethod / @WithWellKnownURL annotations might be worthy of consolidation if we can determine better names.
- The parameter binding annotations such as @AncestorInPath, @Header, @QueryParameter and @InjectedParameter I think are fine where they are as they will only be on an action method which already has the @StaplerPOST etc indicator.
- The meta-annotation @InterceptorAnnotation should not be consolidated, in any case we could not consolidate it and retain usage against older cores
- The other annotations are likely rarely used, but if we can find good names and people think they are generically useful rather than single use-case hacks added into the stapler API, I think consolidation might make the features more widely used.
So, over to you the community of Jenkins developers:
- Would this change have helped you get started quicker?
- Would this change help you even now?
I’m not sure if it would help to get started quicker. I think the UI mapping in Jenkins is still (too?) complex even with these annotations. Maybe it would make sense if you can show for an example plug-in class (and jelly file) how it will look after using the annotations?
- How ugly are my proposed annotation names? Can you provide a less ugly scheme of names?
The names are fine.
Stephen
- Anything else?
Am 05.07.2017 um 11:27 schrieb Stephen Connolly <stephen.al...@gmail.com>:+jenkins-dev
On 5 July 2017 at 02:13, Ullrich Hafner <ullrich...@gmail.com> wrote:Am 04.07.2017 um 18:44 schrieb Stephen Connolly <stephen.alan.connolly@gmail.com>:Ulli,What do you think on this proposal, given that you have contact with a lot of students who have been trying to get to grips with the Jenkins code base.Would it make their task easier?Up to now most students work in the area of testing (ATH), so this will not help them (they would love to see IDs for all entry fields, but that is a totally different topic).So one aspect where this could help is in knowing what to test.The annotations can be used to help identify the intent of the plugin author / core and we could perhaps even develop tooling to identify ATH coverage-StephenOn 3 July 2017 at 05:21, Stephen Connolly <stephen.alan.connolly@gmail.com> wrote:I have been developing Jenkins plugins and changes to Jenkins core for more than 10 years now. As such, I have internalized a lot of the knowledge about how to develop against Jenkins and more specifically against Stapler.
When I talk to people trying to start out development against Jenkins, the magic of Stapler seems to be a big source of confusion - at least to the people I have talked to.
Prospective developers get confused:
- between primary facets and facet fragments.
- where to put facets and facet fragments.
- which facet fragments are optional and which ones are mandatory
This indeed is one of the most confusing things when developing plug-ins. It cost a lot of time to get these things right (mostly by copying and pasting code from another plugin).I'm not sure if annotations are the correct way of dealing with these problems. I think you then need to know where to put an annotation and where not, this will also result in searching for other plugins that do it right.Yes, I would also propose improving the stapler documentation in conjunction with these changes so that it should be easier to find the "recommended" patterns to follow.Though how much energy I personally have to push documentation improvements is another question entirely ;-)
(Did you even know that those jelly / groovy views are called facets and that there are two kinds?)Some of those concerns affect me too... but I am a seasoned Jenkins developer CMD+SHIFT+P, *, ENTER and IntelliJ is showing me a full list of facets and facet fragments from the class hierarchy and I can search each one looking for the <st:include page="fragment" optional="true"> to discover that there is an optional facet fragment... and then try and dig through the Jelly / Groovy logic to determine when and why that fragment should be included.
It doesn't just stop there... There are those methods that we expect Stapler to invoke for us... typically they are the doFillXYZItems() or doCheckXYZ() methods. I find myself having to mark them up like:@SuppressWarnings("unused") // staplerpublic FormValidation doCheckWidgetValue(@QueryParameter String value) {...}So that my IDE stops complaining about the dead code. It's not a big deal in the grand scheme of things, but I'd much rather have an annotation on the method to signify that we expect the method to be used by stapler... Right now I could do that using@WebMethod(name="checkWidgetValue")public FormValidation doCheckWidgetValue(@QueryParameter String value) {...}If I don't like that, I guess I could use the newer HTTP verb annotations in stapler:@GET // staplerpublic FormValidation doCheckWidgetValue(@QueryParameter String value) {...}But do these annotations help to get rid of the unused code warnings? I think you still need to add a @SuppressWarnings.Well you can configure IDEs to say "this annotation is used" and we can even have the Stapler plugin for IntelliJ pre-register the annotations so that IntelliJ users (I'm selfish ;-) ) don't even need to add the setting
But the simple @GET is not screaming out stapler to me, so I feel compelled to add a // stapler comment to remind myself that the annotation is used by stapler
Then we hit the actual name that stapler exposes things on. There are some conventions that stapler follows... and they are magic conventions... so much so that I just keep http://stapler.kohsuke.org/reference.html as the first bookmark in my bookmark bar.
I think we can do better. I think we should do better, and here is my proposal.
We should introduce some annotations. Make them available against older versions of Jenkins so that we don't have to wait for everyone to update their plugin baseline. The annotations can be added as a plugin dependency in the parent pom, that everyone can use them just by upgrading the plugin parent pom.
Here are the class annotations I think we need:
- An annotation (I propose @StaplerObject) that says "This object is expected to bound to a URL by Stapler, the Stapler annotations are complete, check that there are no facets / fragments without a corresponding annotation and no magic on this class please" (so if there is, say a rename.jelly but no @StaplerFacet("rename") or @StaplerFragment("rename")then you get an error)
Actually I nearly forgot Oleg you were driving the Google summer of code last year, what do you think?
--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/UrVVT8wbHIE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr2ShkBiyLgxO18eK%2BKtecKMR5tKWbNfYHiOcc-HqgEG4g%40mail.gmail.com.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2BnPnMz-m49TK7Em%2BxBNb%2BV98dBCz9CrrPXg3uW6%2B_x3KX5gOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
FWIW, I've already discussed this offline with Stephen and I'm generally +1.One suggestion I had for him is to consider using a Java method definition instead of @StaplerFacet and @StaplerFragment. That is, instead of this:@StaplerFacets({@StaplerFacet("index"),@StaplerFacet("config")})@StaplerFragments({@StaplerFragment("main"),@StaplerFragment("side-panel"),@StaplerFragment(value="tasks",optional=true)})public class Widget { ... }Consider that:public class Widget {@StaplerFacet protected void index() {}@StaplerFacet protected void config() {}@StaplerFragment protected abstract void main();@StaplerFragment("side-panel") protected abstract void sidepanel();@StaplerFragment protected void tasks();}
I liked this better because ...
- It fits with the original design thinking behind Stapler, which is that views are like methods. Their inheritance and override semantics are all modeled after methods.
- It avoids a long list of @StaplerFragment/@StaplerFacet at the top of the class declaration. We have some objects in the core that has quite a few views.
- It creates a nice to place to describe view as javadoc.
- 'abstract' and 'final' provides convenient semantics and javac does that work for us. One less thing to do for our annotation processor
Obvious downside is that those are not real methods.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2BnPnMz-m49TK7Em%2BxBNb%2BV98dBCz9CrrPXg3uW6%2B_x3KX5gOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
----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-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAN4CQ4wDS34DE-PQVK6tsCQD5AXWcxCMEVkCgh5MNymRNVcLPw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2BnPnMwio9PeC3uhC_i4XqQ_7OY2dN2Hx34e6hSmHVAeG7RiRA%40mail.gmail.com.
I agree with Stephen here; adding methods seems risky and could break existing plugins, at least in a backwards compat sense.But I at the same time do like the idea of getting javadoc for the facets and fragments. So can we get both somehow?E.g. if there is a @StaplerFacet("login") or @StaplerFragment("main") there should be a corresponding@facet login the login page.@fragment main add this to change the main part of the configuration page.in the javadoc of the class?/B
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CALzHZS10%2BzMD58BLJBiksxY7ch7sDQ7rPQEN9y-SJACGhREoTA%40mail.gmail.com.