-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate JRE enum and dependent tests and add JAVA_24 (#3855)
* Generate code based on YaML file * Use Java Template Engine (JTE) * Add JRE.JAVA_24
- Loading branch information
1 parent
abf5ac3
commit 4c0fa63
Showing
30 changed files
with
644 additions
and
1,178 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
group = "junitbuild.base" | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} |
3 changes: 3 additions & 0 deletions
3
gradle/base/code-generator-model/src/main/kotlin/junitbuild/generator/model/JRE.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,3 @@ | ||
package junitbuild.generator.model | ||
|
||
data class JRE(val version: Int, val since: String?) |
30 changes: 30 additions & 0 deletions
30
gradle/base/code-generator-model/src/main/resources/jre.yaml
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,30 @@ | ||
- version: 8 | ||
- version: 9 | ||
- version: 10 | ||
- version: 11 | ||
- version: 12 | ||
since: '5.4' | ||
- version: 13 | ||
since: '5.4' | ||
- version: 14 | ||
since: '5.5' | ||
- version: 15 | ||
since: '5.6' | ||
- version: 16 | ||
since: '5.7' | ||
- version: 17 | ||
since: '5.7.1' | ||
- version: 18 | ||
since: '5.8.1' | ||
- version: 19 | ||
since: '5.9' | ||
- version: 20 | ||
since: '5.9' | ||
- version: 21 | ||
since: '5.9.2' | ||
- version: 22 | ||
since: '5.10' | ||
- version: 23 | ||
since: '5.11' | ||
- version: 24 | ||
since: '5.11' |
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,3 @@ | ||
rootProject.name = "base" | ||
|
||
include("code-generator-model") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation("junitbuild.base:code-generator-model") | ||
implementation(projects.common) | ||
implementation(libs.jackson.dataformat.yaml) | ||
implementation(libs.jackson.module.kotlin) | ||
implementation(libs.jte) | ||
} |
35 changes: 35 additions & 0 deletions
35
gradle/plugins/code-generator/src/main/kotlin/junitbuild.code-generator.gradle.kts
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 @@ | ||
import junitbuild.generator.GenerateJreRelatedSourceCode | ||
|
||
plugins { | ||
java | ||
} | ||
|
||
val templates by sourceSets.registering | ||
dependencies { | ||
add(templates.get().compileOnlyConfigurationName, dependencyFromLibs("jte")) | ||
add(templates.get().compileOnlyConfigurationName, "junitbuild.base:code-generator-model") | ||
} | ||
|
||
val license: License by rootProject.extra | ||
val rootTargetDir = layout.buildDirectory.dir("generated/sources/jte") | ||
val generateCode by tasks.registering | ||
|
||
sourceSets.named { it != templates.name }.configureEach { | ||
|
||
val sourceSetName = name | ||
val sourceSetTargetDir = rootTargetDir.map { it.dir(sourceSetName) } | ||
|
||
val task = tasks.register(getTaskName("generateJreRelated", "SourceCode"), GenerateJreRelatedSourceCode::class) { | ||
templateDir.convention(layout.dir(templates.map { | ||
it.resources.srcDirs.single().resolve(sourceSetName) | ||
})) | ||
targetDir.convention(sourceSetTargetDir) | ||
licenseHeaderFile.convention(license.headerFile) | ||
} | ||
|
||
java.srcDir(files(sourceSetTargetDir).builtBy(task)) | ||
|
||
generateCode { | ||
dependsOn(task) | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...ugins/code-generator/src/main/kotlin/junitbuild/generator/GenerateJreRelatedSourceCode.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,75 @@ | ||
package junitbuild.generator | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import gg.jte.ContentType | ||
import gg.jte.TemplateEngine | ||
import gg.jte.output.FileOutput | ||
import gg.jte.resolve.DirectoryCodeResolver | ||
import junitbuild.generator.model.JRE | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.CacheableTask | ||
import org.gradle.api.tasks.InputDirectory | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.PathSensitive | ||
import org.gradle.api.tasks.PathSensitivity | ||
import org.gradle.api.tasks.SkipWhenEmpty | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
@CacheableTask | ||
abstract class GenerateJreRelatedSourceCode : DefaultTask() { | ||
|
||
@get:InputDirectory | ||
@get:SkipWhenEmpty | ||
@get:PathSensitive(PathSensitivity.RELATIVE) | ||
abstract val templateDir: DirectoryProperty | ||
|
||
@get:OutputDirectory | ||
abstract val targetDir: DirectoryProperty | ||
|
||
@get:InputFile | ||
@get:PathSensitive(PathSensitivity.NONE) | ||
abstract val licenseHeaderFile: RegularFileProperty | ||
|
||
@TaskAction | ||
fun generateSourceCode() { | ||
val mainTargetDir = targetDir.get().asFile | ||
mainTargetDir.deleteRecursively() | ||
|
||
val templateDir = templateDir.get().asFile | ||
val codeResolver = DirectoryCodeResolver(templateDir.toPath()) | ||
val templateEngine = | ||
TemplateEngine.create(codeResolver, temporaryDir.toPath(), ContentType.Plain, javaClass.classLoader) | ||
|
||
val templates = templateDir.walkTopDown() | ||
.filter { it.extension == "jte" } | ||
.map { it.relativeTo(templateDir) } | ||
.toList() | ||
|
||
if (templates.isNotEmpty()) { | ||
val jres = javaClass.getResourceAsStream("/jre.yaml").use { input -> | ||
val mapper = ObjectMapper(YAMLFactory()) | ||
mapper.registerModule(KotlinModule.Builder().build()) | ||
mapper.readValue(input, object : TypeReference<List<JRE>>() {}) | ||
} | ||
val params = mapOf( | ||
"jres" to jres, | ||
"jresSortedByStringValue" to jres.sortedBy { it.version.toString() }, | ||
"licenseHeader" to licenseHeaderFile.asFile.get().readText() | ||
) | ||
templates.forEach { | ||
val targetFile = mainTargetDir.toPath().resolve(it.resolveSibling(it.nameWithoutExtension).path) | ||
|
||
FileOutput(targetFile).use { output -> | ||
templateEngine.render(it.path, params, output) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
plugins { | ||
id("junitbuild.kotlin-library-conventions") | ||
id("junitbuild.code-generator") | ||
`java-test-fixtures` | ||
} | ||
|
||
|
Oops, something went wrong.