override fun tryParse()

in plugin-dotnet-agent/src/main/kotlin/jetbrains/buildServer/visualStudio/JsonVisualStudioInstanceParser.kt [15:48]


    override fun tryParse(stream: InputStream): ToolInstance? {
        BufferedReader(InputStreamReader(stream)).use {
            val state = _jsonParser.tryParse(it, VisualStudioState::class.java)
            val installationPath = state?.installationPath;
            val detailedVersion = getDetailedVersion(state)
            val productLineVersion = state?.catalogInfo?.productLineVersion
            if (installationPath.isNullOrBlank() || detailedVersion == null || productLineVersion.isNullOrBlank()) {
                LOG.info("Invalid Visual Studio state: $state")
                return null
            }
            if (LOG.isDebugEnabled) {
                LOG.debug("VisualStudio state: $state")
            }

            val productId = state.product?.id;
            if (TeamExplorerProductId.equals(productId, true)) {
                LOG.debug("Ignore Team Explorer installation.")
                return null
            }
            var baseVersion = Version.parse(productLineVersion)
            // starting from Visual Studio 2026 there is no base version in "YYYY" format in the "state.json"
            // we replace "18" with "2026" to keep the "VS2026" agent parameter name consistent with "VS2022" and others
            // maybe there are other reasons for this replacement, not sure...
            if (baseVersion.major == 18) {
                baseVersion = Version.parse("2026")
            }
            return ToolInstance(
                    ToolInstanceType.VisualStudio,
                    File(installationPath, DefaultDevenvPath),
                    detailedVersion,
                    baseVersion,
                    Platform.Default)
        }
    }