Him188 4 роки тому
батько
коміт
ec7b72afb3

+ 22 - 11
tools/gradle-plugin/build.gradle.kts

@@ -22,6 +22,8 @@ plugins {
     id("com.github.johnrengelman.shadow")
 }
 
+val integTest = sourceSets.create("integTest")
+
 dependencies {
     compileOnly(gradleApi())
     compileOnly(gradleKotlinDsl())
@@ -44,11 +46,15 @@ dependencies {
     testApi(kotlin("test-junit5"))
     testApi("org.junit.jupiter:junit-jupiter-api:${Versions.junit}")
     testApi("org.junit.jupiter:junit-jupiter-params:${Versions.junit}")
-    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${Versions.junit}")
-    // testApi("org.spockframework:spock-core:1.3-groovy-2.5")
-    testRuntimeOnly(kotlin("gradle-plugin"))
-    testRuntimeOnly(kotlin("gradle-plugin-api"))
-    testImplementation(gradleTestKit())
+
+    "integTestApi"(kotlin("test-junit5"))
+    "integTestApi"("org.junit.jupiter:junit-jupiter-api:${Versions.junit}")
+    "integTestApi"("org.junit.jupiter:junit-jupiter-params:${Versions.junit}")
+    "integTestImplementation"("org.junit.jupiter:junit-jupiter-engine:${Versions.junit}")
+//    "integTestImplementation"("org.spockframework:spock-core:1.3-groovy-2.5")
+    "integTestImplementation"(kotlin("gradle-plugin"))
+    "integTestImplementation"(kotlin("gradle-plugin-api"))
+    "integTestImplementation"(gradleTestKit())
 }
 
 version = Versions.console
@@ -65,7 +71,7 @@ pluginBundle {
 }
 
 gradlePlugin {
-    testSourceSets(sourceSets.test.get())
+    testSourceSets(integTest)
     plugins {
         create("miraiConsole") {
             id = "net.mamoe.mirai-console"
@@ -83,10 +89,15 @@ kotlin.target.compilations.all {
     }
 }
 
-tasks.withType<GroovyCompile> {
-    if (name.contains("test", ignoreCase = true)) {
-        source = project.fileTree("test")
-    }
+val integrationTestTask = tasks.register<Test>("integTest") {
+    description = "Runs the integration tests."
+    group = "verification"
+    testClassesDirs = integTest.output.classesDirs
+    classpath = integTest.runtimeClasspath
+    mustRunAfter(tasks.test)
+}
+tasks.check {
+    dependsOn(integrationTestTask)
 }
 
 tasks {
@@ -95,7 +106,7 @@ tasks {
     val fillBuildConstants by registering {
         group = "mirai"
         doLast {
-            (compileKotlin as org.jetbrains.kotlin.gradle.tasks.KotlinCompile).source.filter { it.name == "VersionConstants.kt" }.single()
+            projectDir.resolve("src").walk().filter { it.name == "VersionConstants.kt" }.single()
                 .let { file ->
                     file.writeText(
                         file.readText()

+ 9 - 0
tools/gradle-plugin/gradle.properties

@@ -0,0 +1,9 @@
+#
+# 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
+#
+flatten.sourceset=false

+ 19 - 15
tools/gradle-plugin/test/net/mamoe/mirai/console/gradle/AbstractTest.groovy → tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/AbstractTest.groovy

@@ -11,6 +11,7 @@ package net.mamoe.mirai.console.gradle
 
 import kotlin.Pair
 import org.gradle.testkit.runner.GradleRunner
+import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading
 import org.junit.jupiter.api.AfterEach
 import org.junit.jupiter.api.BeforeEach
 import org.junit.jupiter.api.io.TempDir
@@ -28,6 +29,7 @@ abstract class AbstractTest {
     }
 
     def gradleRunner() {
+        println(PluginUnderTestMetadataReading.readImplementationClasspath())
         GradleRunner.create()
                 .withProjectDir(tempDir)
                 .withPluginClasspath()
@@ -62,30 +64,32 @@ abstract class AbstractTest {
         """.stripMargin()
 
 
-//        buildFile = new File(tempDir, "build.gradle")
-//        buildFile.delete()
-//        buildFile << """
-//            plugins {
-//                id 'org.jetbrains.kotlin.jvm' version '1.4.32'
-//                id 'net.mamoe.mirai-console'
-//            }
-//            repositories {
-//                mavenCentral()
-//            }
-//        """
-
-
-        buildFile = new File(tempDir, "build.gradle.kts")
+        buildFile = new File(tempDir, "build.gradle")
         buildFile.delete()
         buildFile << """
             plugins {
-                kotlin("jvm") version "1.4.30"
+                id("org.jetbrains.kotlin.jvm") version "1.4.32"
+                id("org.gradle.maven")
                 id("net.mamoe.mirai-console")
             }
+            
             repositories {
                 mavenCentral()
             }
         """
+
+
+//        buildFile = new File(tempDir, "build.gradle.kts")
+//        buildFile.delete()
+//        buildFile << """
+//            plugins {
+//                kotlin("jvm") version "1.4.30"
+//                id("net.mamoe.mirai-console")
+//            }
+//            repositories {
+//                mavenCentral()
+//            }
+//        """
     }
 
     @AfterEach

+ 1 - 5
tools/gradle-plugin/test/net/mamoe/mirai/console/gradle/TestPluginApply.groovy → tools/gradle-plugin/src/integTest/groovy/net/mamoe/mirai/console/gradle/TestPluginApply.groovy

@@ -11,16 +11,12 @@ package net.mamoe.mirai.console.gradle
 
 import org.junit.jupiter.api.Test
 
-import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
-
 class TestPluginApply extends AbstractTest {
 
     @Test
     void "can apply plugin"() {
-        def result = gradleRunner()
+        gradleRunner()
                 .withArguments("clean", "--stacktrace")
                 .build()
-
-        assert result.task('clean').outcome == SUCCESS
     }
 }

+ 0 - 0
tools/gradle-plugin/src/BuildMiraiPluginTask.kt → tools/gradle-plugin/src/main/kotlin/BuildMiraiPluginTask.kt


+ 4 - 4
tools/gradle-plugin/src/IGNORED_DEPENDENCIES_IN_SHADOW.kt → tools/gradle-plugin/src/main/kotlin/IGNORED_DEPENDENCIES_IN_SHADOW.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
  *
- * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 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/master/LICENSE
  */
 
 @file:JvmMultifileClass

+ 4 - 4
tools/gradle-plugin/src/MiraiConsoleExtension.kt → tools/gradle-plugin/src/main/kotlin/MiraiConsoleExtension.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
  *
- * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 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/master/LICENSE
  */
 
 @file:Suppress("unused", "MemberVisibilityCanBePrivate")

+ 4 - 4
tools/gradle-plugin/src/MiraiConsoleGradlePlugin.kt → tools/gradle-plugin/src/main/kotlin/MiraiConsoleGradlePlugin.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
  *
- * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
- * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 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/master/LICENSE
  */
 
 @file:JvmMultifileClass

+ 0 - 0
tools/gradle-plugin/src/VersionConstants.kt → tools/gradle-plugin/src/main/kotlin/VersionConstants.kt


+ 16 - 12
tools/gradle-plugin/src/publishing.kt → tools/gradle-plugin/src/main/kotlin/publishing.kt

@@ -109,14 +109,16 @@ private fun Project.registerPublishPluginTasks(target: KotlinTarget, isSingleTar
                     "${it.group}:${it.name}:${it.version}"
                 }.distinct()
 
-                val json = Gson().toJson(PluginMetadata(
-                    metadataVersion = 1,
-                    groupId = mirai.publishing.groupId ?: project.group.toString(),
-                    artifactId = mirai.publishing.artifactId ?: project.name,
-                    version = mirai.publishing.version ?: project.version.toString(),
-                    description = mirai.publishing.description ?: project.description,
-                    dependencies = dependencies
-                ))
+                val json = Gson().toJson(
+                    PluginMetadata(
+                        metadataVersion = 1,
+                        groupId = mirai.publishing.groupId ?: project.group.toString(),
+                        artifactId = mirai.publishing.artifactId ?: project.name,
+                        version = mirai.publishing.version ?: project.version.toString(),
+                        description = mirai.publishing.description ?: project.description,
+                        dependencies = dependencies
+                    )
+                )
 
                 logger.info("Generated mirai plugin metadata json: $json")
 
@@ -209,10 +211,12 @@ private fun Project.registerMavenPublications(target: KotlinTarget, isSingleTarg
 
                 artifact(sourcesJar.get())
                 artifact(tasks.filterIsInstance<BuildMiraiPluginTask>().single { it.target == target })
-                artifact(mapOf(
-                    "source" to tasks.getByName("generatePluginMetadata".wrapNameWithPlatform(target, isSingleTarget)).outputs.files.singleFile,
-                    "extension" to "mirai.metadata"
-                ))
+                artifact(
+                    mapOf(
+                        "source" to tasks.getByName("generatePluginMetadata".wrapNameWithPlatform(target, isSingleTarget)).outputs.files.singleFile,
+                        "extension" to "mirai.metadata"
+                    )
+                )
 
                 mirai.publishing.mavenPublicationConfigs.forEach { it.invoke(this) }
             }