|
| 1 | +package org.springdoc.openapi.gradle.plugin |
| 2 | + |
| 3 | +import com.github.jengelman.gradle.plugins.processes.tasks.Fork |
| 4 | +import groovy.lang.MetaClass |
| 5 | +import org.codehaus.groovy.runtime.InvokerHelper |
| 6 | +import org.gradle.api.tasks.Internal |
| 7 | +import org.gradle.process.CommandLineArgumentProvider |
| 8 | + |
| 9 | +/** |
| 10 | + * Extends the Fork task from the gradle-processes plugin to be compatible with Gradle 7. |
| 11 | + * The functionality of the class remains exactly the same; it was just missing an annotation |
| 12 | + * on the [getArgumentProviders] method and the annotation is mandatory in Gradle 7. |
| 13 | + * |
| 14 | + * Since the original class is written in Groovy, we also need to implement some internal |
| 15 | + * Groovy methods that get added to Groovy classes via bytecode manipulation. |
| 16 | + */ |
| 17 | +open class AnnotatedFork : Fork() { |
| 18 | + private var metaClass: MetaClass? = null |
| 19 | + |
| 20 | + override fun invokeMethod(method: String?, args: Any?): Any? { |
| 21 | + return InvokerHelper.invokeMethod(this, method, args) |
| 22 | + } |
| 23 | + |
| 24 | + override fun getProperty(property: String?): Any? { |
| 25 | + return InvokerHelper.getProperty(this, property) |
| 26 | + } |
| 27 | + |
| 28 | + override fun getMetaClass(): MetaClass? { |
| 29 | + if (metaClass == null) { |
| 30 | + metaClass = InvokerHelper.getMetaClass(javaClass) |
| 31 | + } |
| 32 | + return metaClass |
| 33 | + } |
| 34 | + |
| 35 | + override fun setMetaClass(newMetaClass: MetaClass?) { |
| 36 | + metaClass = newMetaClass |
| 37 | + } |
| 38 | + |
| 39 | + @Internal |
| 40 | + override fun getArgumentProviders(): MutableList<CommandLineArgumentProvider>? { |
| 41 | + return super.getArgumentProviders() |
| 42 | + } |
| 43 | +} |
0 commit comments