Skip to content

Commit

Permalink
Replace default values in code with .conf file (#252)
Browse files Browse the repository at this point in the history
* Moved default configurations to reference.conf

* provide a comment to the probe.intellij.version config

* PR fixes - fixed reference.conf comments
  • Loading branch information
LukaszKontowski authored Aug 25, 2022
1 parent dbb3bcc commit ab994b5
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 54 deletions.
8 changes: 4 additions & 4 deletions core/api/src/main/scala/org/virtuslab/ideprobe/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
}
}
129 changes: 129 additions & 0 deletions core/driver/sources/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -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 = "/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -140,4 +140,6 @@ object IntelliJFixture {
config = config
)
}

def readIdeProbeConfig(config: Config, path: String): IdeProbeConfig = config[IdeProbeConfig](path)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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),
Expand All @@ -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(
Expand Down
Empty file.
Loading

0 comments on commit ab994b5

Please sign in to comment.