-
Notifications
You must be signed in to change notification settings - Fork 1
Gradle plugin with multi-spec support #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
35f4b26
feat: add Gradle plugin module with multi-spec support
halotukozak 1c4647e
chore: add .gitignore and remove build artifacts
halotukozak 44c85f8
Merge branch 'feat/client-generation' into feat/plugin
halotukozak 10df8ba
feat: add generateTo methods for output directory handling in generators
halotukozak 506cda9
refactor: consolidate generators into CodeGenerator and remove genera…
halotukozak 9ef0055
refactor: streamline test utilities and update Arrow dependency
halotukozak 630201e
ktlint
halotukozak d342e72
fix: remove unused packageName input from JustworksGenerateTask
halotukozak efd5c1a
refactor: address PR review feedback from MattK97
halotukozak e18237d
refactor: update ApiClientBaseGenerator modifiers and integrate share…
halotukozak 4a83801
refactor: extract cleanAndCreate utility for directory handling in Gr…
halotukozak 0cb23dd
refactor: extract reusable project setup methods in functional tests
halotukozak c3dfcc7
refactor: rename and replace `cleanAndCreate` with `recreateDirectory…
halotukozak 6bff1c7
feat: add Kover plugin and configure coverage for the plugin module
halotukozak d24c6dd
test: add unit tests for `recreateDirectory` extension function in `R…
halotukozak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,4 @@ | ||
| build/ | ||
| .gradle/ | ||
| .kotlin/ | ||
| .idea/ |
This file contains hidden or 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 hidden or 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
core/src/main/kotlin/com/avsystem/justworks/core/gen/CodeGenerator.kt
This file contains hidden or 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 @@ | ||
| package com.avsystem.justworks.core.gen | ||
|
|
||
| import com.avsystem.justworks.core.model.ApiSpec | ||
| import java.io.File | ||
|
|
||
| /** | ||
| * Facade that orchestrates model and client code generation, | ||
| * writing the produced files to the given output directory. | ||
| */ | ||
| object CodeGenerator { | ||
| data class Result(val modelFiles: Int, val clientFiles: Int) | ||
|
|
||
| fun generate( | ||
| spec: ApiSpec, | ||
| modelPackage: String, | ||
| apiPackage: String, | ||
| outputDir: File | ||
| ): Result { | ||
| val modelFiles = ModelGenerator(modelPackage).generate(spec) | ||
| modelFiles.forEach { it.writeTo(outputDir) } | ||
|
|
||
| val hasPolymorphicTypes = modelFiles.any { it.name == SerializersModuleGenerator.FILE_NAME } | ||
|
|
||
| val clientFiles = ClientGenerator(apiPackage, modelPackage).generate(spec, hasPolymorphicTypes) | ||
| clientFiles.forEach { it.writeTo(outputDir) } | ||
|
|
||
| return Result(modelFiles.size, clientFiles.size) | ||
| } | ||
|
|
||
| fun generateSharedTypes(outputDir: File): Int { | ||
| val files = ApiResponseGenerator.generate() + ApiClientBaseGenerator.generate() | ||
| files.forEach { it.writeTo(outputDir) } | ||
| return files.size | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,69 @@ | ||
| plugins { | ||
| kotlin("jvm") | ||
| `java-gradle-plugin` | ||
| `maven-publish` | ||
| id("org.jetbrains.kotlinx.kover") version "0.9.1" | ||
| } | ||
|
|
||
| kotlin { | ||
| jvmToolchain(21) | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":core")) | ||
| testImplementation(kotlin("test")) | ||
| } | ||
|
|
||
| gradlePlugin { | ||
| plugins { | ||
| create("justworks") { | ||
| id = "com.avsystem.justworks" | ||
| implementationClass = "com.avsystem.justworks.gradle.JustworksPlugin" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Functional test source set | ||
| val functionalTest by sourceSets.creating { | ||
| compileClasspath += sourceSets["main"].output | ||
| runtimeClasspath += sourceSets["main"].output | ||
| } | ||
|
|
||
| val functionalTestImplementation by configurations.getting { | ||
| extendsFrom(configurations["testImplementation"]) | ||
| } | ||
|
|
||
| val functionalTestRuntimeOnly by configurations.getting { | ||
| extendsFrom(configurations["testRuntimeOnly"]) | ||
| } | ||
|
|
||
| dependencies { | ||
| functionalTestImplementation(gradleTestKit()) | ||
| } | ||
|
|
||
| val functionalTestTask = | ||
| tasks.register<Test>("functionalTest") { | ||
| testClassesDirs = functionalTest.output.classesDirs | ||
| classpath = functionalTest.runtimeClasspath | ||
| useJUnitPlatform() | ||
| } | ||
|
|
||
| tasks.check { | ||
| dependsOn(functionalTestTask) | ||
| } | ||
|
|
||
| kover { | ||
| currentProject { | ||
| sources { | ||
| excludedSourceSets.add("functionalTest") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.named("koverXmlReport") { | ||
| dependsOn(functionalTestTask) | ||
| } | ||
|
|
||
| tasks.test { | ||
| useJUnitPlatform() | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.