ScriptRunner - can't find plugin module

C May 20, 2015

I have a scripted listener that works when a JIRA event occurs.  I am trying to include the Structure plugin within this scripted listener.  Using your wiki on Scripting Other Plugins, I tried incorporating your minimal example for listing structures from the Structure plugin into my script.  However, it is giving me this error when I try to add/preview the script in JIRA: Problem loading class: java.lang.Exception: Can't find plugin module for class: com.almworks.jira.structure.api.StructureServices, check the plugin is installed / enabled / licensed.

I am using JIRA 6.2.1, Structure 2.10.1, and ScriptRunner 3.0.12.  I have set a script root on JAVA_OPTS where my script is located.  Is there something else I need to do to get the plugin module into my script so I can access Structure?  Thanks!

6 answers

1 vote
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.
May 21, 2015

I just tried it with the latest version of structure and it worked fine. 

Can you put the following in a file, and go to Admin -> Script Console, point to the file and run. 

package examples.docs

import com.almworks.jira.structure.api.PermissionLevel
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.StructureServices

// Specify that classes from this plugin should be available to this script
@WithPlugin("com.almworks.jira.structure")

// Inject plugin module
@PluginModule
StructureServices structureServices
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//noinspection GroovyVariableNotAssigned
def structureManager = structureServices.getStructureManager()
def structures = structureManager.getAllStructures(user, PermissionLevel.VIEW, false)
structures.each {structure ->
    log.debug("Structure: ID: ${structure.id}, name: ${structure.name}")
}
0 votes
C May 21, 2015

That worked!  Any idea why this is different?

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.
May 21, 2015

Looking again at your code it's wrong... the @PluginModule stuff should be outside of the constructor. But it doesn't really explain the error you got.

0 votes
C May 21, 2015

As you suggested, I tried annoting the class with @WithPlugin. To be clear and check that I am doing the right thing, I moved the @WithPlugin to be right before the line declaring class StructureTest.  This gave me the same error.

I also tried putting your AddIssueToStructure example in a post-function script without a class (changing only the structure api version and structure name) and got the same error.

Capture.PNG

0 votes
C May 20, 2015

It has the same error without the @Grab.

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.
May 20, 2015

and the other thing I said to try?

0 votes
C May 20, 2015

Here is a stripped down version of the source code that still has the same error: 

 

package com.torc.listener
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.component.ComponentAccessor
import com.almworks.jira.structure.api.PermissionLevel
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.StructureManager
import com.almworks.jira.structure.api.StructureServices
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import org.apache.log4j.Category

class StructureTest extends AbstractIssueEventListener
{
    StructureTest()
    {
        // Grab only useful for IDE help, not for runtime. Alternatively you can just add this jar to the
        // "provided" scope for the module
        @Grab(group = 'com.almworks.jira.structure', module = 'structure-api', version = '8.7.0')
        // Specify that classes from this plugin should be available to this script
        @WithPlugin("com.almworks.jira.structure")

        // Inject plugin module
        @PluginModule
        StructureServices structureServices

        def structureManager = structureServices.getStructureManager()
        getStructureNames(structureManager)
    }
    void getStructureNames(structureManager)
    {
        def user = ComponentAccessor.getUserManager().getUserByName("scriptrunner")
        def structures = structureManager.getAllStructures(user, PermissionLevel.VIEW, false)
        List<String> structureNames
        structures.each {structure ->
            structureNames.add(structure.name)}
        structureNames //set breakpoint to view names in IDEA
    }
	
}
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.
May 20, 2015

I would try without the @Grab, and the @WithPlugin should annotate the class.

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.
May 20, 2015

Can you paste a bit of your source?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events