From 8b9e1d386054786a65fbaa93c8e967120063c26f Mon Sep 17 00:00:00 2001 From: mustard Date: Fri, 8 Jul 2022 08:14:17 +0000 Subject: [PATCH 1/3] Revert "[jb] fix #10694: respect GW user settings" This reverts commit bd5d3ea95b9567314a009e319e8aabbf58021cdf. --- .../api/GitpodServerLauncher.java | 65 +------------------ .../jetbrains/auth/GitpodAuthService.kt | 8 ++- .../jetbrains/gateway/GatewayGitpodClient.kt | 18 ++--- .../gateway/GitpodConnectionProvider.kt | 29 +++++---- .../gateway/GitpodConnectionService.kt | 46 +++++-------- .../jetbrains/gateway/GitpodConnector.kt | 1 + .../jetbrains/gateway/GitpodConnectorView.kt | 1 + .../gateway/GitpodRecentConnections.kt | 1 + .../gateway/GitpodSettingsConfigurable.kt | 1 + .../jetbrains/gateway/GitpodSettingsState.kt | 5 +- .../jetbrains/gateway/GitpodWorkspacesView.kt | 8 +-- 11 files changed, 62 insertions(+), 121 deletions(-) diff --git a/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/GitpodServerLauncher.java b/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/GitpodServerLauncher.java index 17064ce885e044..10322a6c504f39 100644 --- a/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/GitpodServerLauncher.java +++ b/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/GitpodServerLauncher.java @@ -4,11 +4,6 @@ package io.gitpod.gitpodprotocol.api; -import org.eclipse.jetty.client.HttpClient; -import org.eclipse.jetty.client.HttpProxy; -import org.eclipse.jetty.client.Socks4Proxy; -import org.eclipse.jetty.util.ssl.SslContextFactory; -import org.eclipse.jetty.websocket.jsr356.ClientContainer; import org.eclipse.lsp4j.jsonrpc.Launcher; import org.eclipse.lsp4j.jsonrpc.MessageConsumer; import org.eclipse.lsp4j.jsonrpc.MessageIssueHandler; @@ -16,14 +11,10 @@ import org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints; import org.eclipse.lsp4j.websocket.WebSocketMessageHandler; -import javax.net.ssl.SSLContext; import javax.websocket.*; -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.SocketAddress; +import java.io.IOException; import java.net.URI; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.logging.Level; @@ -56,60 +47,10 @@ public GitpodServerConnection listen( String userAgent, String clientVersion, String token - ) throws Exception { - return listen(apiUrl, origin, userAgent, clientVersion, token, Collections.emptyList(), null); - } - - public GitpodServerConnection listen( - String apiUrl, - String origin, - String userAgent, - String clientVersion, - String token, - List proxies, - SSLContext sslContext - ) throws Exception { + ) throws DeploymentException, IOException { String gitpodHost = URI.create(apiUrl).getHost(); - HttpClient httpClient; - if (sslContext == null) { - httpClient = new HttpClient(); - } else { - SslContextFactory ssl = new SslContextFactory.Client(); - ssl.setSslContext(sslContext); - httpClient = new HttpClient(ssl); - } - for (Proxy proxy : proxies) { - if (proxy.type().equals(Proxy.Type.DIRECT)) { - continue; - } - SocketAddress proxyAddress = proxy.address(); - if (!(proxyAddress instanceof InetSocketAddress)) { - GitpodServerConnectionImpl.LOG.log(Level.WARNING, gitpodHost + ": unexpected proxy:", proxy); - continue; - } - String hostName = ((InetSocketAddress) proxyAddress).getHostString(); - int port = ((InetSocketAddress) proxyAddress).getPort(); - if (proxy.type().equals(Proxy.Type.HTTP)) { - httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(hostName, port)); - } else if (proxy.type().equals(Proxy.Type.SOCKS)) { - httpClient.getProxyConfiguration().getProxies().add(new Socks4Proxy(hostName, port)); - } - } - ClientContainer container = new ClientContainer(httpClient); - // allow clientContainer to own httpClient (for start/stop lifecycle) - container.getClient().addManaged(httpClient); - container.start(); - GitpodServerConnectionImpl connection = new GitpodServerConnectionImpl(gitpodHost); - connection.whenComplete((input, exception) -> { - try { - container.stop(); - } catch (Throwable t) { - GitpodServerConnectionImpl.LOG.log(Level.WARNING, gitpodHost + ": failed to stop websocket container:", t); - } - }); - - connection.setSession(container.connectToServer(new Endpoint() { + connection.setSession(ContainerProvider.getWebSocketContainer().connectToServer(new Endpoint() { @Override public void onOpen(Session session, EndpointConfig config) { session.addMessageHandler(new WebSocketMessageHandler(messageReader, jsonHandler, remoteEndpoint)); diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/auth/GitpodAuthService.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/auth/GitpodAuthService.kt index 5440f6404b80a9..40ea5e7085657c 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/auth/GitpodAuthService.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/auth/GitpodAuthService.kt @@ -38,6 +38,7 @@ import java.util.* import java.util.concurrent.CompletableFuture import kotlin.math.absoluteValue + @Service internal class GitpodAuthService : OAuthServiceBase() { override val name: String @@ -65,7 +66,7 @@ internal class GitpodAuthService : OAuthServiceBase() { constructor(gitpodHost: String) { val codeVerifier = generateCodeVerifier() val codeChallenge = generateCodeChallenge(codeVerifier) - val serviceUrl = newFromEncoded("https://$gitpodHost/api/oauth") + val serviceUrl = newFromEncoded("https://${gitpodHost}/api/oauth") credentialsAcquirer = GitpodAuthCredentialsAcquirer( serviceUrl.resolve("token"), mapOf( "grant_type" to "authorization_code", @@ -93,7 +94,7 @@ internal class GitpodAuthService : OAuthServiceBase() { val bytes = ByteArray(size) secureRandom.nextBytes(bytes) - val mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~" + val mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~"; val scale = 256 / mask.length val builder = StringBuilder() for (i in 0 until size) { @@ -146,6 +147,7 @@ internal class GitpodAuthService : OAuthServiceBase() { private data class AuthorizationResponseData(val accessToken: String) private data class JsonWebToken(val jti: String) + } companion object { @@ -196,7 +198,7 @@ internal class GitpodAuthService : OAuthServiceBase() { listener() } } - dispatcher.addListener(internalListener) + dispatcher.addListener(internalListener); return Disposable { dispatcher.removeListener(internalListener) } } } diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GatewayGitpodClient.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GatewayGitpodClient.kt index 842fb2b8447d02..021934b641cdc6 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GatewayGitpodClient.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GatewayGitpodClient.kt @@ -21,8 +21,7 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock class GatewayGitpodClient( - private val lifetimeDefinition: LifetimeDefinition, - private val gitpodHost: String + private val lifetimeDefinition: LifetimeDefinition, private val gitpodHost: String ) : GitpodClient() { private val mutex = Mutex() @@ -30,7 +29,7 @@ class GatewayGitpodClient( private val listeners = concurrentMapOf>?>() private val timeoutDelayInMinutes = 15 - private var timeoutJob: Job? = null + private var timeoutJob: Job? = null; init { GlobalScope.launch { @@ -60,7 +59,7 @@ class GatewayGitpodClient( } } - private var syncJob: Job? = null + private var syncJob: Job? = null; override fun notifyConnect() { syncJob?.cancel() syncJob = GlobalScope.launch { @@ -70,9 +69,9 @@ class GatewayGitpodClient( continue } try { - syncWorkspace(id) + syncWorkspace(id); } catch (t: Throwable) { - thisLogger().error("$gitpodHost: $id: failed to sync", t) + thisLogger().error("${gitpodHost}: ${id}: failed to sync", t) } } } @@ -80,7 +79,7 @@ class GatewayGitpodClient( override fun onInstanceUpdate(instance: WorkspaceInstance?) { if (instance == null) { - return + return; } GlobalScope.launch { val wsListeners = listeners[instance.workspaceId] ?: return@launch @@ -103,7 +102,7 @@ class GatewayGitpodClient( val listener = Channel() mutex.withLock { val listeners = this.listeners.getOrPut(workspaceId) { CopyOnWriteArrayList() }!! - listeners.add(listener) + listeners.add(listener); cancelTimeout("listening to workspace: $workspaceId") } listenerLifetime.onTerminationOrNow { @@ -121,7 +120,7 @@ class GatewayGitpodClient( if (listeners.isNullOrEmpty()) { return } - listeners.remove(listener) + listeners.remove(listener); if (listeners.isNotEmpty()) { return } @@ -138,4 +137,5 @@ class GatewayGitpodClient( onInstanceUpdate(info.latestInstance) return info } + } diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectionProvider.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectionProvider.kt index ce3244ca25118b..e3bd6fb1596050 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectionProvider.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectionProvider.kt @@ -48,6 +48,7 @@ import javax.swing.JComponent import javax.swing.JLabel import kotlin.coroutines.coroutineContext + class GitpodConnectionProvider : GatewayConnectionProvider { private val gitpod = service() @@ -64,10 +65,10 @@ class GitpodConnectionProvider : GatewayConnectionProvider { requestor: ConnectionRequestor ): GatewayConnectionHandle? { if (parameters["gitpodHost"] == null) { - throw IllegalArgumentException("bad gitpodHost parameter") + throw IllegalArgumentException("bad gitpodHost parameter"); } if (parameters["workspaceId"] == null) { - throw IllegalArgumentException("bad workspaceId parameter") + throw IllegalArgumentException("bad workspaceId parameter"); } val connectParams = ConnectParams( parameters["gitpodHost"]!!, @@ -92,7 +93,7 @@ class GitpodConnectionProvider : GatewayConnectionProvider { background = phaseMessage.background columns = 30 } - var ideUrl = "" + var ideUrl = ""; val connectionPanel = panel { indent { row { @@ -145,18 +146,18 @@ class GitpodConnectionProvider : GatewayConnectionProvider { } GlobalScope.launch { - var thinClient: ThinClientHandle? = null - var thinClientJob: Job? = null + var thinClient: ThinClientHandle? = null; + var thinClientJob: Job? = null; - var lastUpdate: WorkspaceInstance? = null + var lastUpdate: WorkspaceInstance? = null; try { for (update in updates) { try { if (WorkspaceInstance.isUpToDate(lastUpdate, update)) { - continue + continue; } ideUrl = update.ideUrl - lastUpdate = update + lastUpdate = update; if (!update.status.conditions.failed.isNullOrBlank()) { setErrorMessage(update.status.conditions.failed) } @@ -274,7 +275,7 @@ class GitpodConnectionProvider : GatewayConnectionProvider { } } - return GitpodConnectionHandle(connectionLifetime, connectionPanel, connectParams) + return GitpodConnectionHandle(connectionLifetime, connectionPanel, connectParams); } private suspend fun resolveJoinLink( @@ -364,6 +365,7 @@ class GitpodConnectionProvider : GatewayConnectionProvider { break } } + } matchedFingerprint } @@ -376,7 +378,7 @@ class GitpodConnectionProvider : GatewayConnectionProvider { ownerToken: String?, ): String? { val maxRequestTimeout = 30 * 1000L - val timeoutDelayGrowFactor = 1.5 + val timeoutDelayGrowFactor = 1.5; var requestTimeout = 2 * 1000L while (true) { coroutineContext.job.ensureActive() @@ -395,16 +397,16 @@ class GitpodConnectionProvider : GatewayConnectionProvider { return response.body() } if (response.statusCode() < 500) { - thisLogger().error("${connectParams.gitpodHost}: ${connectParams.workspaceId}: failed to fetch '$endpointUrl': ${response.statusCode()}") + thisLogger().error("${connectParams.gitpodHost}: ${connectParams.workspaceId}: failed to fetch '${endpointUrl}': ${response.statusCode()}") return null } - thisLogger().warn("${connectParams.gitpodHost}: ${connectParams.workspaceId}: failed to fetch '$endpointUrl', trying again...: ${response.statusCode()}") + thisLogger().warn("${connectParams.gitpodHost}: ${connectParams.workspaceId}: failed to fetch '${endpointUrl}', trying again...: ${response.statusCode()}") } catch (t: Throwable) { if (t is CancellationException) { throw t } thisLogger().warn( - "${connectParams.gitpodHost}: ${connectParams.workspaceId}: failed to fetch '$endpointUrl', trying again...:", + "${connectParams.gitpodHost}: ${connectParams.workspaceId}: failed to fetch '${endpointUrl}', trying again...:", t ) } @@ -444,4 +446,5 @@ class GitpodConnectionProvider : GatewayConnectionProvider { } private data class SSHHostKey(val type: String, val hostKey: String) + } diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectionService.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectionService.kt index ebdc5eda0221ec..568861872e7dad 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectionService.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectionService.kt @@ -11,8 +11,6 @@ import com.intellij.openapi.extensions.PluginId import com.intellij.remoteDev.util.onTerminationOrNow import com.intellij.util.ExceptionUtil import com.intellij.util.io.DigestUtil -import com.intellij.util.net.ssl.CertificateManager -import com.intellij.util.proxy.CommonProxy import com.jetbrains.rd.util.concurrentMapOf import com.jetbrains.rd.util.lifetime.Lifetime import io.gitpod.gitpodprotocol.api.GitpodServerLauncher @@ -20,13 +18,12 @@ import io.gitpod.jetbrains.auth.GitpodAuthService import kotlinx.coroutines.* import kotlinx.coroutines.future.await import org.eclipse.jetty.websocket.api.UpgradeException -import java.net.URL import java.nio.charset.StandardCharsets @Service class GitpodConnectionService { - private val clients = concurrentMapOf() + private val clients = concurrentMapOf(); fun obtainClient(gitpodHost: String): GatewayGitpodClient { return clients.getOrPut(gitpodHost) { @@ -40,30 +37,22 @@ class GitpodConnectionService { accessToken = GitpodAuthService.authorize(gitpodHost) } if (accessToken == null) { - authorize() + authorize(); } val plugin = PluginManagerCore.getPlugin(PluginId.getId("io.gitpod.jetbrains.gateway"))!! val connect = suspend { ensureActive() - val originalClassLoader = Thread.currentThread().contextClassLoader val connection = try { - val origin = "https://$gitpodHost/" - val proxies = CommonProxy.getInstance().select(URL(origin)) - val sslContext = CertificateManager.getInstance().sslContext - // see https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003146180/comments/360000376240 Thread.currentThread().contextClassLoader = GitpodConnectionProvider::class.java.classLoader - launcher.listen( - "wss://$gitpodHost/api/v1", - origin, - plugin.pluginId.idString, - plugin.version, - accessToken, - proxies, - sslContext + "wss://${gitpodHost}/api/v1", + "https://${gitpodHost}/", + plugin.pluginId.idString, + plugin.version, + accessToken ) } catch (t: Throwable) { val badUpgrade = ExceptionUtil.findCause(t, UpgradeException::class.java) @@ -72,7 +61,7 @@ class GitpodConnectionService { } throw t } finally { - Thread.currentThread().contextClassLoader = originalClassLoader + Thread.currentThread().contextClassLoader = originalClassLoader; } val tokenHash = DigestUtil.sha256Hex(accessToken!!.toByteArray(StandardCharsets.UTF_8)) val tokenScopes = client.server.getGitpodTokenScopes(tokenHash).await() @@ -87,34 +76,34 @@ class GitpodConnectionService { val minReconnectionDelay = 2 * 1000L val maxReconnectionDelay = 30 * 1000L - val reconnectionDelayGrowFactor = 1.5 - var reconnectionDelay = minReconnectionDelay + val reconnectionDelayGrowFactor = 1.5; + var reconnectionDelay = minReconnectionDelay; while (isActive) { try { val connection = try { connect() } catch (t: Throwable) { val e = ExceptionUtil.findCause(t, InvalidTokenException::class.java) ?: throw t - thisLogger().warn("$gitpodHost: invalid token, authorizing again and reconnecting:", e) + thisLogger().warn("${gitpodHost}: invalid token, authorizing again and reconnecting:", e) authorize() connect() } reconnectionDelay = minReconnectionDelay - thisLogger().info("$gitpodHost: connected") + thisLogger().info("${gitpodHost}: connected") val reason = connection.await() if (isActive) { - thisLogger().warn("$gitpodHost: connection closed, reconnecting after $reconnectionDelay milliseconds: $reason") + thisLogger().warn("${gitpodHost}: connection closed, reconnecting after $reconnectionDelay milliseconds: $reason") } else { - thisLogger().info("$gitpodHost: connection permanently closed: $reason") + thisLogger().info("${gitpodHost}: connection permanently closed: $reason") } } catch (t: Throwable) { if (isActive) { thisLogger().warn( - "$gitpodHost: failed to connect, trying again after $reconnectionDelay milliseconds:", - t + "${gitpodHost}: failed to connect, trying again after $reconnectionDelay milliseconds:", + t ) } else { - thisLogger().error("$gitpodHost: connection permanently closed:", t) + thisLogger().error("${gitpodHost}: connection permanently closed:", t) } } delay(reconnectionDelay) @@ -133,4 +122,5 @@ class GitpodConnectionService { } private class InvalidTokenException(message: String) : Exception(message) + } diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnector.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnector.kt index 1f5b2be4dd13d9..249ba89b4f2388 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnector.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnector.kt @@ -54,4 +54,5 @@ class GitpodConnector : GatewayConnector { } override fun initProcedure() {} + } diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectorView.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectorView.kt index 05f6ac000b2537..1e28732e3ef3ba 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectorView.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodConnectorView.kt @@ -44,4 +44,5 @@ class GitpodConnectorView( }.apply { this.background = WelcomeScreenUIManager.getMainAssociatedComponentBackground() } + } diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodRecentConnections.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodRecentConnections.kt index 3b075c7bfec45c..dcb5407dce3dc9 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodRecentConnections.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodRecentConnections.kt @@ -40,4 +40,5 @@ class GitpodRecentConnections : GatewayRecentConnections { this.view.refresh() } } + } diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodSettingsConfigurable.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodSettingsConfigurable.kt index 931eee25ad31a5..95e3333f13043f 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodSettingsConfigurable.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodSettingsConfigurable.kt @@ -42,4 +42,5 @@ class GitpodSettingsConfigurable : BoundConfigurable("Gitpod") { return@run null } } + } diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodSettingsState.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodSettingsState.kt index c0b7b879030865..1bdae030fad697 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodSettingsState.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodSettingsState.kt @@ -22,7 +22,7 @@ class GitpodSettingsState : PersistentStateComponent { var gitpodHost: String = "gitpod.io" set(value) { if (value.isNullOrBlank()) { - return + return; } val gitpodHost = try { URL(value.trim()).host @@ -47,7 +47,7 @@ class GitpodSettingsState : PersistentStateComponent { listener() } } - dispatcher.addListener(internalListener) + dispatcher.addListener(internalListener); return Disposable { dispatcher.removeListener(internalListener) } } @@ -58,4 +58,5 @@ class GitpodSettingsState : PersistentStateComponent { override fun loadState(state: GitpodSettingsState) { XmlSerializerUtil.copyBean(state, this) } + } diff --git a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodWorkspacesView.kt b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodWorkspacesView.kt index b32b6426df64c9..61c1e6c5c85dd8 100644 --- a/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodWorkspacesView.kt +++ b/components/ide/jetbrains/gateway-plugin/src/main/kotlin/io/gitpod/jetbrains/gateway/GitpodWorkspacesView.kt @@ -180,7 +180,7 @@ class GitpodWorkspacesView( ensureActive() updateLifetime?.terminate() updateLifetime = lifetime.createNested() - doUpdate(updateLifetime, workspacesPane) + doUpdate(updateLifetime, workspacesPane); } } lifetime.onTerminationOrNow { updateActor.close() } @@ -239,7 +239,7 @@ class GitpodWorkspacesView( } } catch (e: Throwable) { thisLogger().error( - "$gitpodHost: ${it.workspace.id}: failed to parse creation time", + "${gitpodHost}: ${it.workspace.id}: failed to parse creation time", e ) null @@ -247,7 +247,7 @@ class GitpodWorkspacesView( } for (info in sortedInfos) { if (info.latestInstance == null) { - continue + continue; } indent { row { @@ -330,7 +330,7 @@ class GitpodWorkspacesView( try { info = client.syncWorkspace(update.workspaceId) } catch (t: Throwable) { - thisLogger().error("$gitpodHost: ${update.workspaceId}: failed to sync", t) + thisLogger().error("${gitpodHost}: ${update.workspaceId}: failed to sync", t) continue } workspacesMap[update.workspaceId] = info From cb2b7421947f96cb30a308b8836156d08b2c086d Mon Sep 17 00:00:00 2001 From: mustard Date: Fri, 8 Jul 2022 09:34:31 +0000 Subject: [PATCH 2/3] Revert "Auto-forward Task Terminals Ports on JetBrains IDEs" This reverts commit 95f02d84f59cc0829dcfa7a8818f2ee83d785b20. --- .../remote/latest/GitpodTerminalService.kt | 109 ++++++++---------- 1 file changed, 46 insertions(+), 63 deletions(-) diff --git a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt index ced1f759e52c30..4d7346bf7fa21a 100644 --- a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt +++ b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt @@ -4,14 +4,12 @@ package io.gitpod.jetbrains.remote.latest +import com.intellij.openapi.Disposable import com.intellij.openapi.client.ClientProjectSession import com.intellij.openapi.diagnostic.thisLogger -import com.intellij.openapi.rd.createLifetime import com.intellij.remoteDev.util.onTerminationOrNow import com.intellij.util.application -import com.jetbrains.rdserver.portForwarding.PortForwardingDiscovery -import com.jetbrains.rdserver.portForwarding.PortForwardingManager -import com.jetbrains.rdserver.portForwarding.remoteDev.PortEventsProcessor +import com.jetbrains.rd.util.lifetime.Lifetime import com.jetbrains.rdserver.terminal.BackendTerminalManager import io.gitpod.jetbrains.remote.GitpodManager import io.gitpod.supervisor.api.Status @@ -27,26 +25,32 @@ import java.util.concurrent.CompletableFuture import java.util.concurrent.TimeUnit @Suppress("UnstableApiUsage") -class GitpodTerminalService(private val session: ClientProjectSession) { +class GitpodTerminalService(session: ClientProjectSession) : Disposable { private companion object { - var hasStarted = false - val forwardedPortsList: MutableSet = mutableSetOf() + /** Indicates if this service is already running, because we shouldn't run it more than once. */ + var isRunning = false } + private val lifetime = Lifetime.Eternal.createNested() private val terminalView = TerminalView.getInstance(session.project) private val backendTerminalManager = BackendTerminalManager.getInstance(session.project) - private val portForwardingManager = PortForwardingManager.getInstance(session.project) private val terminalServiceFutureStub = TerminalServiceGrpc.newFutureStub(GitpodManager.supervisorChannel) private val statusServiceStub = StatusServiceGrpc.newStub(GitpodManager.supervisorChannel) - init { start() } + override fun dispose() { + lifetime.terminate() + } + + init { + run() + } - private fun start() { - if (application.isHeadlessEnvironment || hasStarted) return + private fun run() { + if (application.isHeadlessEnvironment || isRunning) return - hasStarted = true + isRunning = true - application.executeOnPooledThread { + val task = application.executeOnPooledThread { val terminals = getSupervisorTerminalsList() val tasks = getSupervisorTasksList() @@ -54,6 +58,10 @@ class GitpodTerminalService(private val session: ClientProjectSession) { createTerminalsAttachedToTasks(terminals, tasks) } } + + lifetime.onTerminationOrNow { + task.cancel(true) + } } private fun createSharedTerminalAndExecuteCommand(title: String, command: String) { @@ -62,11 +70,12 @@ class GitpodTerminalService(private val session: ClientProjectSession) { backendTerminalManager.createNewSharedTerminal(UUID.randomUUID().toString(), title) for (widget in terminalView.widgets) { - if (registeredTerminals.contains(widget)) continue - - widget.terminalTitle.change { applicationTitle = title } - - (widget as ShellTerminalWidget).executeCommand(command) + if (!registeredTerminals.contains(widget)) { + widget.terminalTitle.change { + applicationTitle = title + } + (widget as ShellTerminalWidget).executeCommand(command) + } } } @@ -85,10 +94,11 @@ class GitpodTerminalService(private val session: ClientProjectSession) { for (task in tasks) { val terminalAlias = task.terminal - val terminal = aliasToTerminalMap[terminalAlias] ?: continue + val terminal = aliasToTerminalMap[terminalAlias] - createAttachedSharedTerminal(terminal) - autoForwardAllPortsFromTerminal(terminal) + if (terminal != null) { + createAttachedSharedTerminal(terminal) + } } } @@ -102,17 +112,22 @@ class GitpodTerminalService(private val session: ClientProjectSession) { val taskStatusResponseObserver = object : ClientResponseObserver { - override fun beforeStart(request: ClientCallStreamObserver) = Unit + override fun beforeStart(request: ClientCallStreamObserver) { + lifetime.onTerminationOrNow { + request.cancel(null, null) + } + } override fun onNext(response: Status.TasksStatusResponse) { for (task in response.tasksList) { - if (task.state === Status.TaskState.opening) return + if (task.state === Status.TaskState.opening) { + return + } } - completableFuture.complete(response.tasksList) } - override fun onCompleted() = Unit + override fun onCompleted() {} override fun onError(throwable: Throwable) { completableFuture.completeExceptionally(throwable) @@ -128,7 +143,7 @@ class GitpodTerminalService(private val session: ClientProjectSession) { } thisLogger().error( - "gitpod: Got an error while trying to get tasks list from Supervisor. Trying again in on second.", + "Got an error while trying to get tasks list from Supervisor. Trying again in on second.", throwable ) } @@ -149,6 +164,10 @@ class GitpodTerminalService(private val session: ClientProjectSession) { val listTerminalsResponseFuture = terminalServiceFutureStub.list(listTerminalsRequest) + lifetime.onTerminationOrNow { + listTerminalsResponseFuture.cancel(true) + } + val listTerminalsResponse = listTerminalsResponseFuture.get() terminalsList = listTerminalsResponse.terminalsList @@ -158,7 +177,7 @@ class GitpodTerminalService(private val session: ClientProjectSession) { } thisLogger().error( - "gitpod: Got an error while trying to get terminals list from Supervisor. Trying again in on second.", + "Got an error while trying to get terminals list from Supervisor. Trying again in on second.", throwable ) } @@ -177,40 +196,4 @@ class GitpodTerminalService(private val session: ClientProjectSession) { "gp tasks attach ${supervisorTerminal.alias}" ) } - - private fun autoForwardAllPortsFromTerminal(supervisorTerminal: TerminalOuterClass.Terminal) { - val projectLifetime = session.project.createLifetime() - - val discoveryCallback = object : PortForwardingDiscovery { - /** - * @return Whether port should be forwarded or not. - * We shouldn't try to forward ports that are already forwarded. - */ - override fun onPortDiscovered(hostPort: Int): Boolean = !forwardedPortsList.contains(hostPort) - - override fun getEventsProcessor(hostPort: Int) = object : PortEventsProcessor { - override fun onPortForwarded(hostPort: Int, clientPort: Int) { - forwardedPortsList.add(hostPort) - thisLogger().info("gitpod: Forwarded port $hostPort from Supervisor's Terminal " + - "${supervisorTerminal.pid} to client's port $clientPort.") - - projectLifetime.onTerminationOrNow { - if (forwardedPortsList.contains(hostPort)) { - forwardedPortsList.remove(hostPort) - portForwardingManager.removePort(hostPort) - thisLogger().info("gitpod: Removing forwarded port $hostPort from Supervisor's Terminal " + - "${supervisorTerminal.pid}") - } - } - } - - override fun onPortForwardingFailed(hostPort: Int, reason: String) { - thisLogger().error("gitpod: Failed to forward port $hostPort from Supervisor's Terminal " + - "${supervisorTerminal.pid}: $reason") - } - } - } - - portForwardingManager.forwardPortsOfPid(projectLifetime, supervisorTerminal.pid, discoveryCallback, true) - } } From 562f7d3473fb9168c392d7107757e4921cf65005 Mon Sep 17 00:00:00 2001 From: mustard Date: Fri, 8 Jul 2022 09:34:46 +0000 Subject: [PATCH 3/3] Revert "When using the Latest Release of JetBrains IDEs, if the workspace has tasks defined on .gitpod.yml, the IDE will start with one terminal opened for each task" This reverts commit 41efa4ad17374844bdcb786120e1d599596c75c7. --- .gitpod.yml | 2 +- .../ide/jetbrains/backend-plugin/.gitignore | 1 - .../ide/jetbrains/backend-plugin/BUILD.yaml | 27 +-- .../jetbrains/backend-plugin/build.gradle.kts | 24 +-- .../backend-plugin/gradle-latest.properties | 9 - .../backend-plugin/gradle-stable.properties | 9 - .../backend-plugin/gradle.properties | 12 +- .../{stable => }/GitpodTerminalService.kt | 4 +- .../remote/latest/GitpodTerminalService.kt | 199 ------------------ .../resources-latest/META-INF/extensions.xml | 10 - .../resources-stable/META-INF/extensions.xml | 10 - .../src/main/resources/META-INF/plugin.xml | 4 +- components/ide/jetbrains/image/BUILD.yaml | 16 +- .../ide/jetbrains/image/leeway.Dockerfile | 3 +- 14 files changed, 29 insertions(+), 301 deletions(-) delete mode 100644 components/ide/jetbrains/backend-plugin/gradle-latest.properties delete mode 100644 components/ide/jetbrains/backend-plugin/gradle-stable.properties rename components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/{stable => }/GitpodTerminalService.kt (96%) delete mode 100644 components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt delete mode 100644 components/ide/jetbrains/backend-plugin/src/main/resources-latest/META-INF/extensions.xml delete mode 100644 components/ide/jetbrains/backend-plugin/src/main/resources-stable/META-INF/extensions.xml diff --git a/.gitpod.yml b/.gitpod.yml index a5866cc7694fde..efca58c07a68cc 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -46,7 +46,7 @@ tasks: read -r -p "Press enter to continue Java gradle task" fi leeway exec --package components/supervisor-api/java:lib --package components/gitpod-protocol/java:lib -- ./gradlew --build-cache build - leeway exec --package components/ide/jetbrains/backend-plugin:plugin-latest --package components/ide/jetbrains/gateway-plugin:publish --parallel -- ./gradlew --build-cache buildPlugin + leeway exec --package components/ide/jetbrains/backend-plugin:plugin --package components/ide/jetbrains/gateway-plugin:publish --parallel -- ./gradlew --build-cache buildPlugin - name: TypeScript before: scripts/branch-namespace.sh init: yarn --network-timeout 100000 && yarn build diff --git a/components/ide/jetbrains/backend-plugin/.gitignore b/components/ide/jetbrains/backend-plugin/.gitignore index 9fbea8abb7bbb9..1ba96ae392cf36 100644 --- a/components/ide/jetbrains/backend-plugin/.gitignore +++ b/components/ide/jetbrains/backend-plugin/.gitignore @@ -3,4 +3,3 @@ .vscode bin build -gradle-local.properties diff --git a/components/ide/jetbrains/backend-plugin/BUILD.yaml b/components/ide/jetbrains/backend-plugin/BUILD.yaml index b9d783401e8616..de621855869f41 100644 --- a/components/ide/jetbrains/backend-plugin/BUILD.yaml +++ b/components/ide/jetbrains/backend-plugin/BUILD.yaml @@ -1,5 +1,5 @@ packages: - - name: plugin-stable + - name: plugin type: generic deps: - components/supervisor-api/java:lib @@ -8,32 +8,11 @@ packages: - "**/*.kt" - "build.gradle.kts" - "gradle.properties" - - "gradle-stable.properties" - "gradle/wrapper/*" - "gradlew" - "settings.gradle.kts" - "src/main/resources/*" - - "src/main/resources-stable/*" config: commands: - - ["./gradlew", "-PsupervisorApiProjectPath=components-supervisor-api-java--lib/", "-PgitpodProtocolProjectPath=components-gitpod-protocol-java--lib/", "-PenvironmentName=stable", "runPluginVerifier"] - - ["./gradlew", "-PsupervisorApiProjectPath=components-supervisor-api-java--lib/", "-PgitpodProtocolProjectPath=components-gitpod-protocol-java--lib/", "-PenvironmentName=stable", "buildPlugin"] - - name: plugin-latest - type: generic - deps: - - components/supervisor-api/java:lib - - components/gitpod-protocol/java:lib - srcs: - - "**/*.kt" - - "build.gradle.kts" - - "gradle.properties" - - "gradle-latest.properties" - - "gradle/wrapper/*" - - "gradlew" - - "settings.gradle.kts" - - "src/main/resources/*" - - "src/main/resources-latest/*" - config: - commands: - - ["./gradlew", "-PsupervisorApiProjectPath=components-supervisor-api-java--lib/", "-PgitpodProtocolProjectPath=components-gitpod-protocol-java--lib/", "-PenvironmentName=latest", "runPluginVerifier"] - - ["./gradlew", "-PsupervisorApiProjectPath=components-supervisor-api-java--lib/", "-PgitpodProtocolProjectPath=components-gitpod-protocol-java--lib/", "-PenvironmentName=latest", "buildPlugin"] + - ["./gradlew", "-PsupervisorApiProjectPath=components-supervisor-api-java--lib/", "-PgitpodProtocolProjectPath=components-gitpod-protocol-java--lib/", "runPluginVerifier"] + - ["./gradlew", "-PsupervisorApiProjectPath=components-supervisor-api-java--lib/", "-PgitpodProtocolProjectPath=components-gitpod-protocol-java--lib/", "buildPlugin"] diff --git a/components/ide/jetbrains/backend-plugin/build.gradle.kts b/components/ide/jetbrains/backend-plugin/build.gradle.kts index 3769309c2c9ba2..3c465fb6c1e1f8 100644 --- a/components/ide/jetbrains/backend-plugin/build.gradle.kts +++ b/components/ide/jetbrains/backend-plugin/build.gradle.kts @@ -10,37 +10,19 @@ fun properties(key: String) = project.findProperty(key).toString() plugins { // Java support id("java") - // Kotlin support - check the latest version at https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm - id("org.jetbrains.kotlin.jvm") version "1.7.0" + // Kotlin support + id("org.jetbrains.kotlin.jvm") version "1.5.10" // gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin - id("org.jetbrains.intellij") version "1.6.0" + id("org.jetbrains.intellij") version "1.0" // detekt linter - read more: https://detekt.github.io/detekt/gradle.html id("io.gitlab.arturbosch.detekt") version "1.17.1" // ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle id("org.jlleitschuh.gradle.ktlint") version "10.0.0" - // Gradle Properties Plugin - read more: https://github.com/stevesaliman/gradle-properties-plugin - id("net.saliman.properties") version "1.5.2" } group = properties("pluginGroup") version = properties("version") -val environmentName = properties("environmentName") - -project(":") { - kotlin { - var excludedPackage = "stable" - if (environmentName == excludedPackage) excludedPackage = "latest" - sourceSets["main"].kotlin.exclude("io/gitpod/jetbrains/remote/${excludedPackage}/**") - } - - sourceSets { - main { - resources.srcDirs("src/main/resources-${environmentName}") - } - } -} - // Configure project's dependencies repositories { mavenCentral() diff --git a/components/ide/jetbrains/backend-plugin/gradle-latest.properties b/components/ide/jetbrains/backend-plugin/gradle-latest.properties deleted file mode 100644 index bb2590085d2fd0..00000000000000 --- a/components/ide/jetbrains/backend-plugin/gradle-latest.properties +++ /dev/null @@ -1,9 +0,0 @@ -# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html -# for insight into build numbers and IntelliJ Platform versions. -pluginSinceBuild=222 -pluginUntilBuild=222.* -# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl -# See https://jb.gg/intellij-platform-builds-list for available build versions. -pluginVerifierIdeVersions=2022.2 -# Version from "com.jetbrains.intellij.idea" which can be found at https://www.jetbrains.com/intellij-repository/snapshots -platformVersion=222-EAP-SNAPSHOT diff --git a/components/ide/jetbrains/backend-plugin/gradle-stable.properties b/components/ide/jetbrains/backend-plugin/gradle-stable.properties deleted file mode 100644 index 7cb9c111870a88..00000000000000 --- a/components/ide/jetbrains/backend-plugin/gradle-stable.properties +++ /dev/null @@ -1,9 +0,0 @@ -# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html -# for insight into build numbers and IntelliJ Platform versions. -pluginSinceBuild=221 -pluginUntilBuild=221.* -# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl -# See https://jb.gg/intellij-platform-builds-list for available build versions. -pluginVerifierIdeVersions=2022.1 -# Version from "com.jetbrains.intellij.idea" which can be found at https://www.jetbrains.com/intellij-repository/snapshots -platformVersion=221-EAP-SNAPSHOT diff --git a/components/ide/jetbrains/backend-plugin/gradle.properties b/components/ide/jetbrains/backend-plugin/gradle.properties index 2cbce2c7b77a77..807fa6476d756a 100644 --- a/components/ide/jetbrains/backend-plugin/gradle.properties +++ b/components/ide/jetbrains/backend-plugin/gradle.properties @@ -1,12 +1,18 @@ version=0.0.1 -# Supported environments: stable, latest (via https://github.com/stevesaliman/gradle-properties-plugin) -environmentName=latest # IntelliJ Platform Artifacts Repositories # -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html pluginGroup=io.gitpod.jetbrains pluginName=gitpod-remote -# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-type +# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html +# for insight into build numbers and IntelliJ Platform versions. +pluginSinceBuild=213 +pluginUntilBuild=221.* +# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl +# See https://jb.gg/intellij-platform-builds-list for available build versions. +pluginVerifierIdeVersions=2021.3, 2022.1 +# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties platformType=IU +platformVersion=221-EAP-SNAPSHOT platformDownloadSources=true # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 diff --git a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/stable/GitpodTerminalService.kt b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodTerminalService.kt similarity index 96% rename from components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/stable/GitpodTerminalService.kt rename to components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodTerminalService.kt index 7ad70c8800da37..c6330b99a80111 100644 --- a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/stable/GitpodTerminalService.kt +++ b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodTerminalService.kt @@ -2,7 +2,7 @@ // Licensed under the GNU Affero General Public License (AGPL). // See License-AGPL.txt in the project root for license information. -package io.gitpod.jetbrains.remote.stable +package io.gitpod.jetbrains.remote import com.intellij.openapi.Disposable import com.intellij.openapi.application.runInEdt @@ -24,7 +24,7 @@ import org.jetbrains.plugins.terminal.TerminalToolWindowFactory import org.jetbrains.plugins.terminal.TerminalView import java.util.concurrent.CompletableFuture -@Suppress("UnstableApiUsage", "EXPERIMENTAL_IS_NOT_ENABLED") +@Suppress("UnstableApiUsage", "EXPERIMENTAL_IS_NOT_ENABLED", "OPT_IN_IS_NOT_ENABLED") @OptIn(DelicateCoroutinesApi::class) class GitpodTerminalService(private val project: Project) : Disposable { private val lifetime = Lifetime.Eternal.createNested() diff --git a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt deleted file mode 100644 index 4d7346bf7fa21a..00000000000000 --- a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright (c) 2022 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. - -package io.gitpod.jetbrains.remote.latest - -import com.intellij.openapi.Disposable -import com.intellij.openapi.client.ClientProjectSession -import com.intellij.openapi.diagnostic.thisLogger -import com.intellij.remoteDev.util.onTerminationOrNow -import com.intellij.util.application -import com.jetbrains.rd.util.lifetime.Lifetime -import com.jetbrains.rdserver.terminal.BackendTerminalManager -import io.gitpod.jetbrains.remote.GitpodManager -import io.gitpod.supervisor.api.Status -import io.gitpod.supervisor.api.StatusServiceGrpc -import io.gitpod.supervisor.api.TerminalOuterClass -import io.gitpod.supervisor.api.TerminalServiceGrpc -import io.grpc.stub.ClientCallStreamObserver -import io.grpc.stub.ClientResponseObserver -import org.jetbrains.plugins.terminal.ShellTerminalWidget -import org.jetbrains.plugins.terminal.TerminalView -import java.util.* -import java.util.concurrent.CompletableFuture -import java.util.concurrent.TimeUnit - -@Suppress("UnstableApiUsage") -class GitpodTerminalService(session: ClientProjectSession) : Disposable { - private companion object { - /** Indicates if this service is already running, because we shouldn't run it more than once. */ - var isRunning = false - } - - private val lifetime = Lifetime.Eternal.createNested() - private val terminalView = TerminalView.getInstance(session.project) - private val backendTerminalManager = BackendTerminalManager.getInstance(session.project) - private val terminalServiceFutureStub = TerminalServiceGrpc.newFutureStub(GitpodManager.supervisorChannel) - private val statusServiceStub = StatusServiceGrpc.newStub(GitpodManager.supervisorChannel) - - override fun dispose() { - lifetime.terminate() - } - - init { - run() - } - - private fun run() { - if (application.isHeadlessEnvironment || isRunning) return - - isRunning = true - - val task = application.executeOnPooledThread { - val terminals = getSupervisorTerminalsList() - val tasks = getSupervisorTasksList() - - application.invokeLater { - createTerminalsAttachedToTasks(terminals, tasks) - } - } - - lifetime.onTerminationOrNow { - task.cancel(true) - } - } - - private fun createSharedTerminalAndExecuteCommand(title: String, command: String) { - val registeredTerminals = terminalView.widgets.toMutableList() - - backendTerminalManager.createNewSharedTerminal(UUID.randomUUID().toString(), title) - - for (widget in terminalView.widgets) { - if (!registeredTerminals.contains(widget)) { - widget.terminalTitle.change { - applicationTitle = title - } - (widget as ShellTerminalWidget).executeCommand(command) - } - } - } - - private fun createTerminalsAttachedToTasks( - terminals: List, - tasks: List - ) { - if (tasks.isEmpty()) return - - val aliasToTerminalMap: MutableMap = mutableMapOf() - - for (terminal in terminals) { - val terminalAlias = terminal.alias - aliasToTerminalMap[terminalAlias] = terminal - } - - for (task in tasks) { - val terminalAlias = task.terminal - val terminal = aliasToTerminalMap[terminalAlias] - - if (terminal != null) { - createAttachedSharedTerminal(terminal) - } - } - } - - private tailrec fun getSupervisorTasksList(): List { - var tasksList: List? = null - - try { - val completableFuture = CompletableFuture>() - - val taskStatusRequest = Status.TasksStatusRequest.newBuilder().setObserve(true).build() - - val taskStatusResponseObserver = object : - ClientResponseObserver { - override fun beforeStart(request: ClientCallStreamObserver) { - lifetime.onTerminationOrNow { - request.cancel(null, null) - } - } - - override fun onNext(response: Status.TasksStatusResponse) { - for (task in response.tasksList) { - if (task.state === Status.TaskState.opening) { - return - } - } - completableFuture.complete(response.tasksList) - } - - override fun onCompleted() {} - - override fun onError(throwable: Throwable) { - completableFuture.completeExceptionally(throwable) - } - } - - statusServiceStub.tasksStatus(taskStatusRequest, taskStatusResponseObserver) - - tasksList = completableFuture.get() - } catch (throwable: Throwable) { - if (throwable is InterruptedException) { - throw throwable - } - - thisLogger().error( - "Got an error while trying to get tasks list from Supervisor. Trying again in on second.", - throwable - ) - } - - return if (tasksList != null) { - tasksList - } else { - TimeUnit.SECONDS.sleep(1) - getSupervisorTasksList() - } - } - - private tailrec fun getSupervisorTerminalsList(): List { - var terminalsList: List? = null - - try { - val listTerminalsRequest = TerminalOuterClass.ListTerminalsRequest.newBuilder().build() - - val listTerminalsResponseFuture = terminalServiceFutureStub.list(listTerminalsRequest) - - lifetime.onTerminationOrNow { - listTerminalsResponseFuture.cancel(true) - } - - val listTerminalsResponse = listTerminalsResponseFuture.get() - - terminalsList = listTerminalsResponse.terminalsList - } catch (throwable: Throwable) { - if (throwable is InterruptedException) { - throw throwable - } - - thisLogger().error( - "Got an error while trying to get terminals list from Supervisor. Trying again in on second.", - throwable - ) - } - - return if (terminalsList != null) { - terminalsList - } else { - TimeUnit.SECONDS.sleep(1) - getSupervisorTerminalsList() - } - } - - private fun createAttachedSharedTerminal(supervisorTerminal: TerminalOuterClass.Terminal) { - createSharedTerminalAndExecuteCommand( - supervisorTerminal.title, - "gp tasks attach ${supervisorTerminal.alias}" - ) - } -} diff --git a/components/ide/jetbrains/backend-plugin/src/main/resources-latest/META-INF/extensions.xml b/components/ide/jetbrains/backend-plugin/src/main/resources-latest/META-INF/extensions.xml deleted file mode 100644 index d705f363926944..00000000000000 --- a/components/ide/jetbrains/backend-plugin/src/main/resources-latest/META-INF/extensions.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/components/ide/jetbrains/backend-plugin/src/main/resources-stable/META-INF/extensions.xml b/components/ide/jetbrains/backend-plugin/src/main/resources-stable/META-INF/extensions.xml deleted file mode 100644 index 5961b901e13e92..00000000000000 --- a/components/ide/jetbrains/backend-plugin/src/main/resources-stable/META-INF/extensions.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml b/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml index ca19490a92ab7b..96cf8c00b37a58 100644 --- a/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml +++ b/components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml @@ -3,9 +3,8 @@ Licensed under the GNU Affero General Public License (AGPL). See License-AGPL.txt in the project root for license information. --> - - + io.gitpod.jetbrains.remote Gitpod Remote Gitpod @@ -27,6 +26,7 @@ + diff --git a/components/ide/jetbrains/image/BUILD.yaml b/components/ide/jetbrains/image/BUILD.yaml index c6739793a193b8..709b6c22e729b5 100644 --- a/components/ide/jetbrains/image/BUILD.yaml +++ b/components/ide/jetbrains/image/BUILD.yaml @@ -18,7 +18,7 @@ packages: - "startup.sh" - "supervisor-ide-config_intellij.json" deps: - - components/ide/jetbrains/backend-plugin:plugin-stable + - components/ide/jetbrains/backend-plugin:plugin - components/ide/jetbrains/image/status:app - components/ide/jetbrains/cli:app argdeps: @@ -40,7 +40,7 @@ packages: - "startup.sh" - "supervisor-ide-config_intellij.json" deps: - - components/ide/jetbrains/backend-plugin:plugin-latest + - components/ide/jetbrains/backend-plugin:plugin - components/ide/jetbrains/image/status:app - components/ide/jetbrains/cli:app argdeps: @@ -62,7 +62,7 @@ packages: - "startup.sh" - "supervisor-ide-config_goland.json" deps: - - components/ide/jetbrains/backend-plugin:plugin-stable + - components/ide/jetbrains/backend-plugin:plugin - components/ide/jetbrains/image/status:app - components/ide/jetbrains/cli:app argdeps: @@ -84,7 +84,7 @@ packages: - "startup.sh" - "supervisor-ide-config_goland.json" deps: - - components/ide/jetbrains/backend-plugin:plugin-latest + - components/ide/jetbrains/backend-plugin:plugin - components/ide/jetbrains/image/status:app - components/ide/jetbrains/cli:app argdeps: @@ -106,7 +106,7 @@ packages: - "startup.sh" - "supervisor-ide-config_pycharm.json" deps: - - components/ide/jetbrains/backend-plugin:plugin-stable + - components/ide/jetbrains/backend-plugin:plugin - components/ide/jetbrains/image/status:app - components/ide/jetbrains/cli:app argdeps: @@ -128,7 +128,7 @@ packages: - "startup.sh" - "supervisor-ide-config_pycharm.json" deps: - - components/ide/jetbrains/backend-plugin:plugin-latest + - components/ide/jetbrains/backend-plugin:plugin - components/ide/jetbrains/image/status:app - components/ide/jetbrains/cli:app argdeps: @@ -150,7 +150,7 @@ packages: - "startup.sh" - "supervisor-ide-config_phpstorm.json" deps: - - components/ide/jetbrains/backend-plugin:plugin-stable + - components/ide/jetbrains/backend-plugin:plugin - components/ide/jetbrains/image/status:app - components/ide/jetbrains/cli:app argdeps: @@ -172,7 +172,7 @@ packages: - "startup.sh" - "supervisor-ide-config_phpstorm.json" deps: - - components/ide/jetbrains/backend-plugin:plugin-latest + - components/ide/jetbrains/backend-plugin:plugin - components/ide/jetbrains/image/status:app - components/ide/jetbrains/cli:app argdeps: diff --git a/components/ide/jetbrains/image/leeway.Dockerfile b/components/ide/jetbrains/image/leeway.Dockerfile index 0991507d60cda0..78fb8d6b9c9a27 100644 --- a/components/ide/jetbrains/image/leeway.Dockerfile +++ b/components/ide/jetbrains/image/leeway.Dockerfile @@ -4,11 +4,10 @@ FROM alpine:3.16 as download ARG JETBRAINS_BACKEND_URL -ARG JETBRAINS_BACKEND_QUALIFIER WORKDIR /workdir RUN apk add --no-cache --upgrade curl gzip tar unzip RUN curl -sSLo backend.tar.gz "$JETBRAINS_BACKEND_URL" && tar -xf backend.tar.gz --strip-components=1 && rm backend.tar.gz -COPY --chown=33333:33333 components-ide-jetbrains-backend-plugin--plugin-${JETBRAINS_BACKEND_QUALIFIER}/build/distributions/gitpod-remote-0.0.1.zip /workdir +COPY --chown=33333:33333 components-ide-jetbrains-backend-plugin--plugin/build/distributions/gitpod-remote-0.0.1.zip /workdir RUN unzip gitpod-remote-0.0.1.zip -d plugins/ && rm gitpod-remote-0.0.1.zip # enable shared indexes by default RUN printf '\nshared.indexes.download.auto.consent=true' >> "/workdir/bin/idea.properties"