Skip to content

Commit

Permalink
Migrate internal classes to Kotlin (close #564)
Browse files Browse the repository at this point in the history
PR #570

* Prepare for 5.0.0-alpha.1 release

* Translate EmitterConfig

* Translate EmitterControllerImpl

* Halfway through Emitter

* Translate Emitter stuff

* Translate GDPR stuff

* Translate global contexts stuff

* Translate remote config stuff

* Translate Session stuff

* Translate utils and remove Preconditions

* Fix some types

* Remove deprecated LifecycleOwner in ProcessObserver

* Translate deeplinkstate, activitylifecyclehandler, exceptionhandler

* Add static annotation

* Update tests

* Refactor EmitterBuilder

* Remove dodgy cast

* Translate InstallTracker

* Translate some state stuff

* Translate more state stuff

* Translate subject config stuff

* Translate tracker config stuff

* Specify minimum API level 24

* Translate TrackerEvent

* Translate Logger

* Translate PlatformContext

* Translate SchemaRule

* Translate ServiceProviderInterface

* Translate TrackerWebViewInterface

* Translate Subject

* Translate Tracker, remove TrackerBuilder

* Change other stuff in Tracker

* Make tests build

* Translate ConsentGranted/Withdrawn tests

* Remove AndroidTestCase from tests

* Change EmitterConfigurationUpdate methods into properties

* Translate DeepLinkReceived test

* Translate ApplicationInstall test

* Translate MockEventStore

* Use properties instead of methods in all ConfigUpdate classes

* Remove some brackets

* Translate ECommerce tests

* Translate remaining Event tests

* Translate globalcontext tests

* Add @test annotation for EventStore tests

* Translate EventStore tests

* Translate remote config tests

* Translate ConfigurationTest

* Translate some more tests

* Translate TrackerTest

* Translate Utils tests

* Translate payload tests

* Translate TLSArguments test

* Translate NoiseTest

* Translate some more tests

* Translate LoggingTest

* Translate NetworkConnection tests

* Translate some more tests

* Translate Subject tests

* Translate webview tests

* Translate SessionTest

* Translate EmitterTest

* Translate EventSendingTest

* Translate StateManagerTest

* Remove API 21 from GH workflow test matrix

* Remove legacy v1 v2 Session methods

* Make configUpdate booleans private

* Standardise Tracker/Emitter defaults

* Update TrackerDefaults

* Don't allow null in contexts list

* Remove @JvmField annotations

* Update EventStore interface to be all functions

* Make Util methods all methods

* Tidy up some other functions/properties

* Update tests to use eventStore size function

* Remove unsafe null calls from Emitter

* Make Session null safe

* Update SessionController properties to optionals

* Make DeepLinkStateMachine null safe

* Make LifecycleStateMachine null safe

* Make ScreenStateMachine safe

* Make ServiceProvider safer

* Make StateManager safe

* Make ServiceProvider even safer

* Make Subject null safe

* Fix Tracker test

* Fix LoggerDelegate assignment

* Make TrackerEvent and others null safe

* Make DeviceInfoMonitor safe

* Make utils safe

* Only allow non-null schemas for StateMachines

* Fix Session test

* Make config classes null safe

* Make events safe

* Make global contexts safe

* Make network stuff null safe

* Make payloads safe

* Make Snowplow class safe

* Use HTTPS as default

* Move Emitter- and TrackerDefaults to core

* Fix Tracker test

* Replace context test import

* Use Kotlin lambda instead of Consumer

* Increase API target to 32

* Don't test API 32 after all

* Configure emitTimeout via NetworkConfiguration

* Add docs for 'secret' config options

* Remove unused private Tracker method

* Put the 'get' back in getOrMake method names

* Use properties instead of functions for StateMachineInterface

* Fix tests

* Don't allow null maps for Payloads

* Use API target 31
  • Loading branch information
mscwilson authored Jan 31, 2023
1 parent a01464b commit d533a85
Show file tree
Hide file tree
Showing 267 changed files with 15,486 additions and 18,632 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
fail-fast: false
matrix:
api-level:
- 21
- 24
- 30

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 5.0.0-alpha.1 (2022-11-30)
--------------------------
Migrate published API to Kotlin (#561)

Version 4.1.1 (2022-12-02)
--------------------------
Hardcode the anonymised session user ID (#567)
Expand Down
2 changes: 1 addition & 1 deletion snowplow-demo-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {

defaultConfig {
applicationId "com.snowplowanalytics.snowplowtrackerdemo"
minSdkVersion 21
minSdkVersion 24
targetSdkVersion 31
versionCode 3
versionName "0.3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class Demo : Activity(), LoggerDelegate {
"this is a demo document description"
)
val gcConfiguration = GlobalContextsConfiguration(null)
val pairs: Map<String, Any> = HashMap()
val pairs: MutableMap<String, Any> = HashMap()
Util.addToMap("id", "snowplow", pairs)
Util.addToMap("email", "[email protected]", pairs)
gcConfiguration.add(
Expand Down
4 changes: 2 additions & 2 deletions snowplow-tracker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ android {
useLibrary 'android.test.base'

defaultConfig {
// With API 24: Remove `androidx.appcompat:appcompat` as it's needed for Consumer<T>.
minSdkVersion 21
minSdkVersion 24
targetSdkVersion 31
versionCode 1
versionName "$project.version"
Expand Down Expand Up @@ -81,6 +80,7 @@ dependencies {
implementation 'androidx.annotation:annotation:1.4.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.preference:preference:1.1.1'
compileOnly "androidx.lifecycle:lifecycle-extensions:$project.archLifecycleVersion"
compileOnly "com.android.installreferrer:installreferrer:2.2"
implementation fileTree(dir: 'libs', include: ['*.jar'])
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.snowplowanalytics.snowplow

import android.content.Context
import com.snowplowanalytics.core.constants.Parameters
import com.snowplowanalytics.core.utils.Util.uUIDString
import com.snowplowanalytics.core.constants.TrackerConstants

object TestUtils {
@JvmStatic
fun createSessionSharedPreferences(context: Context, namespaceId: String) {
val sessionVarsName = TrackerConstants.SNOWPLOW_SESSION_VARS + "_" + namespaceId
val sharedPreferences = context.getSharedPreferences(sessionVarsName, Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()
editor.putString(Parameters.SESSION_USER_ID, uUIDString())
editor.putString(Parameters.SESSION_ID, uUIDString())
editor.putInt(Parameters.SESSION_INDEX, 0)
editor.commit()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.snowplowanalytics.snowplow.event

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.snowplowanalytics.core.constants.TrackerConstants
import com.snowplowanalytics.core.emitter.Executor.shutdown
import com.snowplowanalytics.snowplow.Snowplow.createTracker
import com.snowplowanalytics.snowplow.configuration.EmitterConfiguration
import com.snowplowanalytics.snowplow.configuration.NetworkConfiguration
import com.snowplowanalytics.snowplow.configuration.TrackerConfiguration
import com.snowplowanalytics.snowplow.network.HttpMethod
import com.snowplowanalytics.snowplow.payload.SelfDescribingJson
import com.snowplowanalytics.snowplow.tracker.MockEventStore
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.TimeUnit

@RunWith(AndroidJUnit4::class)
class ApplicationInstallTest {
@Before
@Throws(Exception::class)
fun setUp() {
val es = shutdown()
es?.awaitTermination(60, TimeUnit.SECONDS)
}

// Tests
@Test
@Throws(InterruptedException::class)
fun testApplicationInstall() {
val context = InstrumentationRegistry.getInstrumentation().targetContext

// Prepare application install event
val installEvent = SelfDescribingJson(TrackerConstants.SCHEMA_APPLICATION_INSTALL)
val event = SelfDescribing(installEvent)
val currentTimestamp = 12345L
event.trueTimestamp = currentTimestamp

// Setup tracker
val trackerConfiguration = TrackerConfiguration("appId")
.base64encoding(false)
.installAutotracking(false)
val eventStore = MockEventStore()
val networkConfiguration = NetworkConfiguration("fake-url", HttpMethod.POST)
val emitterConfiguration = EmitterConfiguration()
.eventStore(eventStore)
.threadPoolSize(10)
val trackerController = createTracker(
context,
"namespace",
networkConfiguration,
trackerConfiguration,
emitterConfiguration
)

// Track event
trackerController.track(event)
var i = 0
while (eventStore.size() < 1 && i < 10) {
Thread.sleep(1000)
i++
}
val events = eventStore.getEmittableEvents(10)
eventStore.removeAllEvents()
Assert.assertEquals(1, events.size.toLong())
val payload = events[0]!!.payload

// Check timestamp field
val deviceTimestamp = payload.map["dtm"] as String?
val expected = currentTimestamp.toString()
Assert.assertEquals(expected, deviceTimestamp)
}
}

This file was deleted.

Loading

0 comments on commit d533a85

Please sign in to comment.