diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2022-02-05 01:57:41 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-05 01:57:41 +0530 |
| commit | 664e1fbba06792c82ad2ce71d16ca687077e9c9a (patch) | |
| tree | c4dffa3e696538e8b14d41b5679cd5b981703ac7 /build-logic/automation-plugins/src/main/kotlin/psl/PSLUpdateTask.kt | |
| parent | 2b293e58056ea897c305bd39e21b42f5cd4d1a62 (diff) | |
| download | HardenedPass-664e1fbba06792c82ad2ce71d16ca687077e9c9a.tar.gz HardenedPass-664e1fbba06792c82ad2ce71d16ca687077e9c9a.zip | |
Begin rework for configuration cache compatibility (#1709)
Diffstat (limited to 'build-logic/automation-plugins/src/main/kotlin/psl/PSLUpdateTask.kt')
| -rw-r--r-- | build-logic/automation-plugins/src/main/kotlin/psl/PSLUpdateTask.kt | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/build-logic/automation-plugins/src/main/kotlin/psl/PSLUpdateTask.kt b/build-logic/automation-plugins/src/main/kotlin/psl/PSLUpdateTask.kt new file mode 100644 index 00000000..e8fdc498 --- /dev/null +++ b/build-logic/automation-plugins/src/main/kotlin/psl/PSLUpdateTask.kt @@ -0,0 +1,46 @@ +/* + * Copyright © 2014-2022 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package psl + +import okio.buffer +import okio.sink +import org.gradle.api.DefaultTask +import org.gradle.api.file.RegularFile +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.CacheableTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +@CacheableTask +abstract class PSLUpdateTask : DefaultTask() { + @get:Input abstract val pslData: Property<PublicSuffixListData> + @get:OutputFile abstract val outputFile: RegularFileProperty + + @TaskAction + fun updatePSL() { + writeListToDisk(outputFile.get(), pslData.get()) + } + + private fun writeListToDisk(destination: RegularFile, data: PublicSuffixListData) { + val fileSink = destination.asFile.sink() + + fileSink.buffer().use { sink -> + sink.writeInt(data.totalRuleBytes) + + for (domain in data.sortedRules) { + sink.write(domain).writeByte('\n'.toInt()) + } + + sink.writeInt(data.totalExceptionRuleBytes) + + for (domain in data.sortedExceptionRules) { + sink.write(domain).writeByte('\n'.toInt()) + } + } + } +} |
