blob: a23a3361e8b73d31bd207cbd2947296aa4f6e772 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import java.io.InputStream
import java.net.URI
import java.util.zip.GZIPInputStream
abstract class DownloadTarFile : DownloadArchiveFile<TarArchiveInputStream>() {
@get:Input
abstract val gunzip: Property<Boolean>
init {
gunzip.convention(url.map { it.path.endsWith(".tar.gz") })
}
abstract class CGitSource {
abstract val domain: Property<String>
abstract val projectPath: Property<String>
abstract val hash: Property<String>
fun toUrl(): URI {
return URI.create("https://${domain.get()}/${projectPath.get()}/snapshot/${hash.get()}.tar.gz")
}
}
fun cGit(configure: CGitSource.() -> Unit) {
stripRoot.convention(true)
url.set(
project.provider(
project.objects.newInstance(CGitSource::class.java).also(configure)::toUrl
)
)
}
override fun mapInputStream(inputStream: InputStream): TarArchiveInputStream {
return TarArchiveInputStream(
if (gunzip.get()) {
GZIPInputStream(inputStream, 8192)
} else {
inputStream
}
)
}
override fun nextEntry(stream: TarArchiveInputStream): String? {
return stream.nextTarEntry?.name
}
}
|