-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1223 from KronicDeth/1218
Convert mix and mix test run configurations to new format
- Loading branch information
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.elixir_lang.run.conversion | ||
|
||
import com.intellij.conversion.ConversionProcessor | ||
import com.intellij.conversion.ProjectConverter | ||
import com.intellij.conversion.RunManagerSettings | ||
|
||
class Converter : ProjectConverter() { | ||
override fun createRunConfigurationsConverter(): ConversionProcessor<RunManagerSettings> = | ||
RunConfiguration() | ||
|
||
// All conversion done by [createRunConfigurationsConverter] | ||
override fun isConversionNeeded(): Boolean = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.elixir_lang.run.conversion | ||
|
||
import com.intellij.conversion.ConversionContext | ||
import com.intellij.conversion.ConverterProvider | ||
import com.intellij.conversion.ProjectConverter | ||
|
||
class Provider : ConverterProvider("elixir-v8.0.0-run-configurations") { | ||
override fun getConversionDescription(): String = | ||
""" | ||
Mix and Mix ExUnit run configurations now allow more command line options to be set. | ||
Mix Program Arguments is renamed to "`mix` arguments" and gains "`elixir` arguments" and "`erl` arguments". | ||
Mix ExUnit Programs Arguments is renamed to "`mix test` arguments" and gains "`elixir` arguments" and "`erl` arguments". | ||
""".trimIndent() | ||
|
||
override fun createConverter(conversionContext: ConversionContext): ProjectConverter = Converter() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.elixir_lang.run.conversion | ||
|
||
import com.intellij.conversion.ConversionProcessor | ||
import com.intellij.conversion.RunManagerSettings | ||
import org.elixir_lang.exunit.MIX_TEST | ||
import org.elixir_lang.run.* | ||
import org.jdom.Element | ||
|
||
class RunConfiguration : ConversionProcessor<RunManagerSettings>() { | ||
override fun isConversionNeeded(settings: RunManagerSettings): Boolean = | ||
settings.runConfigurations.conversionNeeded().isNotEmpty() | ||
|
||
override fun process(settings: RunManagerSettings) { | ||
settings.runConfigurations.conversionNeeded().process() | ||
} | ||
} | ||
|
||
private val TYPES = arrayOf("MixRunConfigurationType", "MixExUnitRunConfigurationType") | ||
private val OLD_OPTION_NAMES = arrayOf("programParameters", "workingDirectory") | ||
|
||
private fun Element.getOption(name: String): Element? = getChildren("option").first { it.getAttributeValue("name") == name } | ||
private fun Element.hasAnyOption(names: Array<String>): Boolean = getChildren("option").any { it.getAttributeValue("name") in names } | ||
private fun Element.hasOldOptions(): Boolean = hasAnyOption(OLD_OPTION_NAMES) | ||
private fun Element.correctType(): Boolean = getAttributeValue("type") in TYPES | ||
private fun Collection<Element>.conversionNeeded(): Collection<Element> = filter(Element::correctType).filter(Element::hasOldOptions) | ||
private fun Collection<Element>.process() = forEach(Element::process) | ||
|
||
private fun Element.process() { | ||
processProgramParametersOption() | ||
processWorkingDirectoryOption() | ||
putNewModuleFilters() | ||
} | ||
|
||
fun Element.processProgramParametersOption() { | ||
getOption("programParameters")?.let { programParametersOption -> | ||
val command = when { | ||
getAttributeValue("type") == "MixRunConfigurationType" -> MIX | ||
getAttributeValue("type") == "MixExUnitRunConfigurationType" -> MIX_TEST | ||
else -> null | ||
} | ||
|
||
if (command != null) { | ||
val programParameters = programParametersOption.getAttributeValue("value") | ||
|
||
val argumentList = mutableListOf<String>() | ||
argumentList.fromArguments(programParameters) | ||
|
||
writeExternalArgumentList(command, argumentList) | ||
removeContent(programParametersOption) | ||
} | ||
} | ||
} | ||
|
||
fun Element.processWorkingDirectoryOption() { | ||
getOption("workingDirectory")?.let { workingDirectoryOption -> | ||
val oldValue = workingDirectoryOption.getAttributeValue("value") | ||
writeExternalWorkingDirectory("file://$oldValue") | ||
removeContent(workingDirectoryOption) | ||
} | ||
} | ||
|
||
fun Element.putNewModuleFilters() { | ||
if (getChild("module-filters") == null) { | ||
writeModuleFilters(emptyList(), true) | ||
} | ||
} | ||
|