GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / scripts / GenerateAll.groovy
blobe3ea894782c720e81898518d8031b851d96474c3
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.
17 /**
18 * Gant script that generates a CRUD controller and matching views for a given domain class
20 * @author Graeme Rocher
22 * @since 0.4
25 import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU
26 import groovy.text.SimpleTemplateEngine
27 import org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator;
28 import org.codehaus.groovy.grails.scaffolding.*
29 import org.springframework.mock.web.MockServletContext
30 import org.springframework.core.io.Resource
31 import org.codehaus.groovy.grails.commons.ApplicationHolder;
34 Ant.property(environment:"env")
35 grailsHome = Ant.antProject.properties."env.GRAILS_HOME"
37 includeTargets << new File ( "${grailsHome}/scripts/Bootstrap.groovy" )
39 generateViews = true
40 generateController = true
42 target ('default': "Generates a CRUD interface (controller + views) for a domain class") {
43 depends( checkVersion, packageApp )
44 typeName = "Domain Class"
45 promptForName()
46 generateAll()
49 target(generateAll:"The implementation target") {
51 rootLoader.addURL(classesDir.toURI().toURL())
52 loadApp()
54 def name = args.trim()
55 name = name.indexOf('.') > -1 ? name : GCU.getClassNameRepresentation(name)
56 def domainClass = grailsApp.getDomainClass(name)
58 if(!domainClass) {
59 println "Domain class not found in grails-app/domain, trying hibernate mapped classes..."
60 try {
61 def config = new GrailsRuntimeConfigurator(grailsApp, appCtx)
62 appCtx = config.configure(appCtx.servletContext)
64 catch(Exception e) {
65 println e.message
66 e.printStackTrace()
68 domainClass = grailsApp.getDomainClass(name)
71 if(domainClass) {
72 def generator = new DefaultGrailsTemplateGenerator()
73 if(generateViews) {
74 event("StatusUpdate", ["Generating views for domain class ${domainClass.fullName}"])
75 generator.generateViews(domainClass, basedir)
77 if(generateController) {
78 event("StatusUpdate", ["Generating controller for domain class ${domainClass.fullName}"])
79 generator.generateController(domainClass, basedir)
81 event("StatusFinal", ["Finished generation for domain class ${domainClass.fullName}"])
83 else {
84 event("StatusFinal", ["No domain class found for name ${name}. Please try again and enter a valid domain class name"])