-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow custom proto source directories. Resolves #1
Create protoSources convention that can be used to override the default proto file location, i.e., "src/main/proto" etc. Create testProjectCustomProtoDir to test it.
- Loading branch information
1 parent
4c26802
commit 6890bbd
Showing
12 changed files
with
168 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
dependencies { | ||
classpath "com.google.protobuf:protobuf-gradle-plugin:${rootProject.version}" | ||
} | ||
} | ||
|
||
apply plugin: 'protobuf' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile 'com.google.protobuf:protobuf-java:2.6.1' | ||
testCompile 'junit:junit:4.7' | ||
} | ||
|
||
protocDep = 'com.google.protobuf:protoc:2.6.1' | ||
|
||
// Override the default 'src/main/proto' directory | ||
protoSources('main').add fileTree('src/main/protobuf') { | ||
include '**/*.proto' | ||
include '**/*.protodevel' | ||
} | ||
|
||
// Override the default 'src/test/proto' directory | ||
protoSources('test').add fileTree('src/test/protocolbuffers') { | ||
include '**/*.proto' | ||
} | ||
|
||
task printDeps(dependsOn: build) << { | ||
configurations.each { println it } | ||
sourceSets.each { println it.getCompileTaskName("proto") } | ||
sourceSets.each { println it.getCompileTaskName("java") } | ||
sourceSets.each { println it } | ||
println tasks['generateProto'].source | ||
println tasks['compileJava'].source | ||
println project.buildDir | ||
println project.buildDir.path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import com.google.protobuf.MessageLite; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Foo { | ||
public static List<MessageLite> getDefaultInstances() { | ||
ArrayList<MessageLite> list = new ArrayList<MessageLite>(); | ||
// from src/main/protobuf/test.protodevel | ||
list.add(ws.antonov.protobuf.test.Test.TestMessage.getDefaultInstance()); | ||
list.add(ws.antonov.protobuf.test.Test.AnotherMessage.getDefaultInstance()); | ||
list.add(ws.antonov.protobuf.test.Test.Item.getDefaultInstance()); | ||
list.add(ws.antonov.protobuf.test.Test.DataMap.getDefaultInstance()); | ||
// from src/main/protobuf/sample.proto (java_multiple_files == true, thus no outter class) | ||
list.add(com.example.tutorial.Msg.getDefaultInstance()); | ||
list.add(com.example.tutorial.SecondMsg.getDefaultInstance()); | ||
return list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
option java_package = "com.example.tutorial"; | ||
option java_outer_classname = "OuterSample"; | ||
option java_multiple_files = true; | ||
|
||
message Msg { | ||
optional string foo = 1; | ||
optional SecondMsg blah = 2; | ||
} | ||
|
||
message SecondMsg { | ||
optional int32 blah = 1; | ||
} |
23 changes: 23 additions & 0 deletions
23
testProjectCustomProtoDir/src/main/protobuf/test.protodevel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ws.antonov.protobuf.test; | ||
|
||
message TestMessage { | ||
required int32 id = 1; | ||
optional string name = 2; | ||
} | ||
|
||
message AnotherMessage { | ||
repeated string names = 1; | ||
optional DataPayload data = 2; | ||
|
||
message DataPayload { | ||
optional string payload = 1; | ||
} | ||
} | ||
|
||
message Item { | ||
required string name = 1; | ||
optional string value = 2; | ||
} | ||
message DataMap { | ||
repeated Item data_items = 1 [experimental_map_key="name"]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
public class FooTest { | ||
@org.junit.Test | ||
public void testMainProtos() { | ||
org.junit.Assert.assertEquals(6, Foo.getDefaultInstances().size()); | ||
} | ||
|
||
@org.junit.Test | ||
public void testTestProtos() { | ||
// from src/test/protocolbuffers/test.proto | ||
Test.MsgTest.getDefaultInstance(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
testProjectCustomProtoDir/src/test/protocolbuffers/test.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
message MsgTest { | ||
|
||
} |