diff --git a/grails-forge-core/src/main/java/org/grails/forge/feature/grails/templates/plugin.rocker.raw b/grails-forge-core/src/main/java/org/grails/forge/feature/grails/templates/plugin.rocker.raw new file mode 100644 index 00000000..9032f2fe --- /dev/null +++ b/grails-forge-core/src/main/java/org/grails/forge/feature/grails/templates/plugin.rocker.raw @@ -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 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 event) { + // TODO Implement code that is executed when the project configuration changes. + // The event is the same as for 'onChange'. + } + + void onShutdown(Map event) { + // TODO Implement code that is executed when the application shuts down (optional) + } +} \ No newline at end of file diff --git a/grails-forge-core/src/main/java/org/grails/forge/feature/grails/templates/urlMappings.rocker.raw b/grails-forge-core/src/main/java/org/grails/forge/feature/grails/templates/urlMappings.rocker.raw index d1eeb0d1..dc0903bc 100644 --- a/grails-forge-core/src/main/java/org/grails/forge/feature/grails/templates/urlMappings.rocker.raw +++ b/grails-forge-core/src/main/java/org/grails/forge/feature/grails/templates/urlMappings.rocker.raw @@ -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') diff --git a/grails-forge-core/src/main/java/org/grails/forge/feature/lang/groovy/GrailsApplication.java b/grails-forge-core/src/main/java/org/grails/forge/feature/lang/groovy/GrailsApplication.java index 0fc24440..fefefa46 100644 --- a/grails-forge-core/src/main/java/org/grails/forge/feature/lang/groovy/GrailsApplication.java +++ b/grails-forge-core/src/main/java/org/grails/forge/feature/lang/groovy/GrailsApplication.java @@ -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; @@ -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) { diff --git a/grails-forge-core/src/test/groovy/org/grails/forge/feature/lang/GrailsApplicationSpec.groovy b/grails-forge-core/src/test/groovy/org/grails/forge/feature/lang/GrailsApplicationSpec.groovy index 86b272c9..08a4cab3 100644 --- a/grails-forge-core/src/test/groovy/org/grails/forge/feature/lang/GrailsApplicationSpec.groovy +++ b/grails-forge-core/src/test/groovy/org/grails/forge/feature/lang/GrailsApplicationSpec.groovy @@ -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))