Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.0.3
### Changes
- Add keep rules to prevent generated files to be sorted out by r8

## 1.0.2
### Changes
- Migrate to support Gradle 9.0 and higher
Expand Down
2 changes: 1 addition & 1 deletion gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'io.snabble'
version '1.0.2'
version '1.0.3'

publishing {
publications {
Expand Down
28 changes: 23 additions & 5 deletions gradle-plugin/src/main/kotlin/io/snabble/setup/DownloadTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import okhttp3.Request
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.io.File
import java.io.FileInputStream
import java.io.IOException
Expand Down Expand Up @@ -46,12 +49,23 @@ abstract class DownloadTask : DefaultTask() {
val response = OkHttpClientFactory.createOkHttpClient()
.newCall(
Request.Builder()
.url(url.get())
.build()
.url(url.get())
.build()
).execute()
if (response.isSuccessful) {
val progressLogger = ProgressLoggerWrapper(logger, services, "Manifest")
response.body.byteStream().safeToFileWithTempFile(target, progressLogger)

outputDir.get().asFile
.resolve("raw")
.resolve("keep.xml")
.writeText(
"""<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@raw/snabble_*" />
"""
)

} else {
logger.error("Failed to download '${url.get()}'. Server returned status ${response.code}")
}
Expand Down Expand Up @@ -129,7 +143,10 @@ abstract class DownloadTask : DefaultTask() {
* @throws IOException if an I/O error occurs
*/
@Throws(IOException::class)
private fun InputStream.safeToFileWithTempFile(destFile: File, progressLogger: ProgressLoggerWrapper) {
private fun InputStream.safeToFileWithTempFile(
destFile: File,
progressLogger: ProgressLoggerWrapper
) {
//create name of temporary file
val tempFile = File.createTempFile(destFile.name, ".part", destFile.parentFile)

Expand All @@ -147,7 +164,8 @@ abstract class DownloadTask : DefaultTask() {
} catch (e: IOException) {
throw IOException(
"Failed to move temporary file '${tempFile.absolutePath}' to destination " +
"file '${destFile.absolutePath}'.", e)
"file '${destFile.absolutePath}'.", e
)
}
}

Expand Down
Loading