Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Karol Balejko committed Oct 29, 2012
1 parent 1995817 commit 4088ad5
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 79 deletions.
80 changes: 2 additions & 78 deletions scripts/RefreshModules.groovy
Expand Up @@ -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)
5 changes: 4 additions & 1 deletion 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)
}
Expand Down
81 changes: 81 additions & 0 deletions 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.