Hello.
Scripting for jira is my first major programming experience, so if this discussion is too amateurish - please bear with me.
The situation is the following - whenever I write a script with several functions in it and with a need to access let's say customFieldManager in some of them, I have to define this customFieldManager in every function:
def customFieldManager = ComponentAccessor.customFieldManager
It's not that big of a problem, but I feel like there's a better way.
So far I've found three (second while writing this):
1. dummy Constants class:
import static Constants.*
class Constants {
static final MYCONSTANT = "foobar"
}
does what it is - creates a dummy class where you can put your global scoped variables
2. @Field annotation:
import groovy.transform.Field
@Field List awe = [1, 2, 3]
def awesum() { awe.sum() }
assert awesum() == 6
does pretty much the same as method one, just more elegantly I think
3. Own helper class:
much like method one, writing a dummy class, but making it in a separate file with the help of Scriptrunner's Script Roots functionality:
package util.managers
import com.atlassian.jira.component.ComponentAccessor
class managers {
static final customFieldManager = ComponentAccessor.customFieldManager
//all the other components I use frequently
}
so I can access customFieldManager in any of my scripts by just importing this class:
import static util.managers.*
customFieldManager.getCustomFieldObject(12345)
So, the question is, am I inventing a bicycle here, and do you have any tricks or hint to making your script better?
Thanks.