Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import java.net.URL
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.util.Properties

plugins {
kotlin("android")
Expand Down Expand Up @@ -32,7 +33,7 @@ tasks.getByName("clean", type = Delete::class) {
delete(file("release"))
}

val geoFilesDownloadDir = "src/main/assets"
val geoFilesDownloadDir = file("src/main/assets")

task("downloadGeoFiles") {

Expand All @@ -46,14 +47,26 @@ task("downloadGeoFiles") {
doLast {
geoFilesUrls.forEach { (downloadUrl, outputFileName) ->
val url = URL(downloadUrl)
val outputPath = file("$geoFilesDownloadDir/$outputFileName")
val outputPath = geoFilesDownloadDir.resolve(outputFileName)
outputPath.parentFile.mkdirs()
url.openStream().use { input ->
Files.copy(input, outputPath.toPath(), StandardCopyOption.REPLACE_EXISTING)
println("$outputFileName downloaded to $outputPath")
}
}
}

val skipDownloadGeoFiles = providers.provider {
val propsFile =
rootProject.file("local.properties").takeIf { it.exists() }
?: rootProject.file("gradle.properties")
val properties = Properties().apply { propsFile.inputStream().use { load(it) } }
properties.getProperty("skip.downloadGeoFiles").toBoolean() &&
geoFilesDownloadDir.exists() &&
geoFilesDownloadDir.listFiles().orEmpty().size == 3
Comment on lines +64 to +66
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

并不会,这里加了检查,如果设置了标记位且目标路径不为空才会跳过。
方便本地做开发,每次下载这几个文件很耗时。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那你这个PR的标题和内容说明也不对呀

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这实现的明明是当文件存在的时候才允许skipping

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得已经写得非常清楚了

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这标题和说明里可以一点都没提到会判断本地文件是否存在

}
// Skip the task when the flag is set.
onlyIf { !skipDownloadGeoFiles.get() }
}

afterEvaluate {
Expand Down
Loading