Skip to content

Commit

Permalink
Update kotlin template
Browse files Browse the repository at this point in the history
  • Loading branch information
ehyland committed Apr 15, 2023
1 parent 15811d7 commit 339014a
Show file tree
Hide file tree
Showing 41 changed files with 151 additions and 94 deletions.
9 changes: 4 additions & 5 deletions kotlin/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

/*
* This file was generated by the Gradle 'init' task.
*/

plugins {
id("example.kotlin-application-conventions")
}

dependencies {
implementation("org.apache.commons:commons-text")
implementation(platform(Dependencies.wireBom))
implementation(Dependencies.wireSchema)
implementation(Dependencies.kotlinxSerializationJson)
}

application {
Expand Down
29 changes: 28 additions & 1 deletion kotlin/app/src/main/kotlin/example/app/App.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
package example.app

import com.squareup.wire.schema.Location
import com.squareup.wire.schema.MessageType
import com.squareup.wire.schema.Schema
import com.squareup.wire.schema.SchemaLoader
import java.io.File
import java.nio.file.FileSystems

fun main() {
println("Yay!")
val schema = schema()
schema.protoFiles[0].types.forEach { type ->
val message = type as MessageType
println("message ${message.name} {")
message.declaredFields.forEach { field ->
var labels = ""
if (!field.isRequired && !field.isRepeated) labels += "optional "
if (field.isRepeated) labels += "repeated "

println(" ${labels}${field.type} ${field.name} = ${field.tag};")
}
println("}")
}
}

private fun schema(): Schema {
val schemaLoader = SchemaLoader(FileSystems.getDefault())
val root = File("app/src/main/proto").absolutePath
println(root)
schemaLoader.initRoots(listOf(Location.get(root)))
return schemaLoader.loadSchema()
}
23 changes: 23 additions & 0 deletions kotlin/app/src/main/proto/api.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto2";

package squareup.wire.sample;

message SampleMessage {
repeated string array = 1;
}

message SampleRequest {
optional string name = 1;
optional SampleMessage sample_message = 2;
}

message SampleResponse {
optional int32 age = 1;
}

// This is it. A really fantastic service interface.
service SampleApi {
// Call this RPC. You'll be glad you did!
rpc FirstRpc (SampleRequest) returns (SampleResponse);
rpc OtherOne (SampleRequest) returns (SampleResponse);
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion kotlin/bin/gradle
2 changes: 1 addition & 1 deletion kotlin/bin/jar
2 changes: 1 addition & 1 deletion kotlin/bin/jarsigner
2 changes: 1 addition & 1 deletion kotlin/bin/java
2 changes: 1 addition & 1 deletion kotlin/bin/javac
2 changes: 1 addition & 1 deletion kotlin/bin/javadoc
2 changes: 1 addition & 1 deletion kotlin/bin/javap
2 changes: 1 addition & 1 deletion kotlin/bin/jcmd
2 changes: 1 addition & 1 deletion kotlin/bin/jconsole
2 changes: 1 addition & 1 deletion kotlin/bin/jdb
2 changes: 1 addition & 1 deletion kotlin/bin/jdeprscan
2 changes: 1 addition & 1 deletion kotlin/bin/jdeps
2 changes: 1 addition & 1 deletion kotlin/bin/jfr
2 changes: 1 addition & 1 deletion kotlin/bin/jhsdb
2 changes: 1 addition & 1 deletion kotlin/bin/jimage
2 changes: 1 addition & 1 deletion kotlin/bin/jinfo
2 changes: 1 addition & 1 deletion kotlin/bin/jlink
2 changes: 1 addition & 1 deletion kotlin/bin/jmap
2 changes: 1 addition & 1 deletion kotlin/bin/jmod
2 changes: 1 addition & 1 deletion kotlin/bin/jpackage
2 changes: 1 addition & 1 deletion kotlin/bin/jps
2 changes: 1 addition & 1 deletion kotlin/bin/jrunscript
2 changes: 1 addition & 1 deletion kotlin/bin/jshell
2 changes: 1 addition & 1 deletion kotlin/bin/jstack
2 changes: 1 addition & 1 deletion kotlin/bin/jstat
2 changes: 1 addition & 1 deletion kotlin/bin/jstatd
2 changes: 1 addition & 1 deletion kotlin/bin/keytool
2 changes: 1 addition & 1 deletion kotlin/bin/rmiregistry
2 changes: 1 addition & 1 deletion kotlin/bin/serialver
41 changes: 41 additions & 0 deletions kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

repositories {
mavenCentral()
gradlePluginPortal()
}

plugins {
kotlin("jvm").version(Dependencies.kotlinVersion)
kotlin("plugin.serialization").version(Dependencies.kotlinVersion)
}

subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.kotlin.plugin.serialization")
apply(plugin = "application")


repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_17.toString()
targetCompatibility = JavaVersion.VERSION_17.toString()
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = JavaVersion.VERSION_17.toString()
}
}

tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
environment("ENVIRONMENT", "test")
}
}
25 changes: 17 additions & 8 deletions kotlin/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
/*
* This file was generated by the Gradle 'init' task.
*/
//
//plugins {
// // Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
// `kotlin-dsl`
//}
//
//repositories {
// // Use the plugin portal to apply community plugins in convention plugins.
// gradlePluginPortal()
//}
//
//dependencies {
// implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
//}

plugins {
// Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
`kotlin-dsl`
}

repositories {
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
}
// Use Maven Central for resolving dependencies.
mavenCentral()
}
2 changes: 1 addition & 1 deletion kotlin/buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* This settings file is used to specify which projects to include in your build-logic build.
*/

rootProject.name = "buildSrc"
//rootProject.name = "buildSrc"
8 changes: 8 additions & 0 deletions kotlin/buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Dependencies {
const val kotlinVersion ="1.8.20"
const val wireBom = "com.squareup.wire:wire-bom:4.5.5"
const val wireSchema = "com.squareup.wire:wire-schema:"
const val kotlinxSerializationJson = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0"

}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 339014a

Please sign in to comment.