Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to access an xsl resource file from my Task class

BarthélémyH August 7, 2011

I am trying to add an xsl file (ctest2junit.xsl) to the resources directory of my Bamboo plugin. I have modified the atlassian-plugin.xml by adding this line in the taskType tag:

<resource type="download" name="ctest2junit" location="ctest2junit.xsl"/>

Now, how do I access this resource from my Task class ?
In the execute method I tried various things without success :

URL xsl = getClass().getResource("ctest2junit");
// or
URL xsl = getClass().getResource("main/resources/ctest2junit");

I guess I am plain wrong. Could someone tell me how I should do that ?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
James Dumay
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2011

This seems to work (Missing the forward slash!)

URL xsl = getClass().getResource("/foo.xsl");

buildLogger.addBuildLogEntry("xsl : " + xsl );

Sorry for the confusion!

Anecdotally, I think declaring the resource in atlassian-plugin.xml and providing a class to load those resources would be much more straightforward than forcing you to load it from the classloader itself might be a good idea. Ill try to get something like that in the next release of the plugin api.

BarthélémyH August 8, 2011

It works now, thank you very much.

I think that your idea is good. I instinctively tried to add the resource in atlassian-plugin.xml.

Regards

1 vote
James Dumay
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2011

You were half right - you don't need to specify a <resource> element in the plugin discriptor (this is currently only used for resources that can be referenced in the UI). Simply change your code sample like so:

URL xsl = getClass().getResource("ctest2junit.xsl");

and you should get a valid URL to your XSL file :)

BarthélémyH August 7, 2011

Thank you for your message. I have removed the resource element in the plugin descriptor and modified the code as specified :

URL xsl = getClass().getResource("ctest2junit.xsl");
buildLogger.addBuildLogEntry("xsl : " + xsl );

However, I get :

xsl : null

It seems there is still something wrong. The XSL file is in ./src/main/resources/ctest2junit.xsl and the java source is in src/main/java/ch/xxx/yyy/CTest2JUnitConverterTask.java

TAGS
AUG Leaders

Atlassian Community Events