1
-
2
1
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3
2
4
3
plugins {
5
4
id(" java" )
6
5
id(" org.jetbrains.kotlin.jvm" ) version " 1.7.10"
7
- id(" org.jetbrains.intellij" ) version " 1.13.0 "
6
+ id(" org.jetbrains.intellij" ) version " 1.13.3 "
8
7
id(" org.jetbrains.changelog" ) version " 2.0.0"
9
8
// ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle
10
9
// id("org.jlleitschuh.gradle.ktlint") version "10.1.0"
@@ -58,14 +57,15 @@ changelog {
58
57
version.set(pluginVersion)
59
58
headerParserRegex.set(""" (\d+\.\d+\.\d+)""" .toRegex())
60
59
}
61
-
62
60
tasks {
63
- withType<JavaCompile > {
64
- sourceCompatibility = " 11"
65
- targetCompatibility = " 11"
66
- }
67
- withType<KotlinCompile > {
68
- kotlinOptions.jvmTarget = " 11"
61
+ properties(" javaVersion" ).let {
62
+ withType<JavaCompile > {
63
+ sourceCompatibility = it
64
+ targetCompatibility = it
65
+ }
66
+ withType<KotlinCompile > {
67
+ kotlinOptions.jvmTarget = it
68
+ }
69
69
}
70
70
71
71
publishPlugin {
@@ -89,10 +89,10 @@ tasks {
89
89
90
90
register(" copyInspections" ) {
91
91
doLast {
92
- blocks ().forEach {
92
+ inspections ().forEach {
93
93
write(
94
94
File (" src/main/resources/inspectionDescriptions/" + it.file().name),
95
- it.full ()
95
+ it.content ()
96
96
)
97
97
}
98
98
}
@@ -113,7 +113,7 @@ tasks {
113
113
}
114
114
}
115
115
116
- named(" test" ){
116
+ named(" test" ) {
117
117
dependsOn(" checkReadme" )
118
118
}
119
119
named(" buildPlugin" ) {
@@ -138,34 +138,48 @@ fun write(file: File, content: String): Boolean {
138
138
return result
139
139
}
140
140
141
- class Block (private val file : File ) {
141
+ class Descriptor (
142
+ private val file : File ,
143
+ private val uid : String
144
+ ) {
145
+ fun uid () = uid
142
146
fun file () = file
143
- fun uid () = file.name.replace(" Inspection.html" , " " )
144
- fun full () = file.readText()
145
- fun short () = full()
147
+ fun content () = file.readText()
148
+ fun short () = content()
146
149
.replace(Regex (" <!-- main -->(.*)" , RegexOption .DOT_MATCHES_ALL ), " " )
147
150
.trim()
148
151
}
149
152
150
- fun blocks () = File (" src/main/kotlin/com/funivan/idea/phpClean/inspections" )
151
- .walkTopDown()
152
- .filter { it.name.contains(" Inspection.kt" ) }
153
- .map { Block (File (it.path.replace(" .kt" , " .html" ))) }
154
-
155
- fun generatedReadmeContent (readme : File ): String {
156
- var content = readme.readText()
157
- content = content.replace(
158
- Regex (" (<!-- inspections -->)(.+)" , RegexOption .DOT_MATCHES_ALL ),
159
- " $1"
160
- )
161
- content = content + " \n " + blocks().sortedBy { it.uid() }
162
- .map {
163
- val description = it.short().replace(" <pre>" , " ```php" ).replace(" </pre>" , " ```" )
164
- " #### ${it.uid()} \n $description \n "
165
- }
166
- .joinToString(" " )
167
- return content
168
- }
153
+ fun actions () = projectHtmlFiles(" Action" )
154
+ fun inspections () = projectHtmlFiles(" Inspection" )
155
+
156
+
157
+ fun generatedReadmeContent (readme : File ): String =
158
+ readme.readText().replace(
159
+ Regex (" <!-- Autogenerated -->.+" , RegexOption .DOT_MATCHES_ALL ), " "
160
+ ) + " <!-- Autogenerated -->\n " + generateSections()
169
161
170
162
fun readmeFile () = File (" README.md" )
163
+ fun projectHtmlFiles (type : String ) = File (" src/main/kotlin/com/funivan/idea/phpClean" )
164
+ .walkTopDown()
165
+ .filter { it.name.contains(" ${type} .html" ) }
166
+ .map {
167
+ Descriptor (
168
+ File (it.path),
169
+ it.name.replace(" ${type} .html" , " " )
170
+ )
171
+ }
171
172
173
+ fun generateSections () = listOf (
174
+ Pair (" Inspections" , inspections()),
175
+ Pair (" Actions" , actions()),
176
+ ).fold(" " ) { acc, pair ->
177
+ acc + " ## ${pair.first} \n " +
178
+ pair.second.sortedBy { it.uid() }
179
+ .map {
180
+ val description = it.short().replace(" <pre>" , " ```php" ).replace(" </pre>" , " ```" )
181
+ " #### ${it.uid()} \n $description \n "
182
+ }
183
+ .joinToString(" " ) +
184
+ " \n "
185
+ }
0 commit comments