Skip to content

Commit

Permalink
Merge pull request #3 from spine-examples/codegen-plugin
Browse files Browse the repository at this point in the history
Separate modules for plugin and ProtoData model
  • Loading branch information
Oleg-Melnik authored Oct 26, 2023
2 parents 2bd5e10 + deda2cc commit ceb3eb7
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .idea/live-templates/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 39 additions & 39 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


import Build_gradle.Module
import com.google.protobuf.gradle.protobuf
import io.spine.internal.dependency.ErrorProne
import io.spine.internal.dependency.Protobuf
import io.spine.internal.dependency.Spine
import io.spine.internal.dependency.ErrorProne
import io.spine.internal.gradle.javac.configureErrorProne
import io.spine.internal.gradle.javac.configureJavac
import io.spine.internal.gradle.kotlin.applyJvmToolchain
import io.spine.internal.gradle.kotlin.setFreeCompilerArgs
import io.spine.internal.gradle.standardToSpineSdk
import org.gradle.api.Project
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
Expand All @@ -53,56 +49,56 @@ plugins {
idea
}

repositories {
mavenLocal()
standardToSpineSdk()
object BuildSettings {
private const val JAVA_VERSION = 11

val javaVersion: JavaLanguageVersion = JavaLanguageVersion.of(JAVA_VERSION)
}

dependencies {
// Depend on Spine Base to grab the Proto options
// from `spine/options.proto`.
api(Spine.base)
// It is assumed that every module in the project requires
// a typical configuration.
allprojects {

Protobuf.libs.forEach { implementation(it) }
repositories.standardToSpineSdk()

ErrorProne.apply {
errorprone(core)
apply {
plugin("kotlin")
plugin("net.ltgt.errorprone")
plugin("detekt-code-analysis")
plugin("com.google.protobuf")
plugin("io.spine.protodata")
plugin("idea")
}
}

// Uncomment the following section
// to add ProtoData plugins:
dependencies {
api(Spine.base)

/*
protoData {
plugins(
"com.acme.MyProtoDataPlugin",
"com.bar.AnotherProtoDataPlugin"
)
}
*/
Protobuf.libs.forEach { implementation(it) }

protobuf {
protoc {
artifact = Protobuf.compiler
ErrorProne.apply {
errorprone(core)
}
}
}

object BuildSettings {
private const val JAVA_VERSION = 11
protobuf {
protoc {
artifact = Protobuf.compiler
}
}

val javaVersion: JavaLanguageVersion = JavaLanguageVersion.of(JAVA_VERSION)
// Apply a typical configuration to every module.
applyConfiguration()
}

/**
* The alias for typed extensions functions related to modules of this project.
*/
typealias Module = Project

project.run {
fun Module.applyConfiguration() {
configureJava()
configureKotlin()
setupTests()
setUpTests()
applyGeneratedDirectories()
}

Expand All @@ -119,12 +115,16 @@ fun Module.configureKotlin() {
}
}

fun Module.setupTests() {
fun Module.setUpTests() {
tasks.test {
useJUnitPlatform()

testLogging {
events = setOf(TestLogEvent.PASSED, TestLogEvent.FAILED, TestLogEvent.SKIPPED)
events = setOf(
TestLogEvent.PASSED,
TestLogEvent.FAILED,
TestLogEvent.SKIPPED
)
showExceptions = true
showCauses = true
}
Expand All @@ -149,8 +149,8 @@ fun Module.configureJava() {
}

/**
* Adds directories with the generated source code to source sets of the project and
* to IntelliJ IDEA module settings.
* Adds directories with the generated source code to source sets
* of the project and to IntelliJ IDEA module settings.
*/
fun Module.applyGeneratedDirectories() {

Expand Down
32 changes: 32 additions & 0 deletions codegen-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import io.spine.internal.dependency.ProtoData

dependencies {
// To use ProtoData API in code generation plugin.
api(ProtoData.compiler)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.protodata.hello

import io.spine.protodata.plugin.Plugin
import io.spine.protodata.renderer.Renderer

public class CodeGenPlugin : Plugin {
override fun renderers(): List<Renderer<*>> {
return emptyList()
}
}
36 changes: 36 additions & 0 deletions model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* * Copyright 2023, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

dependencies {
// Add module with code generation plugin to ProtoData classpath.
protoData(project(":codegen-plugin"))
}

protoData {
// Deploy the code generation plugin to ProtoData.
plugins(
"io.spine.protodata.hello.CodeGenPlugin"
)
}
7 changes: 6 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

rootProject.name = "Hello-ProtoData"
rootProject.name = "Hello-ProtoData"

include(
"codegen-plugin",
"model"
)

0 comments on commit ceb3eb7

Please sign in to comment.