Skip to content

Commit 6e21682

Browse files
committed
Add test for multiple proto files with same name from a directory referenced by protobuf dependency.
For google#248
1 parent 49e7405 commit 6e21682

File tree

15 files changed

+37
-14
lines changed

15 files changed

+37
-14
lines changed

examples/exampleKotlinDslProject/build.gradle.kts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.gradle.kotlin.dsl.provider.gradleKotlinDslOf
77
plugins {
88
java
99
idea
10-
id("com.google.protobuf") version "0.8.8-SNAPSHOT"
10+
id("com.google.protobuf") version "0.8.8"
1111
}
1212

1313
repositories {
@@ -34,10 +34,10 @@ dependencies {
3434
// Extra proto source files besides the ones residing under
3535
// "src/main".
3636
protobuf(files("lib/protos.tar.gz"))
37-
protobuf(fileTree("ext/"))
37+
protobuf(files("ext/"))
3838

3939
// Adding dependency for configuration from custom sourceSet
40-
"sampleProtobuf"(fileTree("ext/"))
40+
"sampleProtobuf"(files("ext/"))
4141

4242
testCompile("junit:junit:4.12")
4343
// Extra proto source files for test besides the ones residing under

examples/exampleProject/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies {
3131
// Extra proto source files besides the ones residing under
3232
// "src/main".
3333
protobuf files("lib/protos.tar.gz")
34-
protobuf fileTree("ext/")
34+
protobuf files("ext/")
3535

3636
testCompile 'junit:junit:4.12'
3737
// Extra proto source files for test besides the ones residing under

testProject/src/main/java/Foo.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ public static List<MessageLite> getDefaultInstances() {
2020
list.add(More.MoreMsg.getDefaultInstance());
2121
list.add(More.Foo.getDefaultInstance());
2222
// from ext/test1.proto
23-
list.add(Test1.Test1Msg.getDefaultInstance());
23+
list.add(test1.Test1.Test1Msg.getDefaultInstance());
24+
// from ext/ext1/test1.proto
25+
list.add(ext1.Ext1Test1.Ext1Test1Msg.getDefaultInstance());
2426
// from ext/test2.proto
25-
list.add(Test2.Test2Msg.getDefaultInstance());
27+
list.add(test2.Test2.Test2Msg.getDefaultInstance());
2628
return list;
2729
}
2830
}

testProject/src/test/java/FooTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
public class FooTest {
55
@org.junit.Test
66
public void testMainProtos() {
7-
assertEquals(11, Foo.getDefaultInstances().size());
7+
assertEquals(12, Foo.getDefaultInstances().size());
88
}
99

1010
@org.junit.Test

testProjectBase/build_base.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def protobufDep = 'com.google.protobuf:protobuf-java:3.0.0'
2828

2929
dependencies {
3030
protobuf files("lib/protos.tar.gz")
31-
protobuf fileTree("ext/")
31+
protobuf files("ext/")
3232
testProtobuf files("lib/protos-test.tar.gz")
3333

3434
compile protobufDep

testProjectBase/ext/ext1/test1.proto

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
syntax = "proto3";
2+
3+
option java_package = "ext1";
4+
option java_outer_classname = "Ext1Test1";
5+
6+
message Ext1Test1Msg {
7+
string bar = 1;
8+
}

testProjectBase/ext/test1.proto

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
syntax = "proto3";
99

10+
option java_package = "test1";
11+
1012
message Test1Msg {
1113
string bar = 1;
1214
}

testProjectBase/ext/test2.proto

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
syntax = "proto3";
22

3+
option java_package = "test2";
4+
35
message Test2Msg {
46
string bar = 1;
57
}

testProjectBase/src/main/proto/com/example/tutorial/sample.proto

+6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ option java_package = "com.example.tutorial";
44
option java_outer_classname = "OuterSample";
55
option java_multiple_files = true;
66

7+
import "test1.proto";
8+
import "ext1/test1.proto";
9+
import "test2.proto";
710

811
message Msg {
912
string foo = 1;
1013
SecondMsg blah = 2;
14+
Test1Msg test1 = 3;
15+
Test2Msg test2 = 4;
16+
Ext1Test1Msg ext1test1 = 5;
1117
}
1218

1319
message SecondMsg {

testProjectJavaAndKotlin/src/test/java/CallKotlinClass.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ public class CallKotlinClass {
55
@org.junit.Test
66
public void testMainProtosKotlin() {
77
// call kotlin class from java
8-
assertEquals(11, new KotlinFoo().getDefaultInstances().size());
8+
assertEquals(12, new KotlinFoo().getDefaultInstances().size());
99
}
1010
}

testProjectJavaAndKotlin/src/test/kotlin/CallJavaClass.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import org.junit.Assert.assertTrue
44
class CallJavaClass {
55
@org.junit.Test
66
fun testCallJavaFoo() {
7-
assertEquals(11, Foo.getDefaultInstances().size)
7+
assertEquals(12, Foo.getDefaultInstances().size)
88
}
99
}

testProjectKotlin/src/main/kotlin/KotlinFoo.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ class KotlinFoo {
1818
list.add(More.MoreMsg.getDefaultInstance());
1919
list.add(More.Foo.getDefaultInstance());
2020
// from ext/test1.proto
21-
list.add(Test1.Test1Msg.getDefaultInstance());
21+
list.add(test1.Test1.Test1Msg.getDefaultInstance());
22+
// from ext/ext1/test1.proto
23+
list.add(ext1.Ext1Test1.Ext1Test1Msg.getDefaultInstance());
2224
// from ext/test2.proto
23-
list.add(Test2.Test2Msg.getDefaultInstance());
25+
list.add(test2.Test2.Test2Msg.getDefaultInstance());
2426
return list
2527
}
2628
}

testProjectKotlin/src/test/kotlin/KotlinFooTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.junit.Assert.assertTrue
44
class KotlinFooTest {
55
@org.junit.Test
66
fun testMainProtos() {
7-
assertEquals(11, KotlinFoo().getDefaultInstances().size)
7+
assertEquals(12, KotlinFoo().getDefaultInstances().size)
88
}
99

1010
@org.junit.Test

testProjectKotlinDslBase/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ val protobufDep = "com.google.protobuf:protobuf-java:3.0.0"
6060

6161
dependencies {
6262
protobuf(files("lib/protos.tar.gz"))
63-
protobuf(fileTree("ext/"))
63+
protobuf(files("ext/"))
6464
testProtobuf(files("lib/protos-test.tar.gz"))
6565

6666
compile(protobufDep)

testProjectLite/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ targetCompatibility = JavaVersion.VERSION_1_7
1212

1313
dependencies {
1414
compile 'com.google.protobuf:protobuf-lite:3.0.0'
15+
protobuf files("ext/")
1516
testCompile 'junit:junit:4.12'
1617
}
1718

0 commit comments

Comments
 (0)