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