[build] Fully support Android target; Update to Gradle 8.0

This commit is contained in:
Him188 2023-04-17 11:40:28 +01:00
parent fc549d380f
commit 164f621427
39 changed files with 534 additions and 589 deletions

View File

@ -39,8 +39,9 @@ plugins {
id("me.him188.kotlin-jvm-blocking-bridge") version Versions.blockingBridge
id("me.him188.kotlin-dynamic-delegation") version Versions.dynamicDelegation apply false
id("me.him188.maven-central-publish") version Versions.mavenCentralPublish apply false
id("com.gradle.plugin-publish") version "1.0.0-rc-3" apply false
id("com.gradle.plugin-publish") version "1.1.0" apply false
id("org.jetbrains.kotlinx.binary-compatibility-validator") version Versions.binaryValidator apply false
id("com.android.library") apply false
}
osDetector = osdetector
@ -69,9 +70,7 @@ allprojects {
configureMppShadow()
configureEncoding()
configureKotlinTestSettings()
configureKotlinExperimentalUsages()
// useIr()
configureKotlinOptIns()
if (isKotlinJvmProject) {
configureFlattenSourceSets()
@ -110,12 +109,6 @@ extensions.findByName("buildScan")?.withGroovyBuilder {
setProperty("termsOfServiceAgree", "yes")
}
fun Project.useIr() {
kotlinCompilations?.forEach { kotlinCompilation ->
kotlinCompilation.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
}
}
fun Project.configureDokka() {
val isRoot = this@configureDokka == rootProject
if (!isRoot) {

View File

@ -70,6 +70,10 @@ dependencies {
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
}
// https://mvnrepository.com/artifact/com.android.library/com.android.library.gradle.plugin
api("com.android.library:com.android.library.gradle.plugin:${version("androidGradlePlugin")}")
api("com.google.code.gson:gson:2.10.1")
api("gradle.plugin.com.google.gradle:osdetector-gradle-plugin:1.7.0")
api(gradleApi())

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@ -52,7 +52,8 @@ object BinaryCompatibilityConfigurator {
}
}
private fun Project.getValidatorDir(dir: File) = ":validator" + project.path + ":${dir.name}"
// Also change: settings.gradle.kts:116
private fun Project.getValidatorDir(dir: File) = ":validator" + project.path + "-validator:${dir.name}"
private fun File.writeTextIfNeeded(text: String) {
if (!this.exists()) return this.writeText(text)
@ -81,7 +82,13 @@ object BinaryCompatibilityConfigurator {
if (targetName == null) {
tasks.findByName("apiBuild")?.dependsOn(project.tasks.getByName("jar"))
} else {
tasks.findByName("apiBuild")?.dependsOn(project.tasks.getByName("${targetName}Jar"))
tasks.findByName("apiBuild")?.dependsOn(
if (targetName.contains("android")) {
project.tasks.getByName("bundleDebugAar")
} else {
project.tasks.getByName("${targetName}Jar")
}
)
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@ -70,7 +70,6 @@ object DependencyDumper {
val outFile = temporaryDir.resolve(out)
outputs.file(outFile)
val conf = project.configurations.getByName(confName)
dependsOn(conf)
doLast {
outFile.parentFile.mkdirs()

View File

@ -7,9 +7,14 @@
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@file:Suppress("UNUSED_VARIABLE")
import com.android.build.api.dsl.LibraryExtension
import com.google.gradle.osdetector.OsDetector
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.attributes.Attribute
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getting
import org.gradle.kotlin.dsl.withType
@ -23,6 +28,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
import java.io.File
import java.util.*
val MIRAI_PLATFORM_ATTRIBUTE = Attribute.of(
"net.mamoe.mirai.platform", String::class.java
@ -37,7 +43,7 @@ val MIRAI_PLATFORM_INTERMEDIATE = Attribute.of(
val IDEA_ACTIVE = System.getProperty("idea.active") == "true" && System.getProperty("publication.test") != "true"
val OS_NAME = System.getProperty("os.name").toLowerCase()
val OS_NAME = System.getProperty("os.name").lowercase()
lateinit var osDetector: OsDetector
@ -162,7 +168,7 @@ fun Project.configureJvmTargetsHierarchical() {
compilations.all {
this.compileTaskProvider.configure { // IDE complain
enabled = false
}
}
}
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) // magic
attributes.attribute(MIRAI_PLATFORM_ATTRIBUTE, "jvmBase") // avoid resolution
@ -183,16 +189,47 @@ fun Project.configureJvmTargetsHierarchical() {
if (isTargetEnabled("android")) {
if (isAndroidSDKAvailable) {
jvm("android") {
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
// apply(plugin = "com.android.library")
android {
if (IDEA_ACTIVE) {
attributes.attribute(MIRAI_PLATFORM_ATTRIBUTE, "android") // avoid resolution
}
}
configureAndroidTarget()
val androidMain by sourceSets.getting
val androidTest by sourceSets.getting
androidMain.dependsOn(jvmBaseMain)
androidTest.dependsOn(jvmBaseTest)
for (s in arrayOf("androidMain")) {
sourceSets.all { if (name in s) dependsOn(jvmBaseMain) }
}
// this can cause problems on sync
// for (s in arrayOf("androidDebug", "androidRelease")) {
// sourceSets.all { if (name in s) dependsOn(androidMain) }
// }
val androidUnitTest by sourceSets.getting {
dependsOn(jvmBaseTest)
}
// for (s in arrayOf("androidUnitTestDebug", "androidUnitTestRelease")) {
// sourceSets.all { if (name in s) dependsOn(androidUnitTest) }
// }
val androidInstrumentedTest by sourceSets.getting {
dependsOn(jvmBaseTest)
}
// for (s in arrayOf("androidInstrumentedTestDebug")) {
// sourceSets.all { if (name in s) dependsOn(androidInstrumentedTest) }
// }
// afterEvaluate {
//// > androidDebug dependsOn commonMain
//// androidInstrumentedTest dependsOn jvmBaseTest
//// androidInstrumentedTestDebug dependsOn
//// androidMain dependsOn commonMain, jvmBaseMain
//// androidRelease dependsOn commonMain
//// androidUnitTest dependsOn commonTest, jvmBaseTest
//// androidUnitTestDebug dependsOn commonTest
//// androidUnitTestRelease dependsOn commonTest
// error(this@apply.sourceSets.joinToString("\n") {
// it.name + " dependsOn " + it.dependsOn.joinToString { it.name }
// })
// }
} else {
printAndroidNotInstalled()
}
@ -210,6 +247,41 @@ fun Project.configureJvmTargetsHierarchical() {
}
}
@Suppress("UnstableApiUsage")
fun Project.configureAndroidTarget() {
extensions.getByType(KotlinMultiplatformExtension::class.java).apply {
// trick
this.sourceSets.apply {
removeIf { it.name == "androidAndroidTestRelease" }
removeIf { it.name == "androidTestFixtures" }
removeIf { it.name == "androidTestFixturesDebug" }
removeIf { it.name == "androidTestFixturesRelease" }
}
}
extensions.getByType(LibraryExtension::class.java).apply {
compileSdk = 33
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = rootProject.extra["mirai.android.target.api.level"]!!.toString().toInt()
targetSdk = 33
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
buildTypes.getByName("release") {
isMinifyEnabled = true
isShrinkResources = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
)
}
}
}
/**
* ```
* common
@ -235,13 +307,14 @@ fun KotlinMultiplatformExtension.configureNativeTargetsHierarchical(
val nativeMainSets = mutableListOf<KotlinSourceSet>()
val nativeTestSets = mutableListOf<KotlinSourceSet>()
val nativeTargets = mutableListOf<KotlinTarget>() // actually KotlinNativeTarget, but KotlinNativeTarget is an internal API (complained by IDEA)
val nativeTargets =
mutableListOf<KotlinTarget>() // actually KotlinNativeTarget, but KotlinNativeTarget is an internal API (complained by IDEA)
fun KotlinMultiplatformExtension.addNativeTarget(
preset: KotlinTargetPreset<*>,
): KotlinTarget {
val target = targetFromPreset(preset, preset.name)
val target = targetFromPreset(preset, preset.name)
nativeMainSets.add(target.compilations[MAIN_COMPILATION_NAME].kotlinSourceSets.first())
nativeTestSets.add(target.compilations[TEST_COMPILATION_NAME].kotlinSourceSets.first())
nativeTargets.add(target)
@ -387,10 +460,10 @@ fun KotlinMultiplatformExtension.configureNativeTargetBinaries(project: Project)
val target = targets.getByName(targetName) as KotlinNativeTarget
target.binaries {
sharedLib(listOf(NativeBuildType.DEBUG, NativeBuildType.RELEASE)) {
baseName = project.name.toLowerCase().replace("-", "")
baseName = project.name.lowercase(Locale.ROOT).replace("-", "")
}
staticLib(listOf(NativeBuildType.DEBUG, NativeBuildType.RELEASE)) {
baseName = project.name.toLowerCase().replace("-", "")
baseName = project.name.lowercase(Locale.ROOT).replace("-", "")
}
}
}

View File

@ -7,32 +7,23 @@
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@file:Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
import org.gradle.api.JavaVersion
import org.gradle.api.NamedDomainObjectCollection
import org.gradle.api.NamedDomainObjectList
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
fun Project.useIr() {
kotlinCompilations?.forEach { kotlinCompilation ->
kotlinCompilation.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
}
}
private fun Project.jvmVersion(): JavaVersion {
return if (project.path.endsWith("mirai-console-intellij")) {
JavaVersion.VERSION_17
@ -94,22 +85,16 @@ fun Project.preConfigureJvmTarget() {
fun Project.configureJvmTarget() {
val defaultVer = jvmVersion()
configure(kotlinSourceSets.orEmpty()) {
languageSettings {
optIn("net.mamoe.mirai.utils.TestOnly")
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
}
}
extensions.findByType(JavaPluginExtension::class.java)?.run {
sourceCompatibility = defaultVer
targetCompatibility = defaultVer
}
kotlinTargets.orEmpty().filterIsInstance<KotlinJvmTarget>().forEach { target ->
when (target.attributes.getAttribute(KotlinPlatformType.attribute)) { // mirai does magic, don't use target.platformType
allKotlinTargets().all {
if (this !is KotlinJvmTarget) return@all
when (this.attributes.getAttribute(KotlinPlatformType.attribute)) { // mirai does magic, don't use target.platformType
KotlinPlatformType.androidJvm -> {
target.compilations.all {
this.compilations.all {
/*
* Kotlin JVM compiler generates Long.hashCode witch is available since API 26 when targeting JVM 1.8 while IR prefer member function hashCode always.
*/
@ -122,7 +107,7 @@ fun Project.configureJvmTarget() {
else -> {
}
}
target.testRuns["test"].executionTask.configure { useJUnitPlatform() }
this.testRuns["test"].executionTask.configure { useJUnitPlatform() }
}
}
@ -148,7 +133,8 @@ fun Project.configureKotlinTestSettings() {
}
isKotlinMpp -> {
kotlinSourceSets?.forEach { sourceSet ->
kotlinSourceSets?.all {
val sourceSet = this
fun configureJvmTest(sourceSet: KotlinSourceSet) {
sourceSet.dependencies {
implementation(kotlin("test-junit5"))?.because(b)
@ -158,12 +144,14 @@ fun Project.configureKotlinTestSettings() {
}
}
val target = kotlinTargets.orEmpty()
val target = allKotlinTargets()
.find { it.name == sourceSet.name.substringBeforeLast("Main").substringBeforeLast("Test") }
when {
sourceSet.name == "commonTest" -> {
if (isJvmLikePlatform(target)) {
if (target?.platformType == KotlinPlatformType.jvm &&
target.attributes.getAttribute(MIRAI_PLATFORM_INTERMEDIATE) != true
) {
configureJvmTest(sourceSet)
} else {
sourceSet.dependencies {
@ -174,7 +162,9 @@ fun Project.configureKotlinTestSettings() {
}
sourceSet.name.contains("test", ignoreCase = true) -> {
if (isJvmLikePlatform(target)) {
if (target?.platformType == KotlinPlatformType.jvm &&
target.attributes.getAttribute(MIRAI_PLATFORM_INTERMEDIATE) != true
) {
configureJvmTest(sourceSet)
}
}
@ -191,7 +181,9 @@ val testExperimentalAnnotations = arrayOf(
"kotlin.ExperimentalUnsignedTypes",
"kotlin.time.ExperimentalTime",
"io.ktor.util.KtorExperimentalAPI",
"kotlin.io.path.ExperimentalPathApi"
"kotlin.io.path.ExperimentalPathApi",
"kotlinx.coroutines.ExperimentalCoroutinesApi",
"net.mamoe.mirai.utils.TestOnly",
)
val experimentalAnnotations = arrayOf(
@ -217,11 +209,10 @@ val testLanguageFeatures = listOf(
"ContextReceivers"
)
fun Project.configureKotlinExperimentalUsages() {
fun Project.configureKotlinOptIns() {
val sourceSets = kotlinSourceSets ?: return
for (target in sourceSets) {
target.configureKotlinExperimentalUsages()
sourceSets.all {
configureKotlinOptIns()
}
for (name in testLanguageFeatures) {
@ -233,7 +224,7 @@ fun Project.configureKotlinExperimentalUsages() {
}
}
fun KotlinSourceSet.configureKotlinExperimentalUsages() {
fun KotlinSourceSet.configureKotlinOptIns() {
languageSettings.progressiveMode = true
experimentalAnnotations.forEach { a ->
languageSettings.optIn(a)
@ -278,13 +269,22 @@ inline fun <reified T> Any?.safeAs(): T? {
val Project.kotlinSourceSets get() = extensions.findByName("kotlin").safeAs<KotlinProjectExtension>()?.sourceSets
val Project.kotlinTargets
get() =
extensions.findByName("kotlin").safeAs<KotlinSingleTargetExtension<*>>()?.target?.let { listOf(it) }
?: extensions.findByName("kotlin").safeAs<KotlinMultiplatformExtension>()?.targets
fun Project.allKotlinTargets(): NamedDomainObjectCollection<KotlinTarget> {
return extensions.findByName("kotlin")?.safeAs<KotlinSingleTargetExtension<*>>()
?.target?.let { namedDomainObjectListOf(it) }
?: extensions.findByName("kotlin")?.safeAs<KotlinMultiplatformExtension>()?.targets
?: namedDomainObjectListOf()
}
private inline fun <reified T> Project.namedDomainObjectListOf(vararg values: T): NamedDomainObjectList<T> {
return objects.namedDomainObjectList(T::class.java).apply { addAll(values) }
}
val Project.isKotlinJvmProject: Boolean get() = extensions.findByName("kotlin") is KotlinJvmProjectExtension
val Project.isKotlinMpp: Boolean get() = extensions.findByName("kotlin") is KotlinMultiplatformExtension
val Project.kotlinCompilations
get() = kotlinTargets?.flatMap { it.compilations }
fun Project.allKotlinCompilations(action: (KotlinCompilation<KotlinCommonOptions>) -> Unit) {
allKotlinTargets().all {
compilations.all(action)
}
}

View File

@ -98,6 +98,7 @@ fun KotlinDependencyHandler.relocateCompileOnly(
relocatedDependency: RelocatedDependency,
): ExternalModuleDependency {
val dependency = compileOnly(relocatedDependency.notation) {
relocatedDependency.exclusionAction(this)
}
project.relocationFilters.add(
RelocationFilter(
@ -122,6 +123,7 @@ fun DependencyHandler.relocateCompileOnly(
): Dependency {
val dependency =
addDependencyTo(this, "compileOnly", relocatedDependency.notation, Action<ExternalModuleDependency> {
relocatedDependency.exclusionAction(this)
})
project.relocationFilters.add(
RelocationFilter(
@ -145,7 +147,7 @@ fun KotlinDependencyHandler.relocateImplementation(
action: ExternalModuleDependency.() -> Unit = {}
): ExternalModuleDependency {
val dependency = implementation(relocatedDependency.notation) {
relocatedDependency.exclusionAction(this)
}
project.relocationFilters.add(
RelocationFilter(
@ -181,6 +183,7 @@ fun DependencyHandler.relocateImplementation(
): ExternalModuleDependency {
val dependency =
addDependencyTo(this, "implementation", relocatedDependency.notation, Action<ExternalModuleDependency> {
relocatedDependency.exclusionAction(this)
})
project.relocationFilters.add(
RelocationFilter(

View File

@ -55,13 +55,16 @@ fun Project.configureShadowDependenciesForPublishing() {
"configureShadowDependenciesForPublishing can only be used on root project."
}
val jarTaskNames = arrayOf("jvmJar", "jvmBaseJar")
gradle.projectsEvaluated {
// Tasks requested to run in this build
val allTasks = rootProject.allprojects.asSequence().flatMap { it.tasks }
val publishTasks = allTasks.filter { it.name.contains("publish", ignoreCase = true) }
val relocateTasks = allTasks.filter { it.name.contains("relocate", ignoreCase = true) }
val jarTasks = allTasks.filter { it.name.contains("jar", ignoreCase = true) }
val jarTasks = allTasks.filter {
it.name in jarTaskNames
}
val compileKotlinTasks = allTasks.filter { it.name.contains("compileKotlin", ignoreCase = true) }
val compileTestKotlinTasks = allTasks.filter { it.name.contains("compileTestKotlin", ignoreCase = true) }
@ -99,7 +102,7 @@ private fun KotlinTarget.configureRelocationForMppTarget(project: Project) = pro
group = "mirai"
description = "Relocate dependencies to internal package"
destinationDirectory.set(buildDir.resolve("libs")) // build/libs
archiveBaseName.set("${project.name}-${targetName.toLowerCase()}") // e.g. "mirai-core-api-jvm"
archiveBaseName.set("${project.name}-${targetName.lowercase()}") // e.g. "mirai-core-api-jvm"
dependsOn(compilations["main"].compileTaskProvider) // e.g. compileKotlinJvm

View File

@ -0,0 +1,10 @@
/*
* Copyright 2019-2023 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
*/
fun String.capitalize(): String = this.replaceFirstChar { it.uppercaseChar() }

View File

@ -56,7 +56,7 @@ object Versions {
const val dynamicDelegation = "0.4.0-180.1"
const val mavenCentralPublish = "1.0.0"
const val androidGradlePlugin = "4.1.1"
const val androidGradlePlugin = "7.3.1"
const val android = "4.1.1.4"
const val shadow = "8.1.0"
@ -172,6 +172,7 @@ object ExcludeProperties {
val `kotlinx-coroutines` = multiplatformJvm(groupId = "org.jetbrains.kotlinx", "kotlinx-coroutines")
val `ktor-io` = multiplatformJvm(groupId = "io.ktor", "ktor-io")
val `everything from slf4j` = exclude(groupId = "org.slf4j", null)
val `slf4j-api` = exclude(groupId = "org.slf4j", "slf4j-api")
/**
* @see org.gradle.kotlin.dsl.exclude
@ -192,6 +193,7 @@ object ExcludeProperties {
val `ktor-io` = ktor("io", Versions.ktor)
val `ktor-io_relocated` = RelocatedDependency(`ktor-io`, "io.ktor.utils.io") {
exclude(ExcludeProperties.`everything from slf4j`)
exclude(ExcludeProperties.`slf4j-api`)
}
val `ktor-http` = ktor("http", Versions.ktor)

View File

@ -0,0 +1,36 @@
/*
* Copyright 2019-2023 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.dsl.KotlinCompile
/*
* Copyright 2019-2023 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
*/
private val EXPLICIT_API = "-Xexplicit-api=strict"
// Workaround for explicit API in androidMain
// https://youtrack.jetbrains.com/issue/KT-37652/Support-explicit-mode-for-Android-projects
// https://youtrack.jetbrains.com/issue/KT-37652/Support-explicit-mode-for-Android-projects#focus=Comments-27-4501224.0-0
project.tasks
.matching { it is KotlinCompile<*> && !it.name.contains("test", ignoreCase = true) }
.configureEach {
if (!project.hasProperty("kotlin.optOutExplicitApi")) {
val kotlinCompile = this as KotlinCompile<*>
if (EXPLICIT_API !in kotlinCompile.kotlinOptions.freeCompilerArgs) {
kotlinCompile.kotlinOptions.freeCompilerArgs += EXPLICIT_API
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@ -34,7 +34,7 @@ fun ByteArray.toUHexString(
return buildString(length * 2) {
this@toUHexString.forEachIndexed { index, it ->
if (index in offset until lastIndex) {
var ret = it.toUByte().toString(16).toUpperCase()
var ret = it.toUByte().toString(16).uppercase()
if (ret.length == 1) ret = "0$ret"
append(ret)
if (index < lastIndex - 1) append(separator)

View File

@ -1,5 +1,5 @@
#
# Copyright 2019-2022 Mamoe Technologies and contributors.
# Copyright 2019-2023 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.
@ -23,4 +23,7 @@ systemProp.use.maven.local=false
org.gradle.caching=true
kotlin.native.ignoreIncorrectDependencies=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.stability.nowarn=true
kotlin.mpp.stability.nowarn=true
kotlin.mpp.androidSourceSetLayoutVersion=2
android.disableAutomaticComponentCreation=true

Binary file not shown.

View File

@ -1,13 +1,14 @@
#
# Copyright 2019-2021 Mamoe Technologies and contributors.
# Copyright 2019-2023 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.
# 此源代码的使用受 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/master/LICENSE
# https://github.com/mamoe/mirai/blob/dev/LICENSE
#
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

275
gradlew vendored
View File

@ -1,87 +1,122 @@
#!/usr/bin/env sh
#!/bin/sh
#
# Copyright 2019-2020 Mamoe Technologies and contributors.
# Copyright 2019-2023 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.
# 此源代码的使用受 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/master/LICENSE
# https://github.com/mamoe/mirai/blob/dev/LICENSE
#
##############################################################################
##
## Gradle start up script for UN*X
##
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
MAX_FD=maximum
warn () {
echo "$*"
}
} >&2
die () {
echo
echo "$*"
echo
exit 1
}
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD="$JAVA_HOME/bin/java"
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@ -90,7 +125,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
@ -98,79 +133,95 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

25
gradlew.bat vendored
View File

@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@ -51,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@ -61,28 +64,14 @@ echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell

View File

@ -10,6 +10,7 @@
@file:Suppress("UnusedImport")
import BinaryCompatibilityConfigurator.configureBinaryValidator
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
@ -33,9 +34,11 @@ kotlin {
// 搜索 mirai-console (包括 core) 直接使用并对外公开的类 (api)
configurations.create("consoleRuntimeClasspath").attributes {
attribute(Usage.USAGE_ATTRIBUTE,
attribute(
Usage.USAGE_ATTRIBUTE,
project.objects.named(Usage::class.java, Usage.JAVA_API)
)
attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
}.also { consoleRuntimeClasspath ->
consoleRuntimeClasspath.exclude(group = "io.ktor")
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@ -12,6 +12,7 @@
plugins {
kotlin("multiplatform")
`maven-publish`
id("com.android.library")
}
version = Versions.console
@ -19,9 +20,14 @@ description = "Mirai Console compiler annotations"
kotlin {
explicitApi()
apply(plugin = "explicit-api")
configureJvmTargetsHierarchical()
configureNativeTargetsHierarchical(project)
}
configureMppPublishing()
configureMppPublishing()
android {
namespace = "net.mamoe.mirai.compiler.annotations"
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019-2023 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
-->
<manifest package="net.mamoe.mirai.console.compiler.common">
</manifest>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@ -69,20 +69,18 @@ kotlin {
explicitApi()
}
pluginBundle {
website = "https://github.com/mamoe/mirai"
vcsUrl = "https://github.com/mamoe/mirai"
tags = listOf("framework", "kotlin", "mirai")
}
@Suppress("UnstableApiUsage")
gradlePlugin {
testSourceSets(integTest)
website.set("https://github.com/mamoe/mirai")
vcsUrl.set("https://github.com/mamoe/mirai")
plugins {
create("miraiConsole") {
id = "net.mamoe.mirai-console"
displayName = "Mirai Console"
description = project.description
implementationClass = "net.mamoe.mirai.console.gradle.MiraiConsoleGradlePlugin"
tags.set(listOf("framework", "kotlin", "mirai"))
}
}
}

View File

@ -130,7 +130,7 @@ private fun Project.registerMavenPublications(target: KotlinTarget, isSingleTarg
@Suppress("DEPRECATION")
val sourcesJar by tasks.registering(Jar::class) {
classifier = "sources"
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}

View File

@ -11,6 +11,7 @@
import BinaryCompatibilityConfigurator.configureBinaryValidators
plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("plugin.serialization")
@ -27,11 +28,12 @@ description = "Mirai API module"
kotlin {
explicitApi()
apply(plugin = "explicit-api")
configureJvmTargetsHierarchical()
configureNativeTargetsHierarchical(project)
sourceSets {
val commonMain by getting {
dependencies {
@ -44,7 +46,10 @@ kotlin {
implementation(project(":mirai-console-compiler-annotations"))
implementation(`kotlinx-serialization-protobuf`)
implementation(`kotlinx-atomicfu`)
relocateCompileOnly(`ktor-io_relocated`) // runtime from mirai-core-utils
// runtime from mirai-core-utils
relocateCompileOnly(`ktor-io_relocated`)
implementation(`kotlin-jvm-blocking-bridge`)
implementation(`kotlin-dynamic-delegation`)
}
@ -65,9 +70,17 @@ kotlin {
}
}
afterEvaluate {
getByName("androidUnitTest") {
dependencies {
runtimeOnly(`slf4j-api`)
}
}
}
findByName("androidMain")?.apply {
dependencies {
compileOnly(`android-runtime`)
// compileOnly(`android-runtime`)
}
}
@ -116,4 +129,8 @@ configureBinaryValidators(setOf("jvm", "android").filterTargets())
// developer("Mamoe Technologies", email = "support@mamoe.net", url = "https://github.com/mamoe")
// licenseFromGitHubProject("AGPLv3", "dev")
// publishPlatformArtifactsInRootModule = "jvm"
//}
//}
android {
namespace = "net.mamoe.mirai"
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019-2023 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
-->
<manifest package="net.mamoe.mirai" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@ -1,14 +1,12 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
* 此源代码的使用受 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/master/LICENSE
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
@file:Suppress("MemberVisibilityCanBePrivate")
package net.mamoe.mirai.utils
import android.util.Log
@ -26,7 +24,7 @@ public actual open class PlatformLogger actual constructor(
) : MiraiLoggerPlatformBase() {
public override fun verbose0(message: String?) {
Log.v(identity, message)
Log.v(identity, message.toString())
}
public override fun verbose0(message: String?, e: Throwable?) {
@ -35,7 +33,7 @@ public actual open class PlatformLogger actual constructor(
public override fun info0(message: String?) {
Log.i(identity, message)
Log.i(identity, message.toString())
}
public override fun info0(message: String?, e: Throwable?) {
@ -44,7 +42,7 @@ public actual open class PlatformLogger actual constructor(
public override fun warning0(message: String?) {
Log.w(identity, message)
Log.w(identity, message.toString())
}
public override fun warning0(message: String?, e: Throwable?) {
@ -53,7 +51,7 @@ public actual open class PlatformLogger actual constructor(
public override fun error0(message: String?) {
Log.e(identity, message)
Log.e(identity, message.toString())
}
public override fun error0(message: String?, e: Throwable?) {
@ -62,7 +60,7 @@ public actual open class PlatformLogger actual constructor(
public override fun debug0(message: String?) {
Log.d(identity, message)
Log.d(identity, message.toString())
}
public override fun debug0(message: String?, e: Throwable?) {

View File

@ -1,125 +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 android.util
import net.mamoe.mirai.internal.utils.StdoutLogger
// Dummy implementation for tests, since we don't have a SDK
@Suppress("UNUSED_PARAMETER", "unused")
object Log {
const val VERBOSE = 2
const val DEBUG = 3
const val INFO = 4
const val WARN = 5
const val ERROR = 6
const val ASSERT = 7
private val stdout = StdoutLogger("AndroidLog")
@JvmStatic
fun v(tag: String?, msg: String?): Int {
stdout.verbose(msg)
return 0
}
@JvmStatic
fun v(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.verbose(msg, tr)
return 0
}
@JvmStatic
fun d(tag: String?, msg: String?): Int {
stdout.debug(msg, tr)
return 0
}
@JvmStatic
fun d(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.debug(msg, tr)
return 0
}
@JvmStatic
fun i(tag: String?, msg: String?): Int {
stdout.info(msg, tr)
return 0
}
@JvmStatic
fun i(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.info(msg, tr)
return 0
}
@JvmStatic
fun w(tag: String?, msg: String?): Int {
stdout.warning(msg, tr)
return 0
}
@JvmStatic
fun w(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.warning(msg, tr)
return 0
}
@JvmStatic
fun w(tag: String?, tr: Throwable?): Int {
stdout.warning(msg, tr)
return 0
}
@JvmStatic
fun e(tag: String?, msg: String?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun e(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun wtf(tag: String?, msg: String?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun wtf(tag: String?, tr: Throwable?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun wtf(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun getStackTraceString(tr: Throwable): String {
return tr.stackTraceToString()
}
@JvmStatic
fun println(priority: Int, tag: String?, msg: String?): Int {
stdout.info(msg, tr)
return 0
}
private inline val tr get() = null
private inline val msg get() = null
}

View File

@ -10,6 +10,7 @@
@file:Suppress("UNUSED_VARIABLE")
plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("plugin.serialization")
@ -23,6 +24,7 @@ description = "mirai-core utilities"
kotlin {
explicitApi()
apply(plugin = "explicit-api")
configureJvmTargetsHierarchical()
configureNativeTargetsHierarchical(project)
@ -79,22 +81,22 @@ kotlin {
}
}
if (tasks.findByName("androidMainClasses") != null) {
tasks.register("checkAndroidApiLevel") {
doFirst {
analyzes.AndroidApiLevelCheck.check(
buildDir.resolve("classes/kotlin/android/main"),
project.property("mirai.android.target.api.level")!!.toString().toInt(),
project
)
}
group = "verification"
this.mustRunAfter("androidMainClasses")
}
tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
}
//if (tasks.findByName("androidMainClasses") != null) {
// tasks.register("checkAndroidApiLevel") {
// doFirst {
// analyzes.AndroidApiLevelCheck.check(
// buildDir.resolve("classes/kotlin/android/main"),
// project.property("mirai.android.target.api.level")!!.toString().toInt(),
// project
// )
// }
// group = "verification"
// this.mustRunAfter("androidMainClasses")
// }
// tasks.getByName("androidTest").dependsOn("checkAndroidApiLevel")
//}
configureMppPublishing()
//configureMppPublishing()
//mavenCentralPublish {
// artifactId = "mirai-core-utils"
@ -102,4 +104,8 @@ configureMppPublishing()
// developer("Mamoe Technologies", email = "support@mamoe.net", url = "https://github.com/mamoe")
// licenseFromGitHubProject("AGPLv3", "dev")
// publishPlatformArtifactsInRootModule = "jvm"
//}
//}
android {
namespace = "net.mamoe.mirai.utils"
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019-2023 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
-->
<manifest package="net.mamoe.mirai" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@ -1,32 +0,0 @@
/*
* Copyright 2019-2021 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
import kotlin.test.Test
import kotlin.test.assertIs
class AndroidUnwrapTest {
@Test
fun test() {
val e =
IllegalStateException(
OutOfMemoryError().initCause(VerifyError()).apply { addSuppressed(UnsatisfiedLinkError()) }
)
val unwrapped = e.unwrap<IllegalStateException>()
unwrapped.printStackTrace()
assertIs<OutOfMemoryError>(unwrapped)
assertIs<VerifyError>(unwrapped.cause)
assertIs<UnsatisfiedLinkError>(unwrapped.suppressed.first())
assertIs<StacktraceException>(unwrapped.suppressed[1])
}
}

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019-2020 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/master/LICENSE
-->
<manifest package="net.mamoe.mirai" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
</manifest>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractNativeLibrary
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
id("com.android.library")
kotlin("multiplatform")
id("kotlinx-atomicfu")
kotlin("plugin.serialization")
@ -27,6 +28,7 @@ description = "Mirai Protocol implementation for QQ Android"
kotlin {
explicitApi()
apply(plugin = "explicit-api")
configureJvmTargetsHierarchical()
configureNativeTargetsHierarchical(project)
@ -238,4 +240,8 @@ configureBinaryValidators(setOf("jvm", "android").filterTargets())
// developer("Mamoe Technologies", email = "support@mamoe.net", url = "https://github.com/mamoe")
// licenseFromGitHubProject("AGPLv3", "dev")
// publishPlatformArtifactsInRootModule = "jvm"
//}
//}
android {
namespace = "net.mamoe.mirai.internal"
}

View File

@ -0,0 +1,10 @@
/*
* Copyright 2019-2023 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.internal

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@ -9,10 +9,9 @@
package net.mamoe.mirai.internal.test
//import org.bouncycastle.jce.provider.BouncyCastleProvider
import net.mamoe.mirai.utils.MiraiLogger
import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.security.Security
import kotlin.test.Test
import org.junit.jupiter.api.Test
import kotlin.test.assertIs
internal actual fun initPlatform() {
@ -20,10 +19,10 @@ internal actual fun initPlatform() {
}
private val init: Unit by lazy {
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) != null) {
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME)
}
Security.addProvider(BouncyCastleProvider())
// if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) != null) {
// Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME)
// }
// Security.addProvider(BouncyCastleProvider())
Unit
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019-2023 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
-->
<manifest package="net.mamoe.mirai.internal" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@ -1,127 +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
*/
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package android.util
import net.mamoe.mirai.internal.utils.StdoutLogger
// Dummy implementation for tests, since we don't have an Android SDK
@Suppress("UNUSED_PARAMETER", "unused")
object Log {
const val VERBOSE = 2
const val DEBUG = 3
const val INFO = 4
const val WARN = 5
const val ERROR = 6
const val ASSERT = 7
private val stdout = StdoutLogger("AndroidLog")
@JvmStatic
fun v(tag: String?, msg: String?): Int {
stdout.verbose(msg)
return 0
}
@JvmStatic
fun v(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.verbose(msg, tr)
return 0
}
@JvmStatic
fun d(tag: String?, msg: String?): Int {
stdout.debug(msg, tr)
return 0
}
@JvmStatic
fun d(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.debug(msg, tr)
return 0
}
@JvmStatic
fun i(tag: String?, msg: String?): Int {
stdout.info(msg, tr)
return 0
}
@JvmStatic
fun i(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.info(msg, tr)
return 0
}
@JvmStatic
fun w(tag: String?, msg: String?): Int {
stdout.warning(msg, tr)
return 0
}
@JvmStatic
fun w(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.warning(msg, tr)
return 0
}
@JvmStatic
fun w(tag: String?, tr: Throwable?): Int {
stdout.warning(msg, tr)
return 0
}
@JvmStatic
fun e(tag: String?, msg: String?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun e(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun wtf(tag: String?, msg: String?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun wtf(tag: String?, tr: Throwable?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun wtf(tag: String?, msg: String?, tr: Throwable?): Int {
stdout.error(msg, tr)
return 0
}
@JvmStatic
fun getStackTraceString(tr: Throwable): String {
return tr.stackTraceToString()
}
@JvmStatic
fun println(priority: Int, tag: String?, msg: String?): Int {
stdout.info(msg, tr)
return 0
}
private inline val tr get() = null
private inline val msg get() = null
}

View File

@ -1,10 +0,0 @@
/*
* Copyright 2019-2021 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/master/LICENSE
*/
package net.mamoe.mirai.internal

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019-2020 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/master/LICENSE
-->
<manifest package="net.mamoe.mirai.internal" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
</manifest>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@ -113,7 +113,8 @@ fun includeBinaryCompatibilityValidatorProjects() {
if (!validationDir.exists()) continue
validationDir.listFiles().orEmpty<File>().forEach { dir ->
if (dir.resolve("build.gradle.kts").isFile) {
val path = ":validator" + project.path + ":${dir.name}"
// Also change: BinaryCompatibilityConfigurator.getValidatorDir
val path = ":validator" + project.path + "-validator:${dir.name}"
include(path)
project(path).projectDir = dir
// project(path).name = "${project.name}-validator-${dir.name}"
@ -166,8 +167,6 @@ fun includeConsoleIntegrationTestProjects() {
}
fun getLocalProperty(name: String): String? {
return localProperties.getProperty(name)
}