From bea47bf964087974c48e134584cf22c1fe589ea2 Mon Sep 17 00:00:00 2001 From: sdelamo Date: Wed, 27 Sep 2017 15:46:41 +0200 Subject: [PATCH] Fix s2ui-override --- .gitignore | 1 + plugin/build.gradle | 46 +++++++- plugin/src/main/scripts/s2ui-override.groovy | 112 ++++++++++++++----- 3 files changed, 133 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index b13a0d3f..30149a0e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ build classes cobertura.ser kindlegen +/plugin/src/main/templates/views diff --git a/plugin/build.gradle b/plugin/build.gradle index 30007a46..69fdae8b 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -59,4 +59,48 @@ apply from: "${rootProject.projectDir}/gradle/artifactoryPublish.gradle" assets { packagePlugin = true -} \ No newline at end of file +} + + +task copyGspIntoTemplates { + ext.inputFolders = ['aclClass', + 'aclEntry', + 'aclObjectIdentity', + 'aclSid', + 'includes', + 'layouts', + 'login', + 'persistentLogin', + 'register', + 'registrationCode', + 'requestmap', + 'role', + 'securityInfo', + 'user'] + doLast { + mkdir "${project.projectDir}/src/main/templates/views" + for ( String folder : inputFolders ) { + mkdir "${project.projectDir}/src/main/templates/views/${folder}" + } + for ( int i = 0; i < inputFolders.size(); i++ ) { + copy { + from(fileTree("${project.projectDir}/grails-app/views/${inputFolders[i]}")) { + include '*.gsp' + } + into "${project.projectDir}/src/main/templates/views/${inputFolders[i]}" + } + } + } +} + +task removeGspFromTemplates { + doLast { + for ( String folder : copyGspIntoTemplates.inputFolders ) { + delete "${project.projectDir}/src/main/templates/views/${folder}" + } + delete "${project.projectDir}/src/main/templates/views" + } + +} + +compileAstJava.dependsOn copyGspIntoTemplates \ No newline at end of file diff --git a/plugin/src/main/scripts/s2ui-override.groovy b/plugin/src/main/scripts/s2ui-override.groovy index 154cf384..627d76da 100644 --- a/plugin/src/main/scripts/s2ui-override.groovy +++ b/plugin/src/main/scripts/s2ui-override.groovy @@ -42,29 +42,26 @@ File viewsDir = new File(grailsApp, 'views') File layoutsDir = new File(viewsDir, 'layouts') def controllers = [aclclass: 'AclClass', - aclentry: 'AclEntry', - aclobjectidentity: 'AclObjectIdentity', - aclsid: 'AclSid', - persistentlogin: 'PersistentLogin', - register: 'Register', - registrationcode: 'RegistrationCode', - requestmap: 'Requestmap', - role: 'Role', - securityinfo: 'SecurityInfo', - user: 'User'] + aclentry: 'AclEntry', + aclobjectidentity: 'AclObjectIdentity', + aclsid: 'AclSid', + persistentlogin: 'PersistentLogin', + register: 'Register', + registrationcode: 'RegistrationCode', + requestmap: 'Requestmap', + role: 'Role', + securityinfo: 'SecurityInfo', + user: 'User'] if (!controllerPackage) { if ('layout' == type) { - // special case for springSecurityUI.gsp - copy 'layouts/springSecurityUI.gsp', layoutsDir - - copy 'includes/_ajaxLogin.gsp', new File(viewsDir, 'includes') + copy template('views/layouts/springSecurityUI.gsp'), file('grails-app/views/layouts/') + copy template('views/includes/_ajaxLogin.gsp'), new File(viewsDir, 'includes') return } if ('auth' == type) { - // special case for auth.gsp - copy 'login/auth.gsp', new File(viewsDir, 'login') + copy template('views/login/auth.gsp'), new File(viewsDir, 'login') return } } @@ -93,21 +90,86 @@ File destinationDirectory = new File(controllersDir, directoryName) destinationDirectory.mkdirs() render template(controller + 'Controller.groovy.template'), - new File(destinationDirectory, controller + 'Controller.groovy'), - [packageDeclaration: "package $controllerPackage"], false + new File(destinationDirectory, controller + 'Controller.groovy'), + [packageDeclaration: "package $controllerPackage"], false // copy the GSPs directoryName = GrailsNameUtils.getPropertyName(controller) File gspDirectory = new File(viewsDir, directoryName) - for (resource in resources(directoryName + '/*.gsp')) { copy resource, gspDirectory } +switch ( directoryName ) { + case 'aclClass': + copy template('views/aclClass/create.gsp'), new File(viewsDir, 'aclClass') + copy template('views/aclClass/edit.gsp'), new File(viewsDir, 'aclClass') + copy template('views/aclClass/search.gsp'), new File(viewsDir, 'aclClass') + break + case 'aclEntry': + copy template('views/aclEntry/create.gsp'), new File(viewsDir, 'aclEntry') + copy template('views/aclEntry/edit.gsp'), new File(viewsDir, 'aclEntry') + copy template('views/aclEntry/search.gsp'), new File(viewsDir, 'aclEntry') + break + case 'aclObjectIdentity': + copy template('views/aclObjectIdentity/create.gsp'), new File(viewsDir, 'aclObjectIdentity') + copy template('views/aclObjectIdentity/edit.gsp'), new File(viewsDir, 'aclObjectIdentity') + copy template('views/aclObjectIdentity/search.gsp'), new File(viewsDir, 'aclObjectIdentity') + break + case 'aclSid': + copy template('views/aclSid/create.gsp'), new File(viewsDir, 'aclSid') + copy template('views/aclSid/edit.gsp'), new File(viewsDir, 'aclSid') + copy template('views/aclSid/search.gsp'), new File(viewsDir, 'aclSid') + break + case 'persistentLogin': + copy template('views/persistentLogin/search.gsp'), new File(viewsDir, 'persistentLogin') + copy template('views/persistentLogin/edit.gsp'), new File(viewsDir, 'persistentLogin') + break + case 'register': + copy template('views/register/forgotPassword.gsp'), new File(viewsDir, 'register') + copy template('views/register/register.gsp'), new File(viewsDir, 'register') + copy template('views/register/resetPassword.gsp'), new File(viewsDir, 'register') + break + case 'registrationCode': + copy template('views/registrationCode/search.gsp'), new File(viewsDir, 'registrationCode') + copy template('views/registrationCode/edit.gsp'), new File(viewsDir, 'registrationCode') + break + case 'requestmap': + copy template('views/requestmap/create.gsp'), new File(viewsDir, 'requestmap') + copy template('views/requestmap/edit.gsp'), new File(viewsDir, 'requestmap') + copy template('views/requestmap/search.gsp'), new File(viewsDir, 'requestmap') + break + case 'role': + copy template('views/role/create.gsp'), new File(viewsDir, 'role') + copy template('views/role/edit.gsp'), new File(viewsDir, 'role') + copy template('views/role/search.gsp'), new File(viewsDir, 'role') + break + case 'securityInfo': + copy template('views/securityInfo/config.gsp'), new File(viewsDir, 'securityInfo') + copy template('views/securityInfo/currentAuth.gsp'), new File(viewsDir, 'securityInfo') + copy template('views/securityInfo/filterChains.gsp'), new File(viewsDir, 'securityInfo') + copy template('views/securityInfo/logoutHandlers.gsp'), new File(viewsDir, 'securityInfo') + copy template('views/securityInfo/mappings.gsp'), new File(viewsDir, 'securityInfo') + copy template('views/securityInfo/providers.gsp'), new File(viewsDir, 'securityInfo') + copy template('views/securityInfo/secureChannel.gsp'), new File(viewsDir, 'securityInfo') + copy template('views/securityInfo/usercache.gsp'), new File(viewsDir, 'securityInfo') + copy template('views/securityInfo/voters.gsp'), new File(viewsDir, 'securityInfo') + break + case 'user': + copy template('views/user/create.gsp'), new File(viewsDir, 'user') + copy template('views/user/edit.gsp'), new File(viewsDir, 'user') + copy template('views/user/search.gsp'), new File(viewsDir, 'user') + break +} + if ('register' == type) { - layoutsDir.mkdirs() - render template('register.gsp.template'), - new File(layoutsDir, 'register.gsp'), - [:], - false -} \ No newline at end of file + copy template('views/layouts/register.gsp'), file('grails-app/views/layouts/') +} + +private void copy(pathOrResource, File destinationDirectory) { + if ( !destinationDirectory.exists() ) { + destinationDirectory.mkdirs() + } + + copy resource(pathOrResource), destinationDirectory +}