Skip to content

Commit

Permalink
Add support for JetBrains EAP IDEs (2022.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
felladrin committed Sep 28, 2022
1 parent ac6c5a3 commit d485e9c
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 24 deletions.
8 changes: 4 additions & 4 deletions components/ide/jetbrains/backend-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ detekt {

tasks {
withType<JavaCompile> {
sourceCompatibility = "11"
targetCompatibility = "11"
sourceCompatibility = "17"
targetCompatibility = "17"
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
kotlinOptions.jvmTarget = "17"
}

withType<Detekt> {
jvmTarget = "11"
jvmTarget = "17"
}

buildSearchableOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild=222
pluginUntilBuild=222.*
pluginSinceBuild=223
pluginUntilBuild=223.*
# 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
pluginVerifierIdeVersions=2022.3
# Version from "com.jetbrains.intellij.idea" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
platformVersion=222.4167-EAP-CANDIDATE-SNAPSHOT
platformVersion=223.4884-EAP-CANDIDATE-SNAPSHOT
26 changes: 22 additions & 4 deletions components/ide/jetbrains/backend-plugin/launch-dev-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,36 @@
set -e
set -o pipefail

JB_QUALIFIER="latest"
while getopts "s" OPTION
do
case $OPTION in
s) JB_QUALIFIER="stable" ;;
*) ;;
esac
done

TEST_BACKEND_DIR=/workspace/ide-backend
if [ ! -d "$TEST_BACKEND_DIR" ]; then
mkdir -p $TEST_BACKEND_DIR
cp -r /ide-desktop/backend/* $TEST_BACKEND_DIR
if [[ $JB_QUALIFIER == "stable" ]]; then
PRODUCT_TYPE="release"
else
PRODUCT_TYPE="release,rc,eap"
fi
(cd $TEST_BACKEND_DIR &&
echo "Downloading the ${JB_QUALIFIER} version of IntelliJ IDEA..." &&
curl -sSLo backend.tar.gz "https://download.jetbrains.com/product?type=${PRODUCT_TYPE}&distribution=linux&code=IIU" &&
tar -xf backend.tar.gz --strip-components=1 &&
rm backend.tar.gz)
fi

TEST_PLUGINS_DIR="$TEST_BACKEND_DIR/plugins"
TEST_PLUGIN_DIR="$TEST_PLUGINS_DIR/gitpod-remote"
rm -rf $TEST_PLUGIN_DIR

GITPOD_PLUGIN_DIR=/workspace/gitpod/components/ide/jetbrains/backend-plugin
$GITPOD_PLUGIN_DIR/gradlew buildPlugin
$GITPOD_PLUGIN_DIR/gradlew -PenvironmentName="$JB_QUALIFIER" buildPlugin

# TODO(ak) actually should be gradle task to make use of output
GITPOD_PLUGIN_DIST="$GITPOD_PLUGIN_DIR/build/distributions/gitpod-remote.zip"
Expand All @@ -31,7 +49,7 @@ if [ ! -d "$TEST_DIR" ]; then
case $OPTION in
r) TEST_REPO=$OPTARG ;;
*) ;;
esac
esac
done
git clone "$TEST_REPO" $TEST_DIR
fi
Expand All @@ -47,7 +65,7 @@ export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains
export CWM_HOST_STATUS_OVER_HTTP_TOKEN=gitpod

# Build and move idea-cli, then overwrite environment variables initially defined by `components/ide/jetbrains/image/leeway.Dockerfile`
IDEA_CLI_DEV_PATH=/ide-desktop/bin/idea-cli-dev
IDEA_CLI_DEV_PATH=$TEST_BACKEND_DIR/bin/idea-cli-dev
(cd ../cli && go build -o $IDEA_CLI_DEV_PATH)
export EDITOR="$IDEA_CLI_DEV_PATH open"
export VISUAL="$EDITOR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.http.FullHttpRequest
import io.netty.handler.codec.http.QueryStringDecoder
import io.prometheus.client.exporter.common.TextFormat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.jetbrains.ide.RestService
import org.jetbrains.io.response
import java.io.OutputStreamWriter
import java.nio.file.InvalidPathException
import java.nio.file.Path

@Suppress("UnstableApiUsage")
@Suppress("UnstableApiUsage", "OPT_IN_USAGE")
class GitpodCLIService : RestService() {

private val manager = service<GitpodManager>()
Expand Down Expand Up @@ -65,7 +69,11 @@ class GitpodCLIService : RestService() {
val file = parseFilePath(fileStr) ?: return "invalid file"
val shouldWait = getBooleanParameter("wait", urlDecoder)
return withClient(request, context) {
CommandLineProcessor.doOpenFileOrProject(file, shouldWait).future.get()
GlobalScope.launch {
withContext(Dispatchers.IO) {
CommandLineProcessor.doOpenFileOrProject(file, shouldWait).future.get()
}
}
}
}
if (operation == "preview") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package io.gitpod.jetbrains.remote

import com.intellij.codeWithMe.ClientId
import com.intellij.ide.BrowserUtil
import com.intellij.idea.StartupUtil
import com.intellij.notification.NotificationAction
import com.intellij.notification.NotificationType
import com.intellij.openapi.Disposable
Expand All @@ -29,7 +28,6 @@ import io.grpc.stub.ClientCallStreamObserver
import io.grpc.stub.ClientResponseObserver
import kotlinx.coroutines.*
import kotlinx.coroutines.future.await
import org.jetbrains.ide.BuiltInServerManager
import java.util.concurrent.CancellationException
import java.util.concurrent.CompletableFuture

Expand All @@ -44,6 +42,8 @@ class GitpodClientProjectSessionTracker(
private lateinit var info: Info.WorkspaceInfoResponse
private val lifetime = Lifetime.Eternal.createNested()

private val ignoredPortsForNotificationService = service<GitpodIgnoredPortsForNotificationService>()

override fun dispose() {
lifetime.terminate()
}
Expand Down Expand Up @@ -118,10 +118,6 @@ class GitpodClientProjectSessionTracker(
return@launch
}

// Ignore ports that aren't actually used by the user (e.g. ports used internally by JetBrains IDEs)
val backendPort = BuiltInServerManager.getInstance().waitForStart().port
val serverPort = StartupUtil.getServerFuture().await().port
val ignorePorts = listOf(backendPort, serverPort, 5990)
val portsStatus = hashMapOf<Int, PortsStatus>()

val status = StatusServiceGrpc.newStub(GitpodManager.supervisorChannel)
Expand All @@ -141,7 +137,7 @@ class GitpodClientProjectSessionTracker(
override fun onNext(ps: Status.PortsStatusResponse) {
for (port in ps.portsList) {
// Avoiding undesired notifications
if (ignorePorts.contains(port.localPort)) {
if (ignoredPortsForNotificationService.getIgnoredPorts().contains(port.localPort)) {
continue
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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

interface GitpodIgnoredPortsForNotificationService {
fun ignorePort(portNumber: Int)
/** Get ports that aren't actually used by the user (e.g. ports used internally by JetBrains IDEs) */
fun getIgnoredPorts(): Set<Int>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.idea.getServerFutureAsync
import io.gitpod.jetbrains.remote.GitpodIgnoredPortsForNotificationService
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.jetbrains.ide.BuiltInServerManager

@Suppress("OPT_IN_USAGE")
class GitpodIgnoredPortsForNotificationServiceImpl : GitpodIgnoredPortsForNotificationService {
private val ignoredPortsForNotification = mutableSetOf(5990)

init {
GlobalScope.launch {
BuiltInServerManager.getInstance().waitForStart().port.let { ignorePort(it) }
getServerFutureAsync().await()?.port?.let { ignorePort(it) }
}
}

override fun ignorePort(portNumber: Int) {
ignoredPortsForNotification.add(portNumber)
}

override fun getIgnoredPorts(): Set<Int> {
return ignoredPortsForNotification.toSet()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ class GitpodPortForwardingService(private val project: Project) {
for (port in response.portsList) {
val hostPort = port.localPort
val isServed = port.served
val isForwarded = forwardedPortsList.find { it.hostPort == hostPort } != null

if (isServed && !forwardedPortsList.containsKey(hostPort)) {
if (isServed && !isForwarded) {
val portEventsProcessor = object : PortEventsProcessor {
override fun onPortForwarded(hostPort: Int, clientPort: Int) {
portsService.setForwardedPort(hostPort, clientPort)
Expand All @@ -111,15 +112,18 @@ class GitpodPortForwardingService(private val project: Project) {
val portInfo = ForwardedPortInfo(
hostPort,
RdPortType.HTTP,
FORWARDED_PORT_LABEL,
port.exposed.url,
port.name,
port.description,
setOf(FORWARDED_PORT_LABEL),
emptyList(),
portEventsProcessor
)

portForwardingManager.forwardPort(portInfo)
}

if (!isServed && forwardedPortsList.containsKey(hostPort)) {
if (!isServed && isForwarded) {
portForwardingManager.removePort(hostPort)
portsService.removeForwardedPort(hostPort)
thisLogger().info("gitpod: Stopped forwarding port $hostPort.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.stable

import com.intellij.idea.StartupUtil
import io.gitpod.jetbrains.remote.GitpodIgnoredPortsForNotificationService
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.future.await
import org.jetbrains.ide.BuiltInServerManager

@Suppress("OPT_IN_USAGE")
class GitpodIgnoredPortsForNotificationServiceImpl : GitpodIgnoredPortsForNotificationService {
private val ignoredPortsForNotification = mutableSetOf(5990)

init {
GlobalScope.launch {
BuiltInServerManager.getInstance().waitForStart().port.let { ignorePort(it) }
StartupUtil.getServerFuture().await().port?.let { ignorePort(it) }
}
}

override fun ignorePort(portNumber: Int) {
ignoredPortsForNotification.add(portNumber)
}

override fun getIgnoredPorts(): Set<Int> {
return ignoredPortsForNotification.toSet()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
Licensed under the GNU Affero General Public License (AGPL).
See License-AGPL.txt in the project root for license information.
-->
<!--suppress PluginXmlValidity -->
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceInterface="io.gitpod.jetbrains.remote.GitpodIgnoredPortsForNotificationService" serviceImplementation="io.gitpod.jetbrains.remote.latest.GitpodIgnoredPortsForNotificationServiceImpl" preload="true"/>
<projectService serviceImplementation="io.gitpod.jetbrains.remote.latest.GitpodPortForwardingService" preload="true"/>
</extensions>
</idea-plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Licensed under the GNU Affero General Public License (AGPL).
See License-AGPL.txt in the project root for license information.
-->
<!--suppress PluginXmlValidity -->
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceInterface="io.gitpod.jetbrains.remote.GitpodIgnoredPortsForNotificationService" serviceImplementation="io.gitpod.jetbrains.remote.stable.GitpodIgnoredPortsForNotificationServiceImpl" preload="true"/>
</extensions>
</idea-plugin>

0 comments on commit d485e9c

Please sign in to comment.