Using Java based Jelly TagLibrary impls that are in a Plugin

18 views
Skip to first unread message

Tom Fennelly

unread,
Jul 2, 2014, 6:34:54 PM7/2/14
to jenkin...@googlegroups.com
Hi.

Just wondering if anyone can guide me as to how I can write a Java based TagLibrary and have it loadable from a plugin (without setting pluginFirstClassLoader=true).  When I try it I get a classloader exception that makes total sense to me, but I'm wondering if there's some trick or different impl that works around it.

Example... a Simple TagLibrary impl like this... 

public class IconsTaglib extends TagLibrary {
    public IconsTaglib() {
             // Register some tags...
        registerTag("myFunkyTag", MyFunkyTag.class);
    }
}

This class is located in the plugin i.e. not in Jenkins core with other taglibs.

Then in a .jelly tag script (also in the plugin, but for which there are no cloassloading issues) we use the myFunkyTag tag that was implemented in Java e.g.

<myf:myFunkyTag xmlns:myf="jelly:org.jenkins.x.y.MyFunkyTag" />

The above causes a ClassLoading exception because Jelly's XMLParser class (code located in Jenkins - not in the plugin) tries to load the MyFunkyTag class with the wrong classloader (XMLParser line #1024).  What looks like would work (in this specific case at least) is if XMLParser tried using the JellyContext ClassLoader instead, but of course that might cause other issues.

BTW I tried with the MyFunkyTag impl located in Jenkins core and everything works fine as expected.

Any suggestions?  I'm wondering maybe this is not an issue if I implement the Tag in Groovy instead, but would like to know if doing it in Java is not going to work first.

Thanks,

Tom.

Tom Fennelly

unread,
Jul 2, 2014, 6:52:32 PM7/2/14
to jenkin...@googlegroups.com
I grep'd across all repos in https://github.com/jenkinsci and apart from in jenkins and jelly, there are no Java impls of TagLibrary.  So, looks like this is not common, or maybe is never done.

Stephen Connolly

unread,
Jul 3, 2014, 4:46:53 AM7/3/14
to jenkin...@googlegroups.com
Do you inform jenkins that you have a taglibrary?


--
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/d/optout.

Tom Fennelly

unread,
Jul 3, 2014, 4:56:49 AM7/3/14
to jenkin...@googlegroups.com
xmlns:myf="jelly:org.jenkins.x.y.MyFunkyTag" is one way of doing that and, as I said, that works when the TagLibrary impl is located in Jenkins core (Vs out in a plugin).  I didn't see any other way of doing it.  Are you telling me there is another way?
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/9mEnlPmIu1c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.

Stephen Connolly

unread,
Jul 3, 2014, 5:35:58 AM7/3/14
to jenkin...@googlegroups.com
Well I suspect that you need to inform jelly of the TagLibrary class or else it will not discover it. I am suspecting that there is a plugin goal putting the requisite info somewhere on the classpath. That plugin goal is probably working for jenkins core but perhaps not by default in plugins

Stephen Connolly

unread,
Jul 3, 2014, 5:37:49 AM7/3/14
to jenkin...@googlegroups.com
I suspect one thing could be that your class name is IconsTaglib and not IconsTagLib

Stephen Connolly

unread,
Jul 3, 2014, 5:39:49 AM7/3/14
to jenkin...@googlegroups.com
Also you probably need to add the annotation

@org.kohsuke.stapler.jelly.groovy.TagLibraryUri("/shim/layout")

Stephen Connolly

unread,
Jul 3, 2014, 5:48:10 AM7/3/14
to jenkin...@googlegroups.com
Hmmm you might have to have the namespace be the FQCN of the TagLibrary implementation, eg see MorphTagLibrary in core... digging some more

Stephen Connolly

unread,
Jul 3, 2014, 6:05:06 AM7/3/14
to jenkin...@googlegroups.com
can you share your git repos with me so I can debug a little... or pop into hipchat and we can chat and bring the solution back to the list once we have one ;-)

Tom Fennelly

unread,
Jul 3, 2014, 6:53:50 AM7/3/14
to jenkin...@googlegroups.com
I'm using the name consistently - the name was resolvable when in core.

I tried to generalize the description of the problem in the email, but forgot to rename the TagLibrary impl class to from IconsTaglib to MyFunkyTaglib.  Sorry about that... should have just left as is :)

Tom Fennelly

unread,
Jul 3, 2014, 6:54:49 AM7/3/14
to jenkin...@googlegroups.com
Tried that.  It didn't help.  Unless it needs to be done in conjunction with something else.

Tom Fennelly

unread,
Jul 3, 2014, 6:57:06 AM7/3/14
to jenkin...@googlegroups.com
Right... I'm doing that (same as with MorphTagLibrary).  And as I said, that works fine when the TagLibrary impl is in core.

<ic:setIcons xmlns:ic="jelly:org.jenkins.ui.icon.taglib.IconsTaglib" />

Tom Fennelly

unread,
Jul 3, 2014, 7:01:33 AM7/3/14
to jenkin...@googlegroups.com

Stephen Connolly

unread,
Jul 3, 2014, 7:07:37 AM7/3/14
to jenkin...@googlegroups.com
where's the example where you had it as a plugin and where is the example plugin using it?

Tom Fennelly

unread,
Jul 3, 2014, 7:12:09 AM7/3/14
to jenkin...@googlegroups.com
Ah yes, sorry... I checked out and changed the credentials plugin... I just pushed a branch to https://github.com/jenkinsci/credentials-plugin/tree/icon-tag-test

Stephen Connolly

unread,
Jul 3, 2014, 7:21:10 AM7/3/14
to jenkin...@googlegroups.com
that's using the ui:icon taglib directly...

Tom Fennelly

unread,
Jul 3, 2014, 7:30:02 AM7/3/14
to jenkin...@googlegroups.com
Right, and <ui:icon> is using the Java TagLibrary impl that is causing the issue (https://github.com/tfennelly/jenkins/blob/icon-tag/icon/src/main/resources/lib/ui/icon/icon.jelly#L46).

The naming is a bit confusing there atm because I was hacking something just to experiment with Java Taglib impls.  That will get cleaned up if we can get the basic thing to work.

Tom Fennelly

unread,
Jul 3, 2014, 7:47:08 AM7/3/14
to jenkin...@googlegroups.com
I'll simplify this for the purposes of getting to the bottom of this particular problem i.e. create a no-op Java TagLibrary impl on the credentials-plugin.  What I was playing with there is ok for me, but confusing for someone else coz there's other stuff in there that's not related to this problem.


On 03/07/2014 12:21, Stephen Connolly wrote:

Stephen Connolly

unread,
Jul 3, 2014, 7:48:50 AM7/3/14
to jenkin...@googlegroups.com
yeah I'm just setting up some clean plugins which can be used as a test... your hacking existing stuff is messing you up I believe

Tom Fennelly

unread,
Jul 3, 2014, 7:50:59 AM7/3/14
to jenkin...@googlegroups.com
Yeah... you're prob right.

Tom Fennelly

unread,
Jul 3, 2014, 8:01:29 AM7/3/14
to jenkin...@googlegroups.com
Okay, I created a MyFunkyTagLibrary here: https://github.com/jenkinsci/credentials-plugin/tree/java-taglib-test

So we can forget about the other stuff for now.  Sorry for the confusion.


On 03/07/2014 12:48, Stephen Connolly wrote:

Stephen Connolly

unread,
Jul 3, 2014, 8:50:51 AM7/3/14
to jenkin...@googlegroups.com

Stephen Connolly

unread,
Jul 3, 2014, 8:51:19 AM7/3/14
to jenkin...@googlegroups.com
I am hitting the same classloader issue you see... currently seeing if I can indirect myself around it

Tom Fennelly

unread,
Jul 3, 2014, 9:56:21 AM7/3/14
to jenkin...@googlegroups.com
I can't see how you'd get this to work without making changes to Jelly's XMLParser and how it selects the correct classloader to use.  On the other hand, we can do what we need to do using a groovy tag/script.
Reply all
Reply to author
Forward
0 new messages