@@ -38,34 +38,34 @@ class GmavenHelper(val groupId: String, val artifactId: String) {
38
38
}
39
39
40
40
fun hasReleasedVersion (version : String ): Boolean {
41
- try {
42
- val groupIdAsPath = groupId.replace(" ." , " /" )
43
- val mavenMetadataUrl = " ${GMAVEN_ROOT } /${groupIdAsPath} /${artifactId} /maven-metadata.xml"
44
- val factory: DocumentBuilderFactory = DocumentBuilderFactory .newInstance()
45
- val builder: DocumentBuilder = factory.newDocumentBuilder()
46
- val doc: Document = builder.parse(URL (mavenMetadataUrl).openStream())
47
- doc.documentElement.normalize()
41
+ val doc: Document ? = getDocument()
42
+ if (doc != null ) {
48
43
val versions = doc.getElementsByTagName(" version" )
49
44
for (i in 0 .. versions.length - 1 ) {
50
45
if (versions.item(i).textContent == version) {
51
46
return true
52
47
}
53
48
}
54
- } catch (e : FileNotFoundException ) {}
49
+ }
55
50
return false
56
51
}
57
52
58
53
fun getLatestReleasedVersion (): String {
54
+ val doc: Document ? = getDocument()
55
+ return doc?.getElementsByTagName(" latest" )?.item(0 )?.getTextContent() ? : " "
56
+ }
57
+
58
+ fun getDocument (): Document ? {
59
59
try {
60
60
val groupIdAsPath = groupId.replace(" ." , " /" )
61
61
val mavenMetadataUrl = " ${GMAVEN_ROOT } /${groupIdAsPath} /${artifactId} /maven-metadata.xml"
62
62
val factory: DocumentBuilderFactory = DocumentBuilderFactory .newInstance()
63
63
val builder: DocumentBuilder = factory.newDocumentBuilder()
64
64
val doc: Document = builder.parse(URL (mavenMetadataUrl).openStream())
65
65
doc.documentElement.normalize()
66
- return doc.getElementsByTagName( " latest " ).item( 0 ).getTextContent()
66
+ return doc
67
67
} catch (e: FileNotFoundException ) {
68
- return " "
68
+ return null
69
69
}
70
70
}
71
71
}
0 commit comments