Use of Greenhopper classes in Groovy script classes

Alexey Paveliev
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.
December 9, 2012

I need to access Greenhopper classes from Groovy Runner.

import com.atlassian.greenhopper.model.issue.VersionWrapper

issue.getFixVersions().each { version -> 

   def versionWrapper = new VersionWrapper(version)
    log.debug "Version expected  ${versionWrapper.getEndDate()}" 

}

I get:

Problem loading class: startup failed: /jira-plugins/ProductComponentSync.groovy: 17: unable to resolve class com.atlassian.greenhopper.model.issue.VersionWrapper @ line 17, column 1. import com.atlassian.greenhopper.model.issue.VersionWrapper ^ 1 error

The Reference link: http://docs.atlassian.com/greenhopper/6.0.7/com/atlassian/greenhopper/model/issue/VersionWrapper.html

3 answers

1 accepted

1 vote
Answer accepted
Alexey Paveliev
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.
December 10, 2012

Here is the correct link to code which solved my problem in custom event listener in Groovy Script Runner:

How to get Greenhopper Start and End date for Version object

Class greenHopperClass = pluginAccessor.getClassLoader().findClass("com.pyxis.greenhopper.GreenHopper");
def greenHopper = componentManager.getOSGiComponentInstanceOfType(greenHopperClass);

def ghProjectConfig = greenHopper.getConfiguration(event.getProject())
def endDate = ghProjectConfig.getVersionEndDate(version);
def startDate = ghProjectConfig.getVersionStartDate(version);

2 votes
sclowes
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.
December 10, 2012

As Jamie (the author of the Script Runner plugin, thanks Jamie :)) has commented, it's not particularly easy to do this, but you can do it.

Check out this other answers post with some sample Groovy code for getting the class from the plugin classloader, you can then instaniate the class.

Thanks,
Shaun

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.
December 10, 2012

The link didn't work for some reason, it is https://answers.atlassian.com/questions/73449/using-the-greenhopper-api-to-modify-rank?page=1#73622

Great answer though....

Alexey Paveliev
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.
December 10, 2012
Great tip!
 
I need to invoke class constructor though.
Here is the code snippet:
Class versionWrapperClass = pluginAccessor.getClassLoader().findClass("com.atlassian.greenhopper.model.issue.VersionWrapper")
def versionWrapperConstructor = versionWrapperClass.getConstructor(Version.class)
 
def versionWrapper = versionWrapperConstructor.newInstance(version)

For some reason versionWrapper.getEndDate() returns NULL :(
Alexey Paveliev
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.
December 10, 2012

I am not GH API savvy. I might be using wrong approach to getting GH extension to Version object.

Here is another attempt. Still no luck though.

Class versionWrapperClass = pluginAccessor.getClassLoader().findClass("com.atlassian.greenhopper.model.issue.VersionWrapper")
	def versionWrapper = componentManager.getOSGiComponentInstanceOfType(versionWrapperClass);
	Class GHVersionServiceClass = pluginAccessor.getClassLoader().findClass("com.atlassian.greenhopper.service.issue.GHVersionService")
	def GHversionService = componentManager.getOSGiComponentInstanceOfType(GHVersionServiceClass);

Last line returns null.

versionWrapper = GHversionService?.loadGHVersion(version.getId()) 
//fails

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.
December 10, 2012

fails in what way? is GHversionService null?

GHversionService is not a component in the plugin.xml, so not sure if you can do getOSGiComponentInstanceOfType on it.

Alexey Paveliev
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.
December 10, 2012

GHversionService is null despite getOSGiComponentInstanceOfType.

I can add a debug log after pluginAccessor.getClassLoader().findClass("com.atlassian.greenhopper.service.issue.GHVersionService")

to see if it was found

Alexey Paveliev
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.
December 10, 2012

this code results in [LoggerService] Could not get instance of GHversionService

Class GHVersionServiceClass = pluginAccessor.getClassLoader().findClass("com.atlassian.greenhopper.service.issue.GHVersionService")
	 if (!GHVersionServiceClass) log.debug "GHVersionServiceClass not found"
	 def GHversionService = componentManager.getOSGiComponentInstanceOfType(GHVersionServiceClass);
	 if (!GHversionService) log.debug "Could not get instance of GHversionService"

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.
December 9, 2012

There is no straightforward way. You might be better off writing a new plugin and using component-import and bundle-instructions etc etc. The plugins 2 framework doesn't really allow for the possibility of optionally importing stuff to the classpath at runtime, at least I haven't found a good way to do it.

I recently enhanced the "copy project" function to clone the GH version hierarchy, scrum template, and other GH stuff, and elected to do it through http calls rather than the API. Seems to work fine although if you can use the public API that would be better.

The other way that should work is to modify atlassian-plugin.xml and add the imports you need to the bundle-instructions section, but this is not ideal as it would get overwritten when I update it.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events