Skip to content

Commit 28df2ee

Browse files
committed
Use Gradle task to extract FastCSV license
1 parent 3f74e33 commit 28df2ee

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

junit-jupiter-params/junit-jupiter-params.gradle.kts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import junitbuild.extensions.javaModuleName
22
import net.ltgt.gradle.errorprone.errorprone
33
import net.ltgt.gradle.nullaway.nullaway
4-
import java.util.zip.ZipFile
54

65
plugins {
76
id("junitbuild.java-nullability-conventions")
@@ -40,42 +39,24 @@ tasks {
4039
""")
4140
}
4241
}
43-
fun copyFastCsvLicenseTo(file: File, configurations: List<FileCollection>) {
44-
val jarFile = configurations
45-
.flatMap { it.files }
46-
.firstOrNull { it.name.contains("fastcsv") }
47-
?: throw GradleException("Could not find FastCSV dependency JAR")
48-
49-
ZipFile(jarFile).use { zipFile ->
50-
val licenseEntry = zipFile.entries().toList()
51-
.firstOrNull { it.name == "META-INF/LICENSE" }
52-
?: throw GradleException("Could not find META-INF/LICENSE in FastCSV dependency JAR")
53-
54-
zipFile.getInputStream(licenseEntry).use { input ->
55-
file.outputStream().use { output ->
56-
input.copyTo(output)
57-
}
58-
}
42+
val extractFastCSVLicense by registering(Sync::class) {
43+
from(zipTree(project.configurations.shadowedClasspath.map { it.files.single { file -> file.name.contains("fastcsv") } })) {
44+
include("META-INF/LICENSE")
5945
}
46+
into(layout.buildDirectory.dir("fastcsv"))
6047
}
6148
shadowJar {
6249
val tempLicenseFile = projectDir.resolve("LICENSE-fastcsv")
6350

64-
doFirst {
65-
copyFastCsvLicenseTo(tempLicenseFile, configurations)
66-
}
67-
6851
relocate("de.siegmar.fastcsv", "org.junit.jupiter.params.shadow.de.siegmar.fastcsv")
6952

7053
from(projectDir) {
7154
include(tempLicenseFile.name)
7255
into("META-INF")
7356
}
7457

75-
doLast {
76-
if (tempLicenseFile.exists()) {
77-
tempLicenseFile.delete()
78-
}
58+
from(extractFastCSVLicense.map { it.destinationDir }) {
59+
rename { "LICENSE-fastcsv" }
7960
}
8061
}
8162
compileJava {

0 commit comments

Comments
 (0)