Skip to content

Commit

Permalink
Merge pull request #14983 from wordpress-mobile/jetpack/configure-sentry
Browse files Browse the repository at this point in the history
[Jetpack] Configure Sentry
  • Loading branch information
oguzkocer authored Jul 8, 2021
2 parents f1070f6 + fd55a68 commit 63c0faa
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 30 deletions.
11 changes: 8 additions & 3 deletions .configure
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"project_name": "WordPress-Android",
"branch": "trunk",
"pinned_hash": "08dfbcacef71687eebd0febaf97258e4f708ea54",
"pinned_hash": "578dc25a031df0b463a9718464a6e5e23e7d2ec9",
"files_to_copy": [
{
"file": "android/WPAndroid/gradle.properties",
Expand All @@ -14,8 +14,13 @@
"encrypt": true
},
{
"file": "android/WPAndroid/sentry.properties",
"destination": "sentry.properties",
"file": "android/WPAndroid/wordpress-sentry.properties",
"destination": "WordPress/src/wordpress/sentry.properties",
"encrypt": true
},
{
"file": "android/WPAndroid/jetpack-sentry.properties",
"destination": "WordPress/src/jetpack/sentry.properties",
"encrypt": true
},
{
Expand Down
Binary file modified .configure-files/gradle.properties.enc
Binary file not shown.
Binary file added .configure-files/jetpack-sentry.properties.enc
Binary file not shown.
5 changes: 5 additions & 0 deletions .configure-files/wordpress-sentry.properties.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
�7�"���wy�ɏ����1G�.Ѳ��z����.��p��P�����
\�p�u�f�9ں� lX��sꞹ�����S�5O����A���KԀ<ѷ)j4�:
Iޏ�ρ��2�((L��X�H�i-)g_0�3�ߘsUKw��:���U�Ƞ
��f�㗥�"��2�^��M�a�
1pl�j����{s��2�l �GU罈�X�v�C��&΢"*::6I^��g��W�\i2t�!�����r���9���-9�cq���_-P�w�����c�v�P4�0�Fu��o�H�T�1d*wM���c�-�L����Q
Expand Down
67 changes: 40 additions & 27 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ android {
applicationIdSuffix ".prealpha"
dimension "buildType"
}

// Also dynamically add additional `buildConfigFields` to our app flavors from any `wp.`/`jp.`-prefixed property in `gradle.properties`
def properties = loadPropertiesFromFile(checkGradlePropertiesFile())
addBuildConfigFieldsFromPrefixedProperties(wordpress, properties, ['wp'])
addBuildConfigFieldsFromPrefixedProperties(jetpack, properties, ['wp', 'jp']) // Inherit same properties used from WP first then overwrite with JP-specific ones
}

buildTypes {
Expand Down Expand Up @@ -239,6 +244,30 @@ android {
}
}

/// Dynamically add `buildConfigFields` on a given variant/flavor from prefixed properties
/// (This is used to e.g. add every property prefixed `wp.` in `gradle.properties` as a BuildConfigField in the `wordpress` flavor)
///
/// `prefixes` is an array of prefixes to search for, without their `.` dot (e.g. `["wp", "jp"]`).
/// Properties found with prefixes first in that array will be overridden by the ones found with prefixes later in the array.
static def addBuildConfigFieldsFromPrefixedProperties(variant, properties, prefixes) {
// Build a Map of prefixed properties found. Keys in this Map will be lowercased and `.` replaced by `_`
def fields_map = [:]
prefixes.each { prefix ->
properties.each { property ->
if (property.key.toLowerCase().startsWith("${prefix.toLowerCase()}.")) {
def key = property.key.toLowerCase().replace("${prefix.toLowerCase()}.", "").replace(".", "_")
fields_map[key] = property.value
}
}
}

// Then define the found properties as buildConfigFields
// Also define found properties that started with `res.` (`res_*` keys once in the `fields_map`) as resValues
fields_map.each {
variant.buildConfigField "String", it.key.toUpperCase(), "\"${it.value}\""
}
}

// Search for a variant-specific variation of the versionName and versionCode in `version.properties` file, based on the
// variant's app and buildType flavors.
//
Expand Down Expand Up @@ -470,36 +499,20 @@ configurations.all {
exclude group: 'org.wordpress', module: 'analytics'
}

android.buildTypes.all { buildType ->
// Add properties named "wp.xxx" to our BuildConfig
def inputFile = checkGradlePropertiesFile()
def properties = loadPropertiesFromFile(inputFile)
properties.any { property ->
if (property.key.toLowerCase().startsWith("wp.")) {
buildType.buildConfigField "String", property.key.replace("wp.", "").replace(".", "_").toUpperCase(),
"\"${property.value}\""
}
if (property.key.toLowerCase().startsWith("wp.res.")) {
buildType.resValue "string", property.key.replace("wp.res.", "").replace(".", "_").toLowerCase(),
"${property.value}"
}
}

// If Google services file doesn't exist...
if (!file("google-services.json").exists()) {
// ... copy example file.
copy {
from(".")
into(".")
include("google-services.json-example")
rename('google-services.json-example', 'google-services.json')
}
// If Google services file doesn't exist, copy example file
if (!file("google-services.json").exists()) {
copy {
from(".")
into(".")
include("google-services.json-example")
rename('google-services.json-example', 'google-services.json')
}
}

// Print warning message if example Google services file is used.
if ((file('google-services.json').text) == (file('google-services.json-example').text)) {
println("WARNING: You're using the example google-services.json file. Google login will fail.")
}
// Print warning message if example Google services file is used.
if ((file('google-services.json').text) == (file('google-services.json-example').text)) {
println("WARNING: You're using the example google-services.json file. Google login will fail.")
}

tasks.register("violationCommentsToGitHub", se.bjurr.violations.comments.github.plugin.gradle.ViolationCommentsToGitHubTask) {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties-example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ wp.zendesk.domain=https://www.google.com/
wp.zendesk.oauth_client_id=wordpress
wp.reset_db_on_downgrade = false
wp.sentry.dsn=https://00000000000000000000000000000000@sentry.io/00000000
jp.sentry.dsn=https://00000000000000000000000000000000@sentry.io/00000000
wp.tenor.api_key=wordpress
wp.encrypted_logging_key=z0g+oVkqR4kWNUTxJfTozOZQjfXI7W9f6bD0uMJ5VkA=

Expand Down

0 comments on commit 63c0faa

Please sign in to comment.