1717
1818package com.itsaky.androidide.build.config
1919
20- import org.gradle.api.GradleException
21- import java.io.BufferedInputStream
22- import java.net.URI
23- import javax.xml.parsers.DocumentBuilderFactory
24- import javax.xml.xpath.XPathFactory
25-
2620/* *
2721 * @author Akash Yadav
2822 */
@@ -41,44 +35,4 @@ object VersionUtils {
4135 * The latest integration version name.
4236 */
4337 const val LATEST_INTEGRATION = " latest.integration"
44-
45- /* *
46- * The cached version name.
47- */
48- private var cachedVersion: String? = null
49-
50- /* *
51- * Gets the latest snapshot version of the given artifact from the Sonatype snapshots repository.
52- */
53- @JvmStatic
54- fun getLatestSnapshotVersion (artifact : String ): String {
55- cachedVersion?.also { cached ->
56- println (" Found latest version of artifact '$artifact ' : '$cached ' (cached)" )
57- return cached
58- }
59-
60- val groupId = BuildConfig .PACKAGE_NAME .replace(' .' , ' /' )
61- val moduleMetadata = " $SONATYPE_SNAPSHOTS_REPO$groupId /$artifact /maven-metadata.xml"
62- return try {
63- BufferedInputStream (URI .create(moduleMetadata).toURL().openStream()).use { inputStream ->
64- val builderFactory = DocumentBuilderFactory .newInstance()
65- val builder = builderFactory.newDocumentBuilder()
66- val document = builder.parse(inputStream)
67-
68- val xPathFactory = XPathFactory .newInstance()
69- val xPath = xPathFactory.newXPath()
70-
71- val latestVersion = xPath.evaluate(" /metadata/versioning/latest" , document)
72- cachedVersion = latestVersion
73- println (" Found latest version of artifact '$artifact ' : '$latestVersion '" )
74- return @use latestVersion
75- }
76- } catch (err: Throwable ) {
77- if (CI .isCiBuild) {
78- throw GradleException (" Failed to download: $moduleMetadata " , err)
79- }
80- println (" Failed to download $moduleMetadata : ${err.message} " )
81- return LATEST_INTEGRATION
82- }
83- }
8438}
0 commit comments