forked from kropp/toolbox-gateway-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
227 lines (191 loc) · 7.53 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
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
223
224
225
226
227
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.jk1.license.filter.ExcludeTransitiveDependenciesFilter
import com.github.jk1.license.render.JsonReportRenderer
import com.jetbrains.plugin.structure.toolbox.ToolboxMeta
import com.jetbrains.plugin.structure.toolbox.ToolboxPluginDescriptor
import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory
import org.jetbrains.intellij.pluginRepository.model.LicenseUrl
import org.jetbrains.intellij.pluginRepository.model.ProductFamily
import org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfoRt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.nio.file.Path
import java.util.Properties
import kotlin.io.path.createDirectories
import kotlin.io.path.div
import kotlin.io.path.writeText
plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.serialization)
`java-library`
alias(libs.plugins.dependency.license.report)
alias(libs.plugins.gradle.wrapper)
alias(libs.plugins.gettext)
}
repositories {
mavenCentral()
maven("https://packages.jetbrains.team/maven/p/tbx/toolbox-api")
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(libs.marketplace.client)
classpath(libs.plugin.structure)
}
}
jvmWrapper {
unixJvmInstallDir = "jvm"
winJvmInstallDir = "jvm"
linuxAarch64JvmUrl = "https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-linux-aarch64-b631.28.tar.gz"
linuxX64JvmUrl = "https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-linux-x64-b631.28.tar.gz"
macAarch64JvmUrl = "https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-osx-aarch64-b631.28.tar.gz"
macX64JvmUrl = "https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-osx-x64-b631.28.tar.gz"
windowsX64JvmUrl = "https://cache-redirector.jetbrains.com/intellij-jbr/jbr_jcef-21.0.5-windows-x64-b631.28.tar.gz"
}
dependencies {
compileOnly(libs.bundles.toolbox.plugin.api)
compileOnly(libs.bundles.serialization)
compileOnly(libs.coroutines.core)
}
licenseReport {
renderers = arrayOf(JsonReportRenderer("dependencies.json"))
filters = arrayOf(ExcludeTransitiveDependenciesFilter())
// jq script to convert to our format:
// `jq '[.dependencies[] | {name: .moduleName, version: .moduleVersion, url: .moduleUrl, license: .moduleLicense, licenseUrl: .moduleLicenseUrl}]' < build/reports/dependency-license/dependencies.json > src/main/resources/dependencies.json`
}
tasks.compileKotlin {
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
}
tasks.jar {
archiveBaseName.set(extension.id)
dependsOn(extensionJson)
}
// region will be moved to the gradle plugin late
data class ExtensionJsonMeta(
val name: String,
val description: String,
val vendor: String,
val url: String?,
)
data class ExtensionJson(
val id: String,
val version: String,
val meta: ExtensionJsonMeta,
)
fun generateExtensionJson(extensionJson: ExtensionJson, destinationFile: Path) {
val descriptor = ToolboxPluginDescriptor(
id = extensionJson.id,
version = extensionJson.version,
apiVersion = libs.versions.toolbox.plugin.api.get(),
meta = ToolboxMeta(
name = extensionJson.meta.name,
description = extensionJson.meta.description,
vendor = extensionJson.meta.vendor,
url = extensionJson.meta.url,
)
)
val extensionJson = jacksonObjectMapper().writeValueAsString(descriptor)
destinationFile.parent.createDirectories()
destinationFile.writeText(extensionJson)
}
// endregion
val extension = ExtensionJson(
id = "com.jetbrains.toolbox.sample",
version = "1.0.0",
meta = ExtensionJsonMeta(
name = "Toolbox Sample Plugin",
description = "Sample Plugin for JetBrains Toolbox",
vendor = "JetBrains",
url = "https://www.jetbrains.com/toolbox/",
)
)
val extensionJsonFile = layout.buildDirectory.file("generated/extension.json")
val extensionJson by tasks.registering {
inputs.property("extension", extension.toString())
outputs.file(extensionJsonFile)
doLast {
generateExtensionJson(extension, extensionJsonFile.get().asFile.toPath())
}
}
val copyPlugin by tasks.creating(Sync::class.java) {
dependsOn(tasks.assemble)
val userHome = System.getProperty("user.home").let { Path.of(it) }
val toolboxCachesDir = when {
SystemInfoRt.isWindows -> System.getenv("LOCALAPPDATA")?.let { Path.of(it) } ?: (userHome / "AppData" / "Local")
// currently this is the location that TBA uses on Linux
SystemInfoRt.isLinux -> System.getenv("XDG_DATA_HOME")?.let { Path.of(it) } ?: (userHome / ".local" / "share")
SystemInfoRt.isMac -> userHome / "Library" / "Caches"
else -> error("Unknown os")
} / "JetBrains" / "Toolbox-Dev"
val pluginsDir = when {
SystemInfoRt.isWindows -> toolboxCachesDir / "cache"
SystemInfoRt.isLinux || SystemInfoRt.isMac -> toolboxCachesDir
else -> error("Unknown os")
} / "plugins"
val targetDir = pluginsDir / extension.id
from(tasks.jar)
from(extensionJsonFile)
from("src/main/resources") {
include("dependencies.json")
include("icon.svg")
}
into(targetDir)
}
val pluginZip by tasks.registering(Zip::class) {
dependsOn(tasks.assemble)
dependsOn(tasks.getByName("generateLicenseReport"))
from(tasks.assemble.get().outputs.files)
from(extensionJsonFile)
from("src/main/resources") {
include("dependencies.json")
}
from("src/main/resources") {
include("icon.svg")
rename("icon.svg", "pluginIcon.svg")
}
archiveBaseName.set("${extension.id}-${extension.version}")
}
val toolboxPluginPropertiesFile = file("toolbox-plugin.properties")
val pluginMarketplaceToken: String = if (toolboxPluginPropertiesFile.exists()) {
val token = Properties().apply { load(toolboxPluginPropertiesFile.inputStream()) }.getProperty("pluginMarketplaceToken", null)
if (token == null) {
error("pluginMarketplaceToken does not exist in ${toolboxPluginPropertiesFile.absolutePath}.\n" +
"Please set pluginMarketplaceToken property to a token obtained from the marketplace.")
}
token
} else {
error("toolbox-plugin.properties does not exist at ${toolboxPluginPropertiesFile.absolutePath}.\n" +
"Please create the file and set pluginMarketplaceToken property to a token obtained from the marketplace.")
}
println("Plugin Marketplace Token: ${pluginMarketplaceToken.take(5)}*****")
// Work in progress. The public version of Marketplace will not accept the plugin yet
val uploadPlugin by tasks.registering {
dependsOn(pluginZip)
doLast {
val instance = PluginRepositoryFactory.
create(
"https://plugins.jetbrains.com",
pluginMarketplaceToken
)
// first upload
// instance.uploader.uploadNewPlugin(
// pluginZip.get().outputs.files.singleFile,
// listOf("toolbox", "gateway"),
// LicenseUrl.APACHE_2_0,
// ProductFamily.TOOLBOX,
// extension.meta.vendor,
// isHidden = true
// )
// subsequent updates
// instance.uploader.uploadUpdateByXmlIdAndFamily(
// extension.id,
// ProductFamily.TOOLBOX,
// pluginZip.get().outputs.files.singleFile,
// )
}
}
gettext {
potFile = project.layout.projectDirectory.file("src/main/resources/localization/defaultMessages.pot")
keywords = listOf("ptrc:1c,2", "ptrl")
}