-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
176 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
build-logic/src/main/kotlin/ru/gribbirg/todoapp/tasks/ApkFileDetailsTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ru.gribbirg.todoapp.tasks | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import net.lingala.zip4j.ZipFile | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputDirectory | ||
import org.gradle.api.tasks.TaskAction | ||
import ru.gribbirg.todoapp.api.TelegramApi | ||
import ru.gribbirg.todoapp.utils.findApk | ||
import ru.gribbirg.todoapp.utils.roundTo | ||
import javax.inject.Inject | ||
|
||
abstract class ApkFileDetailsTask @Inject constructor( | ||
private val telegramApi: TelegramApi | ||
) : DefaultTask() { | ||
@get:InputDirectory | ||
abstract val apkDir: DirectoryProperty | ||
|
||
@get:Input | ||
abstract val token: Property<String> | ||
|
||
@get:Input | ||
abstract val chatId: Property<String> | ||
|
||
@get:Input | ||
abstract val enabledTask: Property<Boolean> | ||
|
||
@TaskAction | ||
fun sendDetails() { | ||
if (!enabledTask.get()) return | ||
|
||
val file = apkDir.get().findApk() | ||
|
||
val text = ZipFile(file) | ||
.fileHeaders | ||
.groupBy { it.fileName.split("/").first() } | ||
.map { it.key to it.value.sumOf { header -> header.uncompressedSize } / 1024.0 } | ||
.joinToString("\n") { | ||
"${it.first} - ${it.second.roundTo(2)} KB" | ||
} | ||
|
||
runBlocking { | ||
telegramApi.sendMessage( | ||
"Apk details:\n\n$text", | ||
token.get(), | ||
chatId.get() | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
build-logic/src/main/kotlin/ru/gribbirg/todoapp/utils/ApkFinder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ru.gribbirg.todoapp.utils | ||
|
||
import okio.FileNotFoundException | ||
import org.gradle.api.file.Directory | ||
|
||
internal fun Directory.findApk() = | ||
asFile | ||
.listFiles() | ||
?.firstOrNull { it.name.endsWith(".apk") } | ||
?: throw FileNotFoundException("Apk file not found in ${asFile.absolutePath}") |
Oops, something went wrong.