Skip to content

Commit

Permalink
Merge pull request #2 from Keyri-Co/feature/add_readme
Browse files Browse the repository at this point in the history
Feature/add readme
  • Loading branch information
AndrewKuliahin96 authored Jan 17, 2024
2 parents 40bd888 + 2d72b68 commit 5828fde
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 38 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/setup-java@v3

with:
java-version: '11'
java-version: '17'
distribution: 'adopt'

- name: Make gradlew executable
Expand Down
28 changes: 28 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<p style="text-align:center">
<a href="">
<img src="https://keyri.com/wp-content/uploads/2022/09/Keyri-Grey-Logo-Website-300x147.png" width=200 alt=""/>
</a>
</p>

<p style="text-align:center">Gradle plugin for creating and check checksums with Keyri SDK on Android</p>

# 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)
1 change: 0 additions & 1 deletion REAMDE.md

This file was deleted.

46 changes: 44 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
checkstyle
}

buildscript {
repositories {
google()
Expand All @@ -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<JavaExec>("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<JavaExec>("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<Delete>("clean") {
delete(rootProject.buildDir)
}
7 changes: 3 additions & 4 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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")
}

Expand All @@ -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())
Expand All @@ -87,6 +91,7 @@ abstract class KeyriChecksumCheckTask : DefaultTask() {
}
}

// TODO: Send payload to Zain
private fun uploadChecksums(payload: JsonObject) {
try {
// TODO Add url
Expand All @@ -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()
Expand Down

0 comments on commit 5828fde

Please sign in to comment.