aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-06-04 01:02:35 -0400
committerAllan Wang <me@allanwang.ca>2019-06-04 01:02:35 -0400
commit8052a9a4b5f64191d19912d53e16d7e49a587a17 (patch)
tree271aeb302beb48f8d4b4b9d5a09b2663cac3ddba
parentaf8f9685112695f031d93fcb2da8a6e0a3b70c4a (diff)
downloadkau-8052a9a4b5f64191d19912d53e16d7e49a587a17.tar.gz
kau-8052a9a4b5f64191d19912d53e16d7e49a587a17.tar.bz2
kau-8052a9a4b5f64191d19912d53e16d7e49a587a17.zip
Convert plugin to kotlin code
-rw-r--r--.idea/kotlinScripting.xml6
-rw-r--r--build.gradle25
-rw-r--r--buildSrc/build.gradle9
-rw-r--r--buildSrc/build.gradle.kts18
-rw-r--r--buildSrc/src/main/groovy/ca/allanwang/kau/ChangelogGenerator.groovy76
-rw-r--r--buildSrc/src/main/groovy/ca/allanwang/kau/Dependencies.groovy13
-rw-r--r--buildSrc/src/main/groovy/ca/allanwang/kau/KauPlugin.groovy16
-rw-r--r--buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy18
-rw-r--r--buildSrc/src/main/kotlin/ca/allanwang/kau/ChangelogGenerator.kt104
-rw-r--r--buildSrc/src/main/kotlin/ca/allanwang/kau/Dependencies.kt14
-rw-r--r--buildSrc/src/main/kotlin/ca/allanwang/kau/KauPlugin.kt17
-rw-r--r--buildSrc/src/main/kotlin/ca/allanwang/kau/Plugins.kt16
-rw-r--r--buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt (renamed from buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy)65
-rw-r--r--buildSrc/src/main/resources/META-INF/gradle-plugins/ca.allanwang.kau.properties1
14 files changed, 222 insertions, 176 deletions
diff --git a/.idea/kotlinScripting.xml b/.idea/kotlinScripting.xml
new file mode 100644
index 0000000..a6fe551
--- /dev/null
+++ b/.idea/kotlinScripting.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="KotlinScriptingSettings">
+ <option name="isAutoReloadEnabled" value="true" />
+ </component>
+</project> \ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 5ec6404..bdad1e5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,16 +6,21 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
- apply plugin: "ca.allanwang.kau"
-
dependencies {
- classpath kauPlugin.android
- classpath kauPlugin.kotlin
- classpath kauPlugin.androidMaven
- classpath kauPlugin.playPublisher
- classpath kauPlugin.dexCount
- classpath kauPlugin.gitVersion
- classpath kauPlugin.spotless
+ // https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
+ classpath("com.android.tools.build:gradle:3.4.1")
+ // https://kotlinlang.org/docs/reference/using-gradle.html
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31")
+ // https://github.com/dcendents/android-maven-gradle-plugin/releases
+ classpath("com.github.dcendents:android-maven-gradle-plugin:2.1")
+ // https://github.com/Triple-T/gradle-play-publisher/releases
+ classpath("com.github.triplet.gradle:play-publisher:2.1.0")
+ // https://github.com/KeepSafe/dexcount-gradle-plugin/releases
+ classpath("com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.6")
+ // https://github.com/gladed/gradle-android-git-version/releases
+ classpath("com.gladed.androidgitversion:gradle-android-git-version:0.4.9")
+ // https://github.com/diffplug/spotless/blob/master/plugin-gradle/CHANGES.md
+ classpath("com.diffplug.spotless:spotless-plugin-gradle:3.21.1")
}
wrapper.setDistributionType(Wrapper.DistributionType.ALL)
@@ -28,7 +33,7 @@ task clean(type: Delete) {
}
task generateChangelogMd {
- kauChangelog.generate("$project.rootDir/sample/src/main/res/xml/kau_changelog.xml")
+ kauChangelog.generate("${project.rootDir}/sample/src/main/res/xml/kau_changelog.xml")
}
subprojects {
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
deleted file mode 100644
index a51e9ae..0000000
--- a/buildSrc/build.gradle
+++ /dev/null
@@ -1,9 +0,0 @@
-apply plugin: 'groovy'
-apply plugin: 'maven'
-
-group = "ca.allanwang"
-
-dependencies {
- compile gradleApi()
- compile localGroovy()
-} \ No newline at end of file
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts
new file mode 100644
index 0000000..5939d89
--- /dev/null
+++ b/buildSrc/build.gradle.kts
@@ -0,0 +1,18 @@
+plugins {
+ `kotlin-dsl`
+}
+
+group = "ca.allanwang"
+
+gradlePlugin {
+ plugins {
+ register("kau-plugin") {
+ id = "ca.allanwang.kau"
+ implementationClass = "ca.allanwang.kau.KauPlugin"
+ }
+ }
+}
+
+repositories {
+ mavenCentral()
+} \ No newline at end of file
diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/ChangelogGenerator.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/ChangelogGenerator.groovy
deleted file mode 100644
index bb56fa2..0000000
--- a/buildSrc/src/main/groovy/ca/allanwang/kau/ChangelogGenerator.groovy
+++ /dev/null
@@ -1,76 +0,0 @@
-package ca.allanwang.kau
-
-import org.gradle.api.GradleException
-import org.gradle.api.Project
-
-/**
- * Given an xml of the format
- *
- * <?xml version="1.0" encoding="utf-8"?>
- * <resources>
- * <version title="v0.1" />
- * <item text="Initial Changelog" />
- * <item text="Bullet point here" />
- * <item text="More points" />
- * <item text="" /> <!-- this one is empty and therefore ignored -->
- * </resources>
- *
- * Outputs a changelog in markdown format
- */
-class ChangelogGenerator {
-
- static class ChangelogException extends GradleException {
- ChangelogException(String message) {
- super(message)
- }
- }
-
- private Project project
-
- ChangelogGenerator(Project project) {
- this.project = project
- }
-
- private static void fail(String message) {
- throw new ChangelogException(message)
- }
-
- final void generate(String inputUri, String outputUri = "$project.rootDir/docs/Changelog.md") {
- def input = new File(inputUri)
- if (!input.exists())
- fail("Could not generate changelog from ${input.absolutePath}")
-
- def output = new File(outputUri)
-
- if (output.exists()) {
- if (output.isDirectory())
- fail("Cannot save changelog at directory ${output.absolutePath}")
-
-
- if (output.isFile() && !output.delete())
- fail("Could not delete changelog at ${output.absolutePath}")
- } else {
- output.parentFile.mkdirs()
- }
-
- if (!output.createNewFile())
- fail("Could not create changelog file at ${output.absolutePath}")
-
- def parsedProjectXml = (new XmlParser()).parse(inputUri)
- def sw = new StringWriter()
- sw.append("# Changelog\n")
- parsedProjectXml.depthFirst().each {
- switch (it.name()) {
- case "version":
- sw.append("\n## ${it.@title}\n")
- break
- case "item":
- if (it.@text?.trim())
- sw.append("* ${it.@text}\n")
- }
- }
- output.write(sw.toString())
- println("Generated changelog at ${output.absolutePath}")
- }
-
-} \ No newline at end of file
diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/Dependencies.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/Dependencies.groovy
deleted file mode 100644
index a27e503..0000000
--- a/buildSrc/src/main/groovy/ca/allanwang/kau/Dependencies.groovy
+++ /dev/null
@@ -1,13 +0,0 @@
-package ca.allanwang.kau
-
-/**
- * Some common dependencies, backed by the supplied versions
- */
-class Dependencies {
- static def kotlin = "org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}"
- static def kotlinTest = "org.jetbrains.kotlin:kotlin-test-junit:${Versions.kotlin}"
- static def junit = "junit:junit:${Versions.junit}"
- static def espresso = "androidx.test.espresso:espresso-core:${Versions.espresso}"
- static def testRunner = "androidx.test.ext:junit:${Versions.testRunner}"
- static def testRules = "androidx.test:rules:${Versions.testRules}"
-} \ No newline at end of file
diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/KauPlugin.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/KauPlugin.groovy
deleted file mode 100644
index e73564c..0000000
--- a/buildSrc/src/main/groovy/ca/allanwang/kau/KauPlugin.groovy
+++ /dev/null
@@ -1,16 +0,0 @@
-package ca.allanwang.kau
-
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-
-class KauPlugin implements Plugin<Project> {
-
- @Override
- void apply(Project project) {
- project.extensions.create("kau", Versions)
- project.extensions.create("kauPlugin", Plugins)
- project.extensions.create("kauDependency", Dependencies)
- project.extensions.create("kauChangelog", ChangelogGenerator, project)
- }
-
-} \ No newline at end of file
diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy b/buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy
deleted file mode 100644
index 89182f1..0000000
--- a/buildSrc/src/main/groovy/ca/allanwang/kau/Plugins.groovy
+++ /dev/null
@@ -1,18 +0,0 @@
-package ca.allanwang.kau
-
-/**
- * Some common buildscript plugins, backed by the supplied versions
- */
-class Plugins {
- static def android = "com.android.tools.build:gradle:${Versions.gradlePlugin}"
- static def kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
- static
- def androidMaven = "com.github.dcendents:android-maven-gradle-plugin:${Versions.mavenPlugin}"
- static
- def playPublisher = "com.github.triplet.gradle:play-publisher:${Versions.playPublishPlugin}"
- static
- def dexCount = "com.getkeepsafe.dexcount:dexcount-gradle-plugin:${Versions.dexCountPlugin}"
- static
- def gitVersion = "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:${Versions.gitVersionPlugin}"
- static def spotless = "com.diffplug.spotless:spotless-plugin-gradle:${Versions.spotless}"
-} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/ChangelogGenerator.kt b/buildSrc/src/main/kotlin/ca/allanwang/kau/ChangelogGenerator.kt
new file mode 100644
index 0000000..8200484
--- /dev/null
+++ b/buildSrc/src/main/kotlin/ca/allanwang/kau/ChangelogGenerator.kt
@@ -0,0 +1,104 @@
+package ca.allanwang.kau
+
+import groovy.util.Node
+import groovy.util.XmlParser
+import org.gradle.api.GradleException
+import org.gradle.api.Project
+import java.io.File
+
+/**
+ * Given an xml of the format
+ *
+ * <?xml version="1.0" encoding="utf-8"?>
+ * <resources>
+ * <version title="v0.1" />
+ * <item text="Initial Changelog" />
+ * <item text="Bullet point here" />
+ * <item text="More points" />
+ * <item text="" /> <!-- this one is empty and therefore ignored -->
+ * </resources>
+ *
+ * Outputs a changelog in markdown format
+ */
+open class ChangelogGenerator(private val project: Project) {
+
+ class ChangelogException(message: String) : GradleException(message)
+
+ private fun fail(message: String): Nothing =
+ throw ChangelogException(message)
+
+ class ChangelogEntry(val version: String, val items: Array<String>)
+
+ private fun Node.forEachNode(action: (Node) -> Unit) {
+ children().forEach {
+ action(it as Node)
+ }
+ }
+
+ fun read(inputUri: String): List<ChangelogEntry> {
+ val input = File(inputUri)
+ if (!input.exists()) {
+ fail("Could not generate changelog from ${input.absolutePath}")
+ }
+
+ val parser = XmlParser().parse(inputUri)
+
+ val entries: MutableList<ChangelogEntry> = mutableListOf()
+ var version: String? = null
+ val items: MutableList<String> = mutableListOf()
+
+ fun addEntry() {
+ version?.also { v ->
+ entries.add(ChangelogEntry(v, items.toTypedArray()))
+ items.clear()
+ }
+ }
+
+ parser.depthFirst().mapNotNull { it as? Node }.forEach { n ->
+ when (n.name()) {
+ "version" -> {
+ addEntry()
+ version = n.attribute("title")?.toString() ?: ""
+ }
+ "item" -> {
+ n.attribute("text")?.toString()?.takeIf(String::isNotBlank)?.let {
+ items.add(it)
+ }
+ }
+ }
+ }
+ addEntry()
+ return entries
+ }
+
+ @JvmOverloads
+ fun generate(inputUri: String, outputUri: String = "${project.rootDir}/docs/Changelog.md") {
+ val entries = read(inputUri)
+ val output = File(outputUri)
+ if (output.exists()) {
+ if (output.isDirectory) {
+ fail("Cannot save changelog at directory ${output.absolutePath}")
+ }
+ if (output.isFile && !output.delete()) {
+ fail("Could not delete changelog at ${output.absolutePath}")
+ }
+ } else {
+ output.parentFile.mkdirs()
+ }
+
+ if (!output.createNewFile()) {
+ fail("Could not create changelog file at ${output.absolutePath}")
+ }
+ val markdown = buildString {
+ append("# Changelog\n")
+ entries.forEach { e ->
+ append("\n## ${e.version}\n")
+ e.items.forEach {
+ append("* $it\n")
+ }
+ }
+ }
+ output.writeText(markdown)
+ println("Generated changelog at ${output.absolutePath}")
+ }
+} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/Dependencies.kt b/buildSrc/src/main/kotlin/ca/allanwang/kau/Dependencies.kt
new file mode 100644
index 0000000..9e23ac4
--- /dev/null
+++ b/buildSrc/src/main/kotlin/ca/allanwang/kau/Dependencies.kt
@@ -0,0 +1,14 @@
+package ca.allanwang.kau
+
+/**
+ * Some common dependencies, backed by the supplied versions
+ */
+open class Dependencies {
+ private val v = Versions()
+ val kotlin = "org.jetbrains.kotlin:kotlin-stdlib:${v.kotlin}"
+ val kotlinTest = "org.jetbrains.kotlin:kotlin-test-junit:${v.kotlin}"
+ val junit = "junit:junit:${v.junit}"
+ val espresso = "androidx.test.espresso:espresso-core:${v.espresso}"
+ val testRunner = "androidx.test.ext:junit:${v.testRunner}"
+ val testRules = "androidx.test:rules:${v.testRules}"
+} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/KauPlugin.kt b/buildSrc/src/main/kotlin/ca/allanwang/kau/KauPlugin.kt
new file mode 100644
index 0000000..6be15e5
--- /dev/null
+++ b/buildSrc/src/main/kotlin/ca/allanwang/kau/KauPlugin.kt
@@ -0,0 +1,17 @@
+package ca.allanwang.kau
+
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.kotlin.dsl.create
+
+class KauPlugin : Plugin<Project> {
+
+ override fun apply(project: Project) {
+ project.extensions.run {
+ create<Versions>("kau")
+ create<Dependencies>("kauDependency")
+ create<Plugins>("kauPlugin")
+ create<ChangelogGenerator>("kauChangelog", project)
+ }
+ }
+} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/ca/allanwang/kau/Plugins.kt b/buildSrc/src/main/kotlin/ca/allanwang/kau/Plugins.kt
new file mode 100644
index 0000000..c8265ab
--- /dev/null
+++ b/buildSrc/src/main/kotlin/ca/allanwang/kau/Plugins.kt
@@ -0,0 +1,16 @@
+package ca.allanwang.kau
+
+/**
+ * Some common buildscript plugins, backed by the supplied versions
+ */
+open class Plugins {
+ private val v = Versions()
+ val android = "com.android.tools.build:gradle:${v.gradlePlugin}"
+ val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${v.kotlin}"
+ val androidMaven = "com.github.dcendents:android-maven-gradle-plugin:${v.mavenPlugin}"
+ val playPublisher = "com.github.triplet.gradle:play-publisher:${v.playPublishPlugin}"
+ val dexCount = "com.getkeepsafe.dexcount:dexcount-gradle-plugin:${v.dexCountPlugin}"
+ val gitVersion =
+ "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:${v.gitVersionPlugin}"
+ val spotless = "com.diffplug.spotless:spotless-plugin-gradle:${v.spotless}"
+} \ No newline at end of file
diff --git a/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy b/buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt
index a50a7a0..2bcedaa 100644
--- a/buildSrc/src/main/groovy/ca/allanwang/kau/Versions.groovy
+++ b/buildSrc/src/main/kotlin/ca/allanwang/kau/Versions.kt
@@ -1,81 +1,80 @@
package ca.allanwang.kau
-class Versions {
- static def coreMinSdk = 19
- static def minSdk = 21
- static def targetSdk = 28
+open class Versions {
+ val coreMinSdk = 19
+ val minSdk = 21
+ val targetSdk = 28
// https://developer.android.com/studio/releases/build-tools
- static def buildTools = '28.0.3'
+ val buildTools = "28.0.3"
// https://mvnrepository.com/artifact/androidx.appcompat/appcompat?repo=google
- static def appcompat = '1.0.2'
+ val appcompat = "1.0.2"
// https://mvnrepository.com/artifact/com.google.android.material/material
- static def googleMaterial = '1.0.0'
+ val googleMaterial = "1.0.0"
// https://mvnrepository.com/artifact/androidx.recyclerview/recyclerview
- static def recyclerView = '1.0.0'
+ val recyclerView = "1.0.0"
// https://mvnrepository.com/artifact/androidx.cardview/cardview
- static def cardView = '1.0.0'
+ val cardView = "1.0.0"
// https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout
- static def constraintLayout = '1.1.3'
+ val constraintLayout = "1.1.3"
// https://kotlinlang.org/docs/reference/using-gradle.html
- static def kotlin = '1.3.31'
+ val kotlin = "1.3.31"
// https://github.com/Kotlin/kotlinx.coroutines/releases
- static def coroutines = '1.2.1'
+ val coroutines = "1.2.1"
// https://github.com/mikepenz/AboutLibraries/releases
- static def aboutLibraries = '6.2.3'
+ val aboutLibraries = "6.2.3"
// https://github.com/wasabeef/Blurry/releases
- static def blurry = '3.0.0'
+ val blurry = "3.0.0"
// https://github.com/mikepenz/FastAdapter#using-maven
- static def fastAdapter = '3.3.1'
- static def fastAdapterCommons = fastAdapter
+ val fastAdapter = "3.3.1"
+ val fastAdapterCommons = fastAdapter
// https://github.com/bumptech/glide/releases
- static def glide = '4.9.0'
+ val glide = "4.9.0"
// https://github.com/mikepenz/Android-Iconics#1-provide-the-gradle-dependency
- static def iconics = '3.2.5'
- static def iconicsGoogle = '3.0.1.3'
- static def iconicsMaterial = '2.2.0.5'
- static def iconicsCommunity = '3.5.95.1'
+ val iconics = "3.2.5"
+ val iconicsGoogle = "3.0.1.3"
+ val iconicsMaterial = "2.2.0.5"
+ val iconicsCommunity = "3.5.95.1"
// https://github.com/afollestad/material-dialogs/releases
- static def materialDialog = '0.9.6.0'
+ val materialDialog = "0.9.6.0"
// https://mvnrepository.com/artifact/androidx.test.espresso/espresso-core?repo=google
- static def espresso = '3.1.1'
+ val espresso = "3.1.1"
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
- static def junit = '4.12'
+ val junit = "4.12"
-
- static def testRunner = '1.1.0'
+ val testRunner = "1.1.0"
// https://mvnrepository.com/artifact/androidx.test/rules?repo=google
- static def testRules = '1.1.1'
+ val testRules = "1.1.1"
// https://github.com/diffplug/spotless/blob/master/plugin-gradle/CHANGES.md
- static def spotless = '3.18.0'
+ val spotless = "3.18.0"
// https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
- static def gradlePlugin = '3.4.1'
+ val gradlePlugin = "3.4.1"
// https://github.com/dcendents/android-maven-gradle-plugin/releases
- static def mavenPlugin = '2.1'
+ val mavenPlugin = "2.1"
// https://github.com/Triple-T/gradle-play-publisher/releases
- static def playPublishPlugin = '2.1.0'
+ val playPublishPlugin = "2.1.0"
// https://github.com/KeepSafe/dexcount-gradle-plugin/releases
- static def dexCountPlugin = '0.8.6'
+ val dexCountPlugin = "0.8.6"
// https://github.com/gladed/gradle-android-git-version/releases
- static def gitVersionPlugin = '0.4.7'
+ val gitVersionPlugin = "0.4.7"
} \ No newline at end of file
diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/ca.allanwang.kau.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/ca.allanwang.kau.properties
deleted file mode 100644
index ba824cd..0000000
--- a/buildSrc/src/main/resources/META-INF/gradle-plugins/ca.allanwang.kau.properties
+++ /dev/null
@@ -1 +0,0 @@
-implementation-class=ca.allanwang.kau.KauPlugin \ No newline at end of file