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

Bump org.jetbrains.intellij from 1.17.2 to 1.17.3 #5

Closed
Closed
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
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<!-- Keep a Changelog guide -> https://keepachangelog.com -->

# jetbrains-backend-coder Changelog
# coder-gateway-backend changelog

## [Unreleased]
### Added
- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template)
41 changes: 7 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,17 @@
# jetbrains-backend-coder
# coder-gateway-backend

![Build](https://github.com/code-asher/jetbrains-backend-coder/workflows/Build/badge.svg)
[![Version](https://img.shields.io/jetbrains/plugin/v/PLUGIN_ID.svg)](https://plugins.jetbrains.com/plugin/PLUGIN_ID)
[![Downloads](https://img.shields.io/jetbrains/plugin/d/PLUGIN_ID.svg)](https://plugins.jetbrains.com/plugin/PLUGIN_ID)

## Template ToDo list
- [x] Create a new [IntelliJ Platform Plugin Template][template] project.
- [ ] Get familiar with the [template documentation][template].
- [ ] Adjust the [pluginGroup](./gradle.properties), [plugin ID](./src/main/resources/META-INF/plugin.xml) and [sources package](./src/main/kotlin).
- [ ] Adjust the plugin description in `README` (see [Tips][docs:plugin-description])
- [ ] Review the [Legal Agreements](https://plugins.jetbrains.com/docs/marketplace/legal-agreements.html?from=IJPluginTemplate).
- [ ] [Publish a plugin manually](https://plugins.jetbrains.com/docs/intellij/publishing-plugin.html?from=IJPluginTemplate) for the first time.
- [ ] Set the `PLUGIN_ID` in the above README badges.
- [ ] Set the [Plugin Signing](https://plugins.jetbrains.com/docs/intellij/plugin-signing.html?from=IJPluginTemplate) related [secrets](https://github.com/JetBrains/intellij-platform-plugin-template#environment-variables).
- [ ] Set the [Deployment Token](https://plugins.jetbrains.com/docs/marketplace/plugin-upload.html?from=IJPluginTemplate).
- [ ] Click the <kbd>Watch</kbd> button on the top of the [IntelliJ Platform Plugin Template][template] to be notified about releases containing new features and fixes.
![Build](https://github.com/coder/jetbrains-backend-coder/workflows/Build/badge.svg)
[![Version](https://img.shields.io/jetbrains/plugin/v/coder-gateway-backend.svg)](https://plugins.jetbrains.com/plugin/coder-gateway-backend)
[![Downloads](https://img.shields.io/jetbrains/plugin/d/coder-gateway-backend.svg)](https://plugins.jetbrains.com/plugin/coder-gateway-backend)

<!-- Plugin description -->
This Fancy IntelliJ Platform Plugin is going to be your implementation of the brilliant ideas that you have.

This specific section is a source for the [plugin.xml](/src/main/resources/META-INF/plugin.xml) file which will be extracted by the [Gradle](/build.gradle.kts) during the build process.

To keep everything working, do not remove `<!-- ... -->` sections.
This plugin is meant to be installed on a remote machine and used as a companion
to using Coder through Gateway.
<!-- Plugin description end -->

## Installation

- Using the IDE built-in plugin system:

<kbd>Settings/Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>Marketplace</kbd> > <kbd>Search for "jetbrains-backend-coder"</kbd> >
<kbd>Install</kbd>

- Manually:

Download the [latest release](https://github.com/code-asher/jetbrains-backend-coder/releases/latest) and install it manually using
Download the [latest release](https://github.com/coder/jetbrains-backend-coder/releases/latest) and install it manually using
<kbd>Settings/Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>⚙️</kbd> > <kbd>Install plugin from disk...</kbd>


---
Plugin based on the [IntelliJ Platform Plugin Template][template].

[template]: https://github.com/JetBrains/intellij-platform-plugin-template
[docs:plugin-description]: https://plugins.jetbrains.com/docs/intellij/plugin-user-experience.html#plugin-description-and-presentation
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html

pluginGroup = com.github.codeasher.jetbrainsbackendcoder
pluginName = jetbrains-backend-coder
pluginRepositoryUrl = https://github.com/code-asher/jetbrains-backend-coder
pluginGroup = com.coder.jetbrains
pluginName = coder-gateway-backend
pluginRepositoryUrl = https://github.com/coder/jetbrains-backend-coder
# SemVer format -> https://semver.org
pluginVersion = 0.0.1

Expand All @@ -16,7 +16,7 @@ platformVersion = 2022.3.3

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins =
platformPlugins=com.jetbrains.codeWithMe, org.jetbrains.plugins.terminal

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.6
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ annotations = "24.1.0"
# plugins
kotlin = "1.9.23"
changelog = "2.2.0"
gradleIntelliJPlugin = "1.17.2"
gradleIntelliJPlugin = "1.17.3"
qodana = "2023.3.1"
kover = "0.7.6"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.github.codeasher.jetbrainsbackendcoder
package com.coder.jetbrains

import com.intellij.DynamicBundle
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey

@NonNls
private const val BUNDLE = "messages.MyBundle"
private const val BUNDLE = "messages.CoderBundle"

object MyBundle : DynamicBundle(BUNDLE) {
object CoderBundle : DynamicBundle(BUNDLE) {

Check warning on line 10 in src/main/kotlin/com/coder/jetbrains/CoderBundle.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Object "CoderBundle" is never used

@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =

Check warning on line 13 in src/main/kotlin/com/coder/jetbrains/CoderBundle.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "message" is never used
getMessage(key, *params)

@Suppress("unused")
Expand Down
74 changes: 74 additions & 0 deletions src/main/kotlin/com/coder/jetbrains/scanner/PortScanner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.coder.jetbrains.scanner

import java.io.File

private val sources = listOf(
"/proc/net/tcp",
"/proc/net/tcp6"
)

private val whitespaceRe = "\\s+".toRegex()

/**
* Parse a TCP socket /proc interface.
*/
fun readTcpFile(file: File): Set<Int> {
/*
* A typical entry of /proc/net/tcp would look like this (only the first
* four parts since that is all we use):
*
* 46: 010310AC:9C4C 030310AC:1770 01
* | | | | | |--> connection state
* | | | | |------> remote TCP port number
* | | | |-------------> remote IPv4 address
* | | |--------------------> local TCP port number
* | |---------------------------> local IPv4 address
* |----------------------------------> number of entry
*
* connection states:
* TCP_ESTABLISHED,
* TCP_SYN_SENT,
* TCP_SYN_RECV,
* TCP_FIN_WAIT1,
* TCP_FIN_WAIT2,
* TCP_TIME_WAIT,
* TCP_CLOSE,
* TCP_CLOSE_WAIT,
* TCP_LAST_ACK,
* TCP_LISTEN,
* TCP_CLOSING,
* TCP_NEW_SYN_RECV,
*/
return try {
file.readLines()
.asSequence()
// Fields are separated by spaces.
.map { it.trim().split(whitespaceRe) }
// Only TCP_LISTEN.
.filter { it.size >= 4 && it[3] == "0A" }
// Local address.
.map { it[1].split(":") }
.filter { it.size == 2 }
// Decode port from hex.
.map { it[1].toIntOrNull(16) }
.filterNotNull()
.toSet()
} catch (ex: Exception) {
// TODO: Log this exception?
emptySet()
}
}

/**
* Return a list of ports with listening TCP sockets. It does not differentiate
* between ipv4 and ipv6, and it does not return addresses since the forwarding
* API does not appear to let us give it an address anyway.
*
* It only supports Linux, as that is the only place remote IDEs can run anyway.
*/
fun listeningPorts(): Set<Int> {
// REVIEW: We could instead query /workspaceagents/me/listening-ports (after
// adding it to coderd) which would let us share the port scanning code with
// the agent?
return sources.flatMap { readTcpFile(File(it)) }.toSet()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.coder.jetbrains.services

import com.coder.jetbrains.scanner.listeningPorts
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.util.application
import com.jetbrains.rd.platform.codeWithMe.portForwarding.ClientPortAttributes
import com.jetbrains.rd.platform.codeWithMe.portForwarding.ClientPortPickingStrategy
import com.jetbrains.rd.platform.codeWithMe.portForwarding.PerClientPortForwardingManager
import com.jetbrains.rd.platform.codeWithMe.portForwarding.PortAlreadyForwardedException
import com.jetbrains.rd.platform.codeWithMe.portForwarding.PortType
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch

/**
* Automatically forward ports that have something listening on them by scanning
* /proc/net/ipv{,6} at a regular interval.
*
* If a process stops listening the port forward is removed.
*
* If the user manually removes a port, it will be added back at the next
* interval.
*/
@Suppress("UnstableApiUsage")
class CoderPortForwardService(
private val cs: CoroutineScope,
): Disposable {
private var poller: Job? = null

// TODO: Make customizable.
private val ignoreList = setOf(
22, // SSH
5990, // Default JetBrains remote port.
)

init {
thisLogger().info("initializing port forwarding service")
application.invokeLater {
start()
}
}

override fun dispose() {
poller?.cancel()
}

private fun start() {
thisLogger().info("starting port scanner")
poller = cs.launch {
while (isActive) {
thisLogger().debug("scanning for ports")
val listeningPorts = listeningPorts().subtract(ignoreList)
val manager = service<PerClientPortForwardingManager>()
val ports = manager.getPorts()
// Remove ports that are no longer listening.
// TODO: Only remove ones we added?
ports.forEach { old ->
if (!listeningPorts.contains(old.hostPortNumber)) {
try {
thisLogger().info("removing port ${old.hostPortNumber}")
manager.removePort(old)
} catch (ex: Exception) {
thisLogger().error("failed to remove port $old", ex)
}
}
}
// Add ports that are not yet listening.
// TODO: Avoid adding if the user removed it previously?
listeningPorts.forEach {
try {
thisLogger().info("forwarding port $it")
forwardPort(it)
} catch (ex: PortAlreadyForwardedException) {
// All good.
} catch (ex: Exception) {
thisLogger().error("failed to forward port $it", ex)
}
}
// TODO: Customizable interval.
delay(5000)
}
}
}

/**
* Add a port forward to the provided port on the host.
*
* TODO: If privileged, use a different port.
*/
private fun forwardPort(port: Int) {
val manager = service<PerClientPortForwardingManager>()
manager.forwardPort(port, PortType.TCP, setOf("coder"), ClientPortAttributes(
preferredPortNumber = port,
strategy = ClientPortPickingStrategy.REASSIGN_WHEN_BUSY,
))
}
}

This file was deleted.

This file was deleted.

This file was deleted.

18 changes: 9 additions & 9 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<id>com.github.codeasher.jetbrainsbackendcoder</id>
<name>jetbrains-backend-coder</name>
<vendor>code-asher</vendor>
<id>com.coder.jetbrains</id>
<name>Coder Gateway Backend</name>
<vendor>coder</vendor>

<depends>com.intellij.modules.platform</depends>
<dependencies>
<plugin id="com.jetbrains.codeWithMe"/>
</dependencies>

<resource-bundle>messages.MyBundle</resource-bundle>
<resource-bundle>messages.CoderBundle</resource-bundle>

<extensions defaultExtensionNs="com.intellij">
<toolWindow factoryClass="com.github.codeasher.jetbrainsbackendcoder.toolWindow.MyToolWindowFactory" id="MyToolWindow"/>
<applicationService serviceImplementation="com.coder.jetbrains.services.CoderPortForwardService"
client="controller" preload="true"/>
</extensions>

<applicationListeners>
<listener class="com.github.codeasher.jetbrainsbackendcoder.listeners.MyApplicationActivationListener" topic="com.intellij.openapi.application.ApplicationActivationListener"/>
</applicationListeners>
</idea-plugin>
Loading
Loading