Skip to content

Commit

Permalink
Merge pull request #182 from grails/plugin-descriptor
Browse files Browse the repository at this point in the history
Add Plugin Descriptor
  • Loading branch information
puneetbehl authored Jul 24, 2023
2 parents f979688 + 21dd3fa commit b7f5766
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@import org.grails.forge.application.Project
@import org.grails.forge.application.ApplicationType
@import org.grails.forge.util.VersionInfo

@args(Project project, ApplicationType applicationType)

@grailsVersion => { @VersionInfo.getGrailsVersion() }

package @project.getPackageName()

import grails.plugins.*

class @project.getClassName()GrailsPlugin extends Plugin {

// the version or versions of Grails the plugin is designed for
def grailsVersion = "@grailsVersion > *"
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp"
]

// TODO Fill in these fields
def title = "@project.getNaturalName()" // Headline display name of the plugin
def author = "Your name"
def authorEmail = ""
def description = '''\
Brief summary/description of the plugin.
'''
@if(applicationType == ApplicationType.WEB_PLUGIN) {
def profiles = ['web']
}

// URL to the plugin's documentation
def documentation = "https://grails.github.io/@project.getClassName()/"

// Extra (optional) plugin metadata

// License: one of 'APACHE', 'GPL2', 'GPL3'
// def license = "APACHE"

// Details of company behind the plugin (if there is one)
// def organization = [ name: "My Company", url: "https://www.my-company.com/" ]

// Any additional developers beyond the author specified above.
// def developers = [ [ name: "Joe Bloggs", email: "joe@@bloggs.net" ]]

// Location of the plugin's issue tracker.
// def issueManagement = [ system: "GitHub", url: "https://github.com/grails/@project.getClassName()/issues" ]

// Online location of the plugin's browseable source code.
// def scm = [ url: "https://github.com/grails/@project.getClassName()" ]

Closure doWithSpring() { {->
// TODO Implement runtime spring config (optional)
}
}

void doWithDynamicMethods() {
// TODO Implement registering dynamic methods to classes (optional)
}

void doWithApplicationContext() {
// TODO Implement post initialization spring config (optional)
}

void onChange(Map<String, Object> event) {
// TODO Implement code that is executed when any artefact that this plugin is
// watching is modified and reloaded. The event contains: event.source,
// event.application, event.manager, event.ctx, and event.plugin.
}

void onConfigChange(Map<String, Object> event) {
// TODO Implement code that is executed when the project configuration changes.
// The event is the same as for 'onChange'.
}

void onShutdown(Map<String, Object> event) {
// TODO Implement code that is executed when the application shuts down (optional)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class UrlMappings {
post "/$controller(.$format)?"(action:"save")
put "/$controller/$id(.$format)?"(action:"update")
patch "/$controller/$id(.$format)?"(action:"patch")
"/"(controller: 'application', action:'index')
}
"500"(view:'/error')
"404"(view:'/notFound')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.grails.forge.build.gradle.GradlePlugin;
import org.grails.forge.feature.DefaultFeature;
import org.grails.forge.feature.Feature;
import org.grails.forge.feature.grails.templates.plugin;
import org.grails.forge.options.Options;
import org.grails.forge.template.RockerTemplate;

Expand Down Expand Up @@ -56,6 +57,10 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addTemplate("application", new RockerTemplate(getPath(),
application.template(applicationType, generatorContext.getProject(), generatorContext.getFeatures())));
}
if (applicationType == ApplicationType.PLUGIN || applicationType == ApplicationType.WEB_PLUGIN) {
generatorContext.addTemplate("plugin", new RockerTemplate(generatorContext.getSourcePath("/{packagePath}/{className}GrailsPlugin"),
plugin.template(generatorContext.getProject(), applicationType)));
}
}

protected boolean shouldGenerateApplicationFile(ApplicationType applicationType, GeneratorContext generatorContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ class GrailsApplicationSpec extends BeanContextSpec implements CommandOutputFixt
applicationType << [ApplicationType.PLUGIN, ApplicationType.WEB_PLUGIN]
}

void "PluginDescriptor is generated for #applicationType application type"() {
when:
def output = generate(applicationType)

then:
output.containsKey('src/main/groovy/example/grails/FooGrailsPlugin.groovy')
def pluginGroovy = output.get("src/main/groovy/example/grails/FooGrailsPlugin.groovy")

where:
applicationType << [ApplicationType.PLUGIN, ApplicationType.WEB_PLUGIN]
}

void "PluginDescriptor is NOT generated for #applicationType application type"() {
when:
def output = generate(applicationType)

then:
!output.containsKey('src/main/groovy/example/grails/FooGrailsPlugin.groovy')

where:
applicationType << [ApplicationType.WEB, ApplicationType.REST_API]
}

void "test build plugins"() {
given:
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11))
Expand Down

0 comments on commit b7f5766

Please sign in to comment.