|
| 1 | +// Copyright (c) 2024 Gitpod GmbH. All rights reserved. |
| 2 | +// Licensed under the GNU Affero General Public License (AGPL). |
| 3 | +// See License.AGPL.txt in the project root for license information. |
| 4 | + |
| 5 | +import com.github.jk1.license.filter.ExcludeTransitiveDependenciesFilter |
| 6 | +import com.github.jk1.license.render.JsonReportRenderer |
| 7 | +import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory |
| 8 | +import org.jetbrains.intellij.pluginRepository.model.LicenseUrl |
| 9 | +import org.jetbrains.intellij.pluginRepository.model.ProductFamily |
| 10 | +import org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfoRt |
| 11 | +import java.nio.file.Path |
| 12 | +import kotlin.io.path.div |
| 13 | + |
| 14 | +plugins { |
| 15 | + alias(libs.plugins.kotlin) |
| 16 | + alias(libs.plugins.serialization) |
| 17 | + `java-library` |
| 18 | + alias(libs.plugins.dependency.license.report) |
| 19 | + id("com.github.johnrengelman.shadow") version "8.1.1" |
| 20 | +} |
| 21 | + |
| 22 | +buildscript { |
| 23 | + dependencies { |
| 24 | + classpath(libs.marketplace.client) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +repositories { |
| 29 | + mavenCentral() |
| 30 | + maven("https://packages.jetbrains.team/maven/p/tbx/gateway") |
| 31 | +} |
| 32 | + |
| 33 | +dependencies { |
| 34 | + implementation(project(":supervisor-api")) |
| 35 | + implementation(project(":gitpod-publicapi")) |
| 36 | + |
| 37 | + // com.connectrpc https://mvnrepository.com/artifact/com.connectrpc |
| 38 | + // connect rpc dependencies |
| 39 | + implementation("com.squareup.okhttp3:okhttp:4.12.0") |
| 40 | + implementation("com.connectrpc:connect-kotlin-okhttp:0.6.0") |
| 41 | + implementation("com.connectrpc:connect-kotlin:0.6.0") |
| 42 | + // Java specific dependencies. |
| 43 | + implementation("com.connectrpc:connect-kotlin-google-java-ext:0.6.0") |
| 44 | + implementation("com.google.protobuf:protobuf-java:4.27.2") |
| 45 | + // WebSocket |
| 46 | + compileOnly("javax.websocket:javax.websocket-api:1.1") |
| 47 | + compileOnly("org.eclipse.jetty.websocket:websocket-api:9.4.54.v20240208") |
| 48 | + implementation("org.eclipse.jetty.websocket:javax-websocket-client-impl:9.4.54.v20240208") |
| 49 | + // RD-Core https://mvnrepository.com/artifact/com.jetbrains.rd/rd-core |
| 50 | + implementation("com.jetbrains.rd:rd-core:2024.1.1") |
| 51 | + |
| 52 | + implementation(libs.gateway.api) |
| 53 | + implementation(libs.slf4j) |
| 54 | + implementation(libs.bundles.serialization) |
| 55 | + implementation(libs.coroutines.core) |
| 56 | + implementation(libs.okhttp) |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | +val pluginId = "io.gitpod.toolbox.gateway" |
| 61 | +val pluginVersion = "0.0.1-dev" |
| 62 | + |
| 63 | +tasks.shadowJar { |
| 64 | + archiveBaseName.set(pluginId) |
| 65 | + archiveVersion.set(pluginVersion) |
| 66 | + |
| 67 | + val excludedGroups = listOf( |
| 68 | + "com.jetbrains.toolbox.gateway", |
| 69 | + "com.jetbrains", |
| 70 | + "org.jetbrains", |
| 71 | + "com.squareup.okhttp3", |
| 72 | + "org.slf4j", |
| 73 | + "org.jetbrains.intellij", |
| 74 | + "com.squareup.okio", |
| 75 | + "kotlin." |
| 76 | + ) |
| 77 | + |
| 78 | + val includeGroups = listOf( |
| 79 | + "com.jetbrains.rd" |
| 80 | + ) |
| 81 | + |
| 82 | + dependencies { |
| 83 | + exclude { |
| 84 | + excludedGroups.any { group -> |
| 85 | + if (includeGroups.any { includeGroup -> it.name.startsWith(includeGroup) }) { |
| 86 | + return@any false |
| 87 | + } |
| 88 | + it.name.startsWith(group) |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +licenseReport { |
| 95 | + renderers = arrayOf(JsonReportRenderer("dependencies.json")) |
| 96 | + filters = arrayOf(ExcludeTransitiveDependenciesFilter()) |
| 97 | +} |
| 98 | + |
| 99 | +tasks.compileKotlin { |
| 100 | + kotlinOptions.freeCompilerArgs += listOf( |
| 101 | + "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", |
| 102 | + ) |
| 103 | +} |
| 104 | + |
| 105 | +val restartToolbox by tasks.creating { |
| 106 | + group = "01.Gitpod" |
| 107 | + description = "Restarts the JetBrains Toolbox app." |
| 108 | + |
| 109 | + doLast { |
| 110 | + when { |
| 111 | + SystemInfoRt.isMac -> { |
| 112 | + exec { |
| 113 | + commandLine("sh", "-c", "pkill -f 'JetBrains Toolbox' || true") |
| 114 | + } |
| 115 | + Thread.sleep(3000) |
| 116 | + exec { |
| 117 | + commandLine("sh", "-c", "echo debugClean > ~/Library/Logs/JetBrains/Toolbox/toolbox.log") |
| 118 | + } |
| 119 | + exec { |
| 120 | +// environment("TOOLBOX_DEV_DEBUG_SUSPEND", "true") |
| 121 | + commandLine("open", "/Applications/JetBrains Toolbox.app") |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + else -> { |
| 126 | + println("restart Toolbox to make plugin works.") |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +val copyPlugin by tasks.creating(Sync::class.java) { |
| 133 | + group = "01.Gitpod" |
| 134 | + |
| 135 | + dependsOn(tasks.named("shadowJar")) |
| 136 | + from(tasks.named("shadowJar").get().outputs.files) |
| 137 | + |
| 138 | + val userHome = System.getProperty("user.home").let { Path.of(it) } |
| 139 | + val toolboxCachesDir = when { |
| 140 | + SystemInfoRt.isWindows -> System.getenv("LOCALAPPDATA")?.let { Path.of(it) } ?: (userHome / "AppData" / "Local") |
| 141 | + // currently this is the location that TBA uses on Linux |
| 142 | + SystemInfoRt.isLinux -> System.getenv("XDG_DATA_HOME")?.let { Path.of(it) } ?: (userHome / ".local" / "share") |
| 143 | + SystemInfoRt.isMac -> userHome / "Library" / "Caches" |
| 144 | + else -> error("Unknown os") |
| 145 | + } / "JetBrains" / "Toolbox" |
| 146 | + |
| 147 | + val pluginsDir = when { |
| 148 | + SystemInfoRt.isWindows -> toolboxCachesDir / "cache" |
| 149 | + SystemInfoRt.isLinux || SystemInfoRt.isMac -> toolboxCachesDir |
| 150 | + else -> error("Unknown os") |
| 151 | + } / "plugins" |
| 152 | + |
| 153 | + val targetDir = pluginsDir / pluginId |
| 154 | + |
| 155 | + from("src/main/resources") { |
| 156 | + include("extension.json") |
| 157 | + include("dependencies.json") |
| 158 | + include("icon.svg") |
| 159 | + } |
| 160 | + |
| 161 | + into(targetDir) |
| 162 | + |
| 163 | + finalizedBy(restartToolbox) |
| 164 | +} |
| 165 | + |
| 166 | +val pluginZip by tasks.creating(Zip::class) { |
| 167 | + dependsOn(tasks.named("shadowJar")) |
| 168 | + from(tasks.named("shadowJar").get().outputs.files) |
| 169 | + |
| 170 | + from("src/main/resources") { |
| 171 | + include("extension.json") |
| 172 | + include("dependencies.json") |
| 173 | + } |
| 174 | + from("src/main/resources") { |
| 175 | + include("icon.svg") |
| 176 | + rename("icon.svg", "pluginIcon.svg") |
| 177 | + } |
| 178 | + archiveBaseName.set("$pluginId-$pluginVersion") |
| 179 | +} |
| 180 | + |
| 181 | +val uploadPlugin by tasks.creating { |
| 182 | + dependsOn(pluginZip) |
| 183 | + |
| 184 | + doLast { |
| 185 | + val token = System.getenv("JB_MARKETPLACE_PUBLISH_TOKEN") |
| 186 | + val instance = PluginRepositoryFactory.create("https://plugins.jetbrains.com", token) |
| 187 | + |
| 188 | + // first upload |
| 189 | + // instance.uploader.uploadNewPlugin( |
| 190 | + // pluginZip.outputs.files.singleFile, |
| 191 | + // listOf("toolbox", "gateway", "gitpod"), |
| 192 | + // LicenseUrl.GNU_LESSER, |
| 193 | + // ProductFamily.TOOLBOX, |
| 194 | + // "Gitpod", |
| 195 | + // "dev" |
| 196 | + // ) |
| 197 | + |
| 198 | + // subsequent updates |
| 199 | +// instance.uploader.upload(pluginId, pluginZip.outputs.files.singleFile) |
| 200 | + } |
| 201 | +} |
0 commit comments