From ab994b52fe18a91d994314195906cc10c7966704 Mon Sep 17 00:00:00 2001 From: LukaszKontowski <49597713+LukaszKontowski@users.noreply.github.com> Date: Thu, 25 Aug 2022 12:00:55 +0200 Subject: [PATCH] Replace default values in code with .conf file (#252) * Moved default configurations to reference.conf * provide a comment to the probe.intellij.version config * PR fixes - fixed reference.conf comments --- .../scala/org/virtuslab/ideprobe/Config.scala | 8 +- .../sources/src/main/resources/reference.conf | 129 ++++++++++++++++++ .../virtuslab/ideprobe/IdeProbePaths.scala | 3 +- .../virtuslab/ideprobe/IntelliJFixture.scala | 4 +- .../ideprobe/config/CheckConfig.scala | 12 +- .../ideprobe/config/DependenciesConfig.scala | 8 +- .../ideprobe/config/DriverConfig.scala | 24 ++-- .../ideprobe/config/IdeProbeConfig.scala | 10 +- .../ideprobe/config/IntellijConfig.scala | 7 +- .../ideprobe/config/PathsConfig.scala | 12 +- .../dependencies/IntelliJVersion.scala | 3 +- .../dependencies/PluginResolver.scala | 3 +- .../ide/intellij/IntelliJProvider.scala | 23 +++- .../sources/src/test/resources/empty.conf | 0 .../dependencies/IdeProbeConfigTest.scala | 112 +++++++++++++++ .../dependencies/IntelliJProviderTest.scala | 8 +- 16 files changed, 312 insertions(+), 54 deletions(-) create mode 100644 core/driver/sources/src/main/resources/reference.conf create mode 100644 core/driver/sources/src/test/resources/empty.conf create mode 100644 core/driver/sources/src/test/scala/org/virtuslab/ideprobe/dependencies/IdeProbeConfigTest.scala diff --git a/core/api/src/main/scala/org/virtuslab/ideprobe/Config.scala b/core/api/src/main/scala/org/virtuslab/ideprobe/Config.scala index 2178a472..dcf39763 100644 --- a/core/api/src/main/scala/org/virtuslab/ideprobe/Config.scala +++ b/core/api/src/main/scala/org/virtuslab/ideprobe/Config.scala @@ -52,17 +52,17 @@ final case class Config(source: ConfigObjectSource, fallback: Option[Config] = N object Config { val Empty = new Config(ConfigSource.empty) - def fromString(str: String) = new Config(ConfigSource.string(str)) + def fromString(str: String) = new Config(ConfigSource.default(ConfigSource.string(str))) def fromFile(path: Path): Config = { - new Config(ConfigSource.file(path)) + new Config(ConfigSource.default(ConfigSource.file(path))) } def fromClasspath(resourcePath: String): Config = { - new Config(ConfigSource.resources(resourcePath)) + new Config(ConfigSource.default(ConfigSource.resources(resourcePath))) } def fromMap(properties: Map[String, String]): Config = { - new Config(ConfigSource.fromConfig(ConfigFactory.parseMap(properties.asJava))) + new Config(ConfigSource.default(ConfigSource.fromConfig(ConfigFactory.parseMap(properties.asJava)))) } } diff --git a/core/driver/sources/src/main/resources/reference.conf b/core/driver/sources/src/main/resources/reference.conf new file mode 100644 index 00000000..dff4c866 --- /dev/null +++ b/core/driver/sources/src/main/resources/reference.conf @@ -0,0 +1,129 @@ +// Default configuration for the org.virtuslab.ideprobe.config.IdeProbeConfig +// Comments starting with the # sign are for non-default configs which can be used by users. +// Comments starting with the // signs are for descriptions and guides. +probe { + + // `intellij` is for org.virtuslab.ideprobe.config.IntellijConfig - default values below: + intellij { + plugins = [] + version { + // `release` is the "Version" and connected `build` is the "Build Number" of IntelliJ IDEA version. Both should + // be provided and they should match. You can search for proper string pairs here: + // https://www.jetbrains.com/intellij-repository/releases/ under "com.jetbrains.intellij.idea" heading. + // If you want to change the default intellij version, provide both parameters in your .conf file. + build = "212.5080.55" + release = "2021.2.1" + } + // Use below config with proper path if you want to use an existing Intellij instead of downloading a version. + // Example path from IntelliJ installed on macOs: + # path = "/Applications/IntelliJ IDEA CE.app/Contents" + } + + // `workspace` is for `Option[org.virtuslab.ideprobe.config.WorkspaceConfig]` - default None, + // hence comments added as a reference. You can specify the workspace by using the below configurations. + # workspace { + // First option is to use a Default workspace - by just specifying `probe.workspace.path` with a valid string. + // + // `probe.workspace.path` can point to: + // a) a directory on the filesystem: + // `probe.workspace.path = "file://home/foo/bar"` + // b) a directory within a jar: + // `probe.workspace.path = "jar:file://foo.jar!/bar/baz"` + // c) a directory on the classpath: + // `probe.workspace.path = "classpath:/foo/bar"` + // d) an online resource (http/https) - which can be for example a github repository as below: + // + # path = "https://github.com/VirtusLab/git-machete.git" + // + // If `probe.workspace.path` is set and points to a git repository - you can choose one of three additional options: + // `branch`, `tag` or `commit` - to specify the reference which should be checked out on the workspace setup. + // Only one of them can be specified. You can as well not use any of these 3 options - in such scenario the default + // branch will be checked out just like with a plain `git clone` command. Examples below: + # branch = "develop" + # tag = "v0.41.0" + # commit = "a1861fc3b70588acfa171000eb365bf75c143472" + // + // Another option is to use an Existing workspace by passing a proper path to its directory + // - use only `existing` config. In this case, `probe.workspace.path` MUST NOT be defined. + // `probe.workspace.existing` can be used for scenarios where you want to reuse an existing workspace instead of + // copying a workspace each time when tests run. It might be beneficial for big projects / repos. + # existing = "/Users/my_username/code/my_repository" + # } + + // `resolvers` is for `org.virtuslab.ideprobe.config.DependenciesConfig.Resolvers` - default values below + resolvers { + intellij { + repositories = [] + } + // default configuration for `plugins` is Plugins(None) - adding possible parameters in comments for reference + plugins { + // `repository.uri` is the URI of the plugin repository - use this config if you want to use a non-standard + // plugin repository. The standard one used by ide-probe is: https://plugins.jetbrains.com/plugin/download + # repository.uri = "" + } + jbr { + repositories = [] + } + retries = 0 + } + + // `driver` is for `org.virtuslab.ideprobe.config.DriverConfig` - default values below + driver { + launch { + command = [] + timeout = "30.seconds" + } + check { + errors { + enabled = false + includeMessages = [".*"] + excludeMessages = [] + } + freezes { + enabled = false + } + } + xvfb { + screen { + width = 1920 + height = 1080 + depth = 24 + } + } + headless = false + vmOptions = [] + env = {} + } + + // `paths` is for `org.virtuslab.ideprobe.config.PathsConfig` - default values below + paths { + // all parameters below are Options and are None by default - hence commented out + // + // `base` is the base directory used by ide-probe. All files and directories used by ide-probe in runtime + // should be under the `base` directory. By default, it gets resolved by java methods as follows: + // Paths.get(System.getProperty("java.io.tmpdir")).resolve("ide-probe"). + // You can specify a custom directory by using this config. + # base = "/tmp/ide-probe-tests" + // + // `instances` is a directory, where IntelliJ instances are installed in runtime. By default, instances + // directory is a direct subdirectory of the base dir: `base/instances`. + # instances = "/tmp/ide-probe-tests/instances" + // + // `workspaces` is a directory, where workspaces (testing repositories) are copied into in runtime. + // By default, workspaces directory is a direct subdirectory of the base dir: `base/workspaces`. + # workspaces = "/tmp/ide-probe-tests/workspaces" + // + // `screenshots` is a directory, where screenshots made by ide-probe are saved. + // By default, screenshots directory is a direct subdirectory of the base dir: `base/screenshots`. + # screenshots = "/tmp/ide-probe-tests/screenshots" + // + // `cache` is a directory, where IntelliJ instances, plugins and JBR binaries are unpacked and saved into (for + // later installation and usage). By default, cache directory is a direct subdirectory of the base dir: `base/cache`. + # cache = "/tmp/ide-probe-tests/cache" + // + // `trusted` is a directory passed to IntelliJ as a "trusted" directory. It means that IntelliJ instance will + // treat all projects/repositories under the `trusted` directory as "safe" and will run the code without alerts. + // By default, `trusted` is resolved as the root directory: "/". + # trusted = "/" + } +} diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/IdeProbePaths.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/IdeProbePaths.scala index c3259242..879a8fb4 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/IdeProbePaths.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/IdeProbePaths.scala @@ -16,7 +16,8 @@ case class IdeProbePaths( object IdeProbePaths { val Default: IdeProbePaths = { - from(PathsConfig()) + // TODO: replace None parameters with loading defaults from reference.conf + from(PathsConfig(None, None, None, None, None, None)) } def from(config: PathsConfig): IdeProbePaths = { diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/IntelliJFixture.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/IntelliJFixture.scala index ad305a68..36890b01 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/IntelliJFixture.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/IntelliJFixture.scala @@ -131,7 +131,7 @@ object IntelliJFixture { private val ConfigRoot = "probe" def fromConfig(config: Config, path: String = ConfigRoot)(implicit ec: ExecutionContext): IntelliJFixture = { - val probeConfig = config[IdeProbeConfig](path) + val probeConfig = readIdeProbeConfig(config, path) new IntelliJFixture( workspaceProvider = probeConfig.workspace.map(WorkspaceProvider.from).getOrElse(WorkspaceTemplate.Empty), @@ -140,4 +140,6 @@ object IntelliJFixture { config = config ) } + + def readIdeProbeConfig(config: Config, path: String): IdeProbeConfig = config[IdeProbeConfig](path) } diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/CheckConfig.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/CheckConfig.scala index fbb7b2df..7d95adb3 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/CheckConfig.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/CheckConfig.scala @@ -3,17 +3,15 @@ package org.virtuslab.ideprobe.config import org.virtuslab.ideprobe.config.CheckConfig.ErrorConfig import org.virtuslab.ideprobe.config.CheckConfig.FreezeConfig -final case class CheckConfig(errors: ErrorConfig = ErrorConfig(), freezes: FreezeConfig = FreezeConfig()) +final case class CheckConfig(errors: ErrorConfig, freezes: FreezeConfig) object CheckConfig { - val Disabled: CheckConfig = CheckConfig() - case class ErrorConfig( - enabled: Boolean = false, - includeMessages: Seq[String] = Seq(".*"), - excludeMessages: Seq[String] = Nil + enabled: Boolean, + includeMessages: Seq[String], + excludeMessages: Seq[String] ) case class FreezeConfig( - enabled: Boolean = false + enabled: Boolean ) } diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/DependenciesConfig.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/DependenciesConfig.scala index cafd924a..0f79b5f1 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/DependenciesConfig.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/DependenciesConfig.scala @@ -2,10 +2,10 @@ package org.virtuslab.ideprobe.config object DependenciesConfig { case class Resolvers( - intellij: IntelliJ = IntelliJ(Seq.empty), - plugins: Plugins = Plugins(None), - jbr: Jbr = Jbr(Seq.empty), - retries: Int = 0 + intellij: IntelliJ, + plugins: Plugins, + jbr: Jbr, + retries: Int ) case class IntelliJ(repositories: Seq[String]) diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/DriverConfig.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/DriverConfig.scala index 1ecb1127..743b57e5 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/DriverConfig.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/DriverConfig.scala @@ -6,23 +6,23 @@ import org.virtuslab.ideprobe.config.DriverConfig.LaunchParameters import org.virtuslab.ideprobe.config.DriverConfig.XvfbConfig case class DriverConfig( - launch: LaunchParameters = LaunchParameters(), - check: CheckConfig = CheckConfig(), - xvfb: XvfbConfig = XvfbConfig(), - headless: Boolean = false, - vmOptions: Seq[String] = Nil, - env: Map[String, String] = Map.empty + launch: LaunchParameters, + check: CheckConfig, + xvfb: XvfbConfig, + headless: Boolean, + vmOptions: Seq[String], + env: Map[String, String] ) object DriverConfig { case class LaunchParameters( - command: Seq[String] = Nil, - timeout: FiniteDuration = 30.seconds + command: Seq[String], + timeout: FiniteDuration ) - case class XvfbConfig(screen: ScreenConfig = ScreenConfig()) + case class XvfbConfig(screen: ScreenConfig) case class ScreenConfig( - width: Int = 1920, - height: Int = 1080, - depth: Int = 24 + width: Int, + height: Int, + depth: Int ) } diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/IdeProbeConfig.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/IdeProbeConfig.scala index 72137ca3..d189495a 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/IdeProbeConfig.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/IdeProbeConfig.scala @@ -6,11 +6,11 @@ import pureconfig.generic.auto._ import org.virtuslab.ideprobe.ConfigFormat case class IdeProbeConfig( - intellij: IntellijConfig = IntellijConfig(), - workspace: Option[WorkspaceConfig] = None, - resolvers: DependenciesConfig.Resolvers = DependenciesConfig.Resolvers(), - driver: DriverConfig = DriverConfig(), - paths: PathsConfig = PathsConfig() + intellij: IntellijConfig, + workspace: Option[WorkspaceConfig], + resolvers: DependenciesConfig.Resolvers, + driver: DriverConfig, + paths: PathsConfig ) object IdeProbeConfig extends ConfigFormat { diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/IntellijConfig.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/IntellijConfig.scala index 0dc83752..7b57d1bd 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/IntellijConfig.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/IntellijConfig.scala @@ -14,15 +14,14 @@ sealed trait IntellijConfig { } object IntellijConfig extends ConfigFormat { - def apply(): IntellijConfig = Default() case class Default( - version: IntelliJVersion = IntelliJVersion.Latest, - plugins: Seq[Plugin] = Seq.empty + version: IntelliJVersion, + plugins: Seq[Plugin] ) extends IntellijConfig case class Existing( path: Path, - plugins: Seq[Plugin] = Seq.empty + plugins: Seq[Plugin] ) extends IntellijConfig implicit val intelliJConfigReader: ConfigReader[IntellijConfig] = { diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/PathsConfig.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/PathsConfig.scala index 2b7316a2..17e18eea 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/PathsConfig.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/config/PathsConfig.scala @@ -3,10 +3,10 @@ package org.virtuslab.ideprobe.config import java.nio.file.Path case class PathsConfig( - base: Option[Path] = None, - instances: Option[Path] = None, - workspaces: Option[Path] = None, - screenshots: Option[Path] = None, - cache: Option[Path] = None, - trusted: Option[Path] = None + base: Option[Path], + instances: Option[Path], + workspaces: Option[Path], + screenshots: Option[Path], + cache: Option[Path], + trusted: Option[Path] ) diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/IntelliJVersion.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/IntelliJVersion.scala index b21b66e6..8e6db900 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/IntelliJVersion.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/IntelliJVersion.scala @@ -31,7 +31,8 @@ final case class IntelliJVersion(build: String, release: Option[String]) { object IntelliJVersion { implicit val configConvert: ConfigConvert[IntelliJVersion] = deriveConvert[IntelliJVersion] - val Latest = release("2021.2.1", "212.5080.55") + // TODO(#253): replace Latest with reading from reference.conf + val Latest: IntelliJVersion = release("2021.2.1", "212.5080.55") def snapshot(build: String): IntelliJVersion = { IntelliJVersion(build, None) diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/PluginResolver.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/PluginResolver.scala index 64a82b45..13e0668f 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/PluginResolver.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/dependencies/PluginResolver.scala @@ -5,7 +5,8 @@ import org.virtuslab.ideprobe.dependencies.Plugin._ import org.virtuslab.ideprobe.error object PluginResolver { - val Official = PluginResolver("https://plugins.jetbrains.com/plugin/download") + // TODO (#253): replace Official with a default value in reference.conf - `probe.resolvers.plugins.repository.uri` + val Official: DependencyResolver[Plugin] = PluginResolver("https://plugins.jetbrains.com/plugin/download") def apply(uri: String): DependencyResolver[Plugin] = { new Resolver(uri) diff --git a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/ide/intellij/IntelliJProvider.scala b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/ide/intellij/IntelliJProvider.scala index 6f1507ff..26066640 100644 --- a/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/ide/intellij/IntelliJProvider.scala +++ b/core/driver/sources/src/main/scala/org/virtuslab/ideprobe/ide/intellij/IntelliJProvider.scala @@ -5,10 +5,18 @@ import java.nio.file.Path import java.util.stream.Collectors import java.util.stream.{Stream => JStream} +import scala.concurrent.duration._ + import org.virtuslab.ideprobe.Extensions._ import org.virtuslab.ideprobe._ +import org.virtuslab.ideprobe.config.CheckConfig +import org.virtuslab.ideprobe.config.CheckConfig.ErrorConfig +import org.virtuslab.ideprobe.config.CheckConfig.FreezeConfig import org.virtuslab.ideprobe.config.DependenciesConfig import org.virtuslab.ideprobe.config.DriverConfig +import org.virtuslab.ideprobe.config.DriverConfig.LaunchParameters +import org.virtuslab.ideprobe.config.DriverConfig.ScreenConfig +import org.virtuslab.ideprobe.config.DriverConfig.XvfbConfig import org.virtuslab.ideprobe.config.IntellijConfig import org.virtuslab.ideprobe.dependencies.Resource._ import org.virtuslab.ideprobe.dependencies._ @@ -26,7 +34,7 @@ sealed trait IntelliJProvider { // This method differentiates plugins by their root entries in zip // assuming that plugins with same root entries are the same plugin - // and only installs last occurrance of such plugin in the list + // and only installs last occurrence of such plugin in the list // in case of duplicates. protected def installPlugins( dependencies: DependencyProvider, @@ -69,7 +77,7 @@ final case class ExistingIntelliJ( paths: IdeProbePaths, config: DriverConfig ) extends IntelliJProvider { - override val version = IntelliJVersionResolver.version(path) + override val version: IntelliJVersion = IntelliJVersionResolver.version(path) override def withVersion(version: IntelliJVersion): IntelliJProvider = error("Cannot set version for existing IntelliJ instance") @@ -153,7 +161,7 @@ final case class IntelliJFactory( } object IntelliJProvider { - val Default = + val Default: IntelliJFactory = IntelliJFactory( dependencies = new DependencyProvider( new IntelliJDependencyProvider(Seq(IntelliJZipResolver.community), ResourceProvider.Default), @@ -163,7 +171,14 @@ object IntelliJProvider { plugins = Seq.empty, version = IntelliJVersion.Latest, paths = IdeProbePaths.Default, - config = DriverConfig() + config = DriverConfig( // TODO: replace DriverConfig parameters with loading defaults from reference.conf + launch = LaunchParameters(Seq.empty, 30.seconds), + check = CheckConfig(ErrorConfig(enabled = false, Seq(".*"), Seq.empty), FreezeConfig(false)), + xvfb = XvfbConfig(ScreenConfig(1920, 1080, 24)), + headless = false, + vmOptions = Seq.empty, + env = Map.empty + ) ) def from( diff --git a/core/driver/sources/src/test/resources/empty.conf b/core/driver/sources/src/test/resources/empty.conf new file mode 100644 index 00000000..e69de29b diff --git a/core/driver/sources/src/test/scala/org/virtuslab/ideprobe/dependencies/IdeProbeConfigTest.scala b/core/driver/sources/src/test/scala/org/virtuslab/ideprobe/dependencies/IdeProbeConfigTest.scala new file mode 100644 index 00000000..af329973 --- /dev/null +++ b/core/driver/sources/src/test/scala/org/virtuslab/ideprobe/dependencies/IdeProbeConfigTest.scala @@ -0,0 +1,112 @@ +package org.virtuslab.ideprobe.dependencies + +import scala.concurrent.duration._ + +import org.junit.Assert._ +import org.junit.Test + +import org.virtuslab.ideprobe.Config +import org.virtuslab.ideprobe.IdeProbeFixture +import org.virtuslab.ideprobe.IntelliJFixture +import org.virtuslab.ideprobe.config.IntellijConfig +import org.virtuslab.ideprobe.config.WorkspaceConfig + +class IdeProbeConfigTest extends IdeProbeFixture { + private val configRoot = "probe" // same as in object IntelliJFixture + + @Test + def loadsDefaultValuesFromReferenceConfFile(): Unit = { + // loading from an empty file - so all configs will be loaded from reference.conf + val config: Config = Config.fromClasspath("empty.conf") + val probeConfig = IntelliJFixture.readIdeProbeConfig(config, configRoot) + // tests for the intellij: IntellijConfig field + assertTrue(probeConfig.intellij.isInstanceOf[IntellijConfig.Default]) + assertEquals("212.5080.55", probeConfig.intellij.asInstanceOf[IntellijConfig.Default].version.build) + assertEquals(Some("2021.2.1"), probeConfig.intellij.asInstanceOf[IntellijConfig.Default].version.release) + assertEquals(Seq.empty, probeConfig.intellij.asInstanceOf[IntellijConfig.Default].plugins) + // test for the workspace: Option[WorkspaceConfig] field + assertEquals(None, probeConfig.workspace) + // tests for the resolvers: DependenciesConfig.Resolvers field + assertEquals(Seq.empty, probeConfig.resolvers.intellij.repositories) + assertEquals(None, probeConfig.resolvers.plugins.repository) + assertEquals(Seq.empty, probeConfig.resolvers.jbr.repositories) + assertEquals(0, probeConfig.resolvers.retries) + // tests for the driver: DriverConfig field + assertEquals(Seq.empty, probeConfig.driver.launch.command) + assertEquals(30.seconds, probeConfig.driver.launch.timeout) + assertEquals(false, probeConfig.driver.check.errors.enabled) + assertEquals(Seq(".*"), probeConfig.driver.check.errors.includeMessages) + assertEquals(Seq.empty, probeConfig.driver.check.errors.excludeMessages) + assertEquals(false, probeConfig.driver.check.freezes.enabled) + assertEquals(1920, probeConfig.driver.xvfb.screen.width) + assertEquals(1080, probeConfig.driver.xvfb.screen.height) + assertEquals(24, probeConfig.driver.xvfb.screen.depth) + assertEquals(false, probeConfig.driver.headless) + assertEquals(Seq.empty, probeConfig.driver.vmOptions) + assertEquals(Map.empty, probeConfig.driver.env) + // tests for the paths: PathsConfig field + assertEquals(None, probeConfig.paths.base) + assertEquals(None, probeConfig.paths.instances) + assertEquals(None, probeConfig.paths.workspaces) + assertEquals(None, probeConfig.paths.screenshots) + assertEquals(None, probeConfig.paths.cache) + assertEquals(None, probeConfig.paths.trusted) + } + + @Test + def mergesUserConfigsFromFileWithDefaultConfigs(): Unit = { + // loading from a non-empty file - so user configs will be merged with configs from reference.conf + val config: Config = Config.fromClasspath("example.conf") + val probeConfig = IntelliJFixture.readIdeProbeConfig(config, configRoot) + // tests for the intellij: IntellijConfig field + assertTrue(probeConfig.intellij.isInstanceOf[IntellijConfig.Default]) + assertEquals("201.6668.121", probeConfig.intellij.asInstanceOf[IntellijConfig.Default].version.build) + assertEquals(Some("2021.2.1"), probeConfig.intellij.asInstanceOf[IntellijConfig.Default].version.release) + assertEquals(1, probeConfig.intellij.plugins.size) + assertTrue(probeConfig.intellij.plugins.head.isInstanceOf[Plugin.Versioned]) + assertEquals("org.intellij.scala", probeConfig.intellij.plugins.head.asInstanceOf[Plugin.Versioned].id) + assertEquals("2020.1.27", probeConfig.intellij.plugins.head.asInstanceOf[Plugin.Versioned].version) + // test for the workspace: Option[WorkspaceConfig] field + assertTrue(probeConfig.workspace.get.isInstanceOf[WorkspaceConfig.Default]) + assertTrue( + probeConfig.workspace.get + .asInstanceOf[WorkspaceConfig.Default] + .path + .asInstanceOf[Resource.File] + .path + .toString + .nonEmpty + ) + // tests for the resolvers: DependenciesConfig.Resolvers field + assertEquals( + Seq( + "https://www.jetbrains.com/intellij-repository/snapshots/" + + "[orgPath]/[module]/[artifact]/[revision]/[artifact]-[revision].zip" + ), + probeConfig.resolvers.intellij.repositories + ) + assertEquals(None, probeConfig.resolvers.plugins.repository) + assertEquals(Seq.empty, probeConfig.resolvers.jbr.repositories) + assertEquals(0, probeConfig.resolvers.retries) + // tests for the driver: DriverConfig field + assertEquals(Seq("idea"), probeConfig.driver.launch.command) + assertEquals(60.seconds, probeConfig.driver.launch.timeout) + assertEquals(false, probeConfig.driver.check.errors.enabled) + assertEquals(Seq(".*"), probeConfig.driver.check.errors.includeMessages) + assertEquals(Seq.empty, probeConfig.driver.check.errors.excludeMessages) + assertEquals(false, probeConfig.driver.check.freezes.enabled) + assertEquals(1920, probeConfig.driver.xvfb.screen.width) + assertEquals(1080, probeConfig.driver.xvfb.screen.height) + assertEquals(24, probeConfig.driver.xvfb.screen.depth) + assertEquals(true, probeConfig.driver.headless) + assertEquals(Seq.empty, probeConfig.driver.vmOptions) + assertEquals(Map.empty, probeConfig.driver.env) + // tests for the paths: PathsConfig field + assertEquals(None, probeConfig.paths.base) + assertEquals(None, probeConfig.paths.instances) + assertEquals(None, probeConfig.paths.workspaces) + assertEquals(None, probeConfig.paths.screenshots) + assertEquals(None, probeConfig.paths.cache) + assertEquals(None, probeConfig.paths.trusted) + } +} diff --git a/core/driver/sources/src/test/scala/org/virtuslab/ideprobe/dependencies/IntelliJProviderTest.scala b/core/driver/sources/src/test/scala/org/virtuslab/ideprobe/dependencies/IntelliJProviderTest.scala index 0146e03a..daa569fe 100644 --- a/core/driver/sources/src/test/scala/org/virtuslab/ideprobe/dependencies/IntelliJProviderTest.scala +++ b/core/driver/sources/src/test/scala/org/virtuslab/ideprobe/dependencies/IntelliJProviderTest.scala @@ -19,7 +19,7 @@ final class IntelliJProviderTest { private implicit val ec: ExecutionContext = ExecutionContext.fromExecutorService(Executors.newCachedThreadPool()) @Test - def intelliJProviderShouldBeAbleToCorrectlyReadTheExistingInstanceVersion: Unit = givenInstalledIntelliJ { + def intelliJProviderShouldBeAbleToCorrectlyReadTheExistingInstanceVersion(): Unit = givenInstalledIntelliJ { installationRoot => // when trying to read the installed instance's version val intelliJVersion = IntelliJVersionResolver.version(installationRoot) @@ -32,7 +32,7 @@ final class IntelliJProviderTest { } @Test - def existingIntelliJShouldNotBeDeletedDuringCleanup: Unit = givenInstalledIntelliJ { installationRoot => + def existingIntelliJShouldNotBeDeletedDuringCleanup(): Unit = givenInstalledIntelliJ { installationRoot => val config = Config.fromString(s""" |probe.intellij { | path = $installationRoot @@ -55,7 +55,7 @@ final class IntelliJProviderTest { } @Test - def shouldInstallIntellijFromExtractedRepository: Unit = givenInstalledIntelliJ { installationRoot => + def shouldInstallIntellijFromExtractedRepository(): Unit = givenInstalledIntelliJ { installationRoot => val build = IntelliJVersion.Latest.build val installationPattern = installationRoot.toString.replace(build, "[revision]") installationRoot.resolve("dependencies.txt").delete() @@ -81,7 +81,7 @@ final class IntelliJProviderTest { } @Test - def existingIntelliJShouldRetainItsOriginalPluginsDuringCleanup: Unit = givenInstalledIntelliJ { installationRoot => + def existingIntelliJShouldRetainItsOriginalPluginsDuringCleanup(): Unit = givenInstalledIntelliJ { installationRoot => // given a pre-installed IntelliJ and an IntelliJProvider val preInstalledPlugins = installationRoot.resolve("plugins").directChildren().toSet