Skip to content

Instantly share code, notes, and snippets.

@ryo-murai
Created July 26, 2012 01:27
Show Gist options
  • Save ryo-murai/3179735 to your computer and use it in GitHub Desktop.
Save ryo-murai/3179735 to your computer and use it in GitHub Desktop.
gradle script for download some files via http
import java.io.*
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.EncoderRegistry
import static groovyx.net.http.Method.*
import static groovyx.net.http.ContentType.*
buildscript {
repositories {
mavenCentral()
mavenRepo url: "http://repository.codehaus.org"
}
dependencies {
classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2'
}
}
task downloadJslibs << {
def http = new HTTPBuilder('http://ajax.aspnetcdn.com/ajax/')
http.handler.failure = { resp ->
println "Unexpected failure: ${resp.statusLine}"
}
// proxy settings
def (host, port) = [System.properties.'http.proxyHost', System.properties.'http.proxyPort']
if(host) http.setProxy(host, port as int, "http")
def target = 'src/main/webapp/js/libs'
def contents = [
"jQuery/jquery-1.7.2.min.js": "jquery.js",
"jqueryui/1.8.22/jquery-ui.min.js": "jquery-ui.js",
"jquery.validate/1.9/jquery.validate.min.js": "jquery.validate.js",
]
def dest = mkdir(target)
contents.each() {
http.request(GET, TEXT) { req ->
uri.path= it.key
response.success = { resp, reader ->
println "$resp.statusLine saving downloaded file[$it.value] ..."
new File(dest, it.value).setText(reader.text, "UTF-8")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment