Access sub-project application properties in grails/groovy -
i have singleton class
@singleton class customerbundlesingleton { def grailsapplication = holders.getgrailsapplication() string projname private customerbundlesingleton() { line 10: projname = // how sub-project name here ??? } }
application.properties // project running ----------------------- app.name = mynewproject application.properties // located in sub project ----------------------- app.name = mysubproject
i tried grailsapplication.metadata['app.name']
in "line 10:"
returns "mynewproject"
.whereas want way project name of userbundlesingleton located (mysubprojectname). grailsapplication.current.metadata['app.name'] ???? .
so can give me mysubprojectname
instead of mynewproject
??
i have 3 suggestions depending on requirements , 'bundling'.
1) don't have bundle marker/descriptor
assuming know sub-project(grails plugin) name, life gets easier, instead of having loop through plugins...
you can use among these lines.
// plugin name 'hibernate' in example import org.codehaus.groovy.grails.plugins.pluginmanagerholder def hibernateversion = pluginmanagerholder.pluginmanager.getgrailsplugin('hibernate').version // loop through plugins // pluginmanagerholder.pluginmanager.getallplugins()
2) using custom plugin properties lookup plugins of interest
other strategy, if must lookup bundle dynamically.
create custom marker property in each of plugin descriptors
def specialproperty = "whatever"
then inside customerbundlesingleton
pluginmanagerholder.pluginmanager.getallplugins().each { if (it.properties.specialproperty) { def subprojectname = it.name def subprojectversion = it.version } }
3) custom bundle info resolution
you may want consider metadata via meta-inf/manifest.mf or similar mechanism.
hope helps...
Comments
Post a Comment