Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e2e53f2
Convert 'UTSettings.kt' into '.utbot/settings.properties'
Vassiliy-Kudryashov Nov 17, 2022
0fc356d
Parsing UtSettings.kt line by line to get name, type, possible values…
Vassiliy-Kudryashov Nov 17, 2022
e397cda
Misprint
Vassiliy-Kudryashov Nov 17, 2022
bfda1de
Grade task "generateConfigTemplate"
Vassiliy-Kudryashov Nov 18, 2022
5e567df
Add TODOs for myself
Vassiliy-Kudryashov Nov 18, 2022
e5b879c
Implementation of added TODOs
Vassiliy-Kudryashov Nov 20, 2022
8a39fc2
Compact one-line documentation in output file for enum values
Vassiliy-Kudryashov Nov 21, 2022
02cc183
Add Apache 2.0 license to settings.properties output and tune comment…
Vassiliy-Kudryashov Nov 22, 2022
b2a4581
Add generated template to keep is in repository as well
Vassiliy-Kudryashov Nov 22, 2022
52c60b7
Add template generation to gradle build process
Vassiliy-Kudryashov Nov 23, 2022
bc40dbf
Get rid of unused property timeslotForOneToplevelMethodTraversalMs (W…
Vassiliy-Kudryashov Nov 24, 2022
8ab1578
Add AbstractSettings.areCustomized() ability to tell template from us…
Vassiliy-Kudryashov Nov 24, 2022
7cc19c0
Fix misprints in Apache license text.
Vassiliy-Kudryashov Nov 24, 2022
5c83685
Merge branch 'main' into Vassiliy-Kudryashov/experiments
Vassiliy-Kudryashov Nov 25, 2022
2b9373d
Merge branch 'main' into Vassiliy-Kudryashov/experiments
Vassiliy-Kudryashov Nov 25, 2022
aee42d6
Merge branch 'main' into Vassiliy-Kudryashov/experiments
Vassiliy-Kudryashov Nov 28, 2022
5c1328f
Fix an issue with always-default settings state.
Vassiliy-Kudryashov Dec 2, 2022
270aa3c
Fix a misprint in UtSettings property name "treatAssertAsErrorSuite"
Vassiliy-Kudryashov Dec 2, 2022
bd6dde8
Merge branch 'main' into Vassiliy-Kudryashov/experiments
Vassiliy-Kudryashov Dec 2, 2022
b6e4ea7
Fix a misprint in UtSettings property name "treatAssertAsErrorSuite"
Vassiliy-Kudryashov Dec 2, 2022
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
Prev Previous commit
Next Next commit
Add AbstractSettings.areCustomized() ability to tell template from us…
…er-defined custom settings

Make newly created ".utbot" folder hidden under Windows only
  • Loading branch information
Vassiliy-Kudryashov committed Nov 24, 2022
commit 8ab15789e69ff40bfd596570c21399caec4cb532
17 changes: 16 additions & 1 deletion utbot-core/src/main/kotlin/org/utbot/common/AbstractSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import kotlin.reflect.KProperty

interface SettingsContainer {
fun <T> settingFor(defaultValue: T, converter: (String) -> T): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, T>>

// Returns true iff some properties have non-default values
fun isCustomized() = false
}

interface SettingsContainerFactory {
Expand Down Expand Up @@ -47,6 +50,7 @@ class PropertiesSettingsContainer(
}

private val settingsValues: MutableMap<KProperty<*>, Any?> = mutableMapOf()
private var customized: Boolean = false

inner class SettingDelegate<T>(val property: KProperty<*>, val initializer: () -> T): ReadWriteProperty<Any?, T> {
private var value = initializer()
Expand Down Expand Up @@ -74,7 +78,12 @@ class PropertiesSettingsContainer(
return PropertyDelegateProvider { _, property ->
SettingDelegate(property) {
try {
properties.getProperty(property.name)?.let(converter) ?: defaultValue
properties.getProperty(property.name)?.let {
val parsedValue = converter.invoke(it)
customized = customized or (parsedValue != defaultValue)
parsedValue
}
defaultValue
} catch (e: Throwable) {
logger.info(e) { e.message }
defaultValue
Expand All @@ -83,6 +92,10 @@ class PropertiesSettingsContainer(
}
}

override fun isCustomized(): Boolean {
return customized
}

override fun toString(): String =
settingsValues
.mapKeys { it.key.name }
Expand Down Expand Up @@ -115,6 +128,8 @@ abstract class AbstractSettings(
}
}

fun areCustomized(): Boolean = container.isCustomized()

protected fun <T> getProperty(
defaultValue: T,
converter: (String) -> T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.utbot.framework.plugin.api.TreatOverflowAsError
import org.utbot.intellij.plugin.models.GenerateTestsModel
import java.util.concurrent.CompletableFuture
import kotlin.reflect.KClass
import org.utbot.common.isWindows
import org.utbot.framework.plugin.api.isSummarizationCompatible

@State(
Expand Down Expand Up @@ -176,19 +177,22 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
super.initializeComponent()
CompletableFuture.runAsync {
FileUtil.clearTempDirectory(UtSettings.daysLimitForTempFiles)
// In case settings.properties file is not yet presented in {homeDir}/.utbot folder
// we copy it from plugin resource file

// Don't replace file with custom user's settings
if (UtSettings.areCustomized()) return@runAsync
// In case settings.properties file is not yet presented
// (or stays with all default template values) in {homeDir}/.utbot folder
// we copy (or re-write) it from plugin resource file
val settingsClass = javaClass
Paths.get(UtSettings.defaultSettingsPath()).toFile().apply {
if (!this.isFile) {
val parentFile = this.parentFile
if (parentFile.mkdirs()) Files.setAttribute(parentFile.toPath(), "dos:hidden", true)
try {
settingsClass.getResource("../../../../../settings.properties")?.let {
this.writeBytes(it.openStream().readBytes())
}
} catch (ignored: IOException) {
try {
this.parentFile.apply {
if (this.mkdirs() && isWindows) Files.setAttribute(this.toPath(), "dos:hidden", true)
}
settingsClass.getResource("../../../../../settings.properties")?.let {
this.writeBytes(it.openStream().readBytes())
}
} catch (ignored: IOException) {
}
}
}
Expand Down