@@ -71,50 +71,45 @@ abstract class GenerateTask : DefaultTask() {
71
71
72
72
@TaskAction
73
73
fun swaggerGenerate () {
74
- val platform = platform.orNull
75
- val specName = specName.orNull
76
- var packageName = packageName.orNull
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) })
77
80
78
- val inputFile = inputFile.get().asFile
79
- val outputDirectory = outputDirectory.orNull?.asFile
80
-
81
- val specVersion = specVersion.getOrElse(readVersionFromSpecfile(inputFile))
82
-
83
- val defaultOutputDir = File (project.buildDir, DEFAULT_OUTPUT_DIR )
84
- val headersToRemove = features?.headersToRemove?.orNull ? : emptyList()
81
+ val headersToRemove = features?.headersToRemove?.get() ? : emptyList()
85
82
86
83
println ("""
87
84
####################
88
85
Yelp Swagger Codegen
89
86
####################
90
- Platform ${' \t ' } ${ platform ? : " [ DEFAULT ] $DEFAULT_PLATFORM " }
91
- Package ${' \t ' } ${ packageName ? : " [ DEFAULT ] $DEFAULT_PACKAGE " }
92
- specName ${' \t ' } ${ specName ? : " [ DEFAULT ] $DEFAULT_NAME " }
93
- specVers ${' \t ' } ${ specVersion ? : " [ DEFAULT ] $DEFAULT_VERSION " }
87
+ Platform ${' \t ' } $platform
88
+ Package ${' \t ' } $packageName
89
+ specName ${' \t ' } $specName
90
+ specVers ${' \t ' } $specVersion
94
91
input ${" \t\t " } $inputFile
95
- output ${" \t\t " } ${ outputDirectory ? : " [ DEFAULT ] $defaultOutputDir " }
96
- groupId ${' \t ' } ${ packageName ? : " [ DEFAULT ] default " }
97
- artifactId ${' \t ' } ${ packageName ? : " [ DEFAULT ] com.codegen " }
92
+ output ${" \t\t " } $outputDirectory
93
+ groupId ${' \t ' } $packageName
94
+ artifactId ${' \t ' } $packageName
98
95
features ${' \t ' } ${headersToRemove.joinToString(separator = " ," , prefix = " [" , postfix = " ]" )}
99
96
""" .trimIndent())
100
97
101
- packageName = this .packageName.orNull ? : DEFAULT_PACKAGE
102
-
103
98
val params = mutableListOf<String >()
104
99
params.add(" -p" )
105
- params.add(platform ? : DEFAULT_PLATFORM )
100
+ params.add(platform.get() )
106
101
params.add(" -s" )
107
- params.add(specName ? : DEFAULT_NAME )
102
+ params.add(specName.get() )
108
103
params.add(" -v" )
109
- params.add(specVersion ? : DEFAULT_VERSION )
104
+ params.add(specVersion.get() )
110
105
params.add(" -g" )
111
- params.add(packageName.substringBeforeLast(' .' ))
106
+ params.add(packageName.get(). substringBeforeLast(' .' ))
112
107
params.add(" -a" )
113
- params.add(packageName.substringAfterLast(' .' ))
108
+ params.add(packageName.get(). substringAfterLast(' .' ))
114
109
params.add(" -i" )
115
- params.add(inputFile.toString())
110
+ params.add(inputFile.get().asFile. toString())
116
111
params.add(" -o" )
117
- params.add((outputDirectory ? : defaultOutputDir ).toString())
112
+ params.add((outputDirectory.get().asFile ).toString())
118
113
119
114
if (headersToRemove.isNotEmpty()) {
120
115
params.add(" -ignoreheaders" )
@@ -126,10 +121,8 @@ abstract class GenerateTask : DefaultTask() {
126
121
127
122
// Copy over the extra files.
128
123
val source = extraFiles.orNull?.asFile
129
- val destin = outputDirectory
130
- if (source != null && destin != null ) {
131
- source.copyRecursively(destin, overwrite = true )
132
- }
124
+ val destination = outputDirectory.get().asFile
125
+ source?.copyRecursively(destination, overwrite = true )
133
126
}
134
127
135
128
private fun readVersionFromSpecfile (specFile : File ): String {
0 commit comments