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

How to import custom plugin class in Groovy Script Runner?

Kalpen Patel February 12, 2013

I have created a custom plugin called "MyTimesheet" to generate various timesheet report. I have installed the plugin in Jira.

I want to create a groovy script which will send the report, generated by MyTimesheet plugin, via Email.

For that, I need to import the class from MyTimesheet plugin, which will return the HTML object of the report.

MyTimesheet plugin has package "package com.atlassian.tutorial.mytimesheet" and in that there is a class called "timesheetclass". There is a method called "generateReport()" in class timesheetclass.

When I try to import "com.atlassian.tutorial.mytimesheet" or "com.atlassian.tutorial.mytimesheet.timesheetclass", it throws below error.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script19.groovy: 1: unable to resolve class com.atlassian.tutorial.mytimesheet@ line 1, column 1. import com.atlassian.tutorial.helloworld; ^ 1 error

Can you please help me with this. How can I use the method from my custom plugin's class?

5 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Kalpen Patel February 19, 2013

Found alternate solution to send email. "Scheduling Events via SAL"

0 votes
Mizan
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.
February 13, 2013

Try adding the class to a component module in your plugin , refer this document https://developer.atlassian.com/display/JIRADEV/Component+Plugin+Module

Most probably this should solve the unable to resolve class exception

Kalpen Patel February 13, 2013
Hello,
I already have this in my plugin. I have pasted code below from two files.

Code from atlassian-plugin.xml
<component key="TimesheetClass" class="com.atlassian.tutorial.mytimesheet.timesheetclassImpl" public="true">
<interface>com.atlassian.tutorial.mytimesheet.timesheetclass</interface> </component>

Code from timesheetclassImpl.java

package com.atlassian.tutorial.mytimesheet;
import com.atlassian.sal.api.ApplicationProperties;

public class timesheetclassImpl implements timesheetclass
{
    private final ApplicationProperties applicationProperties;

    public timesheetclassImpl (ApplicationProperties applicationProperties)
    {
        this.applicationProperties = applicationProperties;
    }

    public String GenerateReport()
    {
        return "Report is generated.";
    }
}

---------------------------------------------------

Now how can I use GenerateReport() method in Groovy script?

JamieA
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.
February 13, 2013

I think you should be able to use ComponentAccessor.getComponent(your class), but you might need to import it in script runner's pom, which you don't want to do.

Also see https://answers.atlassian.com/questions/73449/using-the-greenhopper-api-to-modify-rank?page=1#73622 - which is an answer for greenhopper, but is basically the sme problem you have.

0 votes
Kalpen Patel February 13, 2013

Oh sorry I have modified the class name in error message. Error is :

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script19.groovy: 1: unable to resolve class com.atlassian.tutorial.mytimesheet@ line 1, column 1. import com.atlassian.tutorial.mytimesheet; ^ 1 error

I am not sure about plugin version but I have created plugin with SDK 4.1.4 and JIRA 5. Is this a helpful?

0 votes
Kalpen Patel February 12, 2013

Oh sorry I have modified the class name in error message. Error is :

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script19.groovy: 1: unable to resolve class com.atlassian.tutorial.mytimesheet@ line 1, column 1. import com.atlassian.tutorial.mytimesheet; ^ 1 error

I am not sure about plugin version but I have created plugin with SDK 4.1.4 and JIRA 5. Is this a helpful?

0 votes
JamieA
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.
February 12, 2013

For a start why does the error message refer to helloworld?

Is your plugin plugins2?

You may need to make a public component module for your plugin.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events