Skip to content

SpineEventEngine/ProtoTap

Repository files navigation

ProtoTap — Gradle plugin for tapping Protobuf

Ubuntu build license

ProtoTap is a Gradle plugin that allows tapping output of Protobuf compiler used in the project to which the plugin is applied, and placing them as test resources.

This way authors of code generators can focus on writing tests rather than on "plumbing" with Protobuf Plugin for Gradle or creating a custom diagnostic plugin for Protobuf Compiler (protoc).

How it works

ProtoTap interacts with Protobuf Plugin for Gradle for copying generated code and related files to test resources of the project. Files are stored under the directory matching the following pattern:

$projectDir/build/resources/test/prototap/

Basic features

Automatic selection of a source set

When tuning code generation, the plugin attempts to find testFixtures source set in the project first. If not found, the plugin attempts to find the test source set.

Using other source sets requires explicit setting, as described in the section below.

Copying protoc output

The code generated by protoc will appear in corresponding subdirectories of the prototap. The name of the subdirectory matches the name of the corresponding protoc built-in or plugin. For example, for java built-in it would be:

my-project
  build
    resources
      test
        prototap
          java   <-- The output of `java` built-in of `protoc`.
            HelloWorld.java

After this, the code of your tests will be able to access the generated code as usual program resources.

Obtaining CodeGeneratorRequest file

CodeGeneratorRequest is passed by protoc to its plugins when .proto files are processed. ProtoTap stores the binary version of the request in the file named CodeGeneratorRequest.binbp next to the directories with the generated code:

my-project
  build
    resources
      test
        prototap
          java
          CodeGeneratorRequest.binbp  <—— The request file.

Simplest usage

Adding to your project via Kotlin DSL looks like this:

plugins {
    id("io.spine.prototap") version "$version"
}

The above snippet assumes that the plugin with the ID "com.google.protobuf" is already added and configured in your project.

Tip

For the latest ProtoTap version please see version.gradle.kts.

The plugin was developed and tested under Gradle 7.6.4.

Using plugin settings

You can tune ProtoTap by using the following DSL:

prototap {
    sourceSet.set(functionalTest)
    generateDescriptorSet.set(true)
}

The sourceSet property is for specifying a source set with the proto files of interest, other than testFixtures or test.

The generateDescriptorSet property makes the Protobuf Compiler produce a descriptor set file, which ProtoTap places next to CodeGeneratorRequest:

my-project
  build
    resources
      test
        prototap
          java
          CodeGeneratorRequest.binbp  
          FileDescriptorSet.binpb <—— The descriptor set file.

By default descriptor set files are not generated.

About

Utilities for tapping `protoc` output

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages 4