Skip to content

Commit

Permalink
Merge pull request #933 from JetBrains/rival/fix-900
Browse files Browse the repository at this point in the history
Use the google.gson lib to deserialize the local.settings.json file
  • Loading branch information
rafaelldi authored Oct 8, 2024
2 parents 795734b + a7c5900 commit b4fc539
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 25 deletions.
4 changes: 4 additions & 0 deletions PluginsAndFeatures/azure-toolkit-for-rider/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## [Unreleased]

### Fixed

- Allow comments in the local.settings.json file ([#900](https://github.com/JetBrains/azure-tools-for-intellij/issues/900))

## [4.2.1] - 2024-10-04

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,73 @@

package com.microsoft.azure.toolkit.intellij.legacy.function.localsettings

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import com.google.gson.annotations.SerializedName

//Return back when `allowComments` is available.
//@Serializable
//data class FunctionLocalSettings(
// @SerialName("IsEncrypted") val isEncrypted: Boolean?,
// @SerialName("Values") val values: FunctionValuesModel?,
// @SerialName("Host") val host: FunctionHostModel?,
// @SerialName("ConnectionStrings") val connectionStrings: Map<String, String>?
//)
//
//@Serializable
//data class FunctionValuesModel(
// @SerialName("FUNCTIONS_WORKER_RUNTIME") val workerRuntime: FunctionWorkerRuntime?,
// @SerialName("AzureWebJobsStorage") val webJobsStorage: String?,
// @SerialName("AzureWebJobsDashboard") val webJobsDashboard: String?,
// @SerialName("AzureWebJobs.HttpExample.Disabled") val webJobsHttpExampleDisabled: Boolean?,
// @SerialName("MyBindingConnection") val bindingConnection: String?
//)
//
//@Serializable
//data class FunctionHostModel(
// @SerialName("LocalHttpPort") val localHttpPort: Int?,
// @SerialName("CORS") val cors: String?,
// @SerialName("CORSCredentials") val corsCredentials: Boolean?
//)
//
//@Serializable
//enum class FunctionWorkerRuntime {
// @SerialName("DOTNET") DOTNET {
// override fun value() = "DOTNET"
// },
// @SerialName("DOTNET-ISOLATED") DOTNET_ISOLATED {
// override fun value() = "DOTNET-ISOLATED"
// };
//
// abstract fun value(): String
//}

@Serializable
data class FunctionLocalSettings(
@SerialName("IsEncrypted") val isEncrypted: Boolean?,
@SerialName("Values") val values: FunctionValuesModel?,
@SerialName("Host") val host: FunctionHostModel?,
@SerialName("ConnectionStrings") val connectionStrings: Map<String, String>?
@SerializedName("IsEncrypted") val isEncrypted: Boolean?,
@SerializedName("Values") val values: FunctionValuesModel?,
@SerializedName("Host") val host: FunctionHostModel?,
@SerializedName("ConnectionStrings") val connectionStrings: Map<String, String>?
)

@Serializable
data class FunctionValuesModel(
@SerialName("FUNCTIONS_WORKER_RUNTIME") val workerRuntime: FunctionWorkerRuntime?,
@SerialName("AzureWebJobsStorage") val webJobsStorage: String?,
@SerialName("AzureWebJobsDashboard") val webJobsDashboard: String?,
@SerialName("AzureWebJobs.HttpExample.Disabled") val webJobsHttpExampleDisabled: Boolean?,
@SerialName("MyBindingConnection") val bindingConnection: String?
@SerializedName("FUNCTIONS_WORKER_RUNTIME") val workerRuntime: FunctionWorkerRuntime?,
@SerializedName("AzureWebJobsStorage") val webJobsStorage: String?,
@SerializedName("AzureWebJobsDashboard") val webJobsDashboard: String?,
@SerializedName("AzureWebJobs.HttpExample.Disabled") val webJobsHttpExampleDisabled: Boolean?,
@SerializedName("MyBindingConnection") val bindingConnection: String?
)

@Serializable
data class FunctionHostModel(
@SerialName("LocalHttpPort") val localHttpPort: Int?,
@SerialName("CORS") val cors: String?,
@SerialName("CORSCredentials") val corsCredentials: Boolean?
@SerializedName("LocalHttpPort") val localHttpPort: Int?,
@SerializedName("CORS") val cors: String?,
@SerializedName("CORSCredentials") val corsCredentials: Boolean?
)

@Serializable
enum class FunctionWorkerRuntime {
@SerialName("DOTNET") DOTNET {
@SerializedName(value = "DOTNET", alternate = ["dotnet"])
DOTNET {
override fun value() = "DOTNET"
},
@SerialName("DOTNET-ISOLATED") DOTNET_ISOLATED {
@SerializedName(value = "DOTNET-ISOLATED", alternate = ["dotnet-isolated"])
DOTNET_ISOLATED {
override fun value() = "DOTNET-ISOLATED"
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package com.microsoft.azure.toolkit.intellij.legacy.function.localsettings

import com.google.gson.Gson
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -40,10 +41,12 @@ class FunctionLocalSettingsService {
runnableProjects.forEach {
val localSettingsFile = getLocalSettingFilePathInternal(Path(it.projectFilePath).parent)
if (!localSettingsFile.exists()) return@forEach
val pathString = localSettingsFile.absolutePathString()
if (cache.containsKey(pathString)) return@forEach
val virtualFile = VfsUtil.findFile(localSettingsFile, true) ?: return@forEach
val localSettingsFileStamp = localSettingsFile.toFile().lastModified()
val localSettings = getFunctionLocalSettings(virtualFile)
cache[localSettingsFile.absolutePathString()] = Pair(localSettingsFileStamp, localSettings)
cache[pathString] = Pair(localSettingsFileStamp, localSettings)
}
}

Expand All @@ -61,11 +64,12 @@ class FunctionLocalSettingsService {
if (!localSettingsFile.exists()) return null

val localSettingsFileStamp = localSettingsFile.toFile().lastModified()
val existingLocalSettings = cache[localSettingsFile.absolutePathString()]
val pathString = localSettingsFile.absolutePathString()
val existingLocalSettings = cache[pathString]
if (existingLocalSettings == null || localSettingsFileStamp != existingLocalSettings.first) {
val virtualFile = VfsUtil.findFile(localSettingsFile, true) ?: return null
val localSettings = getFunctionLocalSettings(virtualFile)
cache[localSettingsFile.absolutePathString()] = Pair(localSettingsFileStamp, localSettings)
cache[pathString] = Pair(localSettingsFileStamp, localSettings)
return localSettings
}

Expand All @@ -79,6 +83,8 @@ class FunctionLocalSettingsService {

private fun getFunctionLocalSettings(localSettingsFile: VirtualFile): FunctionLocalSettings {
val content = localSettingsFile.readText()
return json.decodeFromString<FunctionLocalSettings>(content)
//Return back when `allowComments` is available.
//return json.decodeFromString<FunctionLocalSettings>(content)
return Gson().fromJson(content, FunctionLocalSettings::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = com.jetbrains
pluginName = azure-toolkit-for-rider
pluginRepositoryUrl = https://github.com/JetBrains/azure-tools-for-intellij
# SemVer format -> https://semver.org
pluginVersion = 4.2.1
pluginVersion = 4.2.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 242
Expand Down

0 comments on commit b4fc539

Please sign in to comment.