Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 136 lines (111 sloc) 4.728 kB
3e17890 1.1 branch is now trunk
graeme 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 grails.util.GrailsNameUtils
18 import grails.util.Metadata
19
20 /**
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
21 * Handles the creation of Grails applications.
3e17890 1.1 branch is now trunk
graeme authored
22 *
23 * @author Graeme Rocher
24 *
25 * @since 0.4
26 */
27
28 includeTargets << grailsScript("_GrailsPlugins")
c393d4e @pledbrook Should have been in last commit.
pledbrook authored
29 includeTargets << grailsScript("_GrailsInit")
856e87c @graemerocher Restores creation of eclipse .classpath files etc.
graemerocher authored
30 includeTargets << grailsScript("IntegrateWith")
3e17890 1.1 branch is now trunk
graeme authored
31
32 grailsAppName = ""
33 projectType = "app"
34
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
35 target(createApp: "Creates a Grails application for the given name") {
7a547d7 @burtbeckwith GRAILS-2155 added new 'scriptName' binding variable so the script can…
burtbeckwith authored
36 depends(parseArguments, appName)
3e17890 1.1 branch is now trunk
graeme authored
37 initProject()
38
39 // Create a message bundle to get the user started.
40 touch(file: metadataFile)
41
7a547d7 @burtbeckwith GRAILS-2155 added new 'scriptName' binding variable so the script can…
burtbeckwith authored
42 // Set the default version number for the application
9a0040c no need to set servlet api version in application.properties since th…
Burt Beckwith authored
43 updateMetadata("app.version": grailsAppVersion ?: "0.1")
7a547d7 @burtbeckwith GRAILS-2155 added new 'scriptName' binding variable so the script can…
burtbeckwith authored
44
d4a5181 small fix for Windows to display the path with proper slashes
Burt Beckwith authored
45 event("StatusFinal", ["Created Grails Application at ${new File(basedir).canonicalPath}"])
3e17890 1.1 branch is now trunk
graeme authored
46 }
47
48 def resetBaseDirectory(String basedir) {
49 // Update the build settings and reload the build configuration.
50 grailsSettings.baseDir = new File(basedir)
51 grailsSettings.loadConfig()
52
53 // Reload the application metadata.
54 metadataFile = new File("$basedir/${Metadata.FILE}")
55 metadata = Metadata.getInstance(metadataFile)
56
57 // Reset the plugin stuff.
4d65fc1 @pledbrook When some of the methods from GrailsPluginUtils were extracted into
pledbrook authored
58 pluginSettings.clearCache()
3e17890 1.1 branch is now trunk
graeme authored
59 pluginsHome = grailsSettings.projectPluginsDir.path
60 }
61
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
62 target(createPlugin: "The implementation target") {
3e17890 1.1 branch is now trunk
graeme authored
63 depends(parseArguments, appName)
64 metadataFile = new File("${basedir}/application.properties")
65 projectType = "plugin"
66 initProject()
67
68 // Rename the plugin descriptor.
69 pluginName = GrailsNameUtils.getNameFromScript(grailsAppName)
e50a667 @sarmbruster GRAILS-5635: allowing numbers in plugin names (but not at the beginning)
sarmbruster authored
70 if (!(pluginName ==~ /[a-zA-Z][a-zA-Z0-9-]+/)) {
e3fb07d @burtbeckwith renamed 'console' binding variable to 'grailsConsole' since it confli…
burtbeckwith authored
71 grailsConsole.error "Error: Specified plugin name [$grailsAppName] is invalid. Plugin names can only contain word characters and numbers separated by hyphens."
974f908 @graemerocher fix for GRAILS-5349 "Web-app path of user defined plugins not resolve…
graemerocher authored
72 exit 1
73 }
835947f @burtbeckwith cleanup
burtbeckwith authored
74
3e17890 1.1 branch is now trunk
graeme authored
75 ant.move(
835947f @burtbeckwith cleanup
burtbeckwith authored
76 file: "${basedir}/GrailsPlugin.groovy",
77 tofile: "${basedir}/${pluginName}GrailsPlugin.groovy",
78 overwrite: true)
3e17890 1.1 branch is now trunk
graeme authored
79
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
80 // The plugin's Grails version should be based on the current minor version,
81 // not the patch level. For example, 1.3.6 should be converted to 1.3.
4fdcfca @pledbrook Improved the template Grails plugin descriptor (GrailsPlugin.groovy).…
pledbrook authored
82 def m = grailsVersion =~ /^(\d+\.\d+)(?:\.\d+)?(?:.*)/
83 def pluginGrailsVersion = m[0][1]
84
3e17890 1.1 branch is now trunk
graeme authored
85 // Insert the name of the plugin into whatever files need it.
86 ant.replace(dir:"${basedir}") {
87 include(name: "*GrailsPlugin.groovy")
88 include(name: "scripts/*")
89 replacefilter(token: "@plugin.name@", value: pluginName)
4fdcfca @pledbrook Improved the template Grails plugin descriptor (GrailsPlugin.groovy).…
pledbrook authored
90 replacefilter(token: "@plugin.title@", value: GrailsNameUtils.getNaturalName(pluginName) + " Plugin")
df771f5 @graemerocher new plugin publishing mechanism that eliminates the huge amount of ti…
graemerocher authored
91 replacefilter(token: "@plugin.short.name@", value: GrailsNameUtils.getScriptName(pluginName))
3e17890 1.1 branch is now trunk
graeme authored
92 replacefilter(token: "@plugin.version@", value: grailsAppVersion ?: "0.1")
4fdcfca @pledbrook Improved the template Grails plugin descriptor (GrailsPlugin.groovy).…
pledbrook authored
93 replacefilter(token: "@grails.version@", value: pluginGrailsVersion)
3e17890 1.1 branch is now trunk
graeme authored
94 }
95
96 event("StatusFinal", [ "Created plugin ${pluginName}" ])
97 }
98
99 target(initProject: "Initialise an application or plugin project") {
100 depends(createStructure, updateAppProperties)
101
102 grailsUnpack(dest: basedir, src: "grails-shared-files.jar")
103 grailsUnpack(dest: basedir, src: "grails-$projectType-files.jar")
856e87c @graemerocher Restores creation of eclipse .classpath files etc.
graemerocher authored
104 integrateEclipse()
06182df @graemerocher make sure the create-app and create-project commands have access to r…
graemerocher authored
105
106 // make sure Grails central repo is prepped for default plugin set installation
107 grailsSettings.dependencyManager.parseDependencies {
108 repositories {
109 grailsCentral()
110 }
111 }
3e17890 1.1 branch is now trunk
graeme authored
112 }
113
835947f @burtbeckwith cleanup
burtbeckwith authored
114 target (appName : "Evaluates the application name") {
115 if (!argsMap["params"]) {
7a547d7 @burtbeckwith GRAILS-2155 added new 'scriptName' binding variable so the script can…
burtbeckwith authored
116 String type = scriptName.toLowerCase().indexOf('plugin') > -1 ? 'Plugin' : 'Application'
117 ant.input(message:"$type name not specified. Please enter:",
118 addProperty:"grails.app.name")
119 grailsAppName = ant.antProject.properties."grails.app.name"
120 }
121 else {
122 grailsAppName = argsMap["params"].join(" ")
123 }
3e17890 1.1 branch is now trunk
graeme authored
124
125 if (!argsMap["inplace"]) {
126 basedir = "${basedir}/${grailsAppName}"
127 resetBaseDirectory(basedir)
128 }
129
130 if (argsMap["appVersion"]) {
131 grailsAppVersion = argsMap["appVersion"]
132 }
133
134 appClassName = GrailsNameUtils.getClassNameRepresentation(grailsAppName)
135 }
Something went wrong with that request. Please try again.