Skip to content

Commit 4ba4987

Browse files
committed
WIP: upgrade to latest version
1 parent 42440a0 commit 4ba4987

File tree

13 files changed

+120
-35
lines changed

13 files changed

+120
-35
lines changed
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
# Gitpod Toolbox Plugin
1+
# Gitpod Classic Toolbox Plugin
22

3-
To load plugin into the provided Toolbox App, run `./gradlew build copyPlugin`
3+
Provides a way to connect to Gitpod Classic workspaces within the JetBrains Toolbox App.
44

5-
or put files in the following directory:
5+
## How to Develop
66

7-
* Windows: `%LocalAppData%/JetBrains/Toolbox/cache/plugins/plugin-id`
8-
* macOS: `~/Library/Caches/JetBrains/Toolbox/plugins/plugin-id`
9-
* Linux: `~/.local/share/JetBrains/Toolbox/plugins/plugin-id`
7+
### Requires
8+
- Java 21
9+
- IntelliJ IDEA
10+
- Toolbox App
1011

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

12-
## How to Develop
17+
> To open the Toolbox App in debug mode
18+
> ```bash
19+
> TOOLBOX_DEV_DEBUG_SUSPEND=true && open /Applications/JetBrains\ Toolbox.app
20+
> ```
21+
22+
## Install Plugin manually
1323
14-
- Open the Toolbox App in debug mode
15-
```bash
16-
TOOLBOX_DEV_DEBUG_SUSPEND=true && open /Applications/JetBrains\ Toolbox.app
17-
```
24+
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).

components/ide/jetbrains/toolbox/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import com.github.jk1.license.filter.ExcludeTransitiveDependenciesFilter
66
import com.github.jk1.license.render.JsonReportRenderer
77
import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory
8-
import org.jetbrains.intellij.pluginRepository.model.LicenseUrl
9-
import org.jetbrains.intellij.pluginRepository.model.ProductFamily
108
import org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfoRt
119
import java.nio.file.Path
1210
import kotlin.io.path.div

components/ide/jetbrains/toolbox/gradle/libs.versions.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[versions]
2-
gateway = "2.5.0.32871"
3-
#gateway = "2.4.0.31544"
2+
gateway = "2.6.0.34606"
43
kotlin = "1.9.0"
54
coroutines = "1.7.3"
65
serialization = "1.5.0"

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodAuthManager.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class GitpodAuthManager {
158158
val bearerToken = getBearerToken(oAuthToken)
159159
val client = GitpodPublicApiManager.createClient(URI(gitpodHost).host, bearerToken)
160160
val user = GitpodPublicApiManager.tryGetAuthenticatedUser(UserServiceClient(client))
161-
GitpodAccount(bearerToken, user.id, user.name, gitpodHost)
161+
GitpodAccount(bearerToken, user.id, user.name, gitpodHost, authScopesJetBrainsToolbox)
162162
}
163163
}
164164

@@ -186,18 +186,21 @@ class GitpodAccount : Account {
186186
private val id: String
187187
private val name: String
188188
private val host: String
189+
private val scopes: List<String>
189190

190-
constructor(credentials: String, id: String, name: String, host: String) {
191+
constructor(credentials: String, id: String, name: String, host: String, scopes: List<String>) {
191192
this.credentials = credentials
192193
this.id = id
193194
this.name = name
194195
this.host = URI(host).host
196+
this.scopes = scopes
195197
}
196198

197199
override fun getId() = id
198200
override fun getFullName() = name
199201
fun getCredentials() = credentials
200202
fun getHost() = host
203+
fun getScopes() = scopes
201204

202205
fun encode(): String {
203206
return Json.encodeToString(this)
@@ -214,6 +217,7 @@ class GitpodAccount : Account {
214217
GitpodLogger.debug("validating account $host")
215218
try {
216219
GitpodPublicApiManager.tryGetAuthenticatedUser(UserServiceClient(client))
220+
// TODO: Verify scopes
217221
return true
218222
} catch (e: ConnectException) {
219223
// TODO(hw): Server close jsonrpc so papi server respond internal error

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodLoginPage.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package io.gitpod.toolbox.auth
66

77
import com.jetbrains.toolbox.gateway.ui.*
88
import io.gitpod.toolbox.components.AbstractUiPage
9-
import io.gitpod.toolbox.components.GitpodIcon
9+
import io.gitpod.toolbox.components.GitpodIconColored
1010
import io.gitpod.toolbox.components.SimpleButton
1111
import io.gitpod.toolbox.service.Utils
1212

@@ -33,11 +33,11 @@ class GitpodLoginPage(private val authManager: GitpodAuthManager) : AbstractUiPa
3333
})
3434
}
3535

36-
override fun getTitle() = "Login to Gitpod"
36+
override fun getTitle() = "Log in to Gitpod Classic"
3737

3838
override fun getDescription() = "Always ready to code."
3939

4040
override fun getSvgIcon(): ByteArray {
41-
return GitpodIcon()
41+
return GitpodIconColored()
4242
}
4343
}

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/components/AbstractUiPage.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import java.util.function.BiConsumer
1010
import java.util.function.Function
1111

1212
abstract class AbstractUiPage : UiPage {
13-
private var stateGetter: Function<UiField, *>? = null
13+
private var stateAccessor: UiPage.UiFieldStateAccessor? = null
1414

1515
@Suppress("UNCHECKED_CAST")
16-
fun <T> getFieldValue(field: UiField) = stateGetter?.apply(field) as T?
16+
fun <T> getFieldValue(field: UiField) = stateAccessor?.get(field) as T?
1717

18-
override fun setStateAccessor(setter: BiConsumer<UiField, Any>?, getter: Function<UiField, *>?) {
19-
super.setStateAccessor(setter, getter)
20-
stateGetter = getter
18+
override fun setStateAccessor(stateAccessor: UiPage.UiFieldStateAccessor?) {
19+
super.setStateAccessor(stateAccessor)
20+
this.stateAccessor = stateAccessor
2121
}
2222
}
23+
24+
class EmptyUiPageWithTitle(private val title: String) : UiPage {
25+
override fun getFields(): MutableList<UiField> = mutableListOf()
26+
override fun getTitle() = title
27+
}

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/components/Icon.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ import io.gitpod.toolbox.gateway.GitpodGatewayExtension
1010
fun GitpodIcon(): ByteArray {
1111
return GitpodGatewayExtension::class.java.getResourceAsStream("/icon.svg")?.readAllBytes() ?: byteArrayOf()
1212
}
13+
14+
@Suppress("FunctionName")
15+
fun GitpodIconColored(): ByteArray {
16+
return GitpodGatewayExtension::class.java.getResourceAsStream("/icon-colored.svg")?.readAllBytes() ?: byteArrayOf()
17+
}

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.jetbrains.toolbox.gateway.ui.UiPage
1313
import io.gitpod.publicapi.experimental.v1.Workspaces
1414
import io.gitpod.toolbox.auth.GitpodAuthManager
1515
import io.gitpod.toolbox.auth.GitpodLoginPage
16+
import io.gitpod.toolbox.components.EmptyUiPageWithTitle
1617
import io.gitpod.toolbox.components.GitpodIcon
1718
import io.gitpod.toolbox.components.SimpleButton
1819
import io.gitpod.toolbox.service.*
@@ -63,13 +64,15 @@ class GitpodRemoteProvider(
6364
consumer.consumeEnvironments(environmentMap.values.map { it.second })
6465
}
6566
val joinLinkInfo = workspace!!.fetchJoinLink2Info(publicApi.getWorkspaceOwnerToken(workspaceId))
67+
Utils.clientHelper.prepareClient(joinLinkInfo.ideVersion)
6668
Utils.clientHelper.setAutoConnectOnEnvironmentReady(workspaceId, joinLinkInfo.ideVersion, joinLinkInfo.projectPath)
6769
}
6870

6971
private fun showWorkspacesList() {
7072
Utils.coroutineScope.launch {
7173
val workspaces = publicApi.listWorkspaces()
7274
if (workspaces.isEmpty()) {
75+
consumer.consumeEnvironments(emptyList())
7376
return@launch
7477
}
7578
consumer.consumeEnvironments(workspaces.map {
@@ -120,10 +123,10 @@ class GitpodRemoteProvider(
120123

121124
override fun close() {}
122125

123-
override fun getName(): String = "Gitpod"
126+
override fun getName(): String = "Gitpod Classic"
124127
override fun getSvgIcon() = GitpodIcon()
125128

126-
override fun getNewEnvironmentUiPage() = UiPage.empty
129+
override fun getNewEnvironmentUiPage() = EmptyUiPageWithTitle("")
127130

128131
override fun getAccountDropDown(): AccountDropdownField? {
129132
val account = authManger.getCurrentAccount() ?: return null
@@ -138,11 +141,11 @@ class GitpodRemoteProvider(
138141
Utils.openUrl("https://gitpod.io/docs")
139142
},
140143
)
141-
142144
}
143145

144146
override fun canCreateNewEnvironments(): Boolean = false
145147
override fun isSingleEnvironment(): Boolean = false
148+
override fun getNoEnvironmentsDescription() = "No workspaces"
146149

147150
override fun setVisible(visibilityState: ProviderVisibilityState) {}
148151

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProviderEnvironment.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ package io.gitpod.toolbox.gateway
66

77
import com.jetbrains.toolbox.gateway.AbstractRemoteProviderEnvironment
88
import com.jetbrains.toolbox.gateway.EnvironmentVisibilityState
9+
import com.jetbrains.toolbox.gateway.deploy.CommandExecution
10+
import com.jetbrains.toolbox.gateway.deploy.HostAccessInterfaces
11+
import com.jetbrains.toolbox.gateway.deploy.HostCommandExecutor
12+
import com.jetbrains.toolbox.gateway.deploy.HostFileAccessor
913
import com.jetbrains.toolbox.gateway.environments.EnvironmentContentsView
14+
import com.jetbrains.toolbox.gateway.environments.HostAccessCapableEnvironmentContentsView
1015
import com.jetbrains.toolbox.gateway.states.EnvironmentStateConsumer
1116
import com.jetbrains.toolbox.gateway.states.StandardRemoteEnvironmentState
1217
import com.jetbrains.toolbox.gateway.ui.ActionDescription
@@ -82,6 +87,10 @@ class GitpodRemoteProviderEnvironment(
8287

8388
override fun getActionList(): ObservableList<ActionDescription> = actionList
8489

90+
override fun onDelete() {
91+
watchWorkspaceJob?.cancel()
92+
}
93+
8594
override fun dispose() {
8695
watchWorkspaceJob?.cancel()
8796
}

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodSSHEnvironmentContentsView.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package io.gitpod.toolbox.gateway
66

7+
import com.jetbrains.toolbox.gateway.environments.CachedIdeStub
8+
import com.jetbrains.toolbox.gateway.environments.CachedProjectStub
79
import com.jetbrains.toolbox.gateway.environments.ManualEnvironmentContentsView
810
import com.jetbrains.toolbox.gateway.environments.SshEnvironmentContentsView
911
import com.jetbrains.toolbox.gateway.ssh.SshConnectionInfo
@@ -34,6 +36,30 @@ class GitpodSSHEnvironmentContentsView(
3436

3537
override fun addEnvironmentContentsListener(p0: ManualEnvironmentContentsView.Listener) {
3638
stateListeners += p0
39+
stateListeners.forEach{
40+
it.onProjectListUpdated(listOf(object : CachedProjectStub {
41+
override fun getPath(): String {
42+
return "/workspace/template-golang-cli"
43+
}
44+
45+
override fun getName(): String? {
46+
return "template-golang-cli"
47+
}
48+
49+
override fun getIdeHint(): String? {
50+
return "GO-243.21565.208"
51+
}
52+
}))
53+
it.onIdeListUpdated(listOf(object: CachedIdeStub {
54+
override fun getProductCode(): String {
55+
return "GO-243.21565.208"
56+
}
57+
58+
override fun isRunning(): Boolean? {
59+
return true
60+
}
61+
}))
62+
}
3763
}
3864

3965
override fun removeEnvironmentContentsListener(p0: ManualEnvironmentContentsView.Listener) {

0 commit comments

Comments
 (0)