-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #517 from bugsnag/release/v7.5.0
Release v7.5.0
- Loading branch information
Showing
7 changed files
with
146 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/com/bugsnag/android/gradle/internal/NdkPackageXmlParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.bugsnag.android.gradle.internal | ||
|
||
import org.gradle.util.VersionNumber | ||
import org.w3c.dom.Document | ||
import org.w3c.dom.Node | ||
import java.io.File | ||
import javax.xml.parsers.DocumentBuilderFactory | ||
|
||
internal object NdkPackageXmlParser { | ||
private const val PACKAGE_XML_FILENAME = "package.xml" | ||
private const val TAG_REVISION = "revision" | ||
private const val TAG_MAJOR = "major" | ||
private const val TAG_MINOR = "minor" | ||
private const val TAG_MICRO = "micro" | ||
|
||
internal fun loadVersionFromPackageXml(ndkDir: File): VersionNumber { | ||
val packageFile = File(ndkDir, PACKAGE_XML_FILENAME) | ||
var versionNumber: VersionNumber? = null | ||
if (packageFile.canRead()) { | ||
versionNumber = loadPackageXml(packageFile) { doc -> | ||
val revision = doc.getElementsByTagName(TAG_REVISION).item(0) | ||
val major = revision.getChildValue(TAG_MAJOR) | ||
val minor = revision.getChildValue(TAG_MINOR) | ||
val micro = revision.getChildValue(TAG_MICRO) | ||
|
||
VersionNumber( | ||
major?.toIntOrNull() ?: 0, | ||
minor?.toIntOrNull() ?: 0, | ||
micro?.toIntOrNull() ?: 0, | ||
null | ||
) | ||
} | ||
} | ||
|
||
return versionNumber ?: VersionNumber.parse(ndkDir.name) // fallback to trying to parse the dir name | ||
} | ||
|
||
private inline fun <T> loadPackageXml(packageFile: File, action: (Document) -> T): T? { | ||
return packageFile.inputStream().buffered().use { stream -> | ||
@Suppress("TooGenericExceptionCaught", "SwallowedException") | ||
try { | ||
val builder = DocumentBuilderFactory.newInstance().newDocumentBuilder() | ||
val document = builder.parse(stream) | ||
action(document) | ||
} catch (ex: Exception) { | ||
null | ||
} | ||
} | ||
} | ||
|
||
private fun Node.getChildValue(elementName: String): String? { | ||
val children = childNodes | ||
repeat(children.length) { index -> | ||
if (children.item(index).nodeName == elementName) { | ||
return children.item(index).textContent | ||
} | ||
} | ||
|
||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters