com.gradleup.gr8.StripGradleApiTask.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gr8-plugin Show documentation
Show all versions of gr8-plugin Show documentation
The Gr8 Plugin packaged with all dependencies relocated
package com.gradleup.gr8
import com.gradleup.gr8.ZipHelper.buildZip
import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFile
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Opcodes
import java.io.File
abstract class StripGradleApiTask : DefaultTask() {
@get:InputFile
internal abstract val gradleApiJar: RegularFileProperty
@get:OutputFile
internal abstract val strippedGradleApiJar: RegularFileProperty
fun gradleApiJar(fileCollection: FileCollection) {
gradleApiJar.set(
project.layout.file(
project.provider {
fileCollection.files.single {
//println(it.name)
isGradleApi(it.name)
}
}
)
)
gradleApiJar.disallowChanges()
}
fun gradleApiJar(file: File) {
gradleApiJar.set(file)
gradleApiJar.disallowChanges()
}
fun gradleApiJar(regularFileProperty: RegularFileProperty) {
gradleApiJar.set(regularFileProperty)
gradleApiJar.disallowChanges()
}
fun strippedGradleApiJar(): Provider = strippedGradleApiJar
fun strippedGradleApiJar(file: File) {
strippedGradleApiJar.set(file)
strippedGradleApiJar.disallowChanges()
}
fun strippedGradleApiJar(regularFileProperty: RegularFileProperty) {
strippedGradleApiJar.set(regularFileProperty)
strippedGradleApiJar.disallowChanges()
}
@TaskAction
fun taskAction() {
buildZip(strippedGradleApiJar.asFile.get()) {
addZipFile(gradleApiJar.asFile.get()) {
if (entry.name.startsWith("org/gradle/internal/impldep/META-INF/")) {
skip()
}
}
}
}
companion object {
fun isGradleApi(name: String) = Regex("gradle-api-+[0-9.]*.jar").matches(name)
}
}