1
+ import com.fasterxml.jackson.databind.SerializationFeature
2
+ import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
1
3
import com.github.jk1.license.filter.ExcludeTransitiveDependenciesFilter
2
4
import com.github.jk1.license.render.JsonReportRenderer
5
+ import com.jetbrains.plugin.structure.toolbox.ToolboxMeta
6
+ import com.jetbrains.plugin.structure.toolbox.ToolboxPluginDescriptor
3
7
import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory
4
8
import org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfoRt
5
9
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
6
10
import java.nio.file.Path
11
+ import kotlin.io.path.createDirectories
7
12
import kotlin.io.path.div
13
+ import kotlin.io.path.writeText
8
14
9
15
plugins {
10
16
alias(libs.plugins.kotlin)
@@ -14,23 +20,31 @@ plugins {
14
20
alias(libs.plugins.ksp)
15
21
alias(libs.plugins.gradle.wrapper)
16
22
alias(libs.plugins.changelog)
23
+ alias(libs.plugins.gettext)
17
24
}
18
25
19
- buildscript {
20
- dependencies {
21
- classpath(libs.marketplace.client)
22
- }
23
- }
24
26
25
27
repositories {
26
28
mavenCentral()
27
29
maven(" https://packages.jetbrains.team/maven/p/tbx/toolbox-api" )
28
30
}
29
31
32
+ buildscript {
33
+ repositories {
34
+ mavenCentral()
35
+ }
36
+
37
+ dependencies {
38
+ classpath(libs.marketplace.client)
39
+ classpath(libs.plugin.structure)
40
+ }
41
+ }
42
+
30
43
jvmWrapper {
31
44
unixJvmInstallDir = " jvm"
32
45
winJvmInstallDir = " jvm"
33
- linuxAarch64JvmUrl = " https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-linux-aarch64-b631.28.tar.gz"
46
+ linuxAarch64JvmUrl =
47
+ " https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-linux-aarch64-b631.28.tar.gz"
34
48
linuxX64JvmUrl = " https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-linux-x64-b631.28.tar.gz"
35
49
macAarch64JvmUrl = " https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-osx-aarch64-b631.28.tar.gz"
36
50
macX64JvmUrl = " https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-osx-x64-b631.28.tar.gz"
@@ -39,24 +53,43 @@ jvmWrapper {
39
53
40
54
dependencies {
41
55
compileOnly(libs.bundles.toolbox.plugin.api)
42
- implementation(libs.slf4j)
43
- implementation(libs.bundles.serialization)
44
- implementation(libs.coroutines.core)
56
+ compileOnly(libs.bundles.serialization)
57
+ compileOnly(libs.coroutines.core)
45
58
implementation(libs.okhttp)
46
59
implementation(libs.exec)
47
60
implementation(libs.moshi)
48
61
ksp(libs.moshi.codegen)
49
62
implementation(libs.retrofit)
50
63
implementation(libs.retrofit.moshi)
51
64
testImplementation(kotlin(" test" ))
65
+ testImplementation(libs.mokk)
66
+ testImplementation(libs.bundles.toolbox.plugin.api)
52
67
}
53
68
54
- val pluginId = properties(" group" )
55
- val pluginName = properties(" name" )
56
- val pluginVersion = properties(" version" )
69
+ val extension = ExtensionJson (
70
+ id = properties(" group" ),
71
+
72
+ version = properties(" version" ),
73
+ meta = ExtensionJsonMeta (
74
+ name = " Coder Toolbox" ,
75
+ description = " Connects your JetBrains IDE to Coder workspaces" ,
76
+ vendor = " Coder" ,
77
+ url = " https://github.com/coder/coder-jetbrains-toolbox-plugin" ,
78
+ )
79
+ )
80
+
81
+ val extensionJsonFile = layout.buildDirectory.file(" generated/extension.json" )
82
+ val extensionJson by tasks.registering {
83
+ inputs.property(" extension" , extension.toString())
84
+
85
+ outputs.file(extensionJsonFile)
86
+ doLast {
87
+ generateExtensionJson(extension, extensionJsonFile.get().asFile.toPath())
88
+ }
89
+ }
57
90
58
91
changelog {
59
- version.set(pluginVersion )
92
+ version.set(extension.version )
60
93
groups.set(emptyList())
61
94
title.set(" Coder Toolbox Plugin Changelog" )
62
95
}
@@ -76,24 +109,30 @@ tasks.test {
76
109
useJUnitPlatform()
77
110
}
78
111
79
- val assemblePlugin by tasks.registering(Jar ::class ) {
80
- archiveBaseName.set(pluginId)
81
- from(sourceSets.main.get().output)
112
+
113
+ tasks.jar {
114
+ archiveBaseName.set(extension.id)
115
+ dependsOn(extensionJson)
116
+ from(extensionJson.get().outputs)
82
117
}
83
118
84
119
val copyPlugin by tasks.creating(Sync ::class .java) {
85
- dependsOn(assemblePlugin )
86
- fromCompileDependencies( )
120
+ dependsOn(tasks.jar )
121
+ dependsOn(tasks.getByName( " generateLicenseReport " ) )
87
122
123
+ fromCompileDependencies()
88
124
into(getPluginInstallDir())
89
125
}
90
126
91
127
fun CopySpec.fromCompileDependencies () {
92
- from(assemblePlugin.get().outputs.files)
128
+ from(tasks.jar)
129
+ from(extensionJson.get().outputs.files)
93
130
from(" src/main/resources" ) {
94
- include(" extension.json" )
95
131
include(" dependencies.json" )
132
+ }
133
+ from(" src/main/resources" ) {
96
134
include(" icon.svg" )
135
+ rename(" icon.svg" , " pluginIcon.svg" )
97
136
}
98
137
99
138
// Copy dependencies, excluding those provided by Toolbox.
@@ -106,18 +145,20 @@ fun CopySpec.fromCompileDependencies() {
106
145
" core-api" ,
107
146
" ui-api" ,
108
147
" annotations" ,
148
+ " localization-api"
109
149
).any { file.name.contains(it) }
110
150
}
111
151
},
112
152
)
113
153
}
114
154
115
155
val pluginZip by tasks.creating(Zip ::class ) {
116
- dependsOn(assemblePlugin)
156
+ archiveBaseName.set(properties(" name" ))
157
+ dependsOn(tasks.jar)
158
+ dependsOn(tasks.getByName(" generateLicenseReport" ))
117
159
118
160
fromCompileDependencies()
119
- into(pluginId)
120
- archiveBaseName.set(pluginName)
161
+ into(extension.id) // folder like com.coder.toolbox
121
162
}
122
163
123
164
tasks.register(" cleanAll" , Delete ::class .java) {
@@ -142,7 +183,7 @@ private fun getPluginInstallDir(): Path {
142
183
else -> error(" Unknown os" )
143
184
} / " plugins"
144
185
145
- return pluginsDir / pluginId
186
+ return pluginsDir / extension.id
146
187
}
147
188
148
189
val publishPlugin by tasks.creating {
@@ -158,17 +199,49 @@ val publishPlugin by tasks.creating {
158
199
// instance.uploader.uploadNewPlugin(pluginZip.outputs.files.singleFile, listOf("toolbox", "gateway"), LicenseUrl.APACHE_2_0, ProductFamily.TOOLBOX)
159
200
160
201
// subsequent updates
161
- instance.uploader.upload(pluginId , pluginZip.outputs.files.singleFile)
202
+ instance.uploader.upload(extension.id , pluginZip.outputs.files.singleFile)
162
203
}
163
204
}
164
205
165
- // For use with kotlin-language-server.
166
- tasks.register(" classpath" ) {
167
- doFirst {
168
- File (" classpath" ).writeText(
169
- sourceSets[" main" ].runtimeClasspath.asPath
206
+ fun properties (key : String ) = project.findProperty(key).toString()
207
+
208
+ gettext {
209
+ potFile = project.layout.projectDirectory.file(" src/main/resources/localization/defaultMessages.pot" )
210
+ keywords = listOf (" ptrc:1c,2" , " ptrl" )
211
+ }
212
+
213
+ // region will be moved to the gradle plugin late
214
+ data class ExtensionJsonMeta (
215
+ val name : String ,
216
+ val description : String ,
217
+ val vendor : String ,
218
+ val url : String? ,
219
+ )
220
+
221
+ data class ExtensionJson (
222
+ val id : String ,
223
+ val version : String ,
224
+ val meta : ExtensionJsonMeta ,
225
+ )
226
+
227
+ fun generateExtensionJson (extensionJson : ExtensionJson , destinationFile : Path ) {
228
+ val descriptor = ToolboxPluginDescriptor (
229
+ id = extensionJson.id,
230
+ version = extensionJson.version,
231
+ apiVersion = libs.versions.toolbox.plugin.api.get(),
232
+ meta = ToolboxMeta (
233
+ name = extensionJson.meta.name,
234
+ description = extensionJson.meta.description,
235
+ vendor = extensionJson.meta.vendor,
236
+ url = extensionJson.meta.url,
170
237
)
171
- }
238
+ )
239
+ destinationFile.parent.createDirectories()
240
+ destinationFile.writeText(
241
+ jacksonMapperBuilder()
242
+ .enable(SerializationFeature .INDENT_OUTPUT )
243
+ .build()
244
+ .writeValueAsString(descriptor)
245
+ )
172
246
}
173
-
174
- fun properties (key : String ) = project.findProperty(key).toString()
247
+ // endregion
0 commit comments