Upgrade to protobuf-gradle-plugin:0.4.0

Use the plugin to compile nano for golden test and get rid of the shell
script.
diff --git a/build.gradle b/build.gradle
index 6fe645f..215b441 100644
--- a/build.gradle
+++ b/build.gradle
@@ -50,7 +50,7 @@
             // Only when the codegen is built along with the project, will we be able to recompile
             // the proto files.
             project.apply plugin: 'com.google.protobuf'
-            project.protobufCodeGenPlugins = ["java_plugin:$javaPluginPath"]
+            project.protobufCodeGenPlugins = ["grpc:$javaPluginPath"]
             project.protocDep = "com.google.protobuf:protoc:${protobufVersion}"
             project.generatedFileDir = "${projectDir}/src/generated"
             project.afterEvaluate {
@@ -68,6 +68,11 @@
                 java {
                   srcDir 'src/generated/main'
                 }
+                proto {
+                  plugins {
+                    grpc { }
+                  }
+                }
               }
             }
           }
@@ -85,7 +90,7 @@
                 okhttp: 'com.squareup.okhttp:okhttp:2.2.0',
                 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
                 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufVersion}",
-                protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.3.1',
+                protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.4.0',
 
                 netty: 'io.netty:netty-codec-http2:4.1.0.Beta5',
 
diff --git a/compiler/build.gradle b/compiler/build.gradle
index 4efa261..4433cdd 100644
--- a/compiler/build.gradle
+++ b/compiler/build.gradle
@@ -73,9 +73,45 @@
   }
 }
 
+configurations {
+  testNanoCompile
+}
+
 dependencies {
   testCompile project(':grpc-protobuf'),
               project(':grpc-stub')
+  testNanoCompile project(':grpc-protobuf-nano'),
+                  project(':grpc-stub')
+}
+
+sourceSets {
+  test {
+    proto {
+      plugins {
+        grpc { }
+      }
+    }
+  }
+  testNano {
+    proto {
+      setSrcDirs(['src/test/proto'])
+      builtins {
+        remove java
+        javanano {
+          option 'ignore_services=true'
+        }
+      }
+      plugins {
+        grpc {
+          option 'nano=true'
+        }
+      }
+    }
+  }
+}
+
+checkstyleTestNano {
+  source = fileTree(dir: "src/testNano", include: "**/*.java")
 }
 
 binaries.all {
@@ -152,35 +188,28 @@
 }
 
 project.protocDep = "com.google.protobuf:protoc:${protobufVersion}"
-protobufCodeGenPlugins = ["java_plugin:$javaPluginPath"]
+protobufCodeGenPlugins = ["grpc:$javaPluginPath"]
 
 project.afterEvaluate {
-  generateTestProto.dependsOn 'java_pluginExecutable'
+  [generateTestProto, generateTestNanoProto]*.dependsOn 'java_pluginExecutable'
 }
 
-// Ignore test for the moment on Windows. It will be easier to run once the
-// gradle protobuf plugin can support nano.
-if (osdetector.os != 'windows') {
-  test.dependsOn('testGolden','testNanoGolden')
-}
+test.dependsOn('testGolden', 'testNanoGolden')
 
-task testGolden(type: Exec, dependsOn: 'generateTestProto') {
+def configureTestTask(Task task, String suffix) {
+  task.dependsOn "generateTest${suffix}Proto"
   if (osdetector.os != 'windows') {
-    executable "diff"
+    task.executable "diff"
   } else {
-    executable "fc"
+    task.executable "fc"
   }
   // File isn't found on Windows if last slash is forward-slash
   def slash = System.getProperty("file.separator")
-  args "$buildDir/generated-sources/test/io/grpc/testing/integration" + slash + "TestServiceGrpc.java",
-       "$projectDir/src/test/golden/TestService.java.txt"
+  task.args "$buildDir/generated-sources/test${suffix}/io/grpc/testing/integration" + slash + "TestServiceGrpc.java",
+       "$projectDir/src/test/golden/TestService${suffix}.java.txt"
 }
 
-task testNanoGolden(type: Exec, dependsOn: 'java_pluginExecutable') {
-  doFirst {
-      temporaryDir.createNewFile();
-  }
-
-  environment 'TEST_TMP_DIR', temporaryDir
-  commandLine './src/test/run_nano_test.sh'
-}
+task testGolden(type: Exec)
+task testNanoGolden(type: Exec)
+configureTestTask(testGolden, '')
+configureTestTask(testNanoGolden, 'Nano')
diff --git a/compiler/src/test/run_nano_test.sh b/compiler/src/test/run_nano_test.sh
deleted file mode 100755
index 181c8e9..0000000
--- a/compiler/src/test/run_nano_test.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/bash
-
-if [ -z "$TEST_TMP_DIR" ]; then
-  echo '$TEST_TMP_DIR not set'
-  exit 1;
-fi
-
-cd "$(dirname "$0")"
-
-INPUT_FILE="proto/test.proto"
-OUTPUT_FILE="$TEST_TMP_DIR/TestServiceGrpc.src.jar"
-GRPC_FILE="$TEST_TMP_DIR/io/grpc/testing/integration/TestServiceGrpc.java"
-GOLDEN_FILE="golden/TestServiceNano.java.txt"
-
-protoc --plugin=protoc-gen-java_rpc=../../build/binaries/java_pluginExecutable/protoc-gen-grpc-java \
-  --java_rpc_out=nano=true:"$OUTPUT_FILE" "$INPUT_FILE" && \
-  unzip -o -d "$TEST_TMP_DIR" "$OUTPUT_FILE" && \
-  diff "$GRPC_FILE" "$GOLDEN_FILE" && \
-  echo "PASS"