--- a/core/src/commonMain/kotlin/gms/OssLicenseParser.kt Thu Apr 03 16:11:04 2025 -0400
+++ b/core/src/commonMain/kotlin/gms/OssLicenseParser.kt Thu Apr 03 17:24:24 2025 -0400
@@ -29,16 +29,20 @@
/**
* Parse licences data generated by the "com.google.android.gms.oss-licenses-plugin" gradle plugin.
*/
-class OssLicenseParser {
+class OssLicenseParser(
+ thirdPartyLicensesSource: Source,
+ thirdPartyLicensesMetadataSource: Source
+): AutoCloseable {
+
+ private val thirdPartyLicensesInput = thirdPartyLicensesSource.buffer()
+ private val thirdPartyLicensesMetadataInput = thirdPartyLicensesMetadataSource.buffer()
/**
* Parse licenses
* @param [thirdPartyLicensesInput] is usually res/raw/third_party_licenses file
* @param [thirdPartyLicensesMetadataInput] is usually res/raw/third_party_license_metadata file
*/
- fun parseLicenses(
- thirdPartyLicensesInput: Source, thirdPartyLicensesMetadataInput: Source
- ): Map<String, String> {
+ fun parseLicenses(): Map<String, String> {
val licenses = readLicensesFile(thirdPartyLicensesInput)
return buildLicenseInfo(licenses, thirdPartyLicensesMetadataInput)
}
@@ -71,6 +75,11 @@
}
}
+ override fun close() {
+ thirdPartyLicensesInput.close()
+ thirdPartyLicensesMetadataInput.close()
+ }
+
companion object
}
--- a/core/src/main/java/com/geekorum/aboutoss/core/gms/GmsLicenseInfoRepository.kt Thu Apr 03 16:11:04 2025 -0400
+++ b/core/src/main/java/com/geekorum/aboutoss/core/gms/GmsLicenseInfoRepository.kt Thu Apr 03 17:24:24 2025 -0400
@@ -55,15 +55,12 @@
private suspend fun parseLicenses() = withContext(mainCoroutineDispatcher) {
if (licensesInfo == null) {
val licenses = withContext(ioCoroutineDispatcher) {
- OssLicenseParser.openRawResourcesByName(appContext, thirdPartyLicensesResourceName).use { licensesInput ->
- OssLicenseParser.openRawResourcesByName(appContext, thirdPartyLicenseMetadataResourceName)
- .use { licensesMetadataInput ->
- val parser = OssLicenseParser()
- parser.parseLicenses(
- thirdPartyLicensesInput = licensesInput.source(),
- thirdPartyLicensesMetadataInput = licensesMetadataInput.source()
- )
- }
+ val parser = OssLicenseParser(
+ thirdPartyLicensesSource = OssLicenseParser.openRawResourcesByName(appContext, thirdPartyLicensesResourceName).source(),
+ thirdPartyLicensesMetadataSource = OssLicenseParser.openRawResourcesByName(appContext, thirdPartyLicenseMetadataResourceName).source()
+ )
+ parser.use {
+ it.parseLicenses()
}
}
licensesInfo = licenses