Skip to content

Commit 1a3500d

Browse files
committed
Force the until build on marketplace when publishing
1 parent b526891 commit 1a3500d

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ dependencies {
4545
implementation(libs.intellij.plugin)
4646
implementation(libs.licenser.plugin)
4747
implementation(libs.changelog.plugin)
48+
implementation(libs.intellij.plugin.repository.rest.client)
4849
}

buildSrc/src/main/kotlin/mcdev-publishing.gradle.kts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import java.io.IOException
2+
import java.net.URI
3+
import java.net.http.HttpClient
4+
import java.net.http.HttpRequest
5+
import java.net.http.HttpResponse
6+
import kotlin.io.path.absolute
7+
import org.jetbrains.intellij.platform.gradle.utils.IdeServicesPluginRepositoryService
8+
import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory
9+
110
/*
211
* Minecraft Development for IntelliJ
312
*
@@ -27,4 +36,63 @@ tasks.publishPlugin {
2736
token.set(deployToken.toString())
2837
}
2938
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+
})
3098
}

gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
#
2020

2121
# suppress inspection "UnusedProperty" for whole file
22+
org.gradle.jvmargs=-Xmx1g
23+
2224
ideaVersionName = 2024.2
2325

24-
coreVersion = 1.8.4
26+
coreVersion = 1.8.5
2527

2628
# Silences a build-time warning because we are bundling our own kotlin library
2729
kotlin.stdlib.default.dependency = false

gradle/libs.versions.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ asm = "9.6"
77
fuel = "2.3.1"
88
licenser = "0.6.1"
99
changelog = "2.2.0"
10-
intellij-plugin = "2.4.0"
10+
intellij-plugin = "2.5.0"
11+
intellij-plugin-repository-rest-client = "2.0.46"
1112
intellij-ide = "2024.2"
12-
idea-ext = "1.1.8"
13+
idea-ext = "1.1.10"
1314
psiPlugin = "242.4697"
1415

1516
[plugins]
@@ -20,6 +21,8 @@ licenser = { id = "org.cadixdev.licenser", version.ref = "licenser" }
2021
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
2122

2223
[libraries]
24+
intellij-plugin-repository-rest-client = { module = "org.jetbrains.intellij:plugin-repository-rest-client", version.ref = "intellij-plugin-repository-rest-client" }
25+
2326
kotlin-plugin = { module = "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin", version.ref = "kotlin" }
2427
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
2528
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }

0 commit comments

Comments
 (0)