Skip to content

Commit

Permalink
Clear warning for read descriptor file (#31)
Browse files Browse the repository at this point in the history
* Clear warning for read descriptor file

* Make ktlint happy
  • Loading branch information
devkanro authored Jun 16, 2020
1 parent 223cc0c commit 8db2a71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.bybutter.sisyphus.protobuf

import com.bybutter.sisyphus.io.replaceExtensionName
import com.bybutter.sisyphus.protobuf.primitives.FileDescriptorProto

interface ProtoFileMeta {
val name: String
val descriptor: FileDescriptorProto

fun readDescriptor(): FileDescriptorProto {
val descriptorFile = name.replaceExtensionName("proto", "pb")
this.javaClass.classLoader.getResourceAsStream(descriptorFile)?.use {
return FileDescriptorProto.parse(it)
} ?: throw IllegalStateException("Proto file descriptor '$descriptorFile' not found, check your classpath or recompile proto files.")
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bybutter.sisyphus.protobuf.compiler

import com.bybutter.sisyphus.api.resourceDefinition
import com.bybutter.sisyphus.io.replaceExtensionName
import com.bybutter.sisyphus.protobuf.ProtoFileMeta
import com.bybutter.sisyphus.protobuf.ProtoTypes
import com.bybutter.sisyphus.protobuf.primitives.FileDescriptorProto
Expand Down Expand Up @@ -31,7 +30,6 @@ class FileGenerator(override val parent: ProtobufGenerateContext, val descriptor
val fileMeta = "${kotlinFileNameWithoutExtension}FileMeta"
val internalKotlinName = "proto.internal.$kotlinName"
val fileMetaTypeName = ClassName(internalKotlinName, fileMeta)
val fileDescPath = protoFilePath.replaceExtensionName("proto", "pb")

override val documentation: String = """Generated by the protocol buffer dto plugin. DO NOT EDIT!
|file: $kotlinFilePath
Expand Down Expand Up @@ -131,9 +129,7 @@ class FileGenerator(override val parent: ProtobufGenerateContext, val descriptor
.addProperty(
PropertySpec.builder("descriptor", FileDescriptorProto::class)
.addModifiers(KModifier.OVERRIDE)
.initializer("%T.parse(this.javaClass.classLoader.getResourceAsStream(%S))",
FileDescriptorProto::class,
"$fileDescPath")
.initializer("readDescriptor()")
.build()
)
.addInitializerBlock(
Expand Down

0 comments on commit 8db2a71

Please sign in to comment.