KTI-1046. Tests Replace XmlParser with JDOM in tests-spec

Fix test behaviour with two artifacts of spec on teamcity
This commit is contained in:
Simon Ogorodnik
2022-12-02 16:16:28 +01:00
committed by Space Team
parent 41ff283856
commit 9856204925
2 changed files with 14 additions and 12 deletions
+1 -2
View File
@@ -10,8 +10,7 @@ dependencies {
testImplementation(projectTests(":compiler:tests-common-new"))
testApi(commonDependency("com.google.code.gson:gson"))
testApi(commonDependency("org.codehaus.groovy:groovy"))
testApi(commonDependency("org.codehaus.groovy:groovy-xml"))
testApi(commonDependency("org.jetbrains.intellij.deps:jdom"))
api("org.jsoup:jsoup:1.14.2")
@@ -5,8 +5,7 @@
package org.jetbrains.kotlin.spec.utils.spec
import groovy.util.Node
import groovy.util.XmlParser
import org.jdom.input.SAXBuilder
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import java.io.BufferedInputStream
@@ -29,14 +28,18 @@ object HtmlSpecLoader {
}
private fun getLastSpecVersion(): Pair<String, String> {
val xmlParser = XmlParser()
val buildInfo =
xmlParser.parse("$TC_URL/$TC_PATH_PREFIX/buildType:(id:$SPEC_DOCS_TC_CONFIGURATION_ID),count:1,status:SUCCESS?branch=$STABLE_BRANCH")
val artifactsLink = (buildInfo.children().find { (it as Node).name() == "artifacts" } as Node).attribute("href").toString()
val artifacts = xmlParser.parse(TC_URL + artifactsLink)
val artifactName = (artifacts.children().single() as Node).attribute("name").toString()
val artifactNameMatches =
Pattern.compile("""kotlin-spec-(?<specVersion>\d+\.\d+)-(?<buildNumber>[1-9]\d*)\.zip""").matcher(artifactName).apply { find() }
val sax = SAXBuilder()
val buildInfo = sax.build(
URL("$TC_URL/$TC_PATH_PREFIX/buildType:(id:$SPEC_DOCS_TC_CONFIGURATION_ID),count:1,status:SUCCESS?branch=$STABLE_BRANCH")
)
val artifactsLink = (buildInfo.rootElement.children.find { it.name == "artifacts" })!!.getAttribute("href").value
val artifacts = sax.build(URL(TC_URL + artifactsLink))
val pattern = Pattern.compile("""kotlin-spec-(?<specVersion>latest)-(?<buildNumber>[1-9]\d*)\.zip""")
val artifactNameMatches = artifacts.rootElement.children
.map { it.getAttribute("name").value }
.mapNotNull { pattern.matcher(it) }
.single { it.find() }
return Pair(artifactNameMatches.group("specVersion"), artifactNameMatches.group("buildNumber"))
}