Skip to content

Commit

Permalink
Move debug mode configurations to reference.conf (#314)
Browse files Browse the repository at this point in the history
* Move debug mode configurations to reference.conf

* PR fixes - rename vmOption to vmOptions and add tests
  • Loading branch information
LukaszKontowski authored Nov 2, 2022
1 parent 5dfee1d commit 91a1654
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ IntelliJFixture(workspaceProvider = WorkspaceTemplate.fromFile(path))
2. [Resolvers](docs/custom-resolvers.md)
3. [Workspace](docs/workspace.md)
4. [Display](docs/display.md)
5. [Debugging](docs/debug.md)
5. [Debugging](core/driver/sources/src/main/resources/reference.conf) (search for `probe.driver.debug` config)

## Workflow
Workflow can only be defined programmatically, since it comprises a sequence of intertwined:
Expand Down
25 changes: 25 additions & 0 deletions core/driver/sources/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,31 @@ probe {
// `env` is a Map with string keys and string values (Map[String, String]), so you can add entries like this:
// { "MY_ENV_VARIABLE" : "some important value" }
env = {}

// `driver.debug` is for the usage of the Java Debugger. If enabled, it adds the `-agentlib:jdwp` JVM option
// which attaches a remote debugger to the JVM. JVM debug mode is disabled by default. If `enabled = true`
// then the following option is used by default:
// -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
// You can choose another `driver.debug.port` value. It affects the "address=" part of the option which specifies
// the port, on which you can connect.
// By default, the IDE JVM will not wait for you to connect. If you want to change this behavior and tell the JVM
// to wait until debugger is attached to begin execution, set `driver.debug.suspend` to `true`. Then mentioned
// `-agentlib:jdwp=...` option will be changed so that it uses "suspend=y" option.
// You can read more about the Java debugger usage here: https://www.ibm.com/docs/en/sdk-java-technology/8?topic=applications-debugging-java
//
// All three values can be set directly in the .conf file OR by setting following environment variables, which do
// override the default values:
// IDEPROBE_DEBUG - for `driver.debug.enabled`
// IDEPROBE_DEBUG_PORT - for `driver.debug.port`
// IDEPROBE_DEBUG_SUSPEND - for `driver.debug.suspend`
debug {
enabled = false
enabled = ${?IDEPROBE_DEBUG}
port = 5005
port = ${?IDEPROBE_DEBUG_PORT}
suspend = false
suspend = ${?IDEPROBE_DEBUG_SUSPEND}
}
}

// `paths` is for `org.virtuslab.ideprobe.config.PathsConfig` - default values below
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.virtuslab.ideprobe.config

import scala.concurrent.duration._

import org.virtuslab.ideprobe.config.DriverConfig.DebugConfig
import org.virtuslab.ideprobe.config.DriverConfig.LaunchParameters
import org.virtuslab.ideprobe.config.DriverConfig.XvfbConfig

Expand All @@ -12,7 +13,8 @@ case class DriverConfig(
xvfb: XvfbConfig,
headless: Boolean,
vmOptions: Seq[String],
env: Map[String, String]
env: Map[String, String],
debug: DebugConfig
)

object DriverConfig {
Expand All @@ -26,4 +28,10 @@ object DriverConfig {
height: Int,
depth: Int
)

case class DebugConfig(
enabled: Boolean,
port: Int,
suspend: Boolean
)
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package org.virtuslab.ideprobe.ide.intellij

object DebugMode {
private val enabled: Boolean = env("IDEPROBE_DEBUG", "false").toBoolean
private val suspend: Boolean = env("IDEPROBE_DEBUG_SUSPEND", "false").toBoolean
private val port: Int = env("IDEPROBE_DEBUG_PORT", "5005").toInt
import org.virtuslab.ideprobe.config.DriverConfig.DebugConfig

def vmOption: Seq[String] = {
if (enabled) {
val suspendOpt = if (suspend) "suspend=y" else "suspend=n"
val addressOpt = s"address=$port"
object DebugMode {
def vmOptions(debugMode: DebugConfig): Seq[String] = {
if (debugMode.enabled) {
val suspendOpt = if (debugMode.suspend) "suspend=y" else "suspend=n"
val addressOpt = s"address=${debugMode.port}"
s"-agentlib:jdwp=transport=dt_socket,server=y,$suspendOpt,$addressOpt" :: Nil
} else {
Nil
}
}

private def env(name: String, default: String) = System.getenv.getOrDefault(name, default)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ sealed abstract class InstalledIntelliJ(root: Path, probePaths: IdeProbePaths, c
"-Djb.consents.confirmation.enabled=false"
)

val vmOptions = implementationSpecificVmOptions ++ baseVMOptions ++ DebugMode.vmOption ++ config.vmOptions
val vmOptions =
implementationSpecificVmOptions ++ baseVMOptions ++ DebugMode.vmOptions(config.debug) ++ config.vmOptions
val content = vmOptions.mkString("\n")

root.resolve("bin").resolve("ideprobe.vmoptions").write(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class IdeProbeConfigTest extends IdeProbeFixture {
assertEquals(false, probeConfig.driver.headless)
assertEquals(Seq.empty, probeConfig.driver.vmOptions)
assertEquals(Map.empty, probeConfig.driver.env)
assertEquals(false, probeConfig.driver.debug.enabled)
assertEquals(5005, probeConfig.driver.debug.port)
assertEquals(false, probeConfig.driver.debug.suspend)
// tests for the paths: PathsConfig field
assertEquals(None, probeConfig.paths.base)
assertEquals(None, probeConfig.paths.instances)
Expand Down Expand Up @@ -117,6 +120,9 @@ class IdeProbeConfigTest extends IdeProbeFixture {
assertEquals(true, probeConfig.driver.headless)
assertEquals(Seq.empty, probeConfig.driver.vmOptions)
assertEquals(Map.empty, probeConfig.driver.env)
assertEquals(false, probeConfig.driver.debug.enabled)
assertEquals(5005, probeConfig.driver.debug.port)
assertEquals(false, probeConfig.driver.debug.suspend)
// tests for the paths: PathsConfig field
assertEquals(None, probeConfig.paths.base)
assertEquals(None, probeConfig.paths.instances)
Expand Down
8 changes: 0 additions & 8 deletions docs/debug.md

This file was deleted.

0 comments on commit 91a1654

Please sign in to comment.