diff --git a/CHANGELOG.md b/CHANGELOG.md index fef8f05..17821c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/build.gradle b/build.gradle index 2937165..614ea9d 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/example-project/build.gradle b/example-project/build.gradle index 6549574..72a0b0b 100644 --- a/example-project/build.gradle +++ b/example-project/build.gradle @@ -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' ] } diff --git a/protoc-gen-kroto-plus/generator-tests/krotoPlusConfig.asciipb b/protoc-gen-kroto-plus/generator-tests/krotoPlusConfig.asciipb index 6d56a3c..7783b1c 100644 --- a/protoc-gen-kroto-plus/generator-tests/krotoPlusConfig.asciipb +++ b/protoc-gen-kroto-plus/generator-tests/krotoPlusConfig.asciipb @@ -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 } diff --git a/protoc-gen-kroto-plus/generator-tests/src/test/kotlin/com/github/marcoferrer/krotoplus/generators/ProtoBuildersGeneratorTests.kt b/protoc-gen-kroto-plus/generator-tests/src/test/kotlin/com/github/marcoferrer/krotoplus/generators/ProtoBuildersGeneratorTests.kt index bb44730..ba38958 100644 --- a/protoc-gen-kroto-plus/generator-tests/src/test/kotlin/com/github/marcoferrer/krotoplus/generators/ProtoBuildersGeneratorTests.kt +++ b/protoc-gen-kroto-plus/generator-tests/src/test/kotlin/com/github/marcoferrer/krotoplus/generators/ProtoBuildersGeneratorTests.kt @@ -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 @@ -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" diff --git a/protoc-gen-kroto-plus/src/main/kotlin/com/github/marcoferrer/krotoplus/generators/ProtoBuildersGenerator.kt b/protoc-gen-kroto-plus/src/main/kotlin/com/github/marcoferrer/krotoplus/generators/ProtoBuildersGenerator.kt index 578aa7d..11cc283 100644 --- a/protoc-gen-kroto-plus/src/main/kotlin/com/github/marcoferrer/krotoplus/generators/ProtoBuildersGenerator.kt +++ b/protoc-gen-kroto-plus/src/main/kotlin/com/github/marcoferrer/krotoplus/generators/ProtoBuildersGenerator.kt @@ -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 { @@ -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()) } } diff --git a/test-api/src/main/proto/message/no_dsl_markers.proto b/test-api/src/main/proto/message/no_dsl_markers.proto new file mode 100644 index 0000000..9608ccf --- /dev/null +++ b/test-api/src/main/proto/message/no_dsl_markers.proto @@ -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; +} \ No newline at end of file