-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embed the Zipline app in Android app assets
This allows the app to function without the server running, or without ever having to had connect to the server in the past. It will also allow automated testing of these applications in the future.
- Loading branch information
1 parent
4cc6e10
commit cb055d8
Showing
13 changed files
with
191 additions
and
7 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
78 changes: 78 additions & 0 deletions
78
build-support/src/main/kotlin/app/cash/redwood/buildsupport/ZiplineAppAssetCopyTask.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,78 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.buildsupport | ||
|
||
import app.cash.zipline.ZiplineManifest | ||
import javax.inject.Inject | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.ArchiveOperations | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputFiles | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
private const val ZIPLINE_MANIFEST_JSON = "manifest.zipline.json" | ||
|
||
internal abstract class ZiplineAppAssetCopyTask | ||
@Inject constructor(private val archiveOperations: ArchiveOperations, | ||
): DefaultTask() { | ||
@get:InputFiles | ||
abstract val files: ConfigurableFileCollection | ||
|
||
@get:Input | ||
abstract val appName: Property<String> | ||
|
||
@get:OutputDirectory | ||
abstract val outputDirectory: DirectoryProperty | ||
|
||
@TaskAction | ||
fun execute() { | ||
val zipFile = files.singleFile | ||
val fileMap = archiveOperations.zipTree(zipFile) | ||
.files | ||
.associateBy { it.name } | ||
.toMutableMap() | ||
val inputManifestFile = checkNotNull(fileMap.remove(ZIPLINE_MANIFEST_JSON)) { | ||
"No zipline.manifest.json file found in input files ${fileMap.keys}" | ||
} | ||
val inputManifest = ZiplineManifest.decodeJson(inputManifestFile.readText()) | ||
val outputManifest = inputManifest.copy( | ||
unsigned = inputManifest.unsigned.copy( | ||
freshAtEpochMs = System.currentTimeMillis(), | ||
) | ||
) | ||
|
||
val outputDirectory = outputDirectory.get() | ||
outputDirectory.asFile.apply { | ||
deleteRecursively() | ||
mkdirs() | ||
} | ||
|
||
val outputManifestFile = outputDirectory.file("${appName.get()}.$ZIPLINE_MANIFEST_JSON").asFile | ||
outputManifestFile.writeText(outputManifest.encodeJson()) | ||
|
||
for (module in outputManifest.modules.values) { | ||
val inputFile = checkNotNull(fileMap.remove(module.url)) { | ||
"No ${module.url} file found in input files as specified by the manifest" | ||
} | ||
val outputFile = outputDirectory.file(module.sha256.hex()).asFile | ||
inputFile.copyTo(outputFile) | ||
} | ||
} | ||
} |
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
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