18
18
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
*/
20
20
21
+ import java.io.IOException
22
+ import java.net.URI
23
+ import java.net.http.HttpClient
24
+ import java.net.http.HttpRequest
25
+ import java.net.http.HttpResponse
26
+ import kotlin.io.path.absolute
27
+ import org.jetbrains.intellij.platform.gradle.utils.IdeServicesPluginRepositoryService
28
+ import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory
29
+
21
30
plugins {
22
31
id(" org.jetbrains.intellij.platform" )
23
32
}
@@ -27,4 +36,63 @@ tasks.publishPlugin {
27
36
token.set(deployToken.toString())
28
37
}
29
38
channels.add(properties[" mcdev.deploy.channel" ]?.toString() ? : " Stable" )
39
+
40
+ // Overwrite the publish action, to properly set the until version after publishing (otherwise they ignore it).
41
+ // See https://youtrack.jetbrains.com/issue/IJPL-166094/Plugins-Disable-until-build-range-check-by-default
42
+ actions = listOf (Action {
43
+ if (token.orNull.isNullOrEmpty()) {
44
+ throw GradleException (" No token specified for publishing. Make sure to specify mcdev.deploy.token." )
45
+ }
46
+
47
+ val log = Logging .getLogger(javaClass)
48
+
49
+ val path = archiveFile.get().asFile.toPath().absolute()
50
+ val pluginId = " com.demonwav.minecraft-dev"
51
+ channels.get().forEach { channel ->
52
+ log.info(" Uploading plugin '$pluginId ' from '$path ' to '${host.get()} ', channel: '$channel '" )
53
+
54
+ try {
55
+ val repositoryClient = when (ideServices.get()) {
56
+ true -> PluginRepositoryFactory .createWithImplementationClass(
57
+ host.get(),
58
+ token.get(),
59
+ " Automation" ,
60
+ IdeServicesPluginRepositoryService ::class .java,
61
+ )
62
+
63
+ false -> PluginRepositoryFactory .create(host.get(), token.get())
64
+ }
65
+ @Suppress(" DEPRECATION" )
66
+ val uploadBean = repositoryClient.uploader.upload(
67
+ id = pluginId,
68
+ file = path.toFile(),
69
+ channel = channel.takeIf { it != " default" },
70
+ notes = null ,
71
+ isHidden = hidden.get(),
72
+ )
73
+ log.info(" Uploaded successfully as version ID ${uploadBean.id} " )
74
+
75
+ val since = uploadBean.since
76
+ log.info(" Since is ${since} , until is ${uploadBean.until} " )
77
+ if (since != null && uploadBean.until.isNullOrBlank()) {
78
+ val newUntil = since.substringBefore(" ." ) + " .*"
79
+ log.info(" Updating until to $newUntil " )
80
+ val request = HttpRequest .newBuilder()
81
+ .uri(URI .create(" https://plugins.jetbrains.com/api/updates/${uploadBean.id} /since-until" ))
82
+ .header(" Authorization" , " Bearer ${token.get()} " )
83
+ .header(" Content-Type" , " application/json" )
84
+ .header(" User-Agent" , " Minecraft Development Plugin Publisher" )
85
+ .POST (HttpRequest .BodyPublishers .ofString(" {\" since\" :\" ${uploadBean.since} \" ,\" until\" :\" $newUntil \" }" ))
86
+ .build()
87
+ val response = HttpClient .newHttpClient().send(request, HttpResponse .BodyHandlers .ofString())
88
+ if (response.statusCode() < 200 || response.statusCode() >= 300 ) {
89
+ throw IOException (" Updating until failed with status code ${response.statusCode()} , ${response.body()} " )
90
+ }
91
+ log.info(" Successful with status code ${response.statusCode()} " )
92
+ }
93
+ } catch (exception: Exception ) {
94
+ throw GradleException (" Failed to upload plugin: ${exception.message} " , exception)
95
+ }
96
+ }
97
+ })
30
98
}
0 commit comments