Ver código fonte

[idea] feat: provide an option for whether to use the proxy repo (#2636)

* feat(idea): set proxy repository for gradle plugins

* feat(idea): provide an option for whether to use the proxy repo

* chore: update copyright

* fix: rename the message key
Samarium 2 anos atrás
pai
commit
f0bdd18d26

+ 3 - 2
mirai-console/tools/intellij-plugin/resources/fileTemplates/code/Plugin build.gradle.ft

@@ -9,8 +9,9 @@ group = '$GROUP_ID'
 version = '$VERSION'
 
 repositories {
-    #if($USE_PROXY_REPO)maven { url 'https://maven.aliyun.com/repository/public' }#end
-
+#if($USE_PROXY_REPO)
+    maven { url 'https://maven.aliyun.com/repository/public' }
+#end
     mavenCentral()
 }
 

+ 3 - 2
mirai-console/tools/intellij-plugin/resources/fileTemplates/code/Plugin build.gradle.kts.ft

@@ -10,8 +10,9 @@ group = "$GROUP_ID"
 version = "$VERSION"
 
 repositories {
-    #if($USE_PROXY_REPO)maven("https://maven.aliyun.com/repository/public")#end
-
+#if($USE_PROXY_REPO)
+    maven("https://maven.aliyun.com/repository/public")
+#end
     mavenCentral()
 }
 

+ 9 - 0
mirai-console/tools/intellij-plugin/resources/fileTemplates/code/Plugin settings.gradle.ft

@@ -0,0 +1,9 @@
+pluginManagement {
+    repositories {
+#if($USE_PROXY_REPO)
+        maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
+#end
+        gradlePluginPortal()
+    }
+}
+rootProject.name = "$ARTIFACT_ID"

+ 14 - 0
mirai-console/tools/intellij-plugin/resources/fileTemplates/code/Plugin settings.gradle.html

@@ -0,0 +1,14 @@
+<!--
+  ~ 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
+  -->
+
+<html>
+<body>
+<p>This is a built-in file template used to create a new settings.gradle for Mirai Console Plugin projects.</p>
+</body>
+</html>

+ 8 - 0
mirai-console/tools/intellij-plugin/resources/fileTemplates/code/Plugin settings.gradle.kts.ft

@@ -1 +1,9 @@
+pluginManagement {
+    repositories {
+#if($USE_PROXY_REPO)
+        maven("https://maven.aliyun.com/repository/gradle-plugin")
+#end
+        gradlePluginPortal()
+    }
+}
 rootProject.name = "$ARTIFACT_ID"

+ 2 - 1
mirai-console/tools/intellij-plugin/resources/messages/MiraiProjectWizardBundle.properties

@@ -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.
@@ -37,3 +37,4 @@ validation.plugin.name.forbidden.character="{0}" is forbidden in plugin name
 validation.illegal.plugin.id=Invalid plugin id "{0}"
 validation.illegal.version=Invalid version.\n{0}
 no.error.message=No error message
+text.use.proxy.repo=Use Aliyun Maven repository

+ 2 - 1
mirai-console/tools/intellij-plugin/resources/messages/MiraiProjectWizardBundle_zh.properties

@@ -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.
@@ -37,3 +37,4 @@ validation.plugin.name.forbidden.character=插件名称中不允许存在 "{0}"
 validation.illegal.plugin.id=插件 ID 无效: "{0}"
 validation.illegal.version=插件版本无效\n{0}
 no.error.message=无错误信息
+text.use.proxy.repo=使用阿里云 Maven 镜像

+ 1 - 1
mirai-console/tools/intellij-plugin/src/wizard/MiraiModuleBuilder.kt

@@ -82,7 +82,7 @@ class MiraiModuleBuilder : StarterModuleBuilder() {
                 "GROUP_ID" to projectCoordinates.groupId,
                 "VERSION" to projectCoordinates.version,
                 "PROJECT_NAME" to starterContext,
-                "USE_PROXY_REPO" to "true",
+                "USE_PROXY_REPO" to useProxyRepo,
                 "ARTIFACT_ID" to projectCoordinates.artifactId,
                 "MODULE_NAME" to projectCoordinates.moduleName,
 

+ 2 - 2
mirai-console/tools/intellij-plugin/src/wizard/MiraiProjectModel.kt

@@ -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.
@@ -38,7 +38,7 @@ class MiraiProjectModel(
 
     val buildSystemType: BuildSystemType,
     val languageType: LanguageType,
-
+    val useProxyRepo: Boolean,
 
     val mainClassSimpleName: String = pluginCoordinates.run {
         name.adjustToClassName() ?: id.substringAfterLast('.').adjustToClassName()

+ 9 - 2
mirai-console/tools/intellij-plugin/src/wizard/MiraiProjectWizardInitialStep.kt

@@ -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.
@@ -39,6 +39,7 @@ class MiraiProjectWizardInitialStep(contextProvider: StarterContextProvider) : S
     private val pluginInfoProperty = propertyGraph.lazyProperty { "" }
     private val miraiVersionKindProperty = propertyGraph.property(MiraiVersionKind.Stable)
     private val miraiVersionProperty = propertyGraph.property("0.1.0")
+    private val useProxyRepoProperty = propertyGraph.property(true)
 
     var pluginVersion by pluginVersionProperty.trim()
     var pluginName by pluginNameProperty.trim()
@@ -54,6 +55,8 @@ class MiraiProjectWizardInitialStep(contextProvider: StarterContextProvider) : S
 
     private lateinit var miraiVersionCell: Cell<ComboBox<String>>
 
+    var useProxyRepo by useProxyRepoProperty
+
     override fun addFieldsAfter(layout: Panel) {
         layout.group(message("title.plugin.description")) {
             row(message("label.plugin.id")) {
@@ -141,6 +144,9 @@ class MiraiProjectWizardInitialStep(contextProvider: StarterContextProvider) : S
                 updateVersionItems(miraiVersionKindCell, miraiVersionCell)
                 rowComment(message("comment.mirai.version"))
             }
+            row {
+                checkBox(message("text.use.proxy.repo")).enabled(true).bindSelected(useProxyRepoProperty)
+            }
         }
 
         // Update default values
@@ -181,7 +187,8 @@ class MiraiProjectWizardInitialStep(contextProvider: StarterContextProvider) : S
                     KOTLIN_STARTER_LANGUAGE -> LanguageType.Kotlin
                     JAVA_STARTER_LANGUAGE -> LanguageType.Java
                     else -> error("Unsupported language type: $language")
-                }
+                },
+                useProxyRepo = useProxyRepo
             )
         )
     }