Skip to content

Commit

Permalink
Merge pull request #90 from utybo/76-remove-builder
Browse files Browse the repository at this point in the history
Remove builder (#76) + tests + dependencies update
  • Loading branch information
utybo authored Aug 30, 2023
2 parents 097a85c + 63f2963 commit 020c4cf
Show file tree
Hide file tree
Showing 48 changed files with 267 additions and 202 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
uses: codecov/codecov-action@v3
with:
files: "code-coverage/build/reports/jacoco/aggregatedCodeCoverage/aggregatedCodeCoverage.xml"
token: ${{ secrets.CODECOV_TOKEN }}

check-examples:
name: "Check examples"
Expand Down
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,41 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- **Experimental** Fundefs whose function is annotated with `@Fundef` can now be `put()` like any other component, e.g. `put(::myFundef)` ([#87](https://github.com/utybo/Tegral/pull/87))

- `tegral-prismakt-generator`

- A "shadow" JAR is now published in addition to the regular JAR. Recommendations for integrating PrismaKT Generator into Gradle projects have been updated to use this shadow JAR. ([#90](https://github.com/utybo/Tegral/pull/90))

### Changed

- `tegral-web-appdsl`

- Variations of `useConfiguration` renamed to avoid shadowing: ([#90](https://github.com/utybo/Tegral/pull/90))
- **BREAKING CHANGE**
- `useConfiguration<T>` -> `useConfigurationType<T>`
- `useConfiguration(T::class)` -> `useConfigurationClass(T::class)`

- Dependency updates ([#90](https://github.com/utybo/Tegral/pull/90))

| Dependency | Old version | New version |
| --: | -- | -- |
| Exposed | 0.41.1 | 0.42.0 |
| Hoplite | 2.7.4 | 2.7.5 |
| Jackson | 2.15.0 | 2.15.2 |
| Jimfs | 1.2 | 1.3.0 |
| JUnit | 5.9.2 | 5.10.0 |
| Kotlin | 1.8.21 | 1.9.10 |
| Kotlin Coroutines | 1.7.1 | 1.7.3 |
| Ktor | 2.3.0 | 2.3.3 |
| Lang3 | 3.12.0 | 3.13.0 |
| Swagger Core | 2.2.9 | 2.2.15 |
| Swagger UI | 4.15.5 | 5.3.1 |

### Removed

- `tegral-openapi-dsl`

- `Builder<T>` has been removed. Replace all remaining uses with Tegral Core's `Buildable<T>`.

## [0.0.4] - 2023-05-14

### Added
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ dependencies {
libs.plugins.gradleTestLogger,
libs.plugins.kotlinBcv,
libs.plugins.nodeGradle,
libs.plugins.licenser
libs.plugins.licenser,
libs.plugins.shadow
]

for (pluginDef in pluginsDef) {
Expand Down
43 changes: 26 additions & 17 deletions buildSrc/src/main/groovy/guru.zoroark.tegral.pktg-e2e-test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ plugins {
id 'project-report'
}

configurations {
generator {
canBeResolved true
canBeConsumed false
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.SHADOWED))
}
}
}

dependencies {
implementation libs.exposed.core
implementation libs.exposed.dao
Expand All @@ -16,10 +26,8 @@ dependencies {
implementation libs.sqlite

testImplementation project(":tegral-prismakt:tegral-prismakt-generator-tests-support")
}

configurations {
generator
generator project(path: ":tegral-prismakt:tegral-prismakt-generator")
}

sourceSets {
Expand All @@ -35,24 +43,25 @@ tasks.register('prismaGenerate', NpxTask) {
args = ["generate"]

inputs.file("prisma/schema.prisma")
inputs.files(configurations.generator)
outputs.dir(project.layout.buildDirectory.dir("prismakt-generator"))
}

tasks.register('runGeneratorInternal', JavaExec) {
mainClass = "guru.zoroark.tegral.prismakt.generator.MainKt"
classpath = configurations.generator
standardInput = System.in

outputs.upToDateWhen { false }
}

jacoco {
applyTo runGeneratorInternal
outputs.file(layout.buildDirectory.file("jacoco/generator.exec"))

dependsOn configurations.jacocoAgent
dependsOn configurations.generator

environment = providers.provider {
// Agent file retrieval based on JacocoAgentJar.getJar from the Gradle JaCoCo plugin
def jacocoAgentFile = zipTree(configurations.jacocoAgent.singleFile).find { it.name.equals("jacocoagent.jar") }
def command = "java " +
"-javaagent:" + jacocoAgentFile + "=destfile=" + layout.buildDirectory.file("jacoco/generator.exec").get().asFile.absolutePath +
" -jar " + configurations.generator.find { it.name.endsWith(".jar") }
println("Generated KT command: " + command)
return ["PRISMAKT_CMD": command]
}
}

tasks.register('generatorCodeCoverage', JacocoReport) {
executionData runGeneratorInternal
executionData layout.buildDirectory.file("jacoco/generator.exec")
sourceSets sourceSets.main

dependsOn(tasks.prismaGenerate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ publishing {
afterEvaluate {
for (requiredExtProp in ['humanName', 'description', 'url']) {
if (!project.extensions.extraProperties.properties.containsKey(requiredExtProp)) {
throw new Exception("Missing projet.ext." + requiredExtProp)
throw new Exception("Missing project.ext." + requiredExtProp)
}
}
name = project.ext.humanName
Expand Down
21 changes: 21 additions & 0 deletions docs/blog/2023-12-31-tegral-005/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,24 @@ tegral {
```

For more information on this, refer to the [Tegral Featureful document](/docs/modules/core/featureful#feature-types)

## Misc. breaking changes

The various variations of the `useConfiguration` functions available in the `tegral {}` block have been renamed. As a reminder, these functions allow you to further configure [Hoplite](https://github.com/sksamuel/hoplite) by changing the configuration class, adding property sources (i.e. adding config files), etc.

```kotlin
tegral {
// Previously: useConfiguration<MyConfigClass> { ... }
useConfigurationType<MyConfigClass> { ... }

// Previously: useConfiguration(MyConfigClass::class) { ... }
useConfigurationClass(MyConfigClass::class) { ... }

// This syntax, without a type nor a class, does not change
useConfiguration { ... }
}
```

## Dependency updates

Several dependencies have been updated, including an update from Kotlin 1.8.20 to Kotlin 1.9.
43 changes: 25 additions & 18 deletions docs/docs/modules/core/prismakt/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ This part will focus on creating a two-way integration between Gradle and Prisma
sequenceDiagram
Something ->>+ Gradle: Compile Kotlin files
Gradle ->>+ Prisma: Call prisma generate
Prisma ->>+ Gradle: Call runGeneratorInternal
Gradle ->>- Prisma: Done
Prisma ->>+ PrismaKT: Run
PrismaKT ->>- Prisma: Done
Prisma ->>- Gradle: Done
Gradle ->>- Something: Done
```

In a nutshell, we'll set Prisma to use Gradle to generate the code, and Gradle to call Prisma when we need to compile Kotlin code.
In a nutshell, we'll use Gradle to manage PrismaKT, and give Prisma a command to call said PrismaKT.

### Gradle setup

Expand All @@ -106,7 +106,16 @@ plugins {
}
configurations {
generator
// A configuration that we'll use to depend on
generator {
// This is a configuration intended to be resolved (i.e. retrieve dependencies) and not consumed by others.
canBeConsumed false
canBeResolved true
// We want to get the full JAR, so we need to configure the attributes for this configuration to do so
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.SHADOWED))
}
}
}
dependencies {
Expand All @@ -116,17 +125,6 @@ dependencies {
generator "guru.zoroark.tegral:tegral-prismakt-generator:VERSION"
}
// Set up for running the generator
tasks.register('runGeneratorInternal', JavaExec) {
mainClass = "guru.zoroark.tegral.prismakt.generator.MainKt"
classpath = configurations.generator
standardInput = System.in
// This forces Gradle to always rerun the generator no matter what when Prisma launches it
outputs.upToDateWhen { false }
}
// Set up for letting Gradle call 'prisma generate' and take its results into account
sourceSets {
main {
Expand All @@ -136,6 +134,7 @@ sourceSets {
}
}
// Ensure `prisma generate` is called before compiling any Kotlin code that may rely on the generated code
tasks.compileKotlin.dependsOn prismaGenerate
tasks.compileTestKotlin.dependsOn prismaGenerate
Expand All @@ -144,8 +143,16 @@ tasks.register('prismaGenerate', NpxTask) {
args = ["generate"]
inputs.file("prisma/schema.prisma")
inputs.files(configurations.generator)
outputs.dir(project.layout.buildDirectory.dir("prismakt-generator"))
dependsOn configurations.generator
// Created via providers.provider for lazy evaluation, otherwise this would
// retrieve information from configurations before their resolution
environment = providers.provider {
def command = "java -jar " + configurations.generator.find { it.name.endsWith(".jar") }
return ["PRISMAKT_CMD": command]
}
}
```

Expand All @@ -155,15 +162,15 @@ In your `prisma/schema.prisma` file, add (or replace the current generator with)

```prisma
generator prismakt {
provider = "gradle --console=plain -q runGeneratorInternal"
provider = env("PRISMAKT_CMD")
output = "../build/prismaGeneratedSrc"
exposedTarget = "sql"
}
```

If you want Tegral to generate DAO bindings, use `exposedTarget = "dao"`, otherwise use `exposedTarget = "sql"`

### Testing things out
## Testing things out

You should now be able to run PrismaKT, either by running `prisma generate` (when using JBang) or `gradle prismaGenerate` (when using Gradle).

Expand Down
8 changes: 4 additions & 4 deletions docs/docs/modules/web/appdsl/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Applications ran with AppDSL can be configured using a number of ways (in a desc
Your application's configuration is parsed into a data class that implements `RootConfig`. By default, said data class only contains a `tegral` field (as this field is used by all Tegral features for configuration), but you can also define your own class by:

- Having it implement `RootConfig` (this is once again to ensure that there is a `tegral` field present)
- Using `useConfiguration<...>()` within the `tegral { }` block to specify the class.
- Using `useConfigurationType<...>()` or `useConfigurationClass(...)` within the `tegral { }` block to specify the class.

```kotlin
data class MyConfig(
Expand All @@ -76,7 +76,7 @@ class FoobarService(scope: InjectionScope) {

fun main() {
val app = tegral {
useConfiguration<MyConfig>()
useConfigurationType<MyConfig>()

put(::FoobarService)
}
Expand All @@ -85,13 +85,13 @@ fun main() {

### Configuring Hoplite

You can also further configure Hoplite by passing a lambda to `useConfiguration()`:
You can also further configure Hoplite by passing a lambda to `useConfiguration()`, `useConfigurationClass(...)` or `useConfigurationType<...>()`:

```kotlin
fun main() {
tegral {
// highlight-start
useConfiguration<MyConfig> { // this: ConfigLoaderBuilder
useConfigurationType<MyConfig> { // this: ConfigLoaderBuilder
// You can use any ConfigLoaderBuilder function here
}
// highlight-end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

package guru.zoroark.tegral.e2e.noconfig

import com.sksamuel.hoplite.addResourceSource
import guru.zoroark.tegral.config.core.RootConfig
import guru.zoroark.tegral.config.core.TegralConfig
import guru.zoroark.tegral.di.dsl.put
import guru.zoroark.tegral.di.environment.get
import guru.zoroark.tegral.web.appdsl.tegral
import guru.zoroark.tegral.web.appdsl.useConfigurationType
import guru.zoroark.tegral.web.controllers.KtorController
import io.ktor.client.HttpClient
import io.ktor.client.engine.java.Java
Expand All @@ -37,6 +42,11 @@ class Controller : KtorController() {
}
}

data class NoTegralSectionConfig(
override val tegral: TegralConfig,
val someProperty: String
) : RootConfig

class TestLaunch {
@Test
fun `Test launch without config`() {
Expand All @@ -54,4 +64,25 @@ class TestLaunch {
runBlocking { tegral.stop() }
}
}

@Test
fun `Test launch config without tegral block`() {
val tegral = tegral {
useConfigurationType<NoTegralSectionConfig> {
addResourceSource("/no-tegral-section.toml")
}
put(::Controller)
}
assertEquals("SomeValue", tegral.environment.get<NoTegralSectionConfig>().someProperty)
try {
HttpClient(Java).use {
val res = runBlocking {
it.get("http://localhost:8080/").bodyAsText()
}
assertEquals("Hello!", res)
}
} finally {
runBlocking { tegral.stop() }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
someProperty = "SomeValue"
Loading

1 comment on commit 020c4cf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.