diff options
Diffstat (limited to 'build-logic/automation-plugins/src')
-rw-r--r-- | build-logic/automation-plugins/src/main/kotlin/psl/PSLUpdateTask.kt | 46 | ||||
-rw-r--r-- | build-logic/automation-plugins/src/main/kotlin/psl/PublicSuffixListPlugin.kt | 39 |
2 files changed, 53 insertions, 32 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()) + } + } + } +} diff --git a/build-logic/automation-plugins/src/main/kotlin/psl/PublicSuffixListPlugin.kt b/build-logic/automation-plugins/src/main/kotlin/psl/PublicSuffixListPlugin.kt index 3c003c53..bc503fde 100644 --- a/build-logic/automation-plugins/src/main/kotlin/psl/PublicSuffixListPlugin.kt +++ b/build-logic/automation-plugins/src/main/kotlin/psl/PublicSuffixListPlugin.kt @@ -4,16 +4,15 @@ package psl -import java.io.File +import java.io.Serializable import java.util.TreeSet import okhttp3.OkHttpClient import okhttp3.Request import okio.ByteString import okio.ByteString.Companion.encodeUtf8 -import okio.buffer -import okio.sink import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.kotlin.dsl.register /** * Gradle plugin to update the public suffix list used by the `lib-publicsuffixlist` component. @@ -23,34 +22,10 @@ import org.gradle.api.Project */ class PublicSuffixListPlugin : Plugin<Project> { override fun apply(project: Project) { - project.tasks.register("updatePSL") { - doLast { - val filename = project.projectDir.absolutePath + "/src/main/assets/publicsuffixes" - updatePublicSuffixList(filename) - } - } - } - - private fun updatePublicSuffixList(destination: String) { - val list = fetchPublicSuffixList() - writeListToDisk(destination, list) - } - - private fun writeListToDisk(destination: String, data: PublicSuffixListData) { - val fileSink = File(destination).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()) - } + project.tasks.register<PSLUpdateTask>("updatePSL") { + val list = fetchPublicSuffixList() + pslData.set(list) + outputFile.set(project.layout.projectDirectory.file("src/main/assets/publicsuffixes")) } } @@ -119,4 +94,4 @@ data class PublicSuffixListData( var totalExceptionRuleBytes: Int = 0, val sortedRules: TreeSet<ByteString> = TreeSet(), val sortedExceptionRules: TreeSet<ByteString> = TreeSet() -) +) : Serializable |