Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Karol Balejko
committed
Oct 29, 2012
1 parent
1995817
commit 4088ad5
Showing
3 changed files
with
87 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
|