Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 94 lines (79 sloc) 3.238 kb
7995c9f @graemerocher ignoring test temporarily, as due to infrastructure issues it is not …
graemerocher authored
1 /*
2 * Copyright 2004-2005 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 import org.codehaus.groovy.grails.scaffolding.*
18 import grails.util.GrailsNameUtils
19
20 /**
21 * Gant script that generates a CRUD controller and matching views for a given domain class
22 *
23 * @author Graeme Rocher
24 *
25 * @since 0.4
26 */
27
28 includeTargets << grailsScript("_GrailsBootstrap")
29
30 generateForName = null
31 generateViews = true
32 generateController = true
33
34 target(generateForOne: "Generates controllers and views for only one domain class.") {
35 depends(loadApp)
36
37 def name = generateForName
38 name = name.indexOf('.') > 0 ? name : GrailsNameUtils.getClassNameRepresentation(name)
39 def domainClass = grailsApp.getDomainClass(name)
40
41 if (!domainClass) {
42 grailsConsole.updateStatus "Domain class not found in grails-app/domain, trying hibernate mapped classes..."
43 bootstrap()
44 domainClass = grailsApp.getDomainClass(name)
45 }
46
47 if (domainClass) {
48 generateForDomainClass(domainClass)
49 event("StatusFinal", ["Finished generation for domain class ${domainClass.fullName}"])
50 }
51 else {
52 event("StatusFinal", ["No domain class found for name ${name}. Please try again and enter a valid domain class name"])
53 exit(1)
54 }
55 }
56
57 target(uberGenerate: "Generates controllers and views for all domain classes.") {
58 depends(loadApp)
59
60 def domainClasses = grailsApp.domainClasses
61
62 if (!domainClasses) {
63 println "No domain classes found in grails-app/domain, trying hibernate mapped classes..."
64 bootstrap()
65 domainClasses = grailsApp.domainClasses
66 }
67
68 if (domainClasses) {
69 domainClasses.each { domainClass -> generateForDomainClass(domainClass) }
70 event("StatusFinal", ["Finished generation for domain classes"])
71 }
72 else {
73 event("StatusFinal", ["No domain classes found"])
74 }
75 }
76
77 def generateForDomainClass(domainClass) {
78 def templateGenerator = new DefaultGrailsTemplateGenerator(classLoader)
79 templateGenerator.grailsApplication = grailsApp
80 templateGenerator.pluginManager = pluginManager
81 if (generateViews) {
82 event("StatusUpdate", ["Generating views for domain class ${domainClass.fullName}"])
83 templateGenerator.generateViews(domainClass, basedir)
84 event("GenerateViewsEnd", [domainClass.fullName])
85 }
86
87 if (generateController) {
88 event("StatusUpdate", ["Generating controller for domain class ${domainClass.fullName}"])
89 templateGenerator.generateController(domainClass, basedir)
90 templateGenerator.generateTest(domainClass, "${basedir}/test/unit")
91 event("GenerateControllerEnd", [domainClass.fullName])
92 }
93 }
Something went wrong with that request. Please try again.