How do I list all the controllers/services of a grails plugin. Or How do I know the pluin name of a given GrailsApplication class.
Artifacts from plugins are annotated with the GrailsPlugin
annotation to add metadata about their source. So you can use that to find whether the controller/service/etc. is from the application or a plugin like this:
import org.codehaus.groovy.grails.plugins.metadata.GrailsPlugin
for (type in ['controller', 'service']) {
for (artifactClass in ctx.grailsApplication."${type}Classes") {
def clazz = artifactClass.clazz
def annotation = clazz.getAnnotation(GrailsPlugin)
if (annotation) {
println "$type $clazz.name from plugin '${annotation.name()}'"
}
else {
println "$type $clazz.name from application"
}
}
}
In a newly created Grails application, the grails-app/views/index.gsp has the following:
<g:each var="c" in="${grailsApplication.controllerClasses.sort { it.fullName } }">
<li class="controller"><g:link controller="${c.logicalPropertyName}">${c.fullName}</g:link></li>
</g:each>
You can get services in a similar fashion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With