Skip to content

Commit 94b5522

Browse files
committed
fix for GRAILS-5713 "Package by convention for new artefacts"
1 parent baa216c commit 94b5522

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

scripts/_GrailsCreateArtifacts.groovy

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import grails.util.GrailsNameUtils
2323
* @author Peter Ledbrook
2424
*/
2525

26+
includeTargets << grailsScript("_GrailsPackage")
27+
2628
createArtifact = { Map args = [:] ->
2729
def suffix = args["suffix"]
2830
def type = args["type"]
@@ -37,25 +39,23 @@ createArtifact = { Map args = [:] ->
3739
if (pos != -1) {
3840
pkg = name[0..<pos]
3941
name = name[(pos + 1)..-1]
42+
if(pkg.startsWith("~")) {
43+
pkg = pkg.replace("~", createRootPackage())
44+
}
45+
}
46+
else {
47+
pkg = createRootPackage()
4048
}
4149

4250
// Convert the package into a file path.
43-
def pkgPath = ''
44-
if (pkg) {
45-
pkgPath = pkg.replace('.' as char, '/' as char)
51+
def pkgPath = pkg.replace('.' as char, '/' as char)
4652

47-
// Make sure that the package path exists! Otherwise we won't
48-
// be able to create a file there.
49-
ant.mkdir(dir: "${basedir}/${artifactPath}/${pkgPath}")
53+
// Make sure that the package path exists! Otherwise we won't
54+
// be able to create a file there.
55+
ant.mkdir(dir: "${basedir}/${artifactPath}/${pkgPath}")
5056

51-
// Future use of 'pkgPath' requires a trailing slash.
52-
pkgPath += '/'
53-
}
54-
else if(!args.skipPackagePrompt && isInteractive) {
55-
if(!confirmInput("WARNING: You have not specified a package. It is good practise to place classes in packages (eg. mycompany.Book). Do you want to continue?", "no.package.warning")) {
56-
exit(1)
57-
}
58-
}
57+
// Future use of 'pkgPath' requires a trailing slash.
58+
pkgPath += '/'
5959

6060
// Convert the given name into class name and property name
6161
// representations.
@@ -102,6 +102,11 @@ createArtifact = { Map args = [:] ->
102102
event("CreatedArtefact", [ type, className])
103103
}
104104

105+
private createRootPackage() {
106+
compile()
107+
createConfig()
108+
return (config.grails.project.groupId ?: grailsAppName).replace('-','.').toLowerCase()
109+
}
105110
createIntegrationTest = { Map args = [:] ->
106111
def superClass = args["superClass"] ?: "GrailsUnitTestCase"
107112
createArtifact(name: args["name"], suffix: "${args['suffix']}Tests", type: "Tests", path: "test/integration", superClass: superClass)

scripts/_GrailsPackage.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import grails.util.PluginBuildSettings
3131
* @since 0.4
3232
*/
3333

34+
if (getBinding().variables.containsKey("_grails_package_called")) return
35+
_grails_package_called = true
36+
37+
3438
includeTargets << grailsScript("_GrailsCompile")
3539
includeTargets << grailsScript("_PackagePlugins")
3640

scripts/_PluginDependencies.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ import org.codehaus.groovy.grails.commons.ApplicationHolder
6363
*
6464
* @since 1.1
6565
*/
66+
if (getBinding().variables.containsKey("_plugin_dependencies_called")) return
67+
_plugin_dependencies_called = true
68+
6669

6770
includeTargets << grailsScript("_GrailsClean")
6871
includeTargets << grailsScript("_GrailsArgParsing")

src/grails/grails-app/conf/Config.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// if(System.properties["${appName}.config.location"]) {
1010
// grails.config.locations << "file:" + System.properties["${appName}.config.location"]
1111
// }
12+
13+
grails.project.groupId = appName // change this to alter the default package name and Maven publishing destination
1214
grails.mime.file.extensions = true // enables the parsing of file extensions from URLs into the request format
1315
grails.mime.use.accept.header = false
1416
grails.mime.types = [ html: ['text/html','application/xhtml+xml'],

0 commit comments

Comments
 (0)