Last active
October 8, 2015 08:38
-
-
Save parj/3306722 to your computer and use it in GitHub Desktop.
Gradle AntTasks for using Ant tasks
This file contains hidden or 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
/* | |
Copyright (c) 2011-2013 Parjanya Mudunuri | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | |
associated documentation files (the "Software"), to deal in the Software without restriction, including | |
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to | |
the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial | |
portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | |
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
http://opensource.org/licenses/mit-license.php | |
*/ | |
apply plugin: 'java' | |
apply plugin: 'maven' | |
apply plugin: 'eclipse' | |
apply plugin: 'idea' | |
repositories { | |
mavenCentral() | |
} | |
List compileAll = [ "org.apache.ant:ant:1.8.1", "junit:junit:4.0", "log4j:log4j:1.2.16", //All | |
"xmlunit:xmlunit:1.3", "net.sourceforge.jexcelapi:jxl:2.6.12", //org.pm.xml.AntXMLUnit | |
"net.sf.opencsv:opencsv:2.0", //org.pm.csv.diff | |
"net.sourceforge.jexcelapi:jxl:2.6.10", //org.pm.csv.AntCsvToExcel | |
"commons-codec:commons-codec:1.6", | |
"commons-httpclient:commons-httpclient:3.0", | |
"commons-logging:commons-logging:1.1.1", | |
"org.apache.jackrabbit:jackrabbit-webdav:2.1.1", | |
"org.slf4j:slf4j-api:1.5.8", | |
"org.slf4j:slf4j-log4j12:1.5.2" //org.pm.AntDav | |
] | |
dependencies { | |
compile compileAll | |
runtime fileTree(dir: 'build/libs', include: '*.jar') | |
} | |
configurations { | |
runtime { | |
//extendsFrom compile | |
fileTree(dir: 'build/libs', include: '*.jar') | |
} | |
} | |
tasks.withType(Compile) { | |
options.encoding = 'UTF-8' | |
} | |
uploadArchives { | |
repositories { | |
mavenDeployer { | |
pom.version = '2.0-SNAPSHOT' | |
pom.groupId = 'org.pm' | |
pom.artifactId = 'anttasks' | |
} | |
} | |
} | |
// Push file to a WebDav Server | |
task push << { | |
ant.taskdef(name: 'push', classname: 'org.pm.webdav.Push', classpath: configurations.runtime.asPath) | |
ant.push(user: 'admin', password: "admin", url: "http://localhost:8080/repository/default", overwrite: true) { | |
fileset(dir: 'src/test/resources/webdav', includes: '*.csv') | |
} | |
} | |
// Pull file from a webdav server | |
task pull << { | |
ant.taskdef(name: 'pull', classname: 'org.pm.webdav.Pull', classpath: configurations.runtime.asPath) | |
ant.pull(user: 'admin', password: "admin", url: "http://localhost:8080/repository/default", | |
file: "output.csv", | |
outFile: "src/test/resources/webdav/output.csv", | |
overwrite: true) | |
} | |
// Converts csv to Excel | |
task csvToExcel << { | |
ant.taskdef(name: 'csvToExcel', classname: 'org.pm.csv.AntCsvToExcel', classpath: configurations.runtime.asPath) | |
ant.csvToExcel(outputFile: "build/tmp/report.xls", separator: "^") { | |
fileset(dir: "src/test/resources/csv/CsvToExcel", includes: "*.csv") | |
} | |
} | |
// Diffs two directories containing xml files with the same name | |
task diffxml << { | |
ant.taskdef(name: 'diffxml', classname: 'org.pm.xml.AntXMLUnit', classpath: configurations.runtime.asPath) | |
ant.diffxml(testDirectory: "src/test/resources/xml/AntXMLUnitTest/test", resultDirectory: "out") { | |
fileset(dir: "src/test/resources/xml/AntXMLUnitTest/control", includes: "*.xml") | |
} | |
} | |
// Strips out and modifies tags in xmls and renames them using a naming convention | |
task modifyPath << { | |
ant.taskdef(name: 'xPath', classname: 'org.pm.xml.AntXPath', classpath: configurations.runtime.asPath) | |
ant.taskdef(name: 'modifyPath', classname: 'org.pm.xml.ModifyPath', classpath: configurations.runtime.asPath) | |
//Rename Pattern is the file rename pattern, takes as input as xpaths separated by # | |
ant.xPath(outputDirectory: "out", renamePattern: "//publish_date[position() = 1]#_#//price[position() = 1]" ) { | |
fileset(dir: "src/test/resources/xml/AntXPathTest", includes: "*.xml") | |
modifyPath(path: "//title", delete:"True") | |
modifyPath(path: "//author", value:"ToDo") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment