-
Notifications
You must be signed in to change notification settings - Fork 1
/
GradlePluginsSearcher.kt
executable file
·38 lines (32 loc) · 1.33 KB
/
GradlePluginsSearcher.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package cn.bestwu.intellij.plugins.gradle.codeInsight.completion
import org.jsoup.Jsoup
class GradlePluginsSearcher {
companion object {
private val pluginsCaches = HashMap<String, List<String>>()
private val pluginVersionsCaches = HashMap<String, List<String>>()
}
fun searchPlugins(text: String): List<String> {
var result = pluginsCaches[text]
if (result != null) {
return result
}
val elements = Jsoup.connect("https://plugins.gradle.org/search?term=${text.trim()}").get().select("#search-results tbody tr")
result = elements.map { it.select(".plugin-id a").text() }
pluginsCaches.put(text, result)
return result
}
fun searchPluginVersions(text: String): List<String> {
var result = pluginVersionsCaches[text]
if (result == null) {
result = ArrayList<String>()
} else {
return result
}
val plugin = Jsoup.connect("https://plugins.gradle.org/plugin/${text.trim()}").get()
result.add(plugin.select(".version-info h3").text().replace("^Version (.*) \\(latest\\)$".toRegex(), "$1"))
val elements = plugin.select(".other-versions li")
elements.mapTo(result) { it.select("a").text() }
pluginVersionsCaches.put(text, result)
return result
}
}