Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i list all the controllers/services of a grails plugin

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.

like image 736
dcdrns Avatar asked Dec 16 '22 21:12

dcdrns


2 Answers

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"
      }
   }
}
like image 130
Burt Beckwith Avatar answered Mar 23 '23 04:03

Burt Beckwith


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.

like image 35
Gregg Avatar answered Mar 23 '23 04:03

Gregg