Skip to content

Commit e2ae0de

Browse files
committed
add more options
1 parent 54e18da commit e2ae0de

4 files changed

Lines changed: 64 additions & 4 deletions

File tree

code-generator/shared/src/main/kotlin/com/javaaidev/easyllmtools/codegenerator/ReusableOptions.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ class ReusableOptions {
3030
)
3131
var artifactVersion: String = ""
3232

33+
@CommandLine.Option(
34+
names = ["--parent-group-id"],
35+
description = ["Parent group id"]
36+
)
37+
var parentGroupId: String = ""
38+
39+
@CommandLine.Option(
40+
names = ["--parent-artifact-id"],
41+
description = ["Parent artifact id"]
42+
)
43+
var parentArtifactId: String = ""
44+
45+
@CommandLine.Option(
46+
names = ["--parent-artifact-version"],
47+
description = ["Parent artifact version"]
48+
)
49+
var parentArtifactVersion: String = ""
50+
3351
@CommandLine.Option(
3452
names = ["--package-name"],
3553
defaultValue = "com.javaaidev.easyllmtools.tools.mytool",

code-generator/simple/src/main/kotlin/com/javaaidev/easyllmtools/codegenerator/simple/SimpleCodeGenerator.kt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ data class TemplateContext(
3232
val groupId: String,
3333
val artifactId: String,
3434
val artifactVersion: String,
35+
val hasParentProject: Boolean,
36+
val parentGroupId: String,
37+
val parentArtifactId: String,
38+
val parentArtifactVersion: String,
3539
val packageName: String,
3640
val specPackageName: String,
3741
val generatedSpecPackageName: String,
@@ -73,6 +77,11 @@ object SimpleCodeGenerator {
7377
packageName: String,
7478
outputDir: Path,
7579
overwriteToolImplementation: Boolean,
80+
overwritePomFile: Boolean,
81+
toolIdPrefix: String,
82+
parentGroupId: String,
83+
parentArtifactId: String,
84+
parentArtifactVersion: String,
7685
) {
7786
logger.info("Generate code from {}", inputSpec.toPath().toAbsolutePath().normalize())
7887
val jsonNode = objectMapper.readTree(inputSpec)
@@ -91,7 +100,7 @@ object SimpleCodeGenerator {
91100
val configurationJson = jsonNodeString(jsonNode.get("configuration"))
92101
val modelPackageName = "$packageName.model"
93102
val toolName = CaseUtils.toCamelCase(name, true)
94-
val toolId = definitionNode.get("id")?.textValue() ?: toolName
103+
val toolId = toolIdPrefix + (definitionNode.get("id")?.textValue() ?: toolName)
95104
val hasConfiguration = notEmptyJson(configurationJson)
96105
val configurationClassName =
97106
if (hasConfiguration) "${toolName}Configuration" else "Void"
@@ -126,10 +135,16 @@ object SimpleCodeGenerator {
126135
modelPackageName
127136
)
128137
}
138+
val hasParentProject =
139+
parentGroupId.isNotEmpty() && parentArtifactId.isNotEmpty() && parentArtifactVersion.isNotEmpty()
129140
val context = TemplateContext(
130141
groupId,
131142
artifactId,
132143
artifactVersion,
144+
hasParentProject,
145+
parentGroupId,
146+
parentArtifactId,
147+
parentArtifactVersion,
133148
packageName,
134149
"com.javaaidev.easyllmtools.llmtoolspec",
135150
modelPackageName,
@@ -156,7 +171,7 @@ object SimpleCodeGenerator {
156171
GeneratedFile("abstractTool", sourceDir) { "Abstract${toolName}.java" },
157172
GeneratedFile("toolFactory", sourceDir) { "${toolName}Factory.java" },
158173
GeneratedFile("tool", sourceDir, overwriteToolImplementation) { "${toolName}.java" },
159-
GeneratedFile("pom", outputDir) { "pom.xml" },
174+
GeneratedFile("pom", outputDir, overwritePomFile) { "pom.xml" },
160175
GeneratedFile(
161176
"services",
162177
servicesDir
@@ -166,8 +181,8 @@ object SimpleCodeGenerator {
166181
files.forEach { file ->
167182
val outputFile = file.dir.resolve(file.fileNameSupplier.get())
168183
if (outputFile.exists() && !file.overwrite) {
169-
logger.info("Skip generation of tool implementation")
170-
return
184+
logger.info("Skip generation of file {}", outputFile)
185+
return@forEach
171186
}
172187
val template = handlebars.compile(file.templateName)
173188
template.apply(context).run {

code-generator/simple/src/main/kotlin/com/javaaidev/easyllmtools/codegenerator/simple/SimpleCodeGeneratorCommand.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ class SimpleCodeGeneratorCommand : Callable<Int> {
1717
)
1818
var overwriteToolImplementation: Boolean = false
1919

20+
@CommandLine.Option(
21+
names = ["--overwrite-pom-file"],
22+
defaultValue = "false",
23+
description = ["Should pom file be overwritten"]
24+
)
25+
var overwritePomFile: Boolean = false
26+
27+
@CommandLine.Option(
28+
names = ["--tool-id-prefix"],
29+
defaultValue = "",
30+
description = ["Prefix of generated tool id"]
31+
)
32+
var toolIdPrefix = ""
33+
2034
override fun call(): Int {
2135
SimpleCodeGenerator.generate(
2236
options.inputSpec,
@@ -26,6 +40,11 @@ class SimpleCodeGeneratorCommand : Callable<Int> {
2640
options.packageName,
2741
options.outputDir.toPath(),
2842
overwriteToolImplementation,
43+
overwritePomFile,
44+
toolIdPrefix,
45+
options.parentGroupId,
46+
options.parentArtifactId,
47+
options.parentArtifactVersion,
2948
)
3049
return 0
3150
}

code-generator/simple/src/main/resources/template/pom.hbs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6+
{{#if hasParentProject}}
7+
<parent>
8+
<groupId>{{parentGroupId}}</groupId>
9+
<artifactId>{{parentArtifactId}}</artifactId>
10+
<version>{{parentArtifactVersion}}</version>
11+
</parent>
12+
{{/if}}
13+
614
<groupId>{{groupId}}</groupId>
715
<artifactId>{{artifactId}}</artifactId>
816
<version>{{artifactVersion}}</version>

0 commit comments

Comments
 (0)