Improve Gradle build of protoc grpc plugin

A Gradle protoc plugin is used for generating and compiling the grpc
codegen. The code organization was changed to match what Gradle expects.

Proto 3 is now required.
diff --git a/compiler/build.gradle b/compiler/build.gradle
index acfd0f5..3f12ad6 100644
--- a/compiler/build.gradle
+++ b/compiler/build.gradle
@@ -1,11 +1,26 @@
 apply plugin: "cpp"
+apply plugin: "protobuf"
 
 description = 'The protoc plugin for gRPC Java'
 
+buildscript {
+    repositories {
+        mavenCentral()
+    }
+    dependencies {
+        classpath libraries.protobuf_plugin
+    }
+}
+
 executables {
   java_plugin {}
 }
 
+dependencies {
+  compile project(':grpc-stub'),
+          libraries.protobuf
+}
+
 binaries.all {
   if (toolChain in Gcc) {
     cppCompiler.args "-std=c++11"
@@ -22,19 +37,13 @@
   }
 }
 
-sources {
-  java_plugin {
-    // Configure an existing CppSourceSet
-    cpp {
-      source {
-        srcDirs "src/"
-        include "**/*.cc"
-      }
-    }
-  }
-}
+protobufCodeGenPlugins = ["java_plugin:$buildDir/binaries/java_pluginExecutable/java_plugin"]
 
-task test(type: Exec, dependsOn: 'java_pluginExecutable') {
-  environment 'TEST_TMP_DIR', temporaryDir
-  commandLine './run_test.sh'
+generateTestProto.dependsOn 'java_pluginExecutable'
+test.dependsOn 'testGolden'
+
+task testGolden(type: Exec, dependsOn: 'generateTestProto') {
+  executable "diff"
+  args "$buildDir/generated-sources/test/io/grpc/testing/integration/TestServiceGrpc.java",
+       "$projectDir/src/test/golden/TestService.java.txt"
 }
diff --git a/compiler/run_test.sh b/compiler/run_test.sh
deleted file mode 100755
index 5f311ba..0000000
--- a/compiler/run_test.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/bash
-
-if [ -z "$TEST_TMP_DIR" ]; then
-  echo '$TEST_TMP_DIR not set'
-  exit 1;
-fi
-
-cd $(dirname $0)
-
-TEST_SRC_DIR='test'
-INPUT_FILE="$TEST_SRC_DIR/test.proto"
-OUTPUT_FILE="$TEST_TMP_DIR/TestServiceGrpc.src.jar"
-GOLDEN_FILE="$TEST_SRC_DIR/TestService.java.txt"
-
-protoc --plugin=protoc-gen-java_rpc=build/binaries/java_pluginExecutable/java_plugin \
-  --java_rpc_out="$OUTPUT_FILE" --proto_path="$TEST_SRC_DIR" "$INPUT_FILE" && \
-  unzip -o -d "$TEST_TMP_DIR" "$OUTPUT_FILE" && \
-  diff "$TEST_TMP_DIR/io/grpc/testing/integration/TestServiceGrpc.java" \
-    "$GOLDEN_FILE" && \
-  echo "PASS"
diff --git a/compiler/src/java_generator.cc b/compiler/src/java_plugin/cpp/java_generator.cpp
similarity index 100%
rename from compiler/src/java_generator.cc
rename to compiler/src/java_plugin/cpp/java_generator.cpp
diff --git a/compiler/src/java_generator.h b/compiler/src/java_plugin/cpp/java_generator.h
similarity index 100%
rename from compiler/src/java_generator.h
rename to compiler/src/java_plugin/cpp/java_generator.h
diff --git a/compiler/src/java_plugin.cc b/compiler/src/java_plugin/cpp/java_plugin.cpp
similarity index 100%
rename from compiler/src/java_plugin.cc
rename to compiler/src/java_plugin/cpp/java_plugin.cpp
diff --git a/compiler/test/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt
similarity index 100%
rename from compiler/test/TestService.java.txt
rename to compiler/src/test/golden/TestService.java.txt
diff --git a/compiler/test/test.proto b/compiler/src/test/proto/test.proto
similarity index 100%
rename from compiler/test/test.proto
rename to compiler/src/test/proto/test.proto