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()