-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(model-server): add endpoint /about
Show the server version in the endpoint. Link to the endpoint in the title bar.
- Loading branch information
Showing
17 changed files
with
282 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
dependencies { | ||
// This should ideally be `compileOnly` and not `implementation`. | ||
// The compiled `build-logic` should not bundle the plugin code. | ||
// The project applying code from "build-logic" should add the plugins themselves. | ||
// | ||
// But using `compileOnly` we run into https://github.com/gradle/gradle/issues/23709 | ||
// This is indirectly related to applying any settings plugin in our root "settings.gradle.kts". | ||
// ``` | ||
// plugins { | ||
// id("modelix-repositories") | ||
// } | ||
// ``` | ||
// Applying any settings plugin causes an `InstrumentingVisitableURLClassLoader` to be added as class loader. | ||
// It results in throwing "java.lang.NoClassDefFoundError: org/jetbrains/kotlin/gradle/plugin/KotlinPluginWrapper`. | ||
// | ||
// We therefore use `implementation` as a workaround and bundle the plugin code with "build-logic". | ||
// | ||
// Because we use `implementation` and not `compileOnly` only, | ||
// they must not add any of the Kotlin Gradle plugins again in the applying projects. | ||
// This means we must not call `alias(libs.plugins.kotlin.multiplatform)` | ||
// and `alias(libs.plugins.kotlin.jvm), which tries to add them again as plugins. | ||
// We just have to call `kotlin("multiplatform")` and `kotlin("jvm")` which just enables the plugins, | ||
// but uses the plugin code bundled with `build-logic`. | ||
implementation(libs.kotlin.gradlePlugin) | ||
} |
79 changes: 79 additions & 0 deletions
79
build-logic/src/main/kotlin/org/modelix/GenerateVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.modelix | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.get | ||
import org.gradle.kotlin.dsl.withType | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper | ||
|
||
/** | ||
* Causes code containing the Modelix version to be generated and used in a Kolin project. | ||
* The Kotlin project can be a JVM oder Multiplatform. | ||
*/ | ||
fun Project.registerVersionGenerationTask(packageName: String) { | ||
val packagePath = packageName.replace('.', '/') | ||
|
||
val generateVersionVariable = tasks.register("generateVersionVariable") { | ||
doLast { | ||
val fileContent = buildString { | ||
appendLine("package $packageName") | ||
appendLine() | ||
appendLine("""const val MODELIX_VERSION: String = "$version"""") | ||
if (project.name == "modelql-core") { | ||
appendLine("""@Deprecated("Use the new MODELIX_VERSION", replaceWith = ReplaceWith("MODELIX_VERSION"))""") | ||
appendLine("const val modelqlVersion: String = MODELIX_VERSION") | ||
} | ||
} | ||
val outputDir = layout.buildDirectory.dir("version_gen/$packagePath").get().asFile | ||
outputDir.mkdirs() | ||
outputDir.resolve("Version.kt").writeText(fileContent) | ||
} | ||
} | ||
|
||
// Generate version constant for Kotlin JVM projects | ||
plugins.withType<KotlinPluginWrapper> { | ||
extensions.configure<KotlinJvmProjectExtension> { | ||
sourceSets["main"].kotlin.srcDir(layout.buildDirectory.dir("version_gen")) | ||
} | ||
|
||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all { | ||
dependsOn(generateVersionVariable) | ||
} | ||
} | ||
|
||
// Generate version constant for Kotlin Multiplatform projects | ||
plugins.withType<KotlinMultiplatformPluginWrapper> { | ||
extensions.configure<KotlinMultiplatformExtension> { | ||
sourceSets.commonMain { | ||
kotlin.srcDir(layout.buildDirectory.dir("version_gen")) | ||
} | ||
} | ||
|
||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all { | ||
dependsOn(generateVersionVariable) | ||
} | ||
|
||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon>().all { | ||
dependsOn(generateVersionVariable) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
plugins { | ||
alias(libs.plugins.kotlin.multiplatform) | ||
kotlin("multiplatform") | ||
} | ||
|
||
kotlin { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
model-server/src/main/kotlin/org/modelix/model/server/handlers/AboutApiImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.modelix.model.server.handlers | ||
|
||
import io.ktor.server.application.ApplicationCall | ||
import io.ktor.server.application.call | ||
import io.ktor.server.response.respond | ||
import io.ktor.util.pipeline.PipelineContext | ||
import org.modelix.api.operative.AboutApi | ||
import org.modelix.api.operative.AboutV1 | ||
import org.modelix.model.server.MODELIX_VERSION | ||
|
||
/** | ||
* Responding information about the model server. | ||
*/ | ||
class AboutApiImpl : AboutApi() { | ||
override suspend fun PipelineContext<Unit, ApplicationCall>.getAboutInformationV1() { | ||
val about = AboutV1(MODELIX_VERSION) | ||
call.respond(about) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.