fun parse()

in server/src/main/kotlin/com/jetbrains/teamcity/plugins/unrealengine/server/buildgraph/BuildGraphParser.kt [67:99]


    fun parse(stream: InputStream): BuildGraph<BuildGraphNodeGroup> {
        val buildGraph =
            try {
                json.decodeFromStream<ExportedBuildGraph>(stream)
            } catch (e: Throwable) {
                raise("An error occurred while parsing exported build graph file", e)
            }

        val graph = buildGraph.groups.associateWith { mutableListOf<ExportedGroup>() }
        val nodeToGroup = buildGraph.groups.flatMap { group -> group.nodes.map { it.name to group } }.toMap()

        for (group in buildGraph.groups) {
            for (node in group.nodes) {
                for (nodeDependencyName in node.dependencies()) {
                    val dependencyGroup = nodeToGroup[nodeDependencyName]!!

                    if (dependencyGroup == group) {
                        continue
                    }

                    graph[dependencyGroup]!!.add(group)
                }
            }
        }

        return BuildGraph(
            graph
                .map { (group, successorGroup) ->
                    group.toNodeGroup() to successorGroup.map { it.toNodeGroup() }
                }.toMap(),
            buildGraph.badges.map { it.toBadge() },
        )
    }