This is an automated email from the git hooks/post-receive script. mckinstry pushed a commit to branch debian/master in repository rest-gradle-plugin.
commit db1ab64af8edc1b6d5947b7afae897e910b40389 Author: noamt <[email protected]> Date: Mon Feb 25 15:43:39 2013 +0200 Initial commit with basic request functionality --- build.gradle | 27 ++++++++++ .../groovy/org/_10ne/gradle/rest/RestPlugin.groovy | 15 ++++++ .../groovy/org/_10ne/gradle/rest/RestTask.groovy | 62 ++++++++++++++++++++++ .../META-INF/gradle-plugins/rest.properties | 1 + 4 files changed, 105 insertions(+) diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..431cb18 --- /dev/null +++ b/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'groovy' +apply plugin: 'idea' +apply plugin: 'maven' + +group = 'org._10ne.gradle' +version = '0.1-SNAPSHOT' + +buildscript { + apply from: 'gradle/Bintray.gradle' +} + +repositories { + bintray.jcenter() +} + +dependencies { + compile gradleApi() + groovy 'org.codehaus.groovy:groovy-all:2.1.1' + compile('org.codehaus.groovy.modules.http-builder:http-builder:0.6') { + exclude group: 'org.codehaus.groovy', module: 'groovy-all' + exclude group: 'org.codehaus.groovy', module: 'groovy' + } +} + +task wrapper(type: Wrapper, description: 'Gradle Wrapper task') { + gradleVersion = '1.4' +} \ No newline at end of file diff --git a/src/main/groovy/org/_10ne/gradle/rest/RestPlugin.groovy b/src/main/groovy/org/_10ne/gradle/rest/RestPlugin.groovy new file mode 100644 index 0000000..6626b0a --- /dev/null +++ b/src/main/groovy/org/_10ne/gradle/rest/RestPlugin.groovy @@ -0,0 +1,15 @@ +package org._10ne.gradle.rest + +import org.gradle.api.Plugin +import org.gradle.api.Project + +/** + * @author Noam Y. Tenne + */ +class RestPlugin implements Plugin<Project> { + + @Override + void apply(Project project) { + project.task("rest", type: RestTask) + } +} diff --git a/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy b/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy new file mode 100644 index 0000000..1ba92c3 --- /dev/null +++ b/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy @@ -0,0 +1,62 @@ +package org._10ne.gradle.rest + +import groovyx.net.http.HttpResponseDecorator +import groovyx.net.http.RESTClient +import org.apache.commons.lang.StringUtils +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.TaskExecutionException + +/** + * @author Noam Y. Tenne + */ +class RestTask extends DefaultTask { + + @Input String httpMethod + @Input Object uri + @Input + @Optional String username + @Input + @Optional String password + @Input + @Optional Object requestContentType + @Input + @Optional Object contentType + @Input + @Optional Object requestBody + + RestTask() { + httpMethod = 'get' + } + + @TaskAction + void executeRequest() { + if (!uri || StringUtils.isBlank(uri.toString())) { + throw new TaskExecutionException(this, new IllegalArgumentException('No resource URI provided')) + } + + def client = new RESTClient(uri) + if (StringUtils.isNotBlank(username)) { + client.auth.basic(username, password) + } + + def params = [:] + if (requestBody) { + params.body = requestBody + } + if (contentType) { + params.contentType = contentType + } + if (requestContentType) { + params.requestContentType = requestContentType + } + + println "Executing a '$httpMethod' request to '$uri'" + + HttpResponseDecorator responseDecorator = client."$httpMethod"(params) + + println "Received response: ${responseDecorator.getData()}" + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/gradle-plugins/rest.properties b/src/main/resources/META-INF/gradle-plugins/rest.properties new file mode 100644 index 0000000..58c91d2 --- /dev/null +++ b/src/main/resources/META-INF/gradle-plugins/rest.properties @@ -0,0 +1 @@ +implementation-class=org._10ne.gradle.rest.RestPlugin \ No newline at end of file -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/rest-gradle-plugin.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

