@@ -134,9 +134,8 @@ fun writeParameters(
134
134
135
135
private fun validateConfig (config : BenchmarkConfiguration ) {
136
136
config.reportFormat?.let {
137
- val validFormats = setOf (" json" , " csv" , " scsv" , " text" )
138
- require(it.toLowerCase() in validFormats) {
139
- " Invalid report format: '$it '. Accepted formats: ${validFormats.joinToString(" , " )} (e.g., reportFormat = 'json')."
137
+ require(it.toLowerCase() in ValidOptions .format) {
138
+ " Invalid report format: '$it '. Accepted formats: ${ValidOptions .format.joinToString(" , " )} (e.g., reportFormat = \" json\" )."
140
139
}
141
140
}
142
141
@@ -162,26 +161,23 @@ private fun validateConfig(config: BenchmarkConfiguration) {
162
161
}
163
162
164
163
config.iterationTimeUnit?.let {
165
- val validTimeUnits = setOf (" seconds" , " s" , " microseconds" , " us" , " milliseconds" , " ms" , " nanoseconds" , " ns" , " minutes" , " m" )
166
- require(it.toLowerCase() in validTimeUnits) {
167
- " Invalid iterationTimeUnit: '$it '. Accepted units: ${validTimeUnits.joinToString(" , " )} (e.g., iterationTimeUnit = 'ms')."
164
+ require(it in ValidOptions .timeUnits) {
165
+ " Invalid iterationTimeUnit: '$it '. Accepted units: ${ValidOptions .timeUnits.joinToString(" , " )} (e.g., iterationTimeUnit = \" ms\" )."
168
166
}
169
167
require(config.iterationTime != null ) {
170
168
" Missing iterationTime. Please provide iterationTime when specifying iterationTimeUnit."
171
169
}
172
170
}
173
171
174
172
config.mode?.let {
175
- val validModes = setOf (" thrpt" , " avgt" )
176
- require(it.toLowerCase() in validModes) {
177
- " Invalid benchmark mode: '$it '. Accepted modes: ${validModes.joinToString(" , " )} (e.g., mode = 'thrpt')."
173
+ require(it in ValidOptions .modes) {
174
+ " Invalid benchmark mode: '$it '. Accepted modes: ${ValidOptions .modes.joinToString(" , " )} (e.g., mode = \" thrpt\" )."
178
175
}
179
176
}
180
177
181
178
config.outputTimeUnit?.let {
182
- val validTimeUnits = setOf (" seconds" , " s" , " microseconds" , " us" , " milliseconds" , " ms" , " nanoseconds" , " ns" , " minutes" , " m" )
183
- require(it.toLowerCase() in validTimeUnits) {
184
- " Invalid outputTimeUnit: '$it '. Accepted units: ${validTimeUnits.joinToString(" , " )} (e.g., outputTimeUnit = 'ns')."
179
+ require(it in ValidOptions .timeUnits) {
180
+ " Invalid outputTimeUnit: '$it '. Accepted units: ${ValidOptions .timeUnits.joinToString(" , " )} (e.g., outputTimeUnit = \" ns\" )."
185
181
}
186
182
}
187
183
@@ -207,38 +203,49 @@ private fun validateConfig(config: BenchmarkConfiguration) {
207
203
}
208
204
209
205
config.advanced.forEach { (param, value) ->
210
- println (" Validating advanced param: $param with value: $value " )
211
206
require(param.isNotBlank()) {
212
- " Invalid advanced config param : '$param '. It must not be blank."
207
+ " Invalid advanced option name : '$param '. It must not be blank."
213
208
}
214
209
require(value.toString().isNotBlank()) {
215
- " Invalid value for param '$param ': '$value '. Value should not be blank."
210
+ " Invalid value for advanced option '$param ': '$value '. Value should not be blank."
216
211
}
217
212
218
213
when (param) {
219
214
" nativeFork" -> {
220
- val validValues = setOf (" perbenchmark" , " periteration" )
221
- require(value.toString().toLowerCase() in validValues) {
222
- " Invalid value for 'nativeFork': '$value '. Accepted values: ${validValues.joinToString(" , " )} ."
215
+ require(value.toString() in ValidOptions .nativeForks) {
216
+ " Invalid value for 'nativeFork': '$value '. Accepted values: ${ValidOptions .nativeForks.joinToString(" , " )} ."
223
217
}
224
218
}
225
219
" nativeGCAfterIteration" -> require(value is Boolean ) {
226
220
" Invalid value for 'nativeGCAfterIteration': '$value '. Expected a Boolean value."
227
221
}
228
222
" jvmForks" -> {
229
223
val intValue = value.toString().toIntOrNull()
230
- require(intValue != null && intValue >= 0 || value.toString().toLowerCase() == " definedbyjmh " ) {
231
- " Invalid value for 'jvmForks': '$value '. Expected a non-negative integer or ' definedByJmh' ."
224
+ require(intValue != null && intValue >= 0 || value.toString() == " definedByJmh " ) {
225
+ " Invalid value for 'jvmForks': '$value '. Expected a non-negative integer or \" definedByJmh\" ."
232
226
}
233
227
}
234
228
" jsUseBridge" -> require(value is Boolean ) {
235
229
" Invalid value for 'jsUseBridge': '$value '. Expected a Boolean value."
236
230
}
237
- else -> throw IllegalArgumentException (" Invalid advanced config parameter : '$param '. Accepted parameters: ' nativeFork', ' nativeGCAfterIteration', ' jvmForks', ' jsUseBridge' ." )
231
+ else -> throw IllegalArgumentException (" Invalid advanced option name : '$param '. Accepted options: \" nativeFork\" , \" nativeGCAfterIteration\" , \" jvmForks\" , \" jsUseBridge\" ." )
238
232
}
239
233
}
240
234
}
241
235
236
+ private object ValidOptions {
237
+ val format = setOf (" json" , " csv" , " scsv" , " text" )
238
+ val timeUnits = setOf (
239
+ " NANOSECONDS" , " ns" , " nanos" ,
240
+ " MICROSECONDS" , " us" , " micros" ,
241
+ " MILLISECONDS" , " ms" , " millis" ,
242
+ " SECONDS" , " s" , " sec" ,
243
+ " MINUTES" , " m" , " min"
244
+ )
245
+ val modes = setOf (" thrpt" , " avgt" , " Throughput" , " AverageTime" )
246
+ val nativeForks = setOf (" perBenchmark" , " perIteration" )
247
+ }
248
+
242
249
internal val Gradle .isConfigurationCacheAvailable
243
250
get() = try {
244
251
val startParameters = gradle.startParameter
0 commit comments