Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test preview #19597

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions components/ide/jetbrains/toolbox/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf
6 changes: 6 additions & 0 deletions components/ide/jetbrains/toolbox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Gradle
.gradle
build

# IntelliJ IDEA
.idea
30 changes: 30 additions & 0 deletions components/ide/jetbrains/toolbox/BUILD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
packages:
- name: plugin-stable
type: generic
deps:
- components/supervisor-api/java:lib
- components/public-api/java:lib
srcs:
- "**/*.kt"
- "**/*.kts"
- src/main/resources/*
- gradle.properties
- gradlew
- gradle/*
- build.sh
env:
- JB_QUALIFIER=stable
- SDKMAN_DIR=/home/gitpod/.sdkman
config:
commands:
- - "bash"
- "-c"
- >
echo java=21.0.3.fx-zulu > .sdkmanrc
&& source "$SDKMAN_DIR/bin/sdkman-init.sh"
&& sdk env install
&& ./build.sh "0.0.1-${version}"
&& mv ./build/distributions/io.gitpod.toolbox.gateway.zip .toolbox.zip
&& rm -rf *
&& rm -rf .gradle .kotlin .sdkmanrc
&& mv .toolbox.zip toolbox.zip
24 changes: 24 additions & 0 deletions components/ide/jetbrains/toolbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Gitpod Classic Toolbox Plugin

Provides a way to connect to Gitpod Classic workspaces within the JetBrains Toolbox App.

## How to Develop

### Requires
- Java 21
- IntelliJ IDEA
- Toolbox App

### Steps
- Clone and open this project locally in IntelliJ IDEA
- Run the `./gradlew copyPlugin` task to build and copy the plugin into Toolbox's plugin directory
- Restart the Toolbox Application if needed (for macOS, it can restart by copyPlugin task)

> To open the Toolbox App in debug mode
> ```bash
> TOOLBOX_DEV_DEBUG_SUSPEND=true && open /Applications/JetBrains\ Toolbox.app
> ```

## Install Plugin manually

If you download the plugin from the summary of GitHub Actions, you will need to install it manually. More details can be found [here (internal notes)](https://www.notion.so/gitpod/WIP-Experiment-Toolbox-gateway-feature-with-Gitpod-Classic-14c6425f2d52800297bbf98b88842ac7).
220 changes: 220 additions & 0 deletions components/ide/jetbrains/toolbox/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
// Copyright (c) 2024 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.

import com.github.jk1.license.filter.ExcludeTransitiveDependenciesFilter
import com.github.jk1.license.render.JsonReportRenderer
import org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfoRt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.nio.file.Path
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.io.path.div


plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.serialization)
`java-library`
alias(libs.plugins.dependency.license.report)
id("com.github.johnrengelman.shadow") version "8.1.1"
alias(libs.plugins.gradle.wrapper)
}

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 {
implementation(project(":supervisor-api"))
implementation(project(":gitpod-publicapi"))

// com.connectrpc https://mvnrepository.com/artifact/com.connectrpc
// connect rpc dependencies
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.connectrpc:connect-kotlin-okhttp:0.6.0")
implementation("com.connectrpc:connect-kotlin:0.6.0")
// Java specific dependencies.
implementation("com.connectrpc:connect-kotlin-google-java-ext:0.6.0")
implementation("com.google.protobuf:protobuf-java:4.27.2")
// WebSocket
compileOnly("javax.websocket:javax.websocket-api:1.1")
compileOnly("org.eclipse.jetty.websocket:websocket-api:9.4.54.v20240208")
implementation("org.eclipse.jetty.websocket:javax-websocket-client-impl:9.4.54.v20240208")
// RD-Core https://mvnrepository.com/artifact/com.jetbrains.rd/rd-core
implementation("com.jetbrains.rd:rd-core:2024.1.1")

compileOnly(libs.bundles.toolbox.plugin.api)
// implementation(libs.gateway.api)
implementation(libs.slf4j)
implementation(libs.bundles.serialization)
implementation(libs.coroutines.core)
implementation(libs.okhttp)
}

val pluginId = "io.gitpod.toolbox.gateway"
val defaultVersion = "0.0.1-local-${LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMddHHmm"))}"
val pluginVersion = providers.gradleProperty("pluginVersion").map { it.ifBlank { defaultVersion } }.getOrElse(defaultVersion)

println("Plugin version: $pluginVersion")

tasks.shadowJar {
archiveBaseName.set(pluginId)
archiveVersion.set(pluginVersion)

val excludedGroups = listOf(
"com.jetbrains.toolbox.gateway",
"com.jetbrains",
"org.jetbrains",
"com.squareup.okhttp3",
"org.slf4j",
"org.jetbrains.intellij",
"com.squareup.okio",
"kotlin."
)

val includeGroups = listOf(
"com.jetbrains.rd"
)

dependencies {
exclude {
excludedGroups.any { group ->
if (includeGroups.any { includeGroup -> it.name.startsWith(includeGroup) }) {
return@any false
}
it.name.startsWith(group)
}
}
}
}

licenseReport {
renderers = arrayOf(JsonReportRenderer("dependencies.json"))
filters = arrayOf(ExcludeTransitiveDependenciesFilter())
}


kotlin {
jvmToolchain(21)
}
tasks.compileKotlin {
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
}

val restartToolbox by tasks.creating {
group = "01.Gitpod"
description = "Restarts the JetBrains Toolbox app."

doLast {
when {
SystemInfoRt.isMac -> {
exec {
commandLine("sh", "-c", "pkill -f 'JetBrains Toolbox' || true")
}
Thread.sleep(3000)
exec {
commandLine("sh", "-c", "echo debugClean > ~/Library/Logs/JetBrains/Toolbox/toolbox.log")
}
exec {
// environment("TOOLBOX_DEV_DEBUG_SUSPEND", "true")
commandLine("open", "/Applications/JetBrains Toolbox.app")
}
}

else -> {
println("restart Toolbox to make plugin works.")
}
}
}
}

val copyPlugin by tasks.creating(Sync::class.java) {
group = "01.Gitpod"

dependsOn(tasks.named("shadowJar"))
from(tasks.named("shadowJar").get().outputs.files)

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"

val targetDir = pluginsDir / pluginId

from("src/main/resources") {
include("extension.json")
include("dependencies.json")
include("icon.svg")
include("icon-gray.svg")
}

into(targetDir)

finalizedBy(restartToolbox)
}

val pluginZip by tasks.creating(Zip::class) {
dependsOn(tasks.named("shadowJar"))
from(tasks.named("shadowJar").get().outputs.files)

from("src/main/resources") {
include("extension.json")
include("dependencies.json")
}
from("src/main/resources") {
include("icon.svg")
include("icon-gray.svg")
rename("icon.svg", "pluginIcon.svg")
}
archiveBaseName.set(pluginId)
}

val uploadPlugin by tasks.creating {
dependsOn(pluginZip)

doLast {
// val token = System.getenv("JB_MARKETPLACE_PUBLISH_TOKEN")
// val instance = PluginRepositoryFactory.create("https://plugins.jetbrains.com", token)

// first upload
// instance.uploader.uploadNewPlugin(
// pluginZip.outputs.files.singleFile,
// listOf("toolbox", "gateway", "gitpod"),
// LicenseUrl.GNU_LESSER,
// ProductFamily.TOOLBOX,
// "Gitpod",
// "dev"
// )

// subsequent updates
// instance.uploader.upload(pluginId, pluginZip.outputs.files.singleFile)
}
}
17 changes: 17 additions & 0 deletions components/ide/jetbrains/toolbox/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# Copyright (c) 2024 Gitpod GmbH. All rights reserved.
# Licensed under the GNU Affero General Public License (AGPL).
# See License.AGPL.txt in the project root for license information.

set -e

JB_GP_VERSION=${1}

./gradlew -PsupervisorApiProjectPath=components-supervisor-api-java--lib/ -PgitpodPublicApiProjectPath=components-public-api-java--lib/ -PenvironmentName="$JB_QUALIFIER" -Dgradle.user.home="/workspace/.gradle-tb-$JB_QUALIFIER" -Dplugin.verifier.home.dir="$HOME/.cache/pluginVerifier-tb-$JB_QUALIFIER" -PpluginVersion="$JB_GP_VERSION" pluginZip

# # TODO(hw): Improve me
# tarDir="/tmp/tb-build"
# mkdir -p "$tarDir"
# mv ./build/distributions/io.gitpod.toolbox.gateway-0.0.1-dev.zip "$tarDir/io.gitpod.toolbox.gateway-0.0.1-dev.zip"
# echo "GITPOD_PLUGIN_ZIP=$tarDir/io.gitpod.toolbox.gateway-0.0.1-dev.zip" >> /tmp/__gh_output.txt
# # unzip ./build/distributions/io.gitpod.toolbox.gateway-0.0.1-dev.zip -d ./build
4 changes: 4 additions & 0 deletions components/ide/jetbrains/toolbox/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pluginVersion=
environmentName=latest
supervisorApiProjectPath=../../../supervisor-api/java
gitpodPublicApiProjectPath=../../../public-api/java
33 changes: 33 additions & 0 deletions components/ide/jetbrains/toolbox/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[versions]
toolbox-plugin-api = "0.2"
kotlin = "2.0.10"
coroutines = "1.7.3"
serialization = "1.5.0"
okhttp = "4.10.0"
slf4j = "2.0.3"
dependency-license-report = "2.5"
marketplace-client = "2.0.38"
gradle-wrapper = "0.14.0"

[libraries]
toolbox-core-api = { module = "com.jetbrains.toolbox:core-api", version.ref = "toolbox-plugin-api" }
toolbox-ui-api = { module = "com.jetbrains.toolbox:ui-api", version.ref = "toolbox-plugin-api" }
toolbox-remote-dev-api = { module = "com.jetbrains.toolbox:remote-dev-api", version.ref = "toolbox-plugin-api" }
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" }
serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
serialization-json-okio = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio", version.ref = "serialization" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }

marketplace-client = { module = "org.jetbrains.intellij:plugin-repository-rest-client", version.ref = "marketplace-client" }

[bundles]
serialization = [ "serialization-core", "serialization-json" ]
toolbox-plugin-api = [ "toolbox-core-api", "toolbox-ui-api", "toolbox-remote-dev-api" ]

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
dependency-license-report = { id = "com.github.jk1.dependency-license-report", version.ref = "dependency-license-report" }
gradle-wrapper = { id = "me.filippov.gradle.jvm.wrapper", version.ref = "gradle-wrapper" }
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading