Repository: gora Updated Branches: refs/heads/master 33b9a5bf4 -> 61a4747ff
GORA-330 Gora Gradle plugin (drazzib) closes apache/gora#19 Project: http://git-wip-us.apache.org/repos/asf/gora/repo Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/61a4747f Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/61a4747f Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/61a4747f Branch: refs/heads/master Commit: 61a4747ffc1a329bbe60e95517881e963b4a76a8 Parents: 33b9a5b Author: Damien Raude-Morvan <draz...@drazzib.com> Authored: Sun Feb 15 19:57:32 2015 +0100 Committer: Damien Raude-Morvan <draz...@drazzib.com> Committed: Sun Feb 15 19:58:21 2015 +0100 ---------------------------------------------------------------------- CHANGES.txt | 5 + gora-gradle-plugin/.gitignore | 30 ++++ gora-gradle-plugin/README.md | 46 ++++++ gora-gradle-plugin/build.gradle | 92 +++++++++++ gora-gradle-plugin/examples/simple/build.gradle | 42 +++++ .../examples/simple/gradle.properties | 16 ++ .../simple/src/main/java/test/Sample.java | 29 ++++ .../simple/src/main/resources/test1.avsc | 13 ++ gora-gradle-plugin/gradle.properties | 22 +++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 51018 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + gora-gradle-plugin/gradlew | 164 +++++++++++++++++++ gora-gradle-plugin/gradlew.bat | 90 ++++++++++ .../apache/gora/gradle/GoraCompileTask.groovy | 39 +++++ .../org/apache/gora/gradle/GoraPlugin.groovy | 68 ++++++++ .../gradle-plugins/org.apache.gora.properties | 16 ++ .../apache/gora/gradle/GoraPluginTest.groovy | 38 +++++ 17 files changed, 716 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index a2aa49f..b76d303 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,11 @@ ==CHANGES.txt ======================================================================= +Apache Gora 0.7 Release + +* GORA-330 Import Gora Gradle plugin (drazzib) + + Apache Gora 0.6 Release - 12/02/2015 (dd/mm/yyyy) Release Report - http://s.apache.org/gora-0.6 http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/.gitignore ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/.gitignore b/gora-gradle-plugin/.gitignore new file mode 100644 index 0000000..0a06b14 --- /dev/null +++ b/gora-gradle-plugin/.gitignore @@ -0,0 +1,30 @@ +# Java specific +*.class +target + +# OS / App generated files +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db +*.swp +*.sass-cache +*~ + +# Eclipse +.settings +.classpath +.project +target-eclipse + +# IntelliJ +overlays +*.iml +*.iws +*.ipr +.idea/ +.gradle/ + +# Gradle +build/ +out/ \ No newline at end of file http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/README.md ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/README.md b/gora-gradle-plugin/README.md new file mode 100644 index 0000000..fdf14d3 --- /dev/null +++ b/gora-gradle-plugin/README.md @@ -0,0 +1,46 @@ +gora-gradle-plugin +================== + +[Gradle](http://www.gradle.org/) plugin for processing [Avro](http://avro.apache.org/) files for [Gora](http://gora.apache.org) + +## Overview +Generate [Apache Gora](http://gora.apache.org) java types from an [Apache Avro](http://avro.apache.org/) descriptor (.avsc files). +This plugin will delegate to GoraCompiler all schema read and file generation. + +## Configuration +Configure the plugin in your project as follows: +```groovy +buildscript { + repositories { + jcenter() + } + dependencies { + classpath "org.apache.gora.gradle:gora-gradle-plugin:0.6" + } +} + +apply plugin: "org.apache.gora" + +dependencies { + compile "org.apache.gora:gora-core:0.4" +} +``` + +## Usage in your project +Avro schema descriptors (.avsc) have to in the following directory : +``` +src/main/resources/ +``` + +You can generate Gora java types using compileGora directly or using build task: +``` +$ gradle compileGora +$ gradle build +``` + +## Build this plugin +If you want to build this plugin from a Git checkout, please use Gradle Wrapper : +``` +./gradlew clean build publishToMavenLocal +``` + http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/build.gradle ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/build.gradle b/gora-gradle-plugin/build.gradle new file mode 100644 index 0000000..295ff5a --- /dev/null +++ b/gora-gradle-plugin/build.gradle @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:0.5' + } +} + +apply plugin: 'java-gradle-plugin' +apply plugin: 'groovy' +apply plugin: 'maven' +apply plugin: 'maven-publish' +apply plugin: 'com.jfrog.bintray' + +repositories { + mavenCentral() +} + +dependencies { + compile gradleApi() + compile localGroovy() + compile "org.apache.gora:gora-core:${goraVersion}" + compile "org.apache.gora:gora-compiler:${goraVersion}" +} + +task sourcesJar(type: Jar) { + classifier 'sources' + from sourceSets.main.allSource +} + +task javadocJar(type: Jar) { + classifier 'javadoc' + from javadoc +} + +artifacts { + archives sourcesJar + archives javadocJar +} + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + artifact sourcesJar + artifact javadocJar + } + } +} + +bintray { + user = project.hasProperty('bintrayUser') ? project.getProperty('bintrayUser') : null + key = project.hasProperty('bintrayKey') ? project.getProperty('bintrayKey') : null + + publications = ['mavenJava'] + publish = true + + pkg { + repo = 'gradle-gora-plugin' + name = 'gradle-gora-plugin' + licenses = ['Apache-2.0'] + desc = 'Gradle plugin for generating Gora beans for Avro schemas' + websiteUrl = 'https://github.com/Dictanova/gora-gradle-plugin' + issueTrackerUrl = 'https://github.com/Dictanova/gora-gradle-plugin/issues' + vcsUrl = 'https://github.com/Dictanova/gora-gradle-plugin.git' + labels = ['gradle', 'gora', 'avro'] + publicDownloadNumbers = true + attributes = ['gradle-plugin': 'org.apache.gora:org.apache.gora.gradle:gora-gradle-plugin'] + version = [ + attributes: ['gradle-plugin': 'org.apache.gora:org.apache.gora.gradle:gora-gradle-plugin'] + ] + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/examples/simple/build.gradle ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/examples/simple/build.gradle b/gora-gradle-plugin/examples/simple/build.gradle new file mode 100644 index 0000000..4de3836 --- /dev/null +++ b/gora-gradle-plugin/examples/simple/build.gradle @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Declare buildscript dependencies +buildscript { + repositories { + mavenLocal() + jcenter() + } + dependencies { + classpath 'org.apache.gora.gradle:gora-gradle-plugin:0.7-SNAPSHOT' + classpath "org.apache.gora:gora-core:${goraVersion}" + } +} +// Enable plugins +apply plugin: 'java' +apply plugin: 'org.apache.gora' + +// Project dependencies +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + compile "org.apache.gora:gora-core:${goraVersion}" +} http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/examples/simple/gradle.properties ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/examples/simple/gradle.properties b/gora-gradle-plugin/examples/simple/gradle.properties new file mode 100644 index 0000000..019142a --- /dev/null +++ b/gora-gradle-plugin/examples/simple/gradle.properties @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +goraVersion = 0.5 http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/examples/simple/src/main/java/test/Sample.java ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/examples/simple/src/main/java/test/Sample.java b/gora-gradle-plugin/examples/simple/src/main/java/test/Sample.java new file mode 100644 index 0000000..514ba35 --- /dev/null +++ b/gora-gradle-plugin/examples/simple/src/main/java/test/Sample.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package test; + +import org.apache.gora.mongodb.beans.tests.Test1; + +public class Sample { + + public static void main(String[] args) { + // Try to create new Test1 item + Test1 item = new Test1(); + } + +} http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/examples/simple/src/main/resources/test1.avsc ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/examples/simple/src/main/resources/test1.avsc b/gora-gradle-plugin/examples/simple/src/main/resources/test1.avsc new file mode 100644 index 0000000..b14f528 --- /dev/null +++ b/gora-gradle-plugin/examples/simple/src/main/resources/test1.avsc @@ -0,0 +1,13 @@ +{"name": "Test1", + "type": "record", + "namespace": "org.apache.gora.mongodb.beans.tests", + "fields": [ + {"name": "mapOfBytes", "type": {"type": "map", "values": "bytes"}}, + {"name": "mapOfStrings", "type": {"type": "map", "values": "string"}}, + {"name": "mapOfInt", "type": {"type": "map", "values": "int"}}, + {"name": "listOfInt", "type": {"type": "array", "items": "int"}}, + {"name": "scalarString", "type": "string"}, + {"name": "scalarDate", "type": "string"}, + {"name": "scalarInt", "type": "int"} + ] +} http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/gradle.properties ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/gradle.properties b/gora-gradle-plugin/gradle.properties new file mode 100644 index 0000000..07ec871 --- /dev/null +++ b/gora-gradle-plugin/gradle.properties @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +rootProject.name = 'goraPlugin' + +goraVersion = 0.5 +avroVersion = 1.7.4 + +group = org.apache.gora.gradle +version = 0.7-SNAPSHOT http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/gradle/wrapper/gradle-wrapper.jar ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/gradle/wrapper/gradle-wrapper.jar b/gora-gradle-plugin/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..c97a8bd Binary files /dev/null and b/gora-gradle-plugin/gradle/wrapper/gradle-wrapper.jar differ http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/gradle/wrapper/gradle-wrapper.properties ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/gradle/wrapper/gradle-wrapper.properties b/gora-gradle-plugin/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..d03f232 --- /dev/null +++ b/gora-gradle-plugin/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Feb 09 22:57:35 CET 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/gradlew ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/gradlew b/gora-gradle-plugin/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/gora-gradle-plugin/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/gradlew.bat ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/gradlew.bat b/gora-gradle-plugin/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gora-gradle-plugin/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/src/main/groovy/org/apache/gora/gradle/GoraCompileTask.groovy ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/src/main/groovy/org/apache/gora/gradle/GoraCompileTask.groovy b/gora-gradle-plugin/src/main/groovy/org/apache/gora/gradle/GoraCompileTask.groovy new file mode 100644 index 0000000..b955fd2 --- /dev/null +++ b/gora-gradle-plugin/src/main/groovy/org/apache/gora/gradle/GoraCompileTask.groovy @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gora.gradle + +import org.apache.gora.compiler.GoraCompiler +import org.gradle.api.tasks.SourceTask +import org.gradle.api.tasks.TaskAction + +class GoraCompileTask extends SourceTask { + + static final String SCHEMA_EXTENSION = ".avsc" + + File destinationDir + + GoraCompileTask() { + super() + include "**/*$SCHEMA_EXTENSION" + } + + @TaskAction + void compile() { + GoraCompiler.compileSchema(source as File[], destinationDir) + } +} http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/src/main/groovy/org/apache/gora/gradle/GoraPlugin.groovy ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/src/main/groovy/org/apache/gora/gradle/GoraPlugin.groovy b/gora-gradle-plugin/src/main/groovy/org/apache/gora/gradle/GoraPlugin.groovy new file mode 100644 index 0000000..099e39e --- /dev/null +++ b/gora-gradle-plugin/src/main/groovy/org/apache/gora/gradle/GoraPlugin.groovy @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gora.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.tasks.SourceSet + +class GoraPlugin implements Plugin<Project> { + private static final String GENERATE_GROUP = 'generate' + + @Override + void apply(final Project project) { + project.apply plugin: 'java' + project.sourceSets.all { SourceSet sourceSet -> + setupGoraFor(sourceSet, project) + } + } + + private setupGoraFor(SourceSet sourceSet, Project project) { + def configName = (sourceSet.getName().equals(SourceSet.MAIN_SOURCE_SET_NAME) ? "gora" : sourceSet.getName() + "Gora") + project.configurations.create(configName) { + visible = false + transitive = false + description = "The Gora libraries to be used for this project." + extendsFrom = [] + } + + // Wire task + Task goraTask = createGoraTaskFor(sourceSet, project) + + // Generate source code before java compile + String compileJavaTaskName = sourceSet.getCompileTaskName("java"); + Task compileJavaTask = project.tasks.getByName(compileJavaTaskName); + compileJavaTask.dependsOn(goraTask) + } + + private Task createGoraTaskFor(SourceSet sourceSet, Project project) { + def taskName = taskName(sourceSet) + def goraTask = project.tasks.create(taskName, GoraCompileTask) + goraTask.group = GENERATE_GROUP + goraTask.description = "Generates code from the ${sourceSet.name} Gora schemas." + goraTask.source = 'src/main/resources/' + goraTask.destinationDir = project.file('src/main/java') + + goraTask + } + + private String taskName(SourceSet sourceSet) { + return sourceSet.getTaskName('generate', 'Gora') + } +} http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.apache.gora.properties ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.apache.gora.properties b/gora-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.apache.gora.properties new file mode 100644 index 0000000..41ee6cc --- /dev/null +++ b/gora-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.apache.gora.properties @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +implementation-class=org.apache.gora.gradle.GoraPlugin http://git-wip-us.apache.org/repos/asf/gora/blob/61a4747f/gora-gradle-plugin/src/test/groovy/org/apache/gora/gradle/GoraPluginTest.groovy ---------------------------------------------------------------------- diff --git a/gora-gradle-plugin/src/test/groovy/org/apache/gora/gradle/GoraPluginTest.groovy b/gora-gradle-plugin/src/test/groovy/org/apache/gora/gradle/GoraPluginTest.groovy new file mode 100644 index 0000000..1bda1dd --- /dev/null +++ b/gora-gradle-plugin/src/test/groovy/org/apache/gora/gradle/GoraPluginTest.groovy @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gora.gradle + +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import org.junit.Test + +import static org.junit.Assert.assertTrue + +/** + * @author Damien Raude-Morvan + */ +class GoraPluginTest { + + @Test + public void goraPluginAddsCompileGoraToProject() { + Project project = ProjectBuilder.builder().build() + project.apply plugin: 'org.apache.gora' + + assertTrue(project.tasks.generateGora instanceof GoraCompileTask) + } +}