Upgrade to protobuf-gradle-plugin:0.4.0

Use the plugin to compile nano for golden test and get rid of the shell
script.
This commit is contained in:
Kun Zhang 2015-05-07 17:32:31 -07:00
parent 7ecb6fa431
commit 287a27a930
3 changed files with 56 additions and 41 deletions

View File

@ -50,7 +50,7 @@ subprojects {
// Only when the codegen is built along with the project, will we be able to recompile // Only when the codegen is built along with the project, will we be able to recompile
// the proto files. // the proto files.
project.apply plugin: 'com.google.protobuf' project.apply plugin: 'com.google.protobuf'
project.protobufCodeGenPlugins = ["java_plugin:$javaPluginPath"] project.protobufCodeGenPlugins = ["grpc:$javaPluginPath"]
project.protocDep = "com.google.protobuf:protoc:${protobufVersion}" project.protocDep = "com.google.protobuf:protoc:${protobufVersion}"
project.generatedFileDir = "${projectDir}/src/generated" project.generatedFileDir = "${projectDir}/src/generated"
project.afterEvaluate { project.afterEvaluate {
@ -68,6 +68,11 @@ subprojects {
java { java {
srcDir 'src/generated/main' srcDir 'src/generated/main'
} }
proto {
plugins {
grpc { }
}
}
} }
} }
} }
@ -85,7 +90,7 @@ subprojects {
okhttp: 'com.squareup.okhttp:okhttp:2.2.0', okhttp: 'com.squareup.okhttp:okhttp:2.2.0',
protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}", protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${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', netty: 'io.netty:netty-codec-http2:4.1.0.Beta5',

View File

@ -73,9 +73,45 @@ model {
} }
} }
configurations {
testNanoCompile
}
dependencies { dependencies {
testCompile project(':grpc-protobuf'), testCompile project(':grpc-protobuf'),
project(':grpc-stub') 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 { binaries.all {
@ -152,35 +188,28 @@ artifacts {
} }
project.protocDep = "com.google.protobuf:protoc:${protobufVersion}" project.protocDep = "com.google.protobuf:protoc:${protobufVersion}"
protobufCodeGenPlugins = ["java_plugin:$javaPluginPath"] protobufCodeGenPlugins = ["grpc:$javaPluginPath"]
project.afterEvaluate { 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') { if (osdetector.os != 'windows') {
executable "diff" task.executable "diff"
} else { } else {
executable "fc" task.executable "fc"
} }
// File isn't found on Windows if last slash is forward-slash // File isn't found on Windows if last slash is forward-slash
def slash = System.getProperty("file.separator") def slash = System.getProperty("file.separator")
args "$buildDir/generated-sources/test/io/grpc/testing/integration" + slash + "TestServiceGrpc.java", task.args "$buildDir/generated-sources/test${suffix}/io/grpc/testing/integration" + slash + "TestServiceGrpc.java",
"$projectDir/src/test/golden/TestService.java.txt" "$projectDir/src/test/golden/TestService${suffix}.java.txt"
} }
task testNanoGolden(type: Exec, dependsOn: 'java_pluginExecutable') { task testGolden(type: Exec)
doFirst { task testNanoGolden(type: Exec)
temporaryDir.createNewFile(); configureTestTask(testGolden, '')
} configureTestTask(testNanoGolden, 'Nano')
environment 'TEST_TMP_DIR', temporaryDir
commandLine './src/test/run_nano_test.sh'
}

View File

@ -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"