1 | /* Copyright 2006-2009 the original author or authors. |
---|
2 | * |
---|
3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | * you may not use this file except in compliance with the License. |
---|
5 | * You may obtain a copy of the License at |
---|
6 | * |
---|
7 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | * |
---|
9 | * Unless required by applicable law or agreed to in writing, software |
---|
10 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | * See the License for the specific language governing permissions and |
---|
13 | * limitations under the License. |
---|
14 | */ |
---|
15 | |
---|
16 | /** |
---|
17 | * Generates view files and controller files for Spring Security user management. |
---|
18 | * @author Tsuyoshi Yamamoto |
---|
19 | * @author Haotian Sun |
---|
20 | * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a> |
---|
21 | */ |
---|
22 | |
---|
23 | includeTargets << new File("$acegiPluginDir/scripts/_SecurityTargets.groovy") |
---|
24 | |
---|
25 | pluginTemplatePath = "$templateDir/manager" |
---|
26 | |
---|
27 | target('default': 'Generates view and controller for Spring Security user management') { |
---|
28 | loadConfig() |
---|
29 | |
---|
30 | generateControllerAndViews personClassName, 'User' |
---|
31 | generateControllerAndViews authorityClassName, 'Role' |
---|
32 | generateControllerAndViews requestmapClassName, 'Requestmap' |
---|
33 | } |
---|
34 | |
---|
35 | private void generateControllerAndViews(String name, String templateName) { |
---|
36 | |
---|
37 | String path = "$basedir/grails-app/controllers/${name}Controller.groovy" |
---|
38 | def outFile = new File(path) |
---|
39 | if (outFile.exists()) { |
---|
40 | Ant.input addProperty: 'overwrite', message: "$outFile.name exists - overwrite? y/n" |
---|
41 | if ('y' == Ant.antProject.properties.'overwrite') { |
---|
42 | overwrite = true |
---|
43 | } |
---|
44 | } |
---|
45 | else { |
---|
46 | overwrite = true |
---|
47 | } |
---|
48 | |
---|
49 | println "generating files for $name ......." |
---|
50 | |
---|
51 | println "generating file $path" |
---|
52 | generateFile "$pluginTemplatePath/controllers/_${templateName}Controller.groovy", path |
---|
53 | |
---|
54 | path = "$basedir/grails-app/views/${org.apache.commons.lang.WordUtils.uncapitalize(name)}" |
---|
55 | String viewPath = "$pluginTemplatePath/views/${templateName.toLowerCase()}" |
---|
56 | println "generating view files - $path/* " |
---|
57 | Ant.mkdir dir: path |
---|
58 | generateFile "$viewPath/list.gsp", "$path/list.gsp" |
---|
59 | generateFile "$viewPath/edit.gsp", "$path/edit.gsp" |
---|
60 | generateFile "$viewPath/create.gsp", "$path/create.gsp" |
---|
61 | generateFile "$viewPath/show.gsp", "$path/show.gsp" |
---|
62 | } |
---|