From 9856204925c4ffad485902ec6e14351260fa3c22 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 2 Dec 2022 16:16:28 +0100 Subject: [PATCH] KTI-1046. Tests Replace XmlParser with JDOM in tests-spec Fix test behaviour with two artifacts of spec on teamcity --- compiler/tests-spec/build.gradle.kts | 3 +-- .../kotlin/spec/utils/spec/HtmlSpecLoader.kt | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/compiler/tests-spec/build.gradle.kts b/compiler/tests-spec/build.gradle.kts index ece3a6c3eee..04ce8253da5 100644 --- a/compiler/tests-spec/build.gradle.kts +++ b/compiler/tests-spec/build.gradle.kts @@ -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") diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/spec/HtmlSpecLoader.kt b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/spec/HtmlSpecLoader.kt index 162d4ddcf02..7263c75b707 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/spec/HtmlSpecLoader.kt +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/spec/utils/spec/HtmlSpecLoader.kt @@ -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 { - 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-(?\d+\.\d+)-(?[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-(?latest)-(?[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")) }