Skip to content
Browse files

fix

  • Loading branch information...
1 parent 1995817 commit 4088ad5ea36a7db757434c50c4ab126f4f50e80e Karol Balejko committed Oct 29, 2012
Showing with 87 additions and 79 deletions.
  1. +2 −78 scripts/RefreshModules.groovy
  2. +4 −1 scripts/_Events.groovy
  3. +81 −0 scripts/_RefreshModules.groovy
View
80 scripts/RefreshModules.groovy
@@ -2,87 +2,11 @@ import org.apache.commons.lang.StringUtils
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_GrailsArgParsing")
+includeTargets << new File("${modulesManagerPluginDir}/scripts/_RefreshModules.groovy")
target(refreshModules: "Refresh resources modules") {
depends(parseArguments)
-
- def forceOverride = argsMap.force
-
- def workDir = "${grailsSettings.projectWorkDir}/packagemanager"
-
- grailsSettings.compileDependencies.each {jarfile->
-
- ant.unjar (src: jarfile, dest: workDir) {
- patternset excludes: "**/*.min.css **/*.min.js **/*-min.css **/*-min.js"
- }
-
- // webjars.org support
-
- def deps = []
- def resourcesUrls = []
- def artifactId
-
- if (new File(workDir, "META-INF/resources/webjars").exists()) {
-
- // parse pom
- new File(workDir).eachFileRecurse {file->
- if (!file.file || file.name != 'pom.xml') return
- def pom = new XmlParser().parse(file)
- artifactId = pom.artifactId.text()
- pom.dependencies.findAll {
- deps << it.dependency.artifactId.text()
- }
- }
-
- new File(workDir, "META-INF/resources/webjars").eachFileRecurse {file->
- if (file.file) {
-
- def relpath = StringUtils.removeStart(file.path, "${workDir}/META-INF/resources/webjars/")
-
- def resourcePath = relpath
- def webjarsMatcher = resourcePath =~ /([^\/]+)\/([^\/]+)\/(.+)/
- if (webjarsMatcher.matches()) {
-
- def module = webjarsMatcher.group(1)
- def version = webjarsMatcher.group(2)
- def path = webjarsMatcher.group(3)
-
- if (!artifactId) {
- artifactId = module
- }
-
- if (forceOverride || !new File(grailsSettings.baseDir, "web-app/modules/${artifactId}/${path}").exists()) {
- ant.copyfile(src: file, dest: "${grailsSettings.baseDir}/web-app/modules/${artifactId}/${path}")
- event('CreatedFile', ["${grailsSettings.baseDir}/web-app/modules/${artifactId}/${path}"])
- if (StringUtils.endsWithAny("modules/${artifactId}/${path}", ['.js','.css'] as String[])) {
- resourcesUrls << "modules/${artifactId}/${path}"
- }
- }
- }
- }
- }
-
- def resourceDSLFilepath = "${grailsSettings.baseDir}/grails-app/conf/Modules${StringUtils.capitalise(artifactId)}Resources.groovy"
-
- def templ = "modules = {\n"
- templ += " '${artifactId}' {\n"
- if (deps) {
- templ += " dependsOn '${deps.join()}'\n"
- }
- resourcesUrls.each {
- templ += " resource url: '${it}'\n"
- }
- templ += " }\n"
- templ += "}\n"
-
- if (forceOverride || !new File(resourceDSLFilepath).exists()) {
- ant.echo(file:resourceDSLFilepath,message: templ)
- event('CreatedFile', [resourceDSLFilepath])
- }
- }
-
- ant.delete(dir: workDir)
- }
+ refreshModules(argsMap.force)
}
setDefaultTarget(refreshModules)
View
5 scripts/_Events.groovy
@@ -1,7 +1,10 @@
-includeTargets << new File("${modulesManagerPluginDir}/scripts/RefreshModules.groovy")
+includeTargets << new File("${modulesManagerPluginDir}/scripts/_RefreshModules.groovy")
eventCompileStart = {
+ println "grailsSettings.config.modules?.refreshOnCompile ${grailsSettings.config.modules?.refreshOnCompile}"
+ println "grailsSettings.config.modules?.forceOverride ${grailsSettings.config.modules?.forceOverride}"
+
if (grailsSettings.config.modules?.refreshOnCompile) {
refreshModules(grailsSettings.config.modules?.forceOverride)
}
View
81 scripts/_RefreshModules.groovy
@@ -0,0 +1,81 @@
+import org.apache.commons.lang.StringUtils
+
+refreshModules = {forceOverride->
+
+ def workDir = "${grailsSettings.projectWorkDir}/packagemanager"
+
+ grailsSettings.compileDependencies.each {jarfile->
+
+ ant.unjar (src: jarfile, dest: workDir) {
+ patternset excludes: "**/*.min.css **/*.min.js **/*-min.css **/*-min.js"
+ }
+
+ // webjars.org support
+
+ def deps = []
+ def resourcesUrls = []
+ def artifactId
+
+ if (new File(workDir, "META-INF/resources/webjars").exists()) {
+
+ // parse pom
+ new File(workDir).eachFileRecurse {file->
+ if (!file.file || file.name != 'pom.xml') return
+ def pom = new XmlParser().parse(file)
+ artifactId = pom.artifactId.text()
+ pom.dependencies.findAll {
+ deps << it.dependency.artifactId.text()
+ }
+ }
+
+ new File(workDir, "META-INF/resources/webjars").eachFileRecurse {file->
+ if (file.file) {
+
+ def relpath = StringUtils.removeStart(file.path, "${workDir}/META-INF/resources/webjars/")
+
+ def resourcePath = relpath
+ def webjarsMatcher = resourcePath =~ /([^\/]+)\/([^\/]+)\/(.+)/
+ if (webjarsMatcher.matches()) {
+
+ def module = webjarsMatcher.group(1)
+ def version = webjarsMatcher.group(2)
+ def path = webjarsMatcher.group(3)
+
+ if (!artifactId) {
+ artifactId = module
+ }
+
+ if (forceOverride || !new File(grailsSettings.baseDir, "web-app/modules/${artifactId}/${path}").exists()) {
+ ant.copyfile(src: file, dest: "${grailsSettings.baseDir}/web-app/modules/${artifactId}/${path}")
+ event('CreatedFile', ["${grailsSettings.baseDir}/web-app/modules/${artifactId}/${path}"])
+ if (StringUtils.endsWithAny("modules/${artifactId}/${path}", ['.js','.css'] as String[])) {
+ resourcesUrls << "modules/${artifactId}/${path}"
+ }
+ }
+ }
+ }
+ }
+
+ def resourceDSLFilepath = "${grailsSettings.baseDir}/grails-app/conf/Modules${StringUtils.capitalise(artifactId)}Resources.groovy"
+
+ def templ = "modules = {\n"
+ templ += " '${artifactId}' {\n"
+ if (deps) {
+ templ += " dependsOn '${deps.join()}'\n"
+ }
+ resourcesUrls.each {
+ templ += " resource url: '${it}'\n"
+ }
+ templ += " }\n"
+ templ += "}\n"
+
+ if (forceOverride || !new File(resourceDSLFilepath).exists()) {
+ ant.echo(file:resourceDSLFilepath,message: templ)
+ event('CreatedFile', [resourceDSLFilepath])
+ }
+ }
+
+ ant.delete(dir: workDir)
+ }
+}
+

0 comments on commit 4088ad5

Please sign in to comment.
Something went wrong with that request. Please try again.