mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-28 18:10:38 +00:00
Exclude libsignal-client testing libraries
This commit is contained in:
parent
68b7416e57
commit
b92cbc6a7c
3 changed files with 91 additions and 4 deletions
53
buildSrc/src/main/kotlin/ExcludeFileFromJar.kt
Normal file
53
buildSrc/src/main/kotlin/ExcludeFileFromJar.kt
Normal file
|
@ -0,0 +1,53 @@
|
|||
import org.gradle.api.artifacts.transform.*
|
||||
import org.gradle.api.file.FileSystemLocation
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.PathSensitive
|
||||
import org.gradle.api.tasks.PathSensitivity
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.util.zip.ZipInputStream
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
@CacheableTransform
|
||||
abstract class JarFileExcluder : TransformAction<JarFileExcluder.Parameters> {
|
||||
interface Parameters : TransformParameters {
|
||||
@get:Input
|
||||
var excludeFilesByArtifact: Map<String, Set<String>>
|
||||
}
|
||||
|
||||
@get:PathSensitive(PathSensitivity.NAME_ONLY)
|
||||
@get:InputArtifact
|
||||
abstract val inputArtifact: Provider<FileSystemLocation>
|
||||
|
||||
override
|
||||
fun transform(outputs: TransformOutputs) {
|
||||
val fileName = inputArtifact.get().asFile.name
|
||||
for (entry in parameters.excludeFilesByArtifact) {
|
||||
if (fileName.startsWith(entry.key)) {
|
||||
val nameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."))
|
||||
excludeFiles(inputArtifact.get().asFile, entry.value, outputs.file("${nameWithoutExtension}.jar"))
|
||||
return
|
||||
}
|
||||
}
|
||||
outputs.file(inputArtifact)
|
||||
}
|
||||
|
||||
private fun excludeFiles(artifact: File, excludeFiles: Set<String>, jarFile: File) {
|
||||
ZipInputStream(FileInputStream(artifact)).use { input ->
|
||||
ZipOutputStream(FileOutputStream(jarFile)).use { output ->
|
||||
var entry = input.nextEntry
|
||||
while (entry != null) {
|
||||
if (!excludeFiles.contains(entry.name)) {
|
||||
output.putNextEntry(entry)
|
||||
input.copyTo(output)
|
||||
output.closeEntry()
|
||||
}
|
||||
|
||||
entry = input.nextEntry
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue