diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..0a6aa76 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Lint + +on: + pull_request: + branches: [ master, develop ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: '17' + + - name: lint + run: ./gradlew ktlint + + - name: CheckStyle + run: ./gradlew checkJavaStyle diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 311719e..24d76aa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'adopt' - name: Make gradlew executable diff --git a/.idea/appInsightsSettings.xml b/.idea/appInsightsSettings.xml new file mode 100644 index 0000000..86942ef --- /dev/null +++ b/.idea/appInsightsSettings.xml @@ -0,0 +1,28 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 3da91fe..7027c89 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,15 +4,15 @@ diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index ff9696e..8d81632 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d98256..8a22cbb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ad9ea9e --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +

+ + + +

+ +

Gradle plugin for creating and check checksums with Keyri SDK on Android

+ +# Overview + +This repository contains the open source code for Keyri Checksum Checker Plugin. + +[![Lint](https://github.com/Keyri-Co/keyri-checksum-checker-plugin/actions/workflows/lint.yml/badge.svg)](https://github.com/Keyri-Co/keyri-checksum-checker-plugin/actions/workflows/lint.yml) +[![GitHub release](https://img.shields.io/github/release/Keyri-Co/keyri-checksum-checker-plugin.svg?maxAge=10)](https://github.com/Keyri-Co/keyri-checksum-checker-plugin/releases) + +## Contents + +* [Integration](#integration) +* [Usage](#usage) + +The latest source code of the Keyri Android SDK can be found +here: [Releases](https://github.com/Keyri-Co/keyri-checksum-checker-plugin/releases) + +### **Integration** + +Using the plugins DSL: + +```kotlin +plugins { + id("com.keyri.checksumchecker.plugin") version "$latestPluginVersion" +} +``` + +Using legacy plugin application: + +```kotlin +buildscript { + repositories { + maven { + url = uri("https://plugins.gradle.org/m2/") + } + } + dependencies { + classpath("com.keyri:plugin:$latestPluginVersion") + } +} + +apply(plugin = "com.keyri.checksumchecker.plugin") +``` + +### **Usage** + +[//]: # (TODO: Add implementation) diff --git a/REAMDE.md b/REAMDE.md deleted file mode 100644 index 5e814a0..0000000 --- a/REAMDE.md +++ /dev/null @@ -1 +0,0 @@ -TODO - Add docs diff --git a/build.gradle.kts b/build.gradle.kts index deb9e1f..b48344b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + checkstyle +} + buildscript { repositories { google() @@ -11,7 +15,45 @@ buildscript { } dependencies { - classpath("com.android.tools.build:gradle:7.3.1") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0") + classpath("com.android.tools.build:gradle:8.2.1") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22") + } +} + +allprojects { + val kotlinLint by configurations.creating + + dependencies { + kotlinLint("com.pinterest:ktlint:1.1.1") { + attributes { + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) + } + } } + + repositories { + google() + mavenCentral() + } + + tasks.register("ktlint") { + description = "Check Kotlin code style." + mainClass.set("com.pinterest.ktlint.Main") + classpath = kotlinLint + args("src/**/*.kt") + jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") + } + + tasks.register("ktlintFormat") { + group = "formatting" + description = "Fix Kotlin code style deviations." + mainClass.set("com.pinterest.ktlint.Main") + classpath = kotlinLint + args("-F", "src/**/*.kt") + jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") + } +} + +tasks.create("clean") { + delete(rootProject.buildDir) } diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index c988169..2d52f43 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -1,7 +1,7 @@ plugins { `java-gradle-plugin` `kotlin-dsl` - id("com.gradle.plugin-publish") version "1.1.0" + id("com.gradle.plugin-publish") version "1.2.1" } repositories { @@ -11,13 +11,12 @@ repositories { dependencies { implementation(kotlin("stdlib")) - implementation("com.android.tools.build:gradle:7.4.0") - implementation("com.google.code.gson:gson:2.10") + implementation("com.google.code.gson:gson:2.10.1") } kotlin { jvmToolchain { - version = JavaVersion.VERSION_11 + version = JavaVersion.VERSION_17 } } diff --git a/plugin/src/main/kotlin/com.keyri.checksumchecker.plugin/KeyriCheckerExtension.kt b/plugin/src/main/kotlin/com.keyri.checksumchecker.plugin/KeyriCheckerExtension.kt index e2e04eb..967d9e5 100644 --- a/plugin/src/main/kotlin/com.keyri.checksumchecker.plugin/KeyriCheckerExtension.kt +++ b/plugin/src/main/kotlin/com.keyri.checksumchecker.plugin/KeyriCheckerExtension.kt @@ -1,11 +1,10 @@ package com.keyri.checksumchecker.plugin open class KeyriCheckerExtension { + // TODO: Merge with bundle path var apkFullPath: String? = null + // TODO: Replace with build version var apkID: String? = null - internal var appKey: String? = null - - fun setAppKey(appKey: String) { - this.appKey = appKey - } + var appKey: String? = null + internal set } diff --git a/plugin/src/main/kotlin/com.keyri.checksumchecker.plugin/KeyriChecksumCheckTask.kt b/plugin/src/main/kotlin/com.keyri.checksumchecker.plugin/KeyriChecksumCheckTask.kt index 2f5c01a..14b272e 100644 --- a/plugin/src/main/kotlin/com.keyri.checksumchecker.plugin/KeyriChecksumCheckTask.kt +++ b/plugin/src/main/kotlin/com.keyri.checksumchecker.plugin/KeyriChecksumCheckTask.kt @@ -2,15 +2,16 @@ package com.keyri.checksumchecker.plugin import com.google.gson.JsonArray import com.google.gson.JsonObject -import org.gradle.api.DefaultTask -import org.gradle.api.GradleException -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.TaskAction import java.io.File import java.net.HttpURLConnection import java.net.URL import java.security.MessageDigest import java.util.* +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.TaskAction + abstract class KeyriChecksumCheckTask : DefaultTask() { @@ -34,7 +35,7 @@ abstract class KeyriChecksumCheckTask : DefaultTask() { appKey = keyriCheckerExt.appKey ?: throw GradleException("You should provide valid App Key") apkID = keyriCheckerExt.apkID ?: throw GradleException("You should provide valid APK ID") - return keyriCheckerExt.apkFullPath?.takeIf { it.isNotEmpty() } + return keyriCheckerExt.apkFullPath?.takeIf { File(it).exists() } ?: throw GradleException("You should provide valid APK path") } @@ -45,28 +46,31 @@ abstract class KeyriChecksumCheckTask : DefaultTask() { try { val apkFiles = project.zipTree(apkPath).files + // TODO: Single hash? + var fileName = "" var fileDigest = "" - apkFiles.firstOrNull { it.name == "MANIFEST.MF" }?.readLines()?.asSequence()?.forEach { line -> - if (line.contains("Name:")) { - fileName = line.removePrefix("Name: ") - } + apkFiles.firstOrNull { it.name == "MANIFEST.MF" }?.readLines()?.asSequence() + ?.forEach { line -> + if (line.contains("Name:")) { + fileName = line.removePrefix("Name: ") + } - if (line.contains("SHA-256-Digest:")) { - fileDigest = line.removePrefix("SHA-256-Digest: ") - } + if (line.contains("SHA-256-Digest:")) { + fileDigest = line.removePrefix("SHA-256-Digest: ") + } - if (fileName.isNotEmpty() && fileDigest.isNotEmpty()) { - val apkFileEntity = JsonObject() + if (fileName.isNotEmpty() && fileDigest.isNotEmpty()) { + val apkFileEntity = JsonObject() - apkFileEntity.addProperty(fileName, fileDigest) - checksums.add(apkFileEntity) + apkFileEntity.addProperty(fileName, fileDigest) + checksums.add(apkFileEntity) - fileName = "" - fileDigest = "" - } - } ?: apkFiles.forEach { apkFile -> + fileName = "" + fileDigest = "" + } + } ?: apkFiles.forEach { apkFile -> val apkFileEntity = JsonObject() apkFileEntity.addProperty(apkFile.name, apkFile.digestAndStringBase64()) @@ -87,6 +91,7 @@ abstract class KeyriChecksumCheckTask : DefaultTask() { } } + // TODO: Send payload to Zain private fun uploadChecksums(payload: JsonObject) { try { // TODO Add url @@ -96,7 +101,11 @@ abstract class KeyriChecksumCheckTask : DefaultTask() { doOutput = true } - connection?.outputStream?.write(payload.toString().encodeToByteArray()) + connection?.outputStream?.use { outputStream -> + val input = payload.toString().toByteArray(Charsets.UTF_8) + + outputStream.write(input, 0, input.size) + } if (connection?.responseCode == 200) { val result = connection.inputStream?.readAllBytes()?.decodeToString()