Skip to content

Commit 09bb00a

Browse files
committed
cleanup a bit the default value code
1 parent f5881d3 commit 09bb00a

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

gradle-plugin/plugin/src/main/java/com/yelp/codegen/plugin/CodegenPlugin.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ class CodegenPlugin : Plugin<Project> {
1010
"com.yelp.codegen.plugin requires Gradle version 5.4.1 or greater"
1111
}
1212

13-
val config = project.extensions.create("generateSwagger", GenerateTaskConfiguration::class.java, project)
13+
val config = project.extensions.create("generateSwagger", GenerateTaskConfiguration::class.java)
1414

1515
project.tasks.register("generateSwagger", GenerateTask::class.java) {
16-
it.platform = config.platform
17-
it.packageName = config.packageName
18-
it.specName = config.specName
19-
it.specVersion = config.specVersion
20-
it.inputFile = config.inputFile
21-
it.outputDir = config.outputDir
16+
it.platform.set(config.platform)
17+
it.packageName.set(config.packageName)
18+
it.specName.set(config.specName)
19+
it.specVersion.set(config.specVersion)
20+
it.inputFile.set(config.inputFile)
21+
it.outputDir.set(config.outputDir)
2222

23-
it.extraFiles = config.extraFiles
23+
it.extraFiles.set(config.extraFiles)
2424
it.features = config.features
2525
}
2626
}

gradle-plugin/plugin/src/main/java/com/yelp/codegen/plugin/GenerateTask.kt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ abstract class GenerateTask : DefaultTask() {
5757
@get:OutputDirectory
5858
@get:Optional
5959
@get:Option(option = "outputDir", description = "Configures path of the Generated code directory.")
60-
abstract val outputDirectory: DirectoryProperty
60+
abstract val outputDir: DirectoryProperty
6161

6262
@get:InputFiles
6363
@get:Optional
@@ -71,12 +71,12 @@ abstract class GenerateTask : DefaultTask() {
7171

7272
@TaskAction
7373
fun swaggerGenerate() {
74-
platform.convention(DEFAULT_PLATFORM)
75-
specName.convention(DEFAULT_NAME)
76-
packageName.convention(DEFAULT_PACKAGE)
77-
outputDirectory.convention(project.objects.directoryProperty().value(project.layout.buildDirectory.dir(DEFAULT_OUTPUT_DIR)))
78-
platform.convention(DEFAULT_PLATFORM)
79-
specName.convention(project.provider { readVersionFromSpecfile(inputFile.get().asFile) })
74+
val platform = platform.getOrElse(DEFAULT_PLATFORM)
75+
val specName = specName.getOrElse(DEFAULT_NAME)
76+
val packageName = packageName.getOrElse(DEFAULT_PACKAGE)
77+
val outputDir = outputDir.getOrElse(project.layout.buildDirectory.dir(DEFAULT_OUTPUT_DIR).get()).asFile
78+
val inputFile = inputFile.get().asFile
79+
val specVersion = specVersion.getOrElse(readVersionFromSpecfile(inputFile))
8080

8181
val headersToRemove = features?.headersToRemove?.get() ?: emptyList()
8282

@@ -89,27 +89,27 @@ abstract class GenerateTask : DefaultTask() {
8989
specName ${'\t'} $specName
9090
specVers ${'\t'} $specVersion
9191
input ${"\t\t"} $inputFile
92-
output ${"\t\t"} $outputDirectory
92+
output ${"\t\t"} $outputDir
9393
groupId ${'\t'} $packageName
9494
artifactId ${'\t'} $packageName
9595
features ${'\t'} ${headersToRemove.joinToString(separator = ",", prefix = "[", postfix = "]")}
9696
""".trimIndent())
9797

9898
val params = mutableListOf<String>()
9999
params.add("-p")
100-
params.add(platform.get())
100+
params.add(platform)
101101
params.add("-s")
102-
params.add(specName.get())
102+
params.add(specName)
103103
params.add("-v")
104-
params.add(specVersion.get())
104+
params.add(specVersion)
105105
params.add("-g")
106-
params.add(packageName.get().substringBeforeLast('.'))
106+
params.add(packageName.substringBeforeLast('.'))
107107
params.add("-a")
108-
params.add(packageName.get().substringAfterLast('.'))
108+
params.add(packageName.substringAfterLast('.'))
109109
params.add("-i")
110-
params.add(inputFile.get().asFile.toString())
110+
params.add(inputFile.toString())
111111
params.add("-o")
112-
params.add((outputDirectory.get().asFile).toString())
112+
params.add(outputDir.toString())
113113

114114
if (headersToRemove.isNotEmpty()) {
115115
params.add("-ignoreheaders")
@@ -121,8 +121,7 @@ abstract class GenerateTask : DefaultTask() {
121121

122122
// Copy over the extra files.
123123
val source = extraFiles.orNull?.asFile
124-
val destination = outputDirectory.get().asFile
125-
source?.copyRecursively(destination, overwrite = true)
124+
source?.copyRecursively(outputDir, overwrite = true)
126125
}
127126

128127
private fun readVersionFromSpecfile(specFile: File): String {

0 commit comments

Comments
 (0)