Skip to content

Instantly share code, notes, and snippets.

@martinbonnin
Last active May 29, 2019 17:24
Show Gist options
  • Save martinbonnin/3fc42a5bc315583a2efd1398156fdd27 to your computer and use it in GitHub Desktop.
Save martinbonnin/3fc42a5bc315583a2efd1398156fdd27 to your computer and use it in GitHub Desktop.
#!/usr/bin/env kscript
import okhttp3.OkHttpClient
import okhttp3.Request
import java.util.logging.Level
import java.util.logging.Logger
//DEPS com.squareup.okhttp3:okhttp:3.14.1
object Versions {
const val kotlin = "1.3.31"
}
val supportLibVersion = "28.0.0"
val commonDeps = listOf(
"io.reactivex.rxjava2:rxjava:2.2.2",
"com.squareup.moshi:moshi:1.6.0",
"com.squareup.moshi:moshi-kotlin-codegen:1.6.0",
"com.jakewharton.timber:timber:4.7.1",
"org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}",
"junit:junit:4.12",
"com.annimon:stream:1.2.0",
"io.reactivex:rxandroid:1.2.1",
"io.reactivex.rxjava2:rxandroid:2.1.0",
"com.squareup.retrofit2:retrofit:2.4.0",
"ru.gildor.coroutines:kotlin-coroutines-retrofit:1.1.0",
"com.squareup.retrofit2:converter-gson:2.4.0",
"com.squareup.retrofit2:adapter-rxjava2:2.4.0",
"ar.com.hjg:pngj:2.1.0",
"com.squareup:kotlinpoet:0.5.0",
"com.squareup.okhttp3:okhttp:3.11.0",
"com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0",
"com.squareup.picasso:picasso:2.5.2",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1",
"org.jetbrains.kotlinx:kotlinx-coroutines-rx2:1.2.1",
"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1",
"com.squareup.okhttp3:okhttp:3.14.2",
"com.squareup.okhttp3:okhttp:3.14.1",
"com.squareup.okhttp3:okhttp:3.14.0",
"com.squareup.okhttp3:okhttp:3.13.1",
"com.squareup.okhttp3:okhttp:3.13.0",
"com.squareup.okhttp3:okhttp:3.12.2",
"com.squareup.okhttp3:okhttp:3.12.1",
"com.squareup.okhttp3:okhttp:3.12.0",
"com.squareup.okhttp3:okhttp:3.11.0",
"com.squareup.okhttp3:okhttp:3.10.0",
"com.squareup.okhttp3:okhttp:3.9.0",
"com.squareup.okhttp3:okhttp:3.8.0",
"com.squareup.okhttp3:okhttp:3.7.0",
"com.squareup.okhttp3:okhttp:3.6.0",
"com.google.code.gson:gson:2.8.5"
)
inner class Downloader(val baseUrl: String) {
var total_millis = 0L
var total_bytes = 0L
val okHttpClient = OkHttpClient.Builder().build()
fun download(dep: String, suffix: String): Boolean {
val s = dep.split(":")
val version = s[2]
val artifact = s[1]
val path = s[0].replace(".", "/")
val url = "$baseUrl/$path/$artifact/$version/$artifact-$version$suffix"
val request = Request.Builder().url(url).get().build()
//println("trying $url")
val startTime = System.currentTimeMillis()
val response = okHttpClient.newCall(request).execute()
if (!response.isSuccessful) {
response.close()
return false
}
val bytesTransfered = response.body().use {
it!!.bytes().size
}
val duration = System.currentTimeMillis() - startTime
// println(String.format("%-140s %6dkB in %6fs [%6fkB/s]",
// url,
// bytesTransfered / 1000,
// duration.toDouble() / 1000,
// bytesTransfered.toDouble() / 1000 / (duration.toDouble() / 1000)
// )
// )
total_bytes += bytesTransfered
total_millis += duration
return true
}
fun run() {
commonDeps
//.filter { !it.startsWith("com.google") && !it.startsWith("com.android") && !it.startsWith("androix") }
//.take(10)
.forEach {
if (!download(it, ".jar")) {
if (!download(it, ".aar")) {
println("Cannot download: $it")
}
}
if (!download(it, "-sources.jar")) {
println("Cannot download sources: $it")
}
if (!download(it, "-javadoc.jar")) {
println("Cannot download javadoc: $it")
}
}
println(String.format("%-140s %6dkB in %6fs [%6fkB/s]",
"TOTAL $baseUrl",
total_bytes / 1000,
total_millis.toDouble() / 1000,
total_bytes.toDouble() / 1000 / (total_millis.toDouble() / 1000)
))
}
}
Downloader("https://repo1.maven.org/maven2").run()
Downloader("https://jcenter.bintray.com").run()
Downloader("https://maven-central-eu.storage-download.googleapis.com/repos/central/data").run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment