-
Notifications
You must be signed in to change notification settings - Fork 207
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 #234 from ZacSweers/z/v5ManifestUploading
Support for manifest processing in AGP 4.1.0-alpha04 and above
- Loading branch information
Showing
12 changed files
with
279 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ local.properties | |
maze_output/ | ||
package-lock.json | ||
.cxx | ||
|
||
*.iml |
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
75 changes: 74 additions & 1 deletion
75
src/main/kotlin/com.bugsnag.android.gradle/AndroidManifestInfo.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 |
---|---|---|
@@ -1,8 +1,81 @@ | ||
package com.bugsnag.android.gradle | ||
|
||
import com.squareup.moshi.JsonAdapter | ||
import com.squareup.moshi.JsonReader | ||
import com.squareup.moshi.JsonReader.Token.NULL | ||
import com.squareup.moshi.JsonWriter | ||
import okio.buffer | ||
import okio.sink | ||
import okio.source | ||
import java.io.File | ||
|
||
data class AndroidManifestInfo( | ||
var apiKey: String, | ||
var versionCode: String, | ||
var buildUUID: String, | ||
var versionName: String | ||
) | ||
) { | ||
internal fun write(file: File) { | ||
file.sink().buffer().use { | ||
ADAPTER.toJson(it, this) | ||
} | ||
} | ||
|
||
internal companion object { | ||
private val OPTIONS = JsonReader.Options.of( | ||
"apiKey", | ||
"versionCode", | ||
"buildUUID", | ||
"versionName" | ||
) | ||
|
||
@Suppress("MagicNumber") // They are indices into the OPTIONS field above | ||
private val ADAPTER = object : JsonAdapter<AndroidManifestInfo>() { | ||
override fun fromJson(reader: JsonReader): AndroidManifestInfo? { | ||
if (reader.peek() == NULL) { | ||
return reader.nextNull() | ||
} | ||
lateinit var apiKey: String | ||
lateinit var versionCode: String | ||
lateinit var buildUUID: String | ||
lateinit var versionName: String | ||
reader.beginObject() | ||
while (reader.hasNext()) { | ||
when (reader.selectName(OPTIONS)) { | ||
0 -> apiKey = reader.nextString() | ||
1 -> versionCode = reader.nextString() | ||
2 -> buildUUID = reader.nextString() | ||
3 -> versionName = reader.nextString() | ||
-1 -> reader.skipValue() | ||
} | ||
} | ||
reader.endObject() | ||
return AndroidManifestInfo(apiKey, versionCode, buildUUID, versionName) | ||
} | ||
|
||
override fun toJson(writer: JsonWriter, value: AndroidManifestInfo?) { | ||
if (value == null) { | ||
writer.nullValue() | ||
return | ||
} | ||
writer.beginObject() | ||
.name("apiKey") | ||
.value(value.apiKey) | ||
.name("versionCode") | ||
.value(value.versionCode) | ||
.name("buildUUID") | ||
.value(value.buildUUID) | ||
.name("versionName") | ||
.value(value.versionName) | ||
.endObject() | ||
} | ||
|
||
} | ||
|
||
fun read(file: File): AndroidManifestInfo { | ||
return file.source().buffer().use { | ||
ADAPTER.fromJson(it) ?: error("Failed to parse manifest info.") | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com.bugsnag.android.gradle/AndroidManifestInfoReceiver.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,11 @@ | ||
package com.bugsnag.android.gradle | ||
|
||
import org.gradle.api.file.RegularFileProperty | ||
|
||
interface AndroidManifestInfoReceiver { | ||
val manifestInfoFile: RegularFileProperty | ||
} | ||
|
||
internal fun AndroidManifestInfoReceiver.parseManifestInfo(): AndroidManifestInfo { | ||
return AndroidManifestInfo.read(manifestInfoFile.asFile.get()) | ||
} |
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
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/com.bugsnag.android.gradle/BugsnagManifestUuidTaskV2.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,58 @@ | ||
package com.bugsnag.android.gradle | ||
|
||
import com.android.Version | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.PathSensitive | ||
import org.gradle.api.tasks.PathSensitivity | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.util.VersionNumber | ||
import javax.inject.Inject | ||
|
||
/** | ||
* An AGP-4-compatible implementation of [BugsnagManifestUuidTask]. | ||
*/ | ||
open class BugsnagManifestUuidTaskV2 @Inject constructor( | ||
objects: ObjectFactory | ||
) : BaseBugsnagManifestUuidTask(objects) { | ||
|
||
internal companion object { | ||
private val MIN_AGP_VERSION: VersionNumber = VersionNumber.parse("4.1.0-alpha04") | ||
|
||
fun isApplicable(): Boolean { | ||
return try { | ||
VersionNumber.parse(Version.ANDROID_GRADLE_PLUGIN_VERSION) >= MIN_AGP_VERSION | ||
} catch (ignored: Throwable) { | ||
// Not on a new enough AGP version, return false | ||
false | ||
} | ||
} | ||
} | ||
|
||
// NONE because we only care about its contents, not location. | ||
@get:PathSensitive(PathSensitivity.NONE) | ||
@get:InputFile | ||
val inputManifest: RegularFileProperty = objects.fileProperty() | ||
|
||
@get:OutputFile | ||
val outputManifest: RegularFileProperty = objects.fileProperty() | ||
|
||
init { | ||
group = BugsnagPlugin.GROUP_NAME | ||
description = "Adds a unique build UUID to AndroidManifest to link proguard mappings to crash reports" | ||
} | ||
|
||
@TaskAction | ||
fun updateManifest() { | ||
val manifestParser = AndroidManifestParser() | ||
val output = outputManifest.asFile.get() | ||
manifestParser.writeBuildUuid( | ||
inputManifest.asFile.get(), | ||
outputManifest.asFile.get(), | ||
buildUuid = buildUuid.get() | ||
) | ||
writeManifestInfo(manifestParser.readManifest(output, logger)) | ||
} | ||
} |
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
Oops, something went wrong.