Skip to content

Commit

Permalink
cli 0.3.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ellizio committed Jun 20, 2024
1 parent e1ea726 commit fa3a5ce
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@
![](/img/step3.png)
![](/img/step4.png)

## ⚠️ Known Restrictions

1. ✅ Waiting for release with fix\
Output metadata .xml file is always named `OData ServiceCsdl.xml` which will throw a runtime exception. See more [https://github.com/OData/ODataConnectedService/issues/384](https://github.com/OData/ODataConnectedService/issues/384)\
There is a workaround:\
`a.` Rename `OData ServiceCsdl.xml` to `<Service name>Csdl.xml`, where `<Service name>` is value from OData CLI UI dialog\
`b.` Adjust embedded resource path in `.csproj` file\
`c.` Find `GeneratedEdmModel.filePath` constant in `Reference.cs` and change value from `OData ServiceCsdl.xml` to `<Service name>Csdl.xml`, where `<Service name>` is value from OData CLI UI dialog

## Additional References

- [Changelog](https://github.com/ellizio/rider--plugin--odata-cli-ui/blob/master/CHANGELOG.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@ package ru.ellizio.odatacliui.extensions

import com.jetbrains.rd.ide.model.DotnetToolVersionDefinition

fun DotnetToolVersionDefinition.humanize() : String = "$major.$minor.$patch"
fun DotnetToolVersionDefinition.humanize() : String = "$major.$minor.$patch"

fun DotnetToolVersionDefinition.greaterOrEquals(major: Int, minor: Int, patch: Int) : Boolean {
if (this.major > major)
return true

if (this.major == major && this.minor > minor)
return true

if (this.major == major && this.minor == minor && this.patch >= patch)
return true

return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ import ru.ellizio.odatacliui.extensions.dotnetAddPackageCommand
import ru.ellizio.odatacliui.terminal.BatchCommandLine
import ru.ellizio.odatacliui.terminal.builders.BatchCommandLineBuilder
import com.jetbrains.rider.projectView.solution
import ru.ellizio.odatacliui.extensions.greaterOrEquals
import ru.ellizio.odatacliui.terminal.builders.CommandLineBuilder
import ru.ellizio.odatacliui.utils.DotnetToolsUtils
import kotlin.io.path.Path

private const val CONNECTED_SERVICES = "Connected Services"
private const val CSDL_NAME = "OData ServiceCsdl.xml"
private const val CSDL_NAME_LEGACY = "OData ServiceCsdl.xml"
private const val CSDL_NAME_SUFFIX = "Csdl.xml"

class CliDialogModel(project: Project, private val actionMetadata: ActionMetadata) {
val odataCliTool: DotnetToolDefinition
val dotnetCliPath: String?
private val dotnetCliPath: String?

private val atLeast031: Boolean

init {
odataCliTool = project.solution.protocolModel.getODataCliTool.sync(Unit)
dotnetCliPath = project.solution.dotNetActiveRuntimeModel.activeRuntime.valueOrNull?.dotNetCliExePath

atLeast031 = odataCliTool.version?.greaterOrEquals(0, 3, 1) ?: false
}

val serviceName = MutableProperty("")
Expand All @@ -44,10 +50,14 @@ class CliDialogModel(project: Project, private val actionMetadata: ActionMetadat

private fun getOutputDirectory(): String = Path(Path(actionMetadata.projectPath).parent.toString(), CONNECTED_SERVICES, serviceName.get()).toString()

fun getCsdlPath(): String = Path(CONNECTED_SERVICES, serviceName.get(), CSDL_NAME).toString()
fun getCsdlPath(): String {
val csdl = if (atLeast031) "${serviceName.get()}$CSDL_NAME_SUFFIX" else CSDL_NAME_LEGACY
return Path(CONNECTED_SERVICES, serviceName.get(), csdl).toString()
}

fun buildODataCliCommand(): GeneralCommandLine = CommandLineBuilder(DotnetToolsUtils.getToolDefaultPath("odata-cli"), "generate")
.withParameter("--metadata-uri", metadataUri.get())
.withParameter("--service-name", serviceName.get(), atLeast031)
.withParameter("--file-name", fileName.get())
.withParameter("--custom-headers", customHeaders.get())
.withParameter("--proxy", proxy.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.ui.layout.ValidationInfoBuilder
import javax.swing.JTextField

object CliDialogValidators {
private val serviceNameRegex = Regex("^[0-9a-zA-Z_\\-. ]+\$")
private val proxyRegex = Regex("^(\\w+\\\\\\w+(:\\w+)?@)?\\w+:\\d+\$")

fun serviceNameValidator(): ValidationInfoBuilder.(JTextField) -> ValidationInfo? = {
Expand All @@ -15,6 +16,8 @@ object CliDialogValidators {
error("Service name must not start with a space")
else if (it.text.endsWith(' '))
error("Service name must not end with a space")
else if (!serviceNameRegex.matches(it.text))
error("Service name must be in a valid format")
else
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class CommandLineBuilder(toolName: String, commandName: String) {
return this
}

fun withParameter(parameterName: String, parameterValue: String?, condition: Boolean): CommandLineBuilder {
if (condition)
return withParameter(parameterName, parameterValue)

return this
}

fun withFlag(parameterName: String, parameterValue: Boolean): CommandLineBuilder {
if (!parameterValue)
return this
Expand Down

0 comments on commit fa3a5ce

Please sign in to comment.