-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle.kts
184 lines (167 loc) · 5.41 KB
/
build.gradle.kts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("java")
id("org.jetbrains.kotlin.jvm") version "2.0.21"
id("org.jetbrains.intellij") version "1.17.4"
id("org.jetbrains.changelog") version "2.2.1"
// ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle
// id("org.jlleitschuh.gradle.ktlint") version "10.1.0"
}
fun properties(key: String) = project.findProperty(key).toString()
// Import variables from gradle.properties file
val pluginGroup: String by project
// `pluginName_` variable ends with `_` because of the collision with Kotlin magic getter in the `intellij` closure.
// Read more about the issue: https://github.com/JetBrains/intellij-platform-plugin-template/issues/29
val pluginName_: String by project
val pluginVersion: String by project
val pluginSinceBuild: String by project
val pluginVerifierIdeVersions: String by project
val intellijPublishChannel: String by project
val intellijPublishToken: String by project
val platformType: String by project
val platformVersion: String by project
val platformPlugins: String by project
val platformDownloadSources: String by project
group = pluginGroup
version = pluginVersion
println("version: $version")
// Configure project's dependencies
repositories {
mavenCentral()
}
// Configure gradle-intellij-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
pluginName.set(pluginName_)
version.set(platformVersion)
type.set(platformType)
downloadSources.set(platformDownloadSources.toBoolean())
updateSinceUntilBuild.set(true)
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
}
dependencies {
testImplementation(gradleTestKit())
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit"))
}
// Read more: https://github.com/JetBrains/gradle-changelog-plugin
changelog {
version.set(pluginVersion)
headerParserRegex.set("""(\d+\.\d+\.\d+)""".toRegex())
}
tasks {
properties("javaVersion").let {
withType<JavaCompile> {
sourceCompatibility = it
targetCompatibility = it
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = it
}
}
publishPlugin {
token.set(intellijPublishToken)
channels.set(listOf(intellijPublishChannel, "default").filter(String::isNotEmpty).take(1))
}
patchPluginXml {
version.set(pluginVersion)
sinceBuild.set(pluginSinceBuild)
changeNotes.set(
changelog.getLatest().toHTML()
)
}
runPluginVerifier {
ideVersions.set(
properties("pluginVerifierIdeVersions")
.split(',').map(String::trim).filter(String::isNotEmpty)
)
}
register("copyInspections") {
doLast {
inspections().forEach {
write(
File("src/main/resources/inspectionDescriptions/" + it.file().name),
it.content()
)
}
}
}
register("checkReadme") {
doLast {
if (readmeFile().readText() != generatedReadmeContent(readmeFile())) {
throw GradleException("Readme is not up to date")
}
}
}
register("updateReadme") {
doLast {
val readme = readmeFile()
if (write(readme, generatedReadmeContent(readme))) {
println("Readme updated")
}
}
}
named("test") {
dependsOn("checkReadme")
}
named("buildPlugin") {
dependsOn("copyInspections")
}
named("runIde") {
dependsOn("copyInspections")
}
}
tasks.getByName("buildSearchableOptions").onlyIf { false }
// Custom functions
fun write(file: File, content: String): Boolean {
var result = false
if (!file.exists()) {
file.createNewFile()
}
if (file.readText() != content) {
result = true
file.writeText(content)
}
return result
}
class Descriptor(
private val file: File,
private val uid: String
) {
fun uid() = uid
fun file() = file
fun content() = file.readText()
fun short() = content()
.replace(Regex("<!-- main -->(.*)", RegexOption.DOT_MATCHES_ALL), "")
.trim()
}
fun actions() = projectHtmlFiles("Action")
fun inspections() = projectHtmlFiles("Inspection")
fun generatedReadmeContent(readme: File): String =
readme.readText().replace(
Regex("<!-- Autogenerated -->.+", RegexOption.DOT_MATCHES_ALL), ""
) + "<!-- Autogenerated -->\n" + generateSections()
fun readmeFile() = File("README.md")
fun projectHtmlFiles(type: String) = File("src/main/kotlin/com/funivan/idea/phpClean")
.walkTopDown()
.filter { it.name.contains("${type}.html") }
.map {
Descriptor(
File(it.path),
it.name.replace("${type}.html", "")
)
}
fun generateSections() = listOf(
Pair("Inspections", inspections()),
Pair("Actions", actions()),
).fold("") { acc, pair ->
acc + "## ${pair.first}\n" +
pair.second.sortedBy { it.uid() }
.map {
val description = it.short().replace("<pre>", "```php").replace("</pre>", "```")
"#### ${it.uid()}\n$description\n"
}
.joinToString("") +
"\n"
}