From 1cff5c093b804c649e178e4ddd1b9d0bac40ff70 Mon Sep 17 00:00:00 2001
From: Karlatemp <kar@kasukusakura.com>
Date: Tue, 14 Jun 2022 17:19:16 +0800
Subject: [PATCH] rename to mirai-core-utils-barcode; change to jvm module

---
 .../src/jvmMain/kotlin/utils/SwingSolver.kt   |   2 +-
 mirai-core-utils-addition/build.gradle.kts    |  77 ------------------
 .../kotlin/PlatformImageUtilImpl.kt           |  48 -----------
 .../src/androidMain/kotlin/package.kt         |  10 ---
 .../README.md                                 |   4 +-
 .../build.gradle.kts                          |  21 ++++-
 .../imgs/unsafe-device-verify.png             | Bin
 .../src/BarcodeSupportImpl.kt                 |   6 +-
 .../src}/package.kt                           |   2 +-
 .../{PlatformImage.kt => BarcodeSupport.kt}   |  15 ++--
 mirai-core/build.gradle.kts                   |   2 +-
 settings.gradle.kts                           |   2 +-
 12 files changed, 37 insertions(+), 152 deletions(-)
 delete mode 100644 mirai-core-utils-addition/build.gradle.kts
 delete mode 100644 mirai-core-utils-addition/src/androidMain/kotlin/PlatformImageUtilImpl.kt
 delete mode 100644 mirai-core-utils-addition/src/androidMain/kotlin/package.kt
 rename {mirai-core-utils-addition => mirai-core-utils-barcode}/README.md (65%)
 rename mirai-core-utils-addition/src/jvmMain/kotlin/package.kt => mirai-core-utils-barcode/build.gradle.kts (53%)
 rename {mirai-core-utils-addition => mirai-core-utils-barcode}/imgs/unsafe-device-verify.png (100%)
 rename mirai-core-utils-addition/src/jvmMain/kotlin/PlatformImageUtilImpl.kt => mirai-core-utils-barcode/src/BarcodeSupportImpl.kt (88%)
 rename {mirai-core-utils-addition/src/commonMain/kotlin => mirai-core-utils-barcode/src}/package.kt (90%)
 rename mirai-core-utils/src/commonMain/kotlin/{PlatformImage.kt => BarcodeSupport.kt} (72%)

diff --git a/mirai-core-api/src/jvmMain/kotlin/utils/SwingSolver.kt b/mirai-core-api/src/jvmMain/kotlin/utils/SwingSolver.kt
index 32d23a035..a6961d5c5 100644
--- a/mirai-core-api/src/jvmMain/kotlin/utils/SwingSolver.kt
+++ b/mirai-core-api/src/jvmMain/kotlin/utils/SwingSolver.kt
@@ -106,7 +106,7 @@ public object SwingSolver : LoginSolver() {
                 "", HyperLinkLabel(url, "设备锁验证", title),
                 "URL", JTextField(url),
             ).also { components ->
-                val qr = PlatformImageUtil.generateQRCode(url, 300, 300)
+                val qr = BarcodeSupport.generateQRCode(url, 300, 300)
                 if (qr != null) {
                     components.add("")
                     components.add(JLabel(ImageIcon(qr)))
diff --git a/mirai-core-utils-addition/build.gradle.kts b/mirai-core-utils-addition/build.gradle.kts
deleted file mode 100644
index 826491737..000000000
--- a/mirai-core-utils-addition/build.gradle.kts
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2019-2022 Mamoe Technologies and contributors.
- *
- * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
- *
- * https://github.com/mamoe/mirai/blob/dev/LICENSE
- */
-
-import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
-
-plugins {
-    kotlin("multiplatform")
-    // id("kotlinx-atomicfu")
-    kotlin("plugin.serialization")
-    id("me.him188.kotlin-jvm-blocking-bridge")
-    id("me.him188.kotlin-dynamic-delegation")
-    `maven-publish`
-}
-
-description = "mirai-core utilities additions"
-
-kotlin {
-    explicitApi()
-
-    if (isAndroidSDKAvailable) {
-        jvm("android") {
-            attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
-            //   publishAllLibraryVariants()
-        }
-    } else {
-        printAndroidNotInstalled()
-    }
-
-    jvm("common") {
-        attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
-    }
-
-    jvm("jvm")
-
-    sourceSets {
-        val commonMain by getting {
-            dependencies {
-                implementation(project(":mirai-core-utils"))
-            }
-        }
-
-        val commonTest by getting {
-            dependencies {
-            }
-        }
-
-        if (isAndroidSDKAvailable) {
-            val androidMain by getting {
-                dependencies {
-                    compileOnly(`android-runtime`)
-                    implementation(`zxing-core`)
-                }
-            }
-        }
-
-        val jvmMain by getting {
-            dependencies {
-                implementation(`zxing-javase`)
-            }
-        }
-
-        val jvmTest by getting {
-            dependencies {
-                runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
-            }
-        }
-    }
-}
-
-configureMppPublishing()
-
diff --git a/mirai-core-utils-addition/src/androidMain/kotlin/PlatformImageUtilImpl.kt b/mirai-core-utils-addition/src/androidMain/kotlin/PlatformImageUtilImpl.kt
deleted file mode 100644
index f73eea8bc..000000000
--- a/mirai-core-utils-addition/src/androidMain/kotlin/PlatformImageUtilImpl.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2019-2022 Mamoe Technologies and contributors.
- *
- * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
- *
- * https://github.com/mamoe/mirai/blob/dev/LICENSE
- */
-
-package net.mamoe.mirai.utils.addition
-
-import android.graphics.Bitmap
-import com.google.zxing.BarcodeFormat
-import com.google.zxing.WriterException
-import com.google.zxing.common.BitMatrix
-import com.google.zxing.qrcode.QRCodeWriter
-import net.mamoe.mirai.utils.PlatformImage
-import net.mamoe.mirai.utils.PlatformImageUtil
-
-public class PlatformImageUtilImpl : PlatformImageUtil {
-    override val available: Boolean get() = true
-
-    override fun generateQRCode(content: String, width: Int, height: Int): PlatformImage? {
-        val bitMatrix: BitMatrix = try {
-            QRCodeWriter().encode(
-                content,
-                BarcodeFormat.QR_CODE,
-                width,
-                height
-            )
-        } catch (e: WriterException) {
-            throw RuntimeException(e)
-        }
-        val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
-        for (x in 0 until width) {
-            for (y in 0 until height) {
-                bitmap.setPixel(
-                    x, y, if (bitMatrix[x, y]) {
-                        0x000000
-                    } else {
-                        0xFFFFFF
-                    }
-                )
-            }
-        }
-        return bitmap
-    }
-}
\ No newline at end of file
diff --git a/mirai-core-utils-addition/src/androidMain/kotlin/package.kt b/mirai-core-utils-addition/src/androidMain/kotlin/package.kt
deleted file mode 100644
index a99d33184..000000000
--- a/mirai-core-utils-addition/src/androidMain/kotlin/package.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * Copyright 2019-2022 Mamoe Technologies and contributors.
- *
- * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
- *
- * https://github.com/mamoe/mirai/blob/dev/LICENSE
- */
-
-package net.mamoe.mirai.utils.addition
diff --git a/mirai-core-utils-addition/README.md b/mirai-core-utils-barcode/README.md
similarity index 65%
rename from mirai-core-utils-addition/README.md
rename to mirai-core-utils-barcode/README.md
index b14fc4728..b714d8949 100644
--- a/mirai-core-utils-addition/README.md
+++ b/mirai-core-utils-barcode/README.md
@@ -1,11 +1,11 @@
-# mirai-core-utils-addition
+# mirai-core-utils-barcode
 
 mirai 内部的一些扩展工具, 提供一些扩展支持. 如在 `UnsafeDeviceVerify` 中显示二维码 等.
 
 ### 在 mcl 中安装
 
 ```shell
-./mcl --update-package net.mamoe:mirai-core-utils-addition --type core --channel beta 
+./mcl --update-package net.mamoe:mirai-core-utils-barcode --type core --channel beta 
 ```
 
 -------
diff --git a/mirai-core-utils-addition/src/jvmMain/kotlin/package.kt b/mirai-core-utils-barcode/build.gradle.kts
similarity index 53%
rename from mirai-core-utils-addition/src/jvmMain/kotlin/package.kt
rename to mirai-core-utils-barcode/build.gradle.kts
index a99d33184..60eea705f 100644
--- a/mirai-core-utils-addition/src/jvmMain/kotlin/package.kt
+++ b/mirai-core-utils-barcode/build.gradle.kts
@@ -7,4 +7,23 @@
  * https://github.com/mamoe/mirai/blob/dev/LICENSE
  */
 
-package net.mamoe.mirai.utils.addition
+
+plugins {
+    kotlin("jvm")
+    kotlin("plugin.serialization")
+    `maven-publish`
+}
+
+description = "mirai-core utilities barcode support"
+
+kotlin {
+    explicitApi()
+}
+
+dependencies {
+    implementation(project(":mirai-core-utils"))
+    implementation(`zxing-javase`)
+}
+
+configurePublishing("mirai-core-utils-barcode")
+
diff --git a/mirai-core-utils-addition/imgs/unsafe-device-verify.png b/mirai-core-utils-barcode/imgs/unsafe-device-verify.png
similarity index 100%
rename from mirai-core-utils-addition/imgs/unsafe-device-verify.png
rename to mirai-core-utils-barcode/imgs/unsafe-device-verify.png
diff --git a/mirai-core-utils-addition/src/jvmMain/kotlin/PlatformImageUtilImpl.kt b/mirai-core-utils-barcode/src/BarcodeSupportImpl.kt
similarity index 88%
rename from mirai-core-utils-addition/src/jvmMain/kotlin/PlatformImageUtilImpl.kt
rename to mirai-core-utils-barcode/src/BarcodeSupportImpl.kt
index 3877628a4..d9ee1665e 100644
--- a/mirai-core-utils-addition/src/jvmMain/kotlin/PlatformImageUtilImpl.kt
+++ b/mirai-core-utils-barcode/src/BarcodeSupportImpl.kt
@@ -7,7 +7,7 @@
  * https://github.com/mamoe/mirai/blob/dev/LICENSE
  */
 
-package net.mamoe.mirai.utils.addition
+package net.mamoe.mirai.utils.barcode
 
 import com.google.zxing.BarcodeFormat
 import com.google.zxing.WriterException
@@ -15,9 +15,9 @@ import com.google.zxing.client.j2se.MatrixToImageWriter
 import com.google.zxing.common.BitMatrix
 import com.google.zxing.qrcode.QRCodeWriter
 import net.mamoe.mirai.utils.PlatformImage
-import net.mamoe.mirai.utils.PlatformImageUtil
+import net.mamoe.mirai.utils.BarcodeSupport
 
-public class PlatformImageUtilImpl : PlatformImageUtil {
+public class BarcodeSupportImpl : BarcodeSupport {
     override val available: Boolean get() = true
 
     override fun generateQRCode(content: String, width: Int, height: Int): PlatformImage? {
diff --git a/mirai-core-utils-addition/src/commonMain/kotlin/package.kt b/mirai-core-utils-barcode/src/package.kt
similarity index 90%
rename from mirai-core-utils-addition/src/commonMain/kotlin/package.kt
rename to mirai-core-utils-barcode/src/package.kt
index a99d33184..6715218ee 100644
--- a/mirai-core-utils-addition/src/commonMain/kotlin/package.kt
+++ b/mirai-core-utils-barcode/src/package.kt
@@ -7,4 +7,4 @@
  * https://github.com/mamoe/mirai/blob/dev/LICENSE
  */
 
-package net.mamoe.mirai.utils.addition
+package net.mamoe.mirai.utils.barcode
diff --git a/mirai-core-utils/src/commonMain/kotlin/PlatformImage.kt b/mirai-core-utils/src/commonMain/kotlin/BarcodeSupport.kt
similarity index 72%
rename from mirai-core-utils/src/commonMain/kotlin/PlatformImage.kt
rename to mirai-core-utils/src/commonMain/kotlin/BarcodeSupport.kt
index 04b1506b1..9e0c932be 100644
--- a/mirai-core-utils/src/commonMain/kotlin/PlatformImage.kt
+++ b/mirai-core-utils/src/commonMain/kotlin/BarcodeSupport.kt
@@ -8,13 +8,14 @@
  */
 
 @file:JvmMultifileClass
+@file:JvmName("MiraiUtils")
 
 package net.mamoe.mirai.utils
 
 
 public expect class PlatformImage
 
-public interface PlatformImageUtil {
+public interface BarcodeSupport {
     public val available: Boolean
 
     /**
@@ -26,17 +27,17 @@ public interface PlatformImageUtil {
         height: Int
     ): PlatformImage?
 
-    public companion object INSTANCE : PlatformImageUtil by initService()
+    public companion object INSTANCE : BarcodeSupport by initService()
 }
 
-private fun initService(): PlatformImageUtil {
+private fun initService(): BarcodeSupport {
     return loadServiceOrNull(
-        PlatformImageUtil::class,
-        "net.mamoe.mirai.utils.addition.PlatformImageUtilImpl"
-    ) ?: DummyPIU
+        BarcodeSupport::class,
+        "net.mamoe.mirai.utils.barcode.BarcodeSupportImpl"
+    ) ?: DummyBSI
 }
 
-private object DummyPIU : PlatformImageUtil {
+private object DummyBSI : BarcodeSupport {
     override val available: Boolean get() = false
     override fun generateQRCode(content: String, width: Int, height: Int): PlatformImage? = null
 }
\ No newline at end of file
diff --git a/mirai-core/build.gradle.kts b/mirai-core/build.gradle.kts
index adf1e9c91..983ebeb77 100644
--- a/mirai-core/build.gradle.kts
+++ b/mirai-core/build.gradle.kts
@@ -102,7 +102,7 @@ kotlin {
         val jvmTest by getting {
             dependencies {
                 api(`kotlinx-coroutines-debug`)
-                api(project(":mirai-core-utils-addition"))
+                api(project(":mirai-core-utils-barcode"))
                 //  implementation("net.mamoe:mirai-login-solver-selenium:1.0-dev-14")
             }
         }
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 2a97f99b8..d964ed9be 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -28,7 +28,7 @@ fun includeProject(projectPath: String, dir: String? = null) {
 }
 
 includeProject(":mirai-core-utils")
-includeProject(":mirai-core-utils-addition")
+includeProject(":mirai-core-utils-barcode")
 includeProject(":mirai-core-api")
 includeProject(":mirai-core")
 includeProject(":mirai-core-all")