Skip to content

Commit

Permalink
Bugfix Dsl marker insertions (#106)
Browse files Browse the repository at this point in the history
* prevent builder insertions from being generated when dsl markers are disabled

* update CHANGELOG.md
  • Loading branch information
marcoferrer authored Feb 4, 2020
1 parent aad7b71 commit 7b6e0f5
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 0.6.1
_2020-02-03_

#### Proto Builders (DSL)
* Fix: Dsl marker interfaces are properly omitted from generated code when disabled [PR-106](https://github.com/marcoferrer/kroto-plus/pull/106)

## Version 0.6.0
_2019-12-26_
* New: Update to Kotlin `1.3.61` [PR-97](https://github.com/marcoferrer/kroto-plus/pull/97)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ subprojects{ subproject ->
apply plugin: 'idea'

group = 'com.github.marcoferrer.krotoplus'
version = '0.6.0'
version = '0.6.1'

if(!subproject.path.contains("test-api")){
apply plugin: 'kotlin'
Expand Down
2 changes: 1 addition & 1 deletion example-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
"grpc" : '1.23.0',
"kotlin" : '1.3.61',
"coroutines": '1.3.3',
"krotoplus" : '0.6.0'
"krotoplus" : '0.6.1'
]
}

Expand Down
10 changes: 9 additions & 1 deletion protoc-gen-kroto-plus/generator-tests/krotoPlusConfig.asciipb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ grpc_coroutines {
filter { exclude_path: "google/*" }
}
proto_builders {
filter { exclude_path: "google/*" }
filter {
exclude_path: "google/*"
exclude_path: "message/no_dsl_markers.proto*"
}
unwrap_builders: true
use_dsl_markers: true
}
proto_builders {
filter { include_path: "message/no_dsl_markers.proto*" }
unwrap_builders: true
use_dsl_markers: false
}
grpc_stub_exts {
support_coroutines: true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ import io.grpc.examples.helloworld.HelloRequest
import io.grpc.examples.helloworld.HelloWorldProtoDslBuilder
import io.grpc.examples.helloworld.orDefault
import org.junit.Test
import test.message.*
import test.message.ClassNameCollisionProtoBuilders
import test.message.L1Message2
import test.message.SomeProtoMessage1
import test.message.TestMessages
import test.message.TestMessagesDslBuilder
import test.message.anotherNestedMessage
import test.message.copy
import test.message.multi.MappedMessage
import test.message.nestedMessage
import test.message.nodslmarker.NoDslMarker
import test.message.plus
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

Expand All @@ -38,6 +47,15 @@ class ProtoBuildersGeneratorTests {
)
}

@Test
fun `Test No DSL marker insertion`(){
val expectedValue = 42
assertEquals(expectedValue,NoDslMarker { theField = expectedValue }.theField)
assert(NoDslMarker.Builder::class.java.interfaces.none { "DslBuilder" in it.name }) {
"Builder should not implement any dsl builder interfaces"
}
}

@Test
fun `Test nested message builder generation`(){
val value = "value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ import com.github.marcoferrer.krotoplus.generators.Generator.Companion.AutoGener
import com.github.marcoferrer.krotoplus.proto.ProtoFile
import com.github.marcoferrer.krotoplus.proto.ProtoMessage
import com.github.marcoferrer.krotoplus.proto.getGeneratedAnnotationSpec
import com.github.marcoferrer.krotoplus.utils.*
import com.github.marcoferrer.krotoplus.utils.addFunctions
import com.github.marcoferrer.krotoplus.utils.addTypes
import com.github.marcoferrer.krotoplus.utils.key
import com.github.marcoferrer.krotoplus.utils.toUpperCamelCase
import com.google.protobuf.DescriptorProtos
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Label.LABEL_REPEATED
import com.google.protobuf.compiler.PluginProtos
import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.LambdaTypeName
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.UNIT
import com.squareup.kotlinpoet.asClassName

object ProtoBuildersGenerator : Generator {

Expand All @@ -52,7 +63,7 @@ object ProtoBuildersGenerator : Generator {
.filterNot { it.isMapEntry }
.forEach { protoMessage ->
for (options in context.config.protoBuildersList) {
if (isFileToGenerate(protoMessage.protoFile.name,options.filter))
if (options.useDslMarkers && isFileToGenerate(protoMessage.protoFile.name,options.filter))
responseBuilder.addFile(protoMessage.buildDslInsertion())
}
}
Expand Down
11 changes: 11 additions & 0 deletions test-api/src/main/proto/message/no_dsl_markers.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

package message;

option java_package = "test.message.nodslmarker";
option java_multiple_files = true;
option java_outer_classname = "NoDslOuterName";

message NoDslMarker {
int32 the_field = 1;
}

0 comments on commit 7b6e0f5

Please sign in to comment.