Skip to content

Commit

Permalink
Fixed README.md, added TODO-s, updated libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKuliahin96 committed Jan 17, 2024
1 parent 4b6efa8 commit 2d72b68
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
- name: checkout
uses: actions/checkout@v3

- name: set up JDK 11
- name: set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
java-version: '17'

- name: lint
run: ./gradlew ktlint
Expand Down
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.

10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

This repository contains the open source code for Keyri Checksum Checker Plugin.

![Lint](https://github.com/Keyri-Co/keyri-checksum-checker-plugin/workflows/Lint/badge.svg)
![Release](https://github.com/Keyri-Co/keyri-checksum-checker-plugin/workflows/Release/badge.svg)

[![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
Expand All @@ -29,7 +27,7 @@ Using the plugins DSL:

```kotlin
plugins {
id("com.keyri.checksumchecker.plugin") version "0.0.2"
id("com.keyri.checksumchecker.plugin") version "$latestPluginVersion"
}
```

Expand All @@ -43,7 +41,7 @@ buildscript {
}
}
dependencies {
classpath("com.keyri:plugin:0.0.2")
classpath("com.keyri:plugin:$latestPluginVersion")
}
}

Expand All @@ -52,4 +50,4 @@ apply(plugin = "com.keyri.checksumchecker.plugin")

### **Usage**

In progress
[//]: # (TODO: Add implementation)
1 change: 0 additions & 1 deletion REAMDE.md

This file was deleted.

20 changes: 5 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ 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:0.48.2") {
kotlinLint("com.pinterest:ktlint:1.1.1") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
}
Expand All @@ -36,23 +36,12 @@ allprojects {
mavenCentral()
}

tasks.register("checkJavaStyle", Checkstyle::class.java) {
isShowViolations = true
configFile = file("../settings/checkstyle.xml")
setSource("src/main/java")
include("**/*.java")
exclude("**/gen/**")
exclude("**/R.java")
exclude("**/BuildConfig.java")

classpath = files()
}

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") {
Expand All @@ -61,6 +50,7 @@ allprojects {
mainClass.set("com.pinterest.ktlint.Main")
classpath = kotlinLint
args("-F", "src/**/*.kt")
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}
}

Expand Down
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 2d72b68

Please sign in to comment.