Grails Ant Plugin
Dependency :
compile ":grails-ant:0.1.3"
Summary
Provides ant to Grails applications
Installation
grails install-plugin grails-ant
Description
Overview
This plugin is for using ant within a Grails application. It has nothing to do with building an app. The primary thing it does is really to just get the ant jars available at run time. Even though ant is part of Grails core, since it's primarily a build tool, it's not included in a Grails war file (1). And you can do that in your own app, without this plugin, by adding ant to your build.config.dependencies {
// Workarounds for Grails not shipping ant in WAR
compile 'org.apache.ant:ant:1.7.1' //you can also use runtime
compile 'org.apache.ant:ant-launcher:1.7.1'
}Usage
class DemoController { def index = {
ant.echo message: 'Hello From Ant!' render 'it worked'
}
}def antUtilsService
Zip
To zip up everything in a directory you can just specify the output file name and directory to zip up.//def zip(String destfile,String basedir) antUtilsService.zip("newzip.zip",workingDirName)
//def zip(String destfile,String basedir,String includes) antUtilsService.zip("newzip.zip",workingDirName,"**/*.txt")
//def zip(String destfile,String basedir,String includes,String excludes) antUtilsService.zip("newzip.zip",workingDirName,"**/*.*","**/*.doc")
Unzip
To just unzip a file, specify the zip file name and the directory to put the output. Note that this will not replace the contents of the output directory if it already exists.//def unzip(String zipFile, String destDir) antUtilsService.unzip(planZipFile,workingDirName)
//def unzip(String zipFile, String destDir, Boolean overwrite) antUtilsService.unzip(planZipFile,workingDirName,true)
//def unzip(String zipFile, String destDir, String mapperType) antUtilsService.unzip(planZipFile,workingDirName2,"flatten")
//def unzip(String zipFile, String destDir, String mapperType, Boolean overwrite) antUtilsService.unzip(planZipFile,workingDirName2,"flatten",true)
try { antUtilsService.unzip(notAZipStr,workingDirName) } catch (org.grails.plugins.grailsant.UnzipException e) { println e.message println e.fileName }
References
- http://jira.grails.org/browse/GRAILS-5675
- http://preferisco.blogspot.com/2010/06/using-goovy-antbuilder-to-zip-unzip.html
- http://groovy.codehaus.org/Using+Ant+from+Groovy
- http://groovy-almanac.org/creating-a-zipfile-with-antbuilder/
- http://ant.apache.org/manual/
- http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/test/groovy/util/AntTest.groovy