-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
179 lines (152 loc) · 5.61 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
import com.github.jk1.license.filter.ExcludeTransitiveDependenciesFilter
import com.github.jk1.license.render.JsonReportRenderer
import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory
import org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfoRt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.nio.file.Path
import kotlin.io.path.div
plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.serialization)
`java-library`
alias(libs.plugins.dependency.license.report)
alias(libs.plugins.ksp)
alias(libs.plugins.gradle.wrapper)
alias(libs.plugins.changelog)
}
buildscript {
dependencies {
classpath(libs.marketplace.client)
}
}
repositories {
mavenCentral()
maven("https://packages.jetbrains.team/maven/p/tbx/toolbox-api")
}
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)
implementation(libs.slf4j)
implementation(libs.bundles.serialization)
implementation(libs.coroutines.core)
implementation(libs.okhttp)
implementation(libs.exec)
implementation(libs.moshi)
ksp(libs.moshi.codegen)
implementation(libs.retrofit)
implementation(libs.retrofit.moshi)
testImplementation(kotlin("test"))
}
val pluginId = properties("group")
val pluginName = properties("name")
val pluginVersion = properties("version")
changelog {
version.set(pluginVersion)
groups.set(emptyList())
title.set("Coder Toolbox Plugin Changelog")
}
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.test {
useJUnitPlatform()
}
val assemblePlugin by tasks.registering(Jar::class) {
archiveBaseName.set(pluginId)
from(sourceSets.main.get().output)
}
val copyPlugin by tasks.creating(Sync::class.java) {
dependsOn(assemblePlugin)
from(assemblePlugin.get().outputs.files)
from("src/main/resources") {
include("extension.json")
include("dependencies.json")
include("icon.svg")
}
// Copy dependencies, excluding those provided by Toolbox.
from(
configurations.compileClasspath.map { configuration ->
configuration.files.filterNot { file ->
listOf(
"kotlin",
"remote-dev-api",
"core-api",
"ui-api",
"annotations",
).any { file.name.contains(it) }
}
},
)
into(getPluginInstallDir())
}
tasks.register("cleanAll", Delete::class.java) {
dependsOn(tasks.clean)
delete(getPluginInstallDir())
delete()
}
private fun getPluginInstallDir(): Path {
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"
val pluginsDir = when {
SystemInfoRt.isWindows -> toolboxCachesDir / "cache"
SystemInfoRt.isLinux || SystemInfoRt.isMac -> toolboxCachesDir
else -> error("Unknown os")
} / "plugins"
return pluginsDir / pluginId
}
val pluginZip by tasks.creating(Zip::class) {
dependsOn(assemblePlugin)
from(assemblePlugin.get().outputs.files)
from("src/main/resources") {
include("extension.json")
include("dependencies.json")
}
from("src/main/resources") {
include("icon.svg")
rename("icon.svg", "pluginIcon.svg")
}
into(pluginId)
archiveBaseName.set(pluginName)
}
val publishPlugin by tasks.creating {
dependsOn(pluginZip)
doLast {
val instance = PluginRepositoryFactory.create(
"https://plugins.jetbrains.com",
project.property("PUBLISH_TOKEN").toString()
)
// first upload
// instance.uploader.uploadNewPlugin(pluginZip.outputs.files.singleFile, listOf("toolbox", "gateway"), LicenseUrl.APACHE_2_0, ProductFamily.TOOLBOX)
// subsequent updates
instance.uploader.upload(pluginId, pluginZip.outputs.files.singleFile)
}
}
// For use with kotlin-language-server.
tasks.register("classpath") {
doFirst {
File("classpath").writeText(
sourceSets["main"].runtimeClasspath.asPath
)
}
}
fun properties(key: String) = project.findProperty(key).toString()