-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
222 lines (173 loc) · 6.5 KB
/
build.gradle.kts
File metadata and controls
222 lines (173 loc) · 6.5 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import org.jetbrains.intellij.platform.gradle.tasks.SignPluginTask
plugins {
id("java")
kotlin("jvm") version "2.3.0"
id("org.jetbrains.intellij.platform") version "2.13.1"
}
group = "one.pkg"
version = "1.10.2"
val targetJavaVersion = 21
repositories {
mavenCentral()
maven("https://mvnc.pkg.one/releases")
intellijPlatform {
defaultRepositories()
}
}
java {
val javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion.set(JavaLanguageVersion.of(targetJavaVersion))
}
}
tasks.withType<JavaCompile>().configureEach {
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible) {
options.release.set(targetJavaVersion)
}
options.compilerArgs.add("-Xdiags:verbose")
}
kotlin {
jvmToolchain(targetJavaVersion)
}
dependencies {
intellijPlatform {
intellijIdeaCommunity("2025.2")
bundledPlugin("com.intellij.java")
bundledPlugin("org.jetbrains.kotlin")
bundledPlugin("org.intellij.plugins.markdown")
bundledPlugin("Git4Idea")
}
implementation("com.squareup.okhttp3:okhttp:5.3.2") {
exclude(group = "org.jetbrains.kotlin")
}
implementation("one.tranic:t-proxy:1.0.1")
implementation("one.pkg:tiny-utils:2.2.0")
implementation("one.pkg:sktoml:1.0.0") {
exclude("*")
}
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
compileOnly("com.vladsch.flexmark:flexmark:0.64.8")
compileOnly("com.vladsch.flexmark:flexmark-html2md-converter:0.64.8")
testImplementation(kotlin("test"))
testImplementation("junit:junit:4.13.2")
}
intellijPlatform {
buildSearchableOptions = false
pluginConfiguration {
ideaVersion {
sinceBuild = "252"
}
}
pluginVerification {
ides {
recommended()
}
}
}
tasks.register("generateChangeNotes")
tasks.named("generateChangeNotes") {
description = "Generate change-notes from markdown files"
doLast {
val changeNotesDir = File(projectDir, "changelogs")
val pluginXmlFile = File(projectDir, "src/main/resources/META-INF/plugin.xml")
if (!changeNotesDir.exists()) {
println("Change notes directory not found: ${changeNotesDir.absolutePath}")
println("Creating example directory and file...")
changeNotesDir.mkdirs()
val exampleFile = File(changeNotesDir, "CHANGELOG.md")
exampleFile.writeText(
"""
# Changelog
""".trimIndent()
)
println("Created example changelog at: ${exampleFile.absolutePath}")
}
if (pluginXmlFile.exists()) {
val markdownFiles: List<File> = changeNotesDir.listFiles { _, name ->
name.endsWith(".md") || name.endsWith(".markdown")
}?.sortedByDescending { it.lastModified() } ?: arrayListOf()
if (markdownFiles.isEmpty()) {
println("No markdown files found in ${changeNotesDir.absolutePath}")
return@doLast
}
val htmlContent = convertMarkdownToHtml(markdownFiles)
val pluginXmlContent = pluginXmlFile.readText()
val changeNotesRegex = Regex(
"""(\s*)<change-notes>\s*<!\[CDATA\[(.*?)\]\]>\s*</change-notes>""",
RegexOption.DOT_MATCHES_ALL
)
val updatedContent = pluginXmlContent.replace(changeNotesRegex) { matchResult ->
val leadingSpaces = matchResult.groupValues[1]
"""${leadingSpaces}<change-notes><![CDATA[
$leadingSpaces $htmlContent
$leadingSpaces]]></change-notes>"""
}
pluginXmlFile.writeText(updatedContent)
println("Updated plugin.xml with change-notes from ${markdownFiles.size} markdown file(s)")
} else {
println("plugin.xml not found at: ${pluginXmlFile.absolutePath}")
}
}
}
fun convertMarkdownToHtml(markdownFiles: List<File>): String {
val htmlBuilder = StringBuilder()
for ((index, file) in markdownFiles.withIndex()) {
val content = file.readText()
val html = markdownToHtml(content)
htmlBuilder.append(html)
if (index < markdownFiles.size - 1) {
htmlBuilder.append("\n")
}
}
return htmlBuilder.toString().trim()
}
fun markdownToHtml(markdown: String): String {
var html = markdown
html = html.replace(Regex("\\n\\s*\\n"), "\n")
html = html.replace(Regex("^# (.+)$", RegexOption.MULTILINE), "<h1>$1</h1>")
html = html.replace(Regex("^## (.+)$", RegexOption.MULTILINE), "<h2>$1</h2>")
html = html.replace(Regex("^### (.+)$", RegexOption.MULTILINE), "<h3>$1</h3>")
html = html.replace(Regex("^---+$", RegexOption.MULTILINE), "<hr>")
html = html.replace(Regex("^- (.+)$", RegexOption.MULTILINE), "<li>$1</li>")
html = html.replace(Regex("^\\d+\\. (.+)$", RegexOption.MULTILINE), "<li>$1</li>")
html = html.replace(Regex("""\*\*(.+?)\*\*"""), "<strong>$1</strong>")
html = html.replace(Regex("""\*(.+?)\*"""), "<em>$1</em>")
html = html.replace(Regex("(<li>.*?</li>)(?:\\s*<li>.*?</li>)*", RegexOption.DOT_MATCHES_ALL)) { matchResult ->
val fullMatch = matchResult.value
val isOrderedList = markdown.contains(Regex("^\\d+\\. ", RegexOption.MULTILINE))
if (isOrderedList) {
"<ol>$fullMatch</ol>"
} else {
"<ul>$fullMatch</ul>"
}
}
html = html.replace(Regex("^(?!<[/]?(?:h[1-6]|ul|ol|li|hr|p)>)(.+)$", RegexOption.MULTILINE), "<p>$1</p>")
html = html.replace(Regex("\\s*\\n\\s*"), "")
return html
}
tasks.named<ProcessResources>("processResources") {
dependsOn("generateChangeNotes")
val props = mapOf("version" to version)
inputs.properties(props)
filteringCharset = "UTF-8"
filesMatching("META-INF/plugin.xml") {
expand(props)
}
}
tasks.named<Test>("test") {
testLogging {
events("passed", "skipped", "failed", "standardOut", "standardError")
showStandardStreams = true
}
}
tasks.named<SignPluginTask>("signPlugin") {
val chainFile = file("chain.crt")
val keyFile = file("private.pem")
if (chainFile.exists() && keyFile.exists()) {
certificateChain.set(chainFile.readText())
privateKey.set(keyFile.readText())
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}
}