Skip to content

Commit 9c783b5

Browse files
committed
build: fetch latest nightly LSP4IJ version
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent 5facf73 commit 9c783b5

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

build.gradle.kts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import com.adarshr.gradle.testlogger.theme.ThemeType
22
import org.jetbrains.changelog.markdownToHTML
3-
import org.jetbrains.intellij.tasks.RunPluginVerifierTask.VerificationReportsFormats.*
43
import org.jetbrains.intellij.tasks.RunPluginVerifierTask.FailureLevel.*
4+
import org.jetbrains.intellij.tasks.RunPluginVerifierTask.VerificationReportsFormats.*
5+
import java.net.URI
6+
import java.net.http.HttpClient
7+
import java.net.http.HttpRequest
8+
import java.net.http.HttpResponse
9+
import java.time.Duration
10+
import java.time.temporal.ChronoUnit
11+
import java.util.regex.Pattern
512

613
fun properties(key: String) = providers.gradleProperty(key)
714
fun environment(key: String) = providers.environmentVariable(key)
@@ -132,18 +139,16 @@ intellij {
132139
if (localLsp4ij.isDirectory) {
133140
// In case Gradle fails to build because it can't find some missing jar, try deleting
134141
// ~/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/unzipped.com.jetbrains.plugins/com.redhat.devtools.lsp4ij*
135-
platformPlugins.add(localLsp4ij)
142+
platformPlugins.add(localLsp4ij)
136143
} else {
137144
// When running on CI or when there's no local lsp4ij
138-
//TODO automatically fetch the latest nightly build version
139-
platformPlugins.add("com.redhat.devtools.lsp4ij:0.0.1-20231211-102151@nightly")
145+
val latestLsp4ijNightlyVersion = fetchLatestLsp4ijNightlyVersion()
146+
platformPlugins.add("com.redhat.devtools.lsp4ij:$latestLsp4ijNightlyVersion@nightly")
140147
}
141148
//Uses `platformPlugins` property from the gradle.properties file.
142149
platformPlugins.addAll(properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }.get())
143150
println("platformPlugins: $platformPlugins")
144151
plugins = platformPlugins
145-
146-
147152
}
148153

149154
configurations {
@@ -286,3 +291,27 @@ tasks {
286291
dependsOn(jacocoTestReport)
287292
}
288293
}
294+
295+
fun fetchLatestLsp4ijNightlyVersion(): String {
296+
val client = HttpClient.newBuilder().build();
297+
var onlineVersion = ""
298+
try {
299+
val request: HttpRequest = HttpRequest.newBuilder()
300+
.uri(URI("https://plugins.jetbrains.com/api/plugins/23257/updates?channel=nightly&size=1"))
301+
.GET()
302+
.timeout(Duration.of(10, ChronoUnit.SECONDS))
303+
.build()
304+
val response = client.send(request, HttpResponse.BodyHandlers.ofString());
305+
val pattern = Pattern.compile("\"version\":\"([^\"]+)\"")
306+
val matcher = pattern.matcher(response.body())
307+
if (matcher.find()) {
308+
onlineVersion = matcher.group(1)
309+
println("Latest approved nightly build: $onlineVersion")
310+
}
311+
} catch (e:Exception) {
312+
println("Failed to fetch LSP4IJ nightly build version: ${e.message}")
313+
}
314+
315+
val minVersion = "0.0.1-20231213-012910"
316+
return if (minVersion < onlineVersion) onlineVersion else minVersion
317+
}

0 commit comments

Comments
 (0)