Skip to content

Commit

Permalink
Make the usage of protoSources a little less confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangkun83 committed Apr 24, 2015
1 parent 6890bbd commit da528d5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ protocDep = 'com.google.protobuf:protoc:3.0.0-alpha-2'
// Optional - the location of proto files for each Java sourceSet, defaults to
// fileTree('src/<sourceSetName>/proto') {include '**/*.proto'}
protoSources('main').add fileTree('src/main/protobuf') {
protoSources 'main', fileTree('src/main/protobuf') {
include '**/*.proto'
include '**/*.protodevel'
}
protoSources 'main', fileTree('src/main/protocolbuffers') {
include '**/*.proto'
}
protoSources('test').add fileTree('src/test/protobuf') {
protoSources 'test', fileTree('src/test/protobuf') {
include '**/*.protodevel'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ class ProtobufConvention {
*
* <p>Example:
* <pre>
* protoSources('main').add fileTree('src/main/protobuf') {
* protoSources 'main', fileTree('src/main/protobuf') {
* include '**' + '/' + '*.proto'
* exclude 'src/main/protobuf/excluded.proto'
* }
* </pre>
*/
def List<?> protoSources(String sourceSetName) {
return protoSources.get(sourceSetName)
def protoSources(String sourceSetName, Object sourceFiles) {
protoSources.get(sourceSetName).add(sourceFiles)
}

/**
Expand Down
8 changes: 6 additions & 2 deletions testProjectCustomProtoDir/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ dependencies {
protocDep = 'com.google.protobuf:protoc:2.6.1'

// Override the default 'src/main/proto' directory
protoSources('main').add fileTree('src/main/protobuf') {
// You can specify multiple sources for a sourceSet
protoSources 'main', fileTree('src/main/protobuf') {
include '**/*.proto'
include '**/*.protodevel'
}
protoSources 'main', fileTree('src/main/protocolbuffers') {
include '**/*.proto'
}

// Override the default 'src/test/proto' directory
protoSources('test').add fileTree('src/test/protocolbuffers') {
protoSources 'test', fileTree('src/test/protocolbuffers') {
include '**/*.proto'
}

Expand Down
3 changes: 3 additions & 0 deletions testProjectCustomProtoDir/src/main/java/Foo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public static List<MessageLite> getDefaultInstances() {
// 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());
// from src/main/protocolbuffers/more.proto
list.add(More.MoreMsg.getDefaultInstance());
list.add(More.Foo.getDefaultInstance());
return list;
}
}
7 changes: 7 additions & 0 deletions testProjectCustomProtoDir/src/main/protocolbuffers/more.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
message MoreMsg {
optional string bar = 1;
}

message Foo {
optional string stuff = 1;
}
2 changes: 1 addition & 1 deletion testProjectCustomProtoDir/src/test/java/FooTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
public class FooTest {
@org.junit.Test
public void testMainProtos() {
org.junit.Assert.assertEquals(6, Foo.getDefaultInstances().size());
org.junit.Assert.assertEquals(8, Foo.getDefaultInstances().size());
}

@org.junit.Test
Expand Down

0 comments on commit da528d5

Please sign in to comment.