fun saveMetadata()

in tool/agent-upgrade-dist/src/main/kotlin/Metadata.kt [69:110]


fun saveMetadata(destinationDir: File, agentUpdateMetadata: AgentUpdateMetadata, plugins: List<Plugin>) {
     val doc = DocumentBuilderFactory
            .newInstance()
            .newDocumentBuilder()
            .newDocument()

    doc.xmlStandalone = true
    doc
            .appendChild(
                    E("agent",
                            E("core",
                                    E("file")
                                            .a("name", "buildAgent.zip")
                                            .a("hash", agentUpdateMetadata.hash)
                            ),
                            E("plugins",
                                    plugins
                                            .sortedBy { it.name }
                                            .map {
                                                E("file")
                                                        .a("name", it.name)
                                                        .a("hash", it.metadata.hash)
                                                        .a("type", if (it.metadata.type != PluginType.Bundled) "PLUGIN" else "TOOL")
                                                        .a("allowLoadingOnDemand", if (it.metadata.type != PluginType.Bundled) "false" else "true")
                                            }
                                            .asSequence()
                            )
                    ).a("agent-version", agentUpdateMetadata.version))
            .ownerDocument
            .save(File(destinationDir, "teamcity-agent.xml"))

    val lineSeparator = System.getProperty("line.separator")
    FileWriter(File(destinationDir, "unpacked-plugins.xml"))
            .use { writer ->
                for (plugin in plugins.filter { it.metadata.type != PluginType.Bundled }) {
                    writer.write(plugin.name)
                    writer.write("=")
                    writer.write(plugin.path.path.replace("\\", "/"))
                    writer.write(lineSeparator)
                }
            }
}