Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for GRAILS-5889; was ignoring y/n answer

  • Loading branch information...
commit 5b573a6eddaf282bca7e3a0b5c5e8953c9f5ed5c 1 parent 0f772b3
Burt Beckwith burtbeckwith authored
Showing with 44 additions and 54 deletions.
  1. +19 −24 scripts/InstallTemplates.groovy
  2. +25 −30 scripts/_GrailsSettings.groovy
43 scripts/InstallTemplates.groovy
View
@@ -1,12 +1,12 @@
/*
* Copyright 2004-2005 the original author or authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,7 +16,7 @@
/**
* Gant script that installs artifact and scaffolding templates
- *
+ *
* @author Marcel Overdijk
*
* @since 0.4
@@ -27,27 +27,22 @@ includeTargets << grailsScript("_GrailsInit")
target ('default': "Installs the artifact and scaffolding templates") {
depends(checkVersion, parseArguments)
- targetDir = "${basedir}/src/templates"
- overwrite = false
+ targetDir = "${basedir}/src/templates"
+ overwrite = false
+
+ // only if template dir already exists in, ask to overwrite templates
+ if (new File(targetDir).exists()) {
+ if (!isInteractive || confirmInput("Overwrite existing templates? [y/n]","overwrite.templates"))
+ overwrite = true
+ }
+ else {
+ ant.mkdir(dir: targetDir)
+ }
- // only if template dir already exists in, ask to overwrite templates
- if (new File(targetDir).exists()) {
- if (!isInteractive || confirmInput("Overwrite existing templates? [y/n]","overwrite.templates"))
- overwrite = true
- }
- else {
- ant.mkdir(dir: targetDir)
- }
+ copyGrailsResources("$targetDir/artifacts", "src/grails/templates/artifacts/*", overwrite)
+ copyGrailsResources("$targetDir/scaffolding", "src/grails/templates/scaffolding/*", overwrite)
+ ant.mkdir(dir:"${targetDir}/war")
+ copyGrailsResource("${targetDir}/war/web.xml", grailsResource("src/war/WEB-INF/web${servletVersion}.template.xml"), overwrite)
- copyGrailsResources("$targetDir/artifacts", "src/grails/templates/artifacts/*")
- copyGrailsResources("$targetDir/scaffolding", "src/grails/templates/scaffolding/*")
-// ant.copy(todir: targetDir, overwrite: overwrite) {
-// // copy artifact and scaffolding templates
-// fileset(dir: "${grailsHome}/src/grails/templates", includes: "artifacts/*, scaffolding/*")
-// }
- ant.mkdir(dir:"${targetDir}/war")
- copyGrailsResource("${targetDir}/war/web.xml", grailsResource("src/war/WEB-INF/web${servletVersion}.template.xml"))
-// ant.copy(tofile:"${targetDir}/war/web.xml", file:"${grailsHome}/src/war/WEB-INF/web${servletVersion}.template.xml")
-
event("StatusUpdate", [ "Templates installed successfully"])
}
55 scripts/_GrailsSettings.groovy
View
@@ -1,21 +1,20 @@
/*
-* Copyright 2004-2005 the original author or authors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright 2004-2005 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import grails.util.BuildScope
-import grails.util.BuildSettings
import grails.util.Environment
import grails.util.GrailsNameUtils
import grails.util.GrailsUtil
@@ -67,7 +66,6 @@ getPropertyValue = { String propName, defaultValue ->
return value != null ? value : defaultValue
}
-
// Set up various build settings. System properties take precedence
// over those defined in BuildSettings, which in turn take precedence
// over the defaults.
@@ -195,24 +193,25 @@ grailsResource = {String path ->
if (grailsSettings.grailsHome) {
return new FileSystemResource("${grailsSettings.grailsHome}/$path")
}
- else {
- return new ClassPathResource(path)
- }
+ return new ClassPathResource(path)
}
// Closure that copies a Spring resource to the file system.
-copyGrailsResource = { String targetFile, Resource resource ->
- FileCopyUtils.copy(resource.inputStream, new FileOutputStream(targetFile))
+copyGrailsResource = { targetFile, Resource resource, boolean overwrite = true ->
+ def file = new File(targetFile.toString())
+ if (overwrite || !file.exists()) {
+ FileCopyUtils.copy(resource.inputStream, new FileOutputStream(file))
+ }
}
// Copies a set of resources to a given directory. The set is specified
// by an Ant-style path-matching pattern.
-copyGrailsResources = { String destDir, String pattern ->
- new File(destDir).mkdirs()
+copyGrailsResources = { destDir, pattern, boolean overwrite = true ->
+ new File(destDir.toString()).mkdirs()
Resource[] resources = resolveResources("classpath:${pattern}")
resources.each { Resource res ->
if (res.readable) {
- copyGrailsResource("${destDir}/${res.filename}", res)
+ copyGrailsResource("${destDir}/${res.filename}", res, overwrite)
}
}
}
@@ -236,14 +235,11 @@ grailsUnpack = {Map args ->
exclude(name: "META-INF/**")
}
}
-
-
}
finally {
// Don't need the JAR file any more, so remove it.
- ant.delete(file: "${dir}/${src}", failonerror:false)
+ ant.delete(file: "${dir}/${src}", failonerror:false)
}
-
}
/**
@@ -296,9 +292,8 @@ exit = {
// Prevent system.exit during unit/integration testing
if (System.getProperty("grails.cli.testing") || System.getProperty("grails.disable.exit")) {
throw new ScriptExitException(it)
- } else {
- System.exit(it)
}
+ System.exit(it)
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.