Skip to content

Commit

Permalink
Merge branch '5.1.x' into matrei/update-build
Browse files Browse the repository at this point in the history
  • Loading branch information
matrei authored Oct 11, 2024
2 parents 8c56f98 + d898904 commit ac150f9
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jobs:
- name: "☕️ Setup JDK"
uses: actions/setup-java@v4
with:
distribution: temurin
distribution: liberica
java-version: 11
- name: "🐘 Setup Gradle"
uses: gradle/actions/setup-gradle@v4
- name: "🔨 Run Build"
env:
DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
run: ./gradlew build
run: ./gradlew build -Dgeb.env=chromeHeadless
- name: "📤 Publish Snapshot to repo.grails.org"
if: success() && github.event_name == 'push'
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: "☕️ Setup JDK"
uses: actions/setup-java@v4
with:
distribution: temurin
distribution: liberica
java-version: 11
- name: "🐘 Setup Gradle"
uses: gradle/actions/setup-gradle@v4
Expand Down
1 change: 1 addition & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java=11.0.24-librca
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ dependencyManagement {
}

dependencies {
api 'org.grails:grails-dependencies'
api 'org.grails:grails-web-boot'

api "io.github.gpc:fields:$fieldsVersion"

console 'org.grails:grails-console'
compileOnly "org.codehaus.groovy:groovy"
compileOnly "org.grails:grails-plugin-rest"
api "org.grails.plugins:fields:$fieldsVersion"
}

grailsPublish {
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
projectVersion=5.1.1-SNAPSHOT
grailsVersion=6.1.1
fieldsVersion=5.0.3
projectVersion=5.1.3-SNAPSHOT
grailsVersion=6.2.0
fieldsVersion=5.1.0
groovyVersion=3.0.22

org.gradle.caching=true
org.gradle.daemon=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package grails.plugin.scaffolding

import grails.plugins.*
import org.grails.web.servlet.view.GroovyPageViewResolver
import grails.util.Environment
import grails.util.Metadata

class ScaffoldingGrailsPlugin extends Plugin {

Expand Down Expand Up @@ -38,10 +39,14 @@ Plugin that generates scaffolded controllers and views for a Grails application.

@Override
Closure doWithSpring() { {->
Environment env = Environment.current
boolean reloadEnabled = env.isReloadEnabled() || (Metadata.getCurrent().isDevelopmentEnvironmentAvailable() && env == Environment.DEVELOPMENT)

// Configure a Spring MVC view resolver
jspViewResolver(ScaffoldingViewResolver) { bean ->
bean.lazyInit = true
bean.parent = "abstractViewResolver"
enableReload = reloadEnabled
}
}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource

ResourceLoader resourceLoader
protected Map<String, View> generatedViewCache = new ConcurrentHashMap<>()
protected boolean enableReload = false
void setEnableReload(boolean enableReload) {
this.enableReload = enableReload
}

protected String buildCacheKey(String viewName) {
String viewCacheKey = groovyPageLocator.resolveViewFormat(viewName)
Expand Down Expand Up @@ -100,7 +104,7 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource
def view = super.loadView(viewName, locale)
if (view == null) {
String cacheKey = buildCacheKey(viewName)
view = generatedViewCache.get(cacheKey)
view = enableReload? null : generatedViewCache.get(cacheKey)
if (view != null) {
return view
} else {
Expand Down Expand Up @@ -130,7 +134,7 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource
def contents = new FastStringWriter()
t.make(model.asMap()).writeTo(contents)

def template = templateEngine.createTemplate(new ByteArrayResource(contents.toString().getBytes(templateEngine.gspEncoding), "view:$cacheKey"))
def template = templateEngine.createTemplate(new ByteArrayResource(contents.toString().getBytes(templateEngine.gspEncoding), "view:$cacheKey"), !enableReload)
view = new GroovyPageView()
view.setServletContext(getServletContext())
view.setTemplate(template)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ScaffoldingControllerInjector implements GrailsArtefactClassInjector {
}
}
classNode.setSuperClass(GrailsASTUtils.nonGeneric(superClassNode, domainClass))
def readOnlyExpression = (ConstantExpression) annotationNode.getMember("readOnly")
def readOnlyExpression = (ConstantExpression) annotationNode?.getMember("readOnly")
new ResourceTransform().addConstructor(classNode, domainClass, readOnlyExpression?.getValue()?.asBoolean()?:false)
} else if (!currentSuperClass.isDerivedFrom(superClassNode)) {
GrailsASTUtils.error(source, classNode, "Scaffolded controllers (${classNode.name}) cannot extend other classes: ${currentSuperClass.getName()}", true)
Expand Down
16 changes: 16 additions & 0 deletions src/main/scripts/CreateScaffoldController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
description("Creates a scaffolded controller") {
usage 'create-controller [controller name]'
completer org.grails.cli.interactive.completers.DomainClassCompleter
argument name:'Controller Name', description:"The name of controller", required:true
flag name:'force', description:"Whether to overwrite existing files"
}

def model = model(args[0])
def overwrite = flag('force') ? true : false

render template: template('scaffolding/ScaffoldedController.groovy'),
destination: file("grails-app/controllers/${model.packagePath}/${model.convention("Controller")}.groovy"),
model: model,
overwrite: overwrite

return true
15 changes: 15 additions & 0 deletions src/main/scripts/GenerateAll.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import org.grails.cli.interactive.completers.DomainClassCompleter

description("Generates a controller that performs CRUD operations and the associated views") {
usage "grails generate-all [DOMAIN CLASS]"
argument name: 'Domain Class', description: "The name of the domain class", required: true
completer DomainClassCompleter
flag name: 'force', description: "Whether to overwrite existing files"
}

if (args) {
generateController(*args)
generateViews(*args)
} else {
error "No domain class specified"
}
41 changes: 41 additions & 0 deletions src/main/scripts/GenerateAsyncController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.grails.cli.interactive.completers.DomainClassCompleter

description( "Generates an asynchronous controller that performs CRUD operations" ) {
usage "grails generate-async-controller [DOMAIN CLASS]"
completer DomainClassCompleter
flag name:'force', description:"Whether to overwrite existing files"
}


if(args) {
def classNames = args
if(args[0] == '*') {
classNames = resources("file:grails-app/domain/**/*.groovy")
.collect { className(it) }
}
for(arg in classNames) {
def sourceClass = source(arg)
def overwrite = flag('force') ? true : false
if(sourceClass) {
def model = model(sourceClass)
render template: template('scaffolding/AsyncController.groovy'),
destination: file("grails-app/controllers/${model.packagePath}/${model.convention('Controller')}.groovy"),
model: model,
overwrite: overwrite

render template: template('scaffolding/AsyncSpec.groovy'),
destination: file("src/test/groovy/${model.packagePath}/${model.convention('ControllerSpec')}.groovy"),
model: model,
overwrite: overwrite


addStatus "Scaffolding completed for ${projectPath(sourceClass)}"
}
else {
error "Domain class not found for name $arg"
}
}
}
else {
error "No domain class specified"
}
51 changes: 51 additions & 0 deletions src/main/scripts/GenerateController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import org.grails.cli.interactive.completers.DomainClassCompleter

description( "Generates a controller that performs CRUD operations" ) {
usage "grails generate-controller [DOMAIN CLASS]"
completer DomainClassCompleter
flag name:'force', description:"Whether to overwrite existing files"
}


if(args) {
def classNames = args
if(args[0] == '*') {
classNames = resources("file:grails-app/domain/**/*.groovy")
.collect { className(it) }
}
for(arg in classNames) {
def sourceClass = source(arg)
def overwrite = flag('force') ? true : false
if(sourceClass) {
def model = model(sourceClass)
render template: template('scaffolding/Controller.groovy'),
destination: file("grails-app/controllers/${model.packagePath}/${model.convention('Controller')}.groovy"),
model: model,
overwrite: overwrite

render template: template('scaffolding/Service.groovy'),
destination: file("grails-app/services/${model.packagePath}/${model.convention('Service')}.groovy"),
model: model,
overwrite: overwrite

render template: template('scaffolding/Spec.groovy'),
destination: file("src/test/groovy/${model.packagePath}/${model.convention('ControllerSpec')}.groovy"),
model: model,
overwrite: overwrite

render template: template('scaffolding/ServiceSpec.groovy'),
destination: file("src/integration-test/groovy/${model.packagePath}/${model.convention('ServiceSpec')}.groovy"),
model: model,
overwrite: overwrite


addStatus "Scaffolding completed for ${projectPath(sourceClass)}"
}
else {
error "Domain class not found for name $arg"
}
}
}
else {
error "No domain class specified"
}
45 changes: 45 additions & 0 deletions src/main/scripts/GenerateViews.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.grails.cli.interactive.completers.DomainClassCompleter

description( "Generates GSP views for the specified domain class" ) {
usage "grails generate-views [DOMAIN CLASS]|*"
argument name:'Domain Class', description:"The name of the domain class, or '*' for all", required:true
completer DomainClassCompleter
flag name:'force', description:"Whether to overwrite existing files"
}

if(args) {
def classNames = args
if(args[0] == '*') {
classNames = resources("file:grails-app/domain/**/*.groovy").collect { className(it) }
}
def viewNames = resources("file:src/main/templates/scaffolding/*.gsp")
.collect {
it.filename
}
if(!viewNames) {
viewNames = resources("classpath*:META-INF/templates/scaffolding/*.gsp")
.collect {
it.filename
}
}

for(arg in classNames) {
def sourceClass = source(arg)
def overwrite = flag('force') ? true : false
if(sourceClass) {
def model = model(sourceClass)
viewNames.each {
render template: template('scaffolding/'+it),
destination: file("grails-app/views/${model.propertyName}/"+it),
model: model,
overwrite: overwrite
}

addStatus "Views generated for ${projectPath(sourceClass)}"
} else {
error "Domain class not found for name $arg"
}
}
} else {
error "No domain class specified"
}
29 changes: 29 additions & 0 deletions src/main/scripts/InstallTemplates.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2012 Rob Fletcher
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

description "Installs scaffolding templates that use f:all to render properties", "grails install-templates"

updateStatus "Copying scaffolding templates"
mkdir "src/main/templates/scaffolding"
copy {
from templates("scaffolding/*.gsp")
into "src/main/templates/scaffolding"
}
copy {
from templates("scaffolding/*.groovy")
into "src/main/templates/scaffolding"
}
addStatus "Template installation complete"

0 comments on commit ac150f9

Please sign in to comment.