-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f72240
commit 81e5208
Showing
25 changed files
with
4,116 additions
and
26 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
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
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/io/hpkl/gradle/cli/CliJavaCodeGeneratorOptions.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
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/io/hpkl/gradle/cli/CliKotlinCodeGenerator.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,43 @@ | ||
package io.hpkl.gradle.cli | ||
|
||
import io.hpkl.gradle.codegen.kotlin.KotlinCodeGenerator | ||
import io.hpkl.gradle.codegen.kotlin.KotlinCodeGeneratorException | ||
import org.pkl.commons.cli.CliCommand | ||
import org.pkl.commons.cli.CliException | ||
import org.pkl.commons.createParentDirectories | ||
import org.pkl.commons.writeString | ||
import org.pkl.core.Closeables | ||
import org.pkl.core.ModuleSource | ||
import java.io.IOException | ||
|
||
class CliKotlinCodeGenerator(private val options: CliKotlinCodeGeneratorOptions) | ||
: CliCommand(options.base) { | ||
|
||
override fun doRun() { | ||
val builder = evaluatorBuilder() | ||
try { | ||
builder.build().use { evaluator -> | ||
for (moduleUri in options.base.normalizedSourceModules) { | ||
val moduleSource = ModuleSource.uri(moduleUri) | ||
val schema = evaluator.evaluateSchema(moduleSource) | ||
val codeGenerator = KotlinCodeGenerator(schema, moduleSource, options.toKotlinCodeGeneratorOptions()) | ||
try { | ||
for ((fileName, fileContents) in codeGenerator.output) { | ||
val outputFile = options.outputDir.resolve(fileName) | ||
try { | ||
outputFile.createParentDirectories().writeString(fileContents) | ||
} catch (e: IOException) { | ||
throw CliException("I/O error writing file `$outputFile`.\nCause: ${e.message}") | ||
} | ||
} | ||
} catch (e: KotlinCodeGeneratorException) { | ||
throw CliException(e.message!!) | ||
} | ||
} | ||
} | ||
} finally { | ||
Closeables.closeQuietly(builder.moduleKeyFactories) | ||
Closeables.closeQuietly(builder.resourceReaders) | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/kotlin/io/hpkl/gradle/cli/CliKotlinCodeGeneratorOptions.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 @@ | ||
package io.hpkl.gradle.cli | ||
|
||
import io.hpkl.gradle.codegen.java.JavaCodeGeneratorOptions | ||
import io.hpkl.gradle.codegen.kotlin.KotlinCodeGeneratorOptions | ||
import org.pkl.commons.cli.CliBaseOptions | ||
import java.nio.file.Path | ||
|
||
class CliKotlinCodeGeneratorOptions ( | ||
/** Base options shared between CLI commands. */ | ||
val base: CliBaseOptions, | ||
|
||
/** The directory where generated source code is placed. */ | ||
val outputDir: Path, | ||
|
||
/** The characters to use for indenting generated source code. */ | ||
val indent: String = " ", | ||
|
||
val durationClass : String, | ||
|
||
val dataSizeClass : String, | ||
|
||
val durationUnitClass : String, | ||
|
||
val dataSizeUnitClass : String, | ||
|
||
val mutableObjects: Boolean = false, | ||
|
||
/** Whether to generate Javadoc based on doc comments for Pkl modules, classes, and properties. */ | ||
val generateKdoc: Boolean = false, | ||
|
||
/** Whether to generate config classes for use with Spring Boot. */ | ||
val generateSpringBootConfig: Boolean = false, | ||
|
||
val springConfigAnnotation: String = "SpringConfigProperties", | ||
|
||
/** Whether to make generated classes implement [java.io.Serializable] */ | ||
val implementSerializable: Boolean = false, | ||
|
||
/** | ||
* A rename mapping for class names. | ||
* | ||
* When you need to have Java class or package names different from the default names derived from | ||
* Pkl module names, you can define a rename mapping, where the key is a prefix of the original | ||
* Pkl module name, and the value is the desired replacement. | ||
*/ | ||
val renames: Map<String, String> = emptyMap(), | ||
|
||
val generateAnnotationClasses: Boolean = false, | ||
|
||
val setDefaultValues: Boolean = false, | ||
|
||
val durationClassConverter: String? = null, | ||
|
||
val dataSizeConverter: String? = null | ||
) { | ||
@Suppress("DeprecatedCallableAddReplaceWith") | ||
@Deprecated("deprecated without replacement") | ||
fun toKotlinCodegenOptions() = toKotlinCodeGeneratorOptions() | ||
|
||
internal fun toKotlinCodeGeneratorOptions() = | ||
KotlinCodeGeneratorOptions( | ||
indent = indent, | ||
durationClass = durationClass, | ||
durationUnitClass = durationUnitClass, | ||
dataSizeClass = dataSizeClass, | ||
dataSizeUnitClass =dataSizeUnitClass, | ||
generateKdoc = generateKdoc, | ||
mutableObjects = mutableObjects, | ||
generateSpringBootConfig = generateSpringBootConfig, | ||
springConfigAnnotation = springConfigAnnotation, | ||
implementSerializable = implementSerializable, | ||
renames = renames, | ||
generateAnnotationClasses = generateAnnotationClasses, | ||
setDefaultValues = setDefaultValues, | ||
baseCliBaseOptions = base, | ||
durationClassConverter = durationClassConverter, | ||
dataSizeConverter = dataSizeConverter | ||
) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...radle/codegen/JavaCodeGeneratorOptions.kt → .../codegen/java/JavaCodeGeneratorOptions.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.hpkl.gradle.codegen | ||
package io.hpkl.gradle.codegen.java | ||
|
||
import org.pkl.commons.cli.CliBaseOptions | ||
|
||
|
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.