Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
152dd3fb
Commit
152dd3fb
authored
May 30, 2019
by
Denys M
Committed by
Sebastian Kaspari
Jun 05, 2019
Browse files
For #2346. Enable kotlin warningsAsErrors for `service-glean` module.
parent
6971977e
Changes
4
Hide whitespace changes
Inline
Side-by-side
buildSrc/src/main/java/KotlinCompiler.kt
View file @
152dd3fb
...
...
@@ -13,7 +13,6 @@ object KotlinCompiler {
@JvmStatic
val
projectsWithWarningsAsErrorsDisabled
=
setOf
(
"browser-domains"
,
"feature-prompts"
,
"service-glean"
"feature-prompts"
)
}
components/service/glean/src/main/java/mozilla/components/service/glean/private/EventMetricType.kt
View file @
152dd3fb
...
...
@@ -47,7 +47,6 @@ data class EventMetricType<ExtraKeysEnum : Enum<ExtraKeysEnum>>(
* identifiers. This is used for events where additional richer context is needed.
* The maximum length for values is defined by [MAX_LENGTH_EXTRA_KEY_VALUE]
*/
@Suppress
(
"NestedBlockDepth"
)
fun
record
(
extra
:
Map
<
ExtraKeysEnum
,
String
>?
=
null
)
{
if
(!
shouldRecord
(
logger
))
{
return
...
...
@@ -57,26 +56,7 @@ data class EventMetricType<ExtraKeysEnum : Enum<ExtraKeysEnum>>(
// might get executed.
val
monotonicElapsed
=
SystemClock
.
elapsedRealtime
()
// Convert the extra key enums to strings before passing to the storage engine
val
extraStrings
=
extra
?.
let
{
extra
->
// There are two extra "keys" in play here:
// 1. The Kotlin enumeration names, in CamelCase
// 2. The keys sent in the ping, in snake_case
// Here we need to get (2) to send in the ping.
if
(
extra
.
size
>
0
)
{
val
result
=
mutableMapOf
<
String
,
String
>()
for
((
k
,
v
)
in
extra
)
{
allowedExtraKeys
.
getOrNull
(
k
.
ordinal
)
?.
let
{
stringKey
->
result
[
stringKey
]
=
v
}
?:
run
{
logger
.
debug
(
"No string value for enum ${k.ordinal}"
)
}
}
result
}
else
{
null
}
}
val
extraStrings
=
extra
?.
convertAllowedToStrings
(
allowedExtraKeys
)
@Suppress
(
"EXPERIMENTAL_API_USAGE"
)
Dispatchers
.
API
.
launch
{
...
...
@@ -89,6 +69,22 @@ data class EventMetricType<ExtraKeysEnum : Enum<ExtraKeysEnum>>(
}
}
// Convert the extra key enums to strings before passing to the storage engine
// There are two extra "keys" in play here:
// 1. The Kotlin enumeration names, in CamelCase
// 2. The keys sent in the ping, in snake_case
// Here we need to get (2) to send in the ping.
private
fun
Map
<
ExtraKeysEnum
,
String
>.
convertAllowedToStrings
(
allowedKeys
:
List
<
String
>):
Map
<
String
,
String
>?
=
mapNotNull
{
(
k
,
v
)
->
val
stringKey
=
allowedKeys
.
getOrNull
(
k
.
ordinal
)
if
(
stringKey
!=
null
)
{
stringKey
to
v
}
else
run
{
logger
.
debug
(
"No string value for enum ${k.ordinal}"
)
null
}
}.
toMap
()
/**
* Tests whether a value is stored for the metric for testing purposes only. This function will
* attempt to await the last task (if any) writing to the the metric's storage engine before
...
...
components/service/glean/src/test/java/mozilla/components/service/glean/GleanTest.kt
View file @
152dd3fb
...
...
@@ -22,22 +22,21 @@ import mozilla.components.service.glean.private.Lifetime
import
mozilla.components.service.glean.private.NoExtraKeys
import
mozilla.components.service.glean.private.PingType
import
mozilla.components.service.glean.private.StringMetricType
import
mozilla.components.service.glean.private.TimeUnit
as
GleanTimeUnit
import
mozilla.components.service.glean.private.UuidMetricType
import
mozilla.components.service.glean.storages.StringsStorageEngine
import
mozilla.components.service.glean.scheduler.GleanLifecycleObserver
import
mozilla.components.service.glean.scheduler.PingUploadWorker
import
mozilla.components.service.glean.storages.StorageEngineManager
import
mozilla.components.service.glean.storages.StringsStorageEngine
import
mozilla.components.service.glean.utils.getLanguageFromLocale
import
mozilla.components.service.glean.utils.getLocaleTag
import
org.json.JSONObject
import
org.junit.Assert.assertEquals
import
org.junit.Assert.assertFalse
import
org.junit.Assert.assertNotEquals
import
org.junit.Assert.assertNotNull
import
org.junit.Assert.assertNull
import
org.junit.Assert.assertSame
import
org.junit.Assert.assertTrue
import
org.junit.Assert.assertFalse
import
org.junit.Assert.assertNotEquals
import
org.junit.Before
import
org.junit.Test
import
org.junit.runner.RunWith
...
...
@@ -49,11 +48,12 @@ import org.robolectric.RobolectricTestRunner
import
java.io.BufferedReader
import
java.io.File
import
java.io.FileReader
import
java.
lang.AssertionError
import
java.
time.Instant
import
java.util.Date
import
java.util.Locale
import
java.util.UUID
import
java.util.concurrent.TimeUnit
import
mozilla.components.service.glean.private.TimeUnit
as
GleanTimeUnit
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
...
...
@@ -373,7 +373,8 @@ class GleanTest {
sendInPings
=
listOf
(
"glean_ping_info"
),
timeUnit
=
GleanTimeUnit
.
Day
)
firstRunDateMetric
.
set
(
Date
(
2200
,
1
,
1
))
firstRunDateMetric
.
set
(
Date
.
from
(
Instant
.
parse
(
"2200-01-01T00:00:00.00Z"
)))
assertTrue
(
GleanInternalMetrics
.
clientId
.
testHasValue
())
assertTrue
(
GleanInternalMetrics
.
firstRunDate
.
testHasValue
())
...
...
components/service/glean/src/test/java/mozilla/components/service/glean/private/EventMetricTypeTest.kt
View file @
152dd3fb
...
...
@@ -4,22 +4,19 @@
package
mozilla.components.service.glean.private
import
android.content.Context
import
android.os.SystemClock
import
androidx.test.core.app.ApplicationProvider
import
kotlinx.coroutines.ExperimentalCoroutinesApi
import
kotlinx.coroutines.ObsoleteCoroutinesApi
import
mozilla.components.service.glean.Glean
import
mozilla.components.service.glean.resetGlean
import
org.junit.Assert.assertEquals
import
org.junit.Assert.assertTrue
import
org.junit.Assert.assertFalse
import
org.junit.Assert.assertTrue
import
org.junit.Assert.fail
import
org.junit.Test
import
org.junit.Before
import
org.junit.Test
import
org.junit.runner.RunWith
import
org.robolectric.RobolectricTestRunner
import
java.lang.NullPointerException
// Declared here, since Kotlin can not declare nested enum classes.
enum
class
click
Keys
{
...
...
@@ -184,8 +181,6 @@ class EventMetricTypeTest {
@Test
fun
`events
should
not
record
when
upload
is
disabled`
()
{
val
context
=
ApplicationProvider
.
getApplicationContext
<
Context
>()
val
eventMetric
=
EventMetricType
<
test
NameKeys
>(
disabled
=
false
,
category
=
"ui"
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment