project dsl — support reading of List<Object>

GitOrigin-RevId: bcc12557ea621f243dc0aeff250f5796d82b33af
This commit is contained in:
Vladimir Krivosheev
2020-02-19 17:02:46 +01:00
committed by intellij-monorepo-bot
parent 9948c4dc2c
commit 3560e0a4f4
19 changed files with 287 additions and 174 deletions

1
.idea/modules.xml generated
View File

@@ -466,6 +466,7 @@
<module fileurl="file://$PROJECT_DIR$/plugins/ant/jps-plugin/intellij.ant.jps.iml" filepath="$PROJECT_DIR$/plugins/ant/jps-plugin/intellij.ant.jps.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/commander/intellij.commander.iml" filepath="$PROJECT_DIR$/plugins/commander/intellij.commander.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/configuration-script/intellij.configurationScript.iml" filepath="$PROJECT_DIR$/plugins/configuration-script/intellij.configurationScript.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/configuration-script/intellij.configurationScript.test.java.iml" filepath="$PROJECT_DIR$/plugins/configuration-script/intellij.configurationScript.test.java.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/copyright/intellij.copyright.iml" filepath="$PROJECT_DIR$/plugins/copyright/intellij.copyright.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/cucumber-jvm-formatter/intellij.cucumber.jvmFormatter.iml" filepath="$PROJECT_DIR$/plugins/cucumber-jvm-formatter/intellij.cucumber.jvmFormatter.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/cucumber-jvm-formatter3/intellij.cucumber.jvmFormatter3.iml" filepath="$PROJECT_DIR$/plugins/cucumber-jvm-formatter3/intellij.cucumber.jvmFormatter3.iml" />

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.configurationStore;
import com.intellij.openapi.components.PersistentStateComponent;
@@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
public class ComponentSerializationUtil {
public final class ComponentSerializationUtil {
@NotNull
public static <S> Class<S> getStateClass(@NotNull Class<? extends PersistentStateComponent> aClass) {
TypeVariable<Class<PersistentStateComponent>> variable = PersistentStateComponent.class.getTypeParameters()[0];

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/testJava">
<sourceFolder url="file://$MODULE_DIR$/testJava" isTestSource="true" packagePrefix="com.intellij.configurationScript" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="intellij.configurationScript" scope="TEST" />
<orderEntry type="module" module-name="intellij.java.execution.impl" scope="TEST" />
<orderEntry type="library" scope="TEST" name="kotlin-stdlib-jdk8" level="project" />
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
<orderEntry type="library" scope="TEST" name="assertJ" level="project" />
</component>
</module>

View File

@@ -2,10 +2,9 @@
package com.intellij.configurationScript
import com.intellij.configurationScript.inspection.InspectionJsonSchemaGenerator
import com.intellij.configurationScript.providers.PluginsConfiguration
import com.intellij.configurationScript.schemaGenerators.ComponentStateJsonSchemaGenerator
import com.intellij.configurationScript.schemaGenerators.PluginJsonSchemaGenerator
import com.intellij.configurationScript.schemaGenerators.RunConfigurationJsonSchemaGenerator
import com.intellij.configurationScript.schemaGenerators.buildJsonSchema
import com.intellij.json.JsonFileType
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.DumbAware
@@ -85,6 +84,7 @@ internal class IntellijConfigurationJsonSchemaProviderFactory : JsonSchemaProvid
private fun generateConfigurationSchema(): CharSequence {
return doGenerateConfigurationSchema(listOf(
PluginJsonSchemaGenerator(),
RunConfigurationJsonSchemaGenerator(),
ComponentStateJsonSchemaGenerator(),
InspectionJsonSchemaGenerator())
@@ -111,14 +111,6 @@ internal fun doGenerateConfigurationSchema(generators: List<SchemaGenerator>): C
"type" to "object"
map("properties") {
map(Keys.plugins) {
"type" to "object"
"description" to "The plugins"
map("properties") {
buildJsonSchema(PluginsConfiguration(), this, subObjectSchemaGenerator = null)
}
}
for (generator in generators) {
generator.generate(this)
}
@@ -144,6 +136,4 @@ internal fun doGenerateConfigurationSchema(generators: List<SchemaGenerator>): C
internal object Keys {
const val runConfigurations = "runConfigurations"
const val templates = "templates"
const val plugins = "plugins"
}

View File

@@ -0,0 +1,30 @@
package com.intellij.configurationScript
import com.intellij.openapi.components.BaseState
import com.intellij.util.xmlb.BeanBinding
import java.lang.reflect.ParameterizedType
internal class ItemTypeInfoProvider(private val hostClass: Class<out BaseState>) {
private val accessors by lazy(LazyThreadSafetyMode.NONE) {
BeanBinding.getAccessors(hostClass)
}
fun getListItemType(propertyName: String): Class<out BaseState>? {
val accessor = accessors.find { it.name == propertyName }
if (accessor == null) {
LOG.warn("Property not found (name=$propertyName, hostClass=${hostClass.name})")
return null
}
val type = accessor.genericType
if (type !is ParameterizedType) {
LOG.error("$type not supported (name=$propertyName, hostClass=${hostClass.name})")
return null
}
val actualTypeArguments = type.actualTypeArguments
LOG.assertTrue(actualTypeArguments.size == 1)
@Suppress("UNCHECKED_CAST")
return actualTypeArguments[0] as Class<out BaseState>
}
}

View File

@@ -5,6 +5,7 @@ import com.intellij.openapi.components.ScalarProperty
import com.intellij.openapi.components.StoredProperty
import com.intellij.serialization.stateProperties.CollectionStoredProperty
import com.intellij.serialization.stateProperties.MapStoredProperty
import com.intellij.util.ReflectionUtil
import org.snakeyaml.engine.v2.nodes.MappingNode
import org.snakeyaml.engine.v2.nodes.NodeTuple
import org.snakeyaml.engine.v2.nodes.ScalarNode
@@ -16,6 +17,7 @@ internal fun <T : BaseState> readIntoObject(instance: T, node: MappingNode, affe
internal fun <T : BaseState> readIntoObject(instance: T, nodes: List<NodeTuple>, affectedPropertyConsumer: ((StoredProperty<Any>) -> Unit)? = null): T {
val properties = instance.__getProperties()
val itemTypeInfoProvider = ItemTypeInfoProvider(instance.javaClass)
for (tuple in nodes) {
val valueNode = tuple.valueNode
val key = (tuple.keyNode as ScalarNode).value
@@ -40,7 +42,7 @@ internal fun <T : BaseState> readIntoObject(instance: T, nodes: List<NodeTuple>,
else if (valueNode is SequenceNode) {
for (property in properties) {
if (property is CollectionStoredProperty<*, *> && key == property.name) {
readCollection(property, valueNode)
readCollection(property, itemTypeInfoProvider, valueNode)
affectedPropertyConsumer?.invoke(property)
break
}
@@ -50,14 +52,25 @@ internal fun <T : BaseState> readIntoObject(instance: T, nodes: List<NodeTuple>,
return instance
}
private fun readCollection(property: CollectionStoredProperty<*, *>, valueNode: SequenceNode) {
private fun readCollection(property: CollectionStoredProperty<*, *>, itemTypeInfoProvider: ItemTypeInfoProvider, valueNode: SequenceNode) {
@Suppress("UNCHECKED_CAST")
val collection = (property as CollectionStoredProperty<String, MutableList<String>>).__getValue()
val collection = (property as CollectionStoredProperty<Any, MutableList<Any>>).__getValue()
collection.clear()
if (!valueNode.value.isEmpty()) {
for (itemNode in valueNode.value) {
val itemValue = (itemNode as? ScalarNode)?.value ?: continue
collection.add(itemValue)
if (valueNode.value.isEmpty()) {
return
}
val itemType by lazy { itemTypeInfoProvider.getListItemType(property.name!!) }
for (itemNode in valueNode.value) {
if (itemNode is ScalarNode) {
collection.add(itemNode.value ?: continue)
}
else if (itemNode is MappingNode) {
// object
val itemInstance = ReflectionUtil.newInstance(itemType ?: continue, false)
readIntoObject(itemInstance, itemNode.value)
collection.add(itemInstance)
}
}
}
@@ -66,7 +79,7 @@ private fun readMap(property: MapStoredProperty<*, *>, valueNode: MappingNode) {
@Suppress("UNCHECKED_CAST")
val map = (property as MapStoredProperty<String, String>).__getValue()
map.clear()
if (!valueNode.value.isEmpty()) {
if (valueNode.value.isNotEmpty()) {
for (tuple in valueNode.value) {
val key = (tuple.keyNode as? ScalarNode)?.value ?: continue
val value = (tuple.valueNode as? ScalarNode)?.value ?: continue

View File

@@ -29,7 +29,7 @@ internal class InspectionJsonSchemaGenerator : SchemaGenerator {
}
}
}
"additionalProperties" to false
}
"additionalProperties" to false
}
}

View File

@@ -1,8 +1,8 @@
package com.intellij.configurationScript.providers
import com.intellij.configurationScript.ConfigurationFileManager
import com.intellij.configurationScript.Keys
import com.intellij.configurationScript.readIntoObject
import com.intellij.configurationScript.schemaGenerators.PluginJsonSchemaGenerator
import com.intellij.openapi.components.BaseState
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.processOpenedProjects
@@ -10,10 +10,11 @@ import com.intellij.openapi.updateSettings.impl.UpdateSettingsProvider
import com.intellij.openapi.util.NotNullLazyKey
import com.intellij.util.SmartList
import com.intellij.util.concurrency.SynchronizedClearableLazy
import com.intellij.util.xmlb.annotations.XCollection
private val dataKey = NotNullLazyKey.create<SynchronizedClearableLazy<PluginsConfiguration?>, Project>("MyUpdateSettingsProvider") { project ->
val data = SynchronizedClearableLazy {
val node = ConfigurationFileManager.getInstance(project).findValueNode(Keys.plugins) ?: return@SynchronizedClearableLazy null
val node = ConfigurationFileManager.getInstance(project).findValueNode(PluginJsonSchemaGenerator.plugins) ?: return@SynchronizedClearableLazy null
readIntoObject(PluginsConfiguration(), node)
}
@@ -34,5 +35,6 @@ private class MyUpdateSettingsProvider : UpdateSettingsProvider {
}
internal class PluginsConfiguration : BaseState() {
@get:XCollection
val repositories by list<String>()
}

View File

@@ -1,5 +1,6 @@
package com.intellij.configurationScript.schemaGenerators
import com.intellij.configurationScript.ItemTypeInfoProvider
import com.intellij.configurationScript.LOG
import com.intellij.configurationStore.Property
import com.intellij.openapi.components.BaseState
@@ -9,10 +10,8 @@ import com.intellij.serialization.stateProperties.MapStoredProperty
import com.intellij.util.ReflectionUtil
import gnu.trove.THashMap
import org.jetbrains.io.JsonObjectBuilder
import java.lang.reflect.ParameterizedType
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.memberProperties
import kotlin.reflect.jvm.javaType
internal class OptionClassJsonSchemaGenerator(val definitionNodeKey: String) {
val definitionPointerPrefix = "#/$definitionNodeKey/"
@@ -71,6 +70,8 @@ internal fun buildJsonSchema(state: BaseState,
propertyToAnnotation.put(property.name, annotation)
}
val itemTypeInfoProvider = ItemTypeInfoProvider(state.javaClass)
for (property in properties) {
val name = property.name!!
val annotation = propertyToAnnotation?.get(name)
@@ -99,31 +100,21 @@ internal fun buildJsonSchema(state: BaseState,
}
}
is CollectionStoredProperty<*, *> -> {
val propertyInfo = state.javaClass.kotlin.members.first { it.name == property.name }
val type = propertyInfo.returnType.javaType
if (type !is ParameterizedType) {
LOG.error("$type not supported for collection property $propertyInfo")
}
else {
val actualTypeArguments = type.actualTypeArguments
LOG.assertTrue(actualTypeArguments.size == 1)
val listType = actualTypeArguments[0]
when {
listType === java.lang.String::class.java -> {
map("items") {
"type" to "string"
}
val listType = itemTypeInfoProvider.getListItemType(name) ?: return@map
when {
listType === java.lang.String::class.java -> {
map("items") {
"type" to "string"
}
subObjectSchemaGenerator == null -> {
LOG.error("$type not supported for collection property $propertyInfo because subObjectSchemaGenerator is not specified")
}
else -> {
map("items") {
@Suppress("UNCHECKED_CAST")
definitionReference(subObjectSchemaGenerator.definitionPointerPrefix,
subObjectSchemaGenerator.addClass(listType as Class<out BaseState>))
}
}
subObjectSchemaGenerator == null -> {
LOG.error("$listType not supported for collection property $name because subObjectSchemaGenerator is not specified")
}
else -> {
map("items") {
@Suppress("UNCHECKED_CAST")
definitionReference(subObjectSchemaGenerator.definitionPointerPrefix,
subObjectSchemaGenerator.addClass(listType))
}
}
}

View File

@@ -0,0 +1,23 @@
package com.intellij.configurationScript.schemaGenerators
import com.intellij.configurationScript.SchemaGenerator
import com.intellij.configurationScript.providers.PluginsConfiguration
import org.jetbrains.io.JsonObjectBuilder
internal class PluginJsonSchemaGenerator : SchemaGenerator {
companion object {
const val plugins = "plugins"
}
override fun generate(rootBuilder: JsonObjectBuilder) {
rootBuilder.map(plugins) {
"type" to "object"
"description" to "The plugins"
map("properties") {
buildJsonSchema(
PluginsConfiguration(), this, subObjectSchemaGenerator = null)
}
"additionalProperties" to false
}
}
}

View File

@@ -2,6 +2,7 @@
package com.intellij.configurationScript
import com.fasterxml.jackson.core.JsonFactory
import com.intellij.configurationScript.providers.readRunConfigurations
import com.intellij.configurationScript.schemaGenerators.rcTypeIdToPropertyName
//import com.intellij.execution.application.JvmMainMethodRunConfigurationOptions
import com.intellij.execution.configurations.ConfigurationTypeBase
@@ -59,7 +60,7 @@ class ConfigurationFileTest {
@Test
fun empty() {
val result = readRunConfigurations("""
val result = collectRunConfigurations("""
runConfigurations:
""")
assertThat(result).isEmpty()
@@ -67,7 +68,7 @@ class ConfigurationFileTest {
@Test
fun `empty rc type group`() {
val result = readRunConfigurations("""
val result = collectRunConfigurations("""
runConfigurations:
java:
""")
@@ -76,7 +77,7 @@ class ConfigurationFileTest {
@Test
fun `empty rc`() {
val result = readRunConfigurations("""
val result = collectRunConfigurations("""
runConfigurations:
java:
-
@@ -84,46 +85,9 @@ class ConfigurationFileTest {
assertThat(result).isEmpty()
}
//@Test
//fun `one java`() {
// val result = readRunConfigurations("""
// runConfigurations:
// java:
// isAlternativeJrePathEnabled: true
// """)
// val options = JvmMainMethodRunConfigurationOptions()
// options.isAlternativeJrePathEnabled = true
// assertThat(result).containsExactly(options)
//}
//
//@Test
//fun `one java as list`() {
// val result = readRunConfigurations("""
// runConfigurations:
// java:
// - isAlternativeJrePathEnabled: true
// """)
// val options = JvmMainMethodRunConfigurationOptions()
// options.isAlternativeJrePathEnabled = true
// assertThat(result).containsExactly(options)
//}
//
//@Test
//fun `one v as list - template`() {
// val result = readRunConfigurations("""
// runConfigurations:
// templates:
// java:
// - isAlternativeJrePathEnabled: true
// """, isTemplatesOnly = true)
// val options = JvmMainMethodRunConfigurationOptions()
// options.isAlternativeJrePathEnabled = true
// assertThat(result).containsExactly(options)
//}
@Test
fun `templates as invalid node type`() {
val result = readRunConfigurations("""
val result = collectRunConfigurations("""
runConfigurations:
templates: foo
""", isTemplatesOnly = true)
@@ -131,9 +95,9 @@ class ConfigurationFileTest {
}
}
internal fun readRunConfigurations(@Language("YAML") data: String, isTemplatesOnly: Boolean = false): List<Any> {
fun collectRunConfigurations(@Language("YAML") data: String, isTemplatesOnly: Boolean = false): List<Any> {
val list = SmartList<Any>()
com.intellij.configurationScript.providers.readRunConfigurations(doRead(data.trimIndent().reader())!!, isTemplatesOnly) { _, state ->
readRunConfigurations(doRead(data.trimIndent().reader())!!, isTemplatesOnly) { _, state ->
list.add(state)
}
return list

View File

@@ -2,6 +2,7 @@ package com.intellij.configurationScript
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.configurationScript.providers.PluginsConfiguration
import com.intellij.configurationScript.schemaGenerators.ComponentStateJsonSchemaGenerator
import com.intellij.configurationScript.schemaGenerators.RunConfigurationJsonSchemaGenerator
import com.intellij.json.JsonFileType
@@ -26,7 +27,7 @@ internal class ConfigurationSchemaTest : BasePlatformTestCase() {
}
fun `test map and description`() {
val variants = test("""
val variants = testRunConfigurations("""
runConfigurations:
java:
<caret>
@@ -39,7 +40,7 @@ internal class ConfigurationSchemaTest : BasePlatformTestCase() {
}
fun `test array or object`() {
val variants = test("""
val variants = testRunConfigurations("""
runConfigurations:
java: <caret>
""".trimIndent())
@@ -53,7 +54,7 @@ internal class ConfigurationSchemaTest : BasePlatformTestCase() {
}
fun `test no isAllowRunningInParallel if singleton policy not configurable`() {
val variants = test("""
val variants = testRunConfigurations("""
runConfigurations:
compound:
<caret>
@@ -84,17 +85,6 @@ internal class ConfigurationSchemaTest : BasePlatformTestCase() {
""")
}
@Suppress("unused")
private class JdkAutoHint: BaseState() {
var sdkName by string()
var sdkPath by string()
}
private class JdkAutoHints : BaseState() {
@get:XCollection
val sdks by list<JdkAutoHint>()
}
fun `test list of objects`() {
testComponentState("sdks", """
sdks:
@@ -102,11 +92,18 @@ internal class ConfigurationSchemaTest : BasePlatformTestCase() {
""", beanClass = JdkAutoHints::class.java, expectedVariants = """sdks (array)""")
}
fun `test list of strings`() {
testComponentState("plugins", """
plugins:
<caret>
""", beanClass = PluginsConfiguration::class.java, expectedVariants = """repositories (array)""")
}
private fun testFooComponentState(path: String, fileContent: String) {
testComponentState(path, fileContent, Foo::class.java, expectedVariants = "a (string)")
}
private fun testComponentState(path: String, fileContent: String, beanClass: Class<out BaseState>, expectedVariants: String) {
private fun testComponentState(path: String, @Language("YAML") fileContent: String, beanClass: Class<out BaseState>, expectedVariants: String) {
val variants = test(fileContent.trimIndent(), listOf(object : SchemaGenerator {
private val componentStateJsonSchemaGenerator = ComponentStateJsonSchemaGenerator()
@@ -133,7 +130,11 @@ internal class ConfigurationSchemaTest : BasePlatformTestCase() {
assertThat(presentation.typeText).isEqualTo(expectedDescription)
}
private fun test(@Language("YAML") text: String, generators: List<SchemaGenerator> = listOf(RunConfigurationJsonSchemaGenerator()), schemaValidator: ((CharSequence) -> Unit)? = null): List<LookupElement> {
private fun testRunConfigurations(@Language("YAML") text: String, schemaValidator: ((CharSequence) -> Unit)? = null): List<LookupElement> {
return test(text, listOf(RunConfigurationJsonSchemaGenerator()), schemaValidator)
}
private fun test(@Language("YAML") text: String, generators: List<SchemaGenerator>, schemaValidator: ((CharSequence) -> Unit)? = null): List<LookupElement> {
val position = EditorTestUtil.getCaretPosition(text)
assertThat(position).isGreaterThan(0)
@@ -164,4 +165,15 @@ private fun getTypeTest(variant: LookupElement): String {
val presentation = LookupElementPresentation()
variant.renderElement(presentation)
return presentation.typeText!!
}
@Suppress("unused")
internal class JdkAutoHint: BaseState() {
var sdkName by string()
var sdkPath by string()
}
internal class JdkAutoHints : BaseState() {
@get:XCollection
val sdks by list<JdkAutoHint>()
}

View File

@@ -1,12 +1,13 @@
package com.intellij.configurationScript
//import com.intellij.execution.application.JvmMainMethodRunConfigurationOptions
import com.intellij.configurationScript.providers.PluginsConfiguration
import com.intellij.configurationScript.schemaGenerators.PluginJsonSchemaGenerator
import com.intellij.testFramework.ProjectRule
import com.intellij.testFramework.assertions.Assertions.assertThat
import org.intellij.lang.annotations.Language
import org.junit.ClassRule
import org.junit.Test
import org.snakeyaml.engine.v2.nodes.MappingNode
class PropertyValueReaderTest {
companion object {
@@ -15,32 +16,6 @@ class PropertyValueReaderTest {
val projectRule = ProjectRule()
}
//@Test
//fun `enum`() {
// val result = readRunConfigurations("""
// runConfigurations:
// java:
// shortenClasspath: MANIFEST
// """)
// val options = JvmMainMethodRunConfigurationOptions()
// options.shortenClasspath = ShortenCommandLine.MANIFEST
// assertThat(result).containsExactly(options)
//}
//@Test
//fun map() {
// val result = readRunConfigurations("""
// runConfigurations:
// java:
// env:
// foo: bar
// answer: 42
// """)
// val options = JvmMainMethodRunConfigurationOptions()
// options.env = linkedMapOf("foo" to "bar", "answer" to "42")
// assertThat(result).containsExactly(options)
//}
@Test
fun collection() {
val result = doReadPluginsConfiguration("""
@@ -54,8 +29,26 @@ class PropertyValueReaderTest {
options.repositories.addAll(listOf("foo", "bar", "http://example.com"))
assertThat(result).isEqualTo(options)
}
@Test
fun `list of objects`() {
val result = JdkAutoHints()
readIntoObject(result, readYaml("""
sdks:
- sdkName: foo
sdkPath: /home/foo
"""))
assertThat(result.sdks).hasSize(1)
val sdks = result.sdks
assertThat(sdks).hasSize(1)
}
}
private fun doReadPluginsConfiguration(@Language("YAML") data: String): PluginsConfiguration? {
return readIntoObject(PluginsConfiguration(), findValueNodeByPath(Keys.plugins, doRead(data.trimIndent().reader())!!.value)!!)
private fun readYaml(@Language("YAML") data: String): MappingNode {
return doRead(data.trimIndent().reader())!!
}
private fun doReadPluginsConfiguration(@Suppress("SameParameterValue") @Language("YAML") data: String): PluginsConfiguration? {
return readIntoObject(PluginsConfiguration(), findValueNodeByPath(PluginJsonSchemaGenerator.plugins, readYaml(data).value)!!)
}

View File

@@ -0,0 +1,53 @@
@file:Suppress("UsePropertyAccessSyntax")
package com.intellij.configurationScript
import com.intellij.execution.application.JvmMainMethodRunConfigurationOptions
import com.intellij.testFramework.ProjectRule
import org.assertj.core.api.Assertions.assertThat
import org.junit.ClassRule
import org.junit.Test
class JavaConfigurationFileTest {
companion object {
@JvmField
@ClassRule
val projectRule = ProjectRule()
}
@Test
fun `one java`() {
val result = collectRunConfigurations("""
runConfigurations:
java:
isAlternativeJrePathEnabled: true
""")
val options = JvmMainMethodRunConfigurationOptions()
options.isAlternativeJrePathEnabled = true
assertThat(result).containsExactly(options)
}
@Test
fun `one java as list`() {
val result = collectRunConfigurations("""
runConfigurations:
java:
- isAlternativeJrePathEnabled: true
""")
val options = JvmMainMethodRunConfigurationOptions()
options.isAlternativeJrePathEnabled = true
assertThat(result).containsExactly(options)
}
@Test
fun `one v as list - template`() {
val result = collectRunConfigurations("""
runConfigurations:
templates:
java:
- isAlternativeJrePathEnabled: true
""", isTemplatesOnly = true)
val options = JvmMainMethodRunConfigurationOptions()
options.isAlternativeJrePathEnabled = true
assertThat(result).containsExactly(options)
}
}

View File

@@ -0,0 +1,42 @@
package com.intellij.configurationScript
import com.intellij.execution.ShortenCommandLine
import com.intellij.execution.application.JvmMainMethodRunConfigurationOptions
import com.intellij.testFramework.ProjectRule
import org.assertj.core.api.Assertions.assertThat
import org.junit.ClassRule
import org.junit.Test
class JavaPropertyValueReaderTest {
companion object {
@JvmField
@ClassRule
val projectRule = ProjectRule()
}
@Test
fun `enum`() {
val result = collectRunConfigurations("""
runConfigurations:
java:
shortenClasspath: MANIFEST
""")
val options = JvmMainMethodRunConfigurationOptions()
options.shortenClasspath = ShortenCommandLine.MANIFEST
assertThat(result).containsExactly(options)
}
@Test
fun map() {
val result = collectRunConfigurations("""
runConfigurations:
java:
env:
foo: bar
answer: 42
""")
val options = JvmMainMethodRunConfigurationOptions()
options.env = linkedMapOf("foo" to "bar", "answer" to "42")
assertThat(result).containsExactly(options)
}
}

View File

@@ -1,17 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#","$id": "https://jetbrains.com/intellij-configuration.schema.json","title": "IntelliJ Configuration","description": "IntelliJ Configuration to configure IDE behavior, run configurations and so on","type": "object",
"properties": {
"plugins": {
"type": "object","description": "The plugins",
"properties": {
"repositories": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"foo": {
"type": "object",
"properties": {

View File

@@ -1,17 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#","$id": "https://jetbrains.com/intellij-configuration.schema.json","title": "IntelliJ Configuration","description": "IntelliJ Configuration to configure IDE behavior, run configurations and so on","type": "object",
"properties": {
"plugins": {
"type": "object","description": "The plugins",
"properties": {
"repositories": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"foo": {
"type": "object",
"properties": {

View File

@@ -1,31 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#","$id": "https://jetbrains.com/intellij-configuration.schema.json","title": "IntelliJ Configuration","description": "IntelliJ Configuration to configure IDE behavior, run configurations and so on","type": "object",
"properties": {
"plugins": {
"type": "object","description": "The plugins",
"properties": {
"repositories": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"sdks": {
"type": "object",
"properties": {
"sdks": {
"type": "array",
"items": {
"$ref": "#/classDefinitions/com_intellij_configurationScript_ConfigurationSchemaTest$JdkAutoHint"
"$ref": "#/classDefinitions/com_intellij_configurationScript_JdkAutoHint"
}
}
},"additionalProperties": false
}
},
"classDefinitions": {
"com_intellij_configurationScript_ConfigurationSchemaTest$JdkAutoHint": {
"com_intellij_configurationScript_JdkAutoHint": {
"type": "object",
"properties": {
"sdkName": {

View File

@@ -0,0 +1,16 @@
{
"$schema": "http://json-schema.org/draft-07/schema#","$id": "https://jetbrains.com/intellij-configuration.schema.json","title": "IntelliJ Configuration","description": "IntelliJ Configuration to configure IDE behavior, run configurations and so on","type": "object",
"properties": {
"plugins": {
"type": "object",
"properties": {
"repositories": {
"type": "array",
"items": {
"type": "string"
}
}
},"additionalProperties": false
}
},"additionalProperties": false
}