Skip to content

Commit 61fcacf

Browse files
authored
feat: split LogoutListener from AttributeListener (#685)
* feat: split LogoutListener from AttributeListener * feat: use local versions in ci during the checks
1 parent 71c4c53 commit 61fcacf

22 files changed

Lines changed: 139 additions & 50 deletions

File tree

.github/workflows/daily.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ jobs:
224224
uses: actions/checkout@v6
225225
with:
226226
ref: regression/${{ github.run_number }}
227+
- run: echo "ORG_GRADLE_PROJECT_VERSION=$(head -n 1 VERSION)" >> $GITHUB_ENV
228+
- run: echo "ORG_GRADLE_PROJECT_version=$(head -n 1 VERSION)" >> $GITHUB_ENV
227229
- name: "Install JDK 17"
228230
uses: actions/setup-java@v5
229231
with:
@@ -233,12 +235,11 @@ jobs:
233235
- name: "Run Android Core SDK Lint"
234236
run: ./gradlew lint
235237
- name: "Setup Android Kit Lint"
236-
run: ./gradlew publishMavenPublicationToMavenLocal -PVERSION=$(head -n 1 VERSION)
238+
run: ./gradlew publishMavenPublicationToMavenLocal
237239
- name: "Run Android Kit Lint"
238-
run: ./gradlew lint -c settings-kits.gradle
240+
run: ./gradlew lint -c settings-kits.gradle -Pmparticle.kit.mparticleFromMavenLocalOnly=true
239241
- name: "Run Isolated Kit Lint (urbanairship-kit)"
240-
working-directory: kits/urbanairship/urbanairship-20
241-
run: ./gradlew lint
242+
run: ./gradlew -Pmparticle.kit.mparticleFromMavenLocalOnly=true -p kits/urbanairship/urbanairship-20 lint
242243
- name: "Archive Test Results"
243244
uses: actions/upload-artifact@v7
244245
if: always()
@@ -262,6 +263,8 @@ jobs:
262263
uses: actions/checkout@v6
263264
with:
264265
ref: regression/${{ github.run_number }}
266+
- run: echo "ORG_GRADLE_PROJECT_VERSION=$(head -n 1 VERSION)" >> $GITHUB_ENV
267+
- run: echo "ORG_GRADLE_PROJECT_version=$(head -n 1 VERSION)" >> $GITHUB_ENV
265268
- name: "Install JDK 17"
266269
uses: actions/setup-java@v5
267270
with:
@@ -271,12 +274,11 @@ jobs:
271274
- name: "Run Android Core SDK Kotlin Lint"
272275
run: ./gradlew ktlintCheck
273276
- name: "Setup Android Kit Kotlin Lint"
274-
run: ./gradlew publishMavenPublicationToMavenLocal -PVERSION=$(head -n 1 VERSION)
277+
run: ./gradlew publishMavenPublicationToMavenLocal
275278
- name: "Run Android Kit Kotlin Lint"
276-
run: ./gradlew ktlintCheck -c settings-kits.gradle
279+
run: ./gradlew ktlintCheck -c settings-kits.gradle -Pmparticle.kit.mparticleFromMavenLocalOnly=true
277280
- name: "Run Isolated Kit Kotlin Lint (urbanairship-kit)"
278-
working-directory: kits/urbanairship/urbanairship-20
279-
run: ./gradlew ktlintCheck
281+
run: ./gradlew -Pmparticle.kit.mparticleFromMavenLocalOnly=true -p kits/urbanairship/urbanairship-20 ktlintCheck
280282
- name: "Archive Test Results"
281283
uses: actions/upload-artifact@v7
282284
if: always()
@@ -305,19 +307,20 @@ jobs:
305307
with:
306308
repository: mparticle/mparticle-android-sdk
307309
ref: regression/${{ github.run_number }}
310+
- run: echo "ORG_GRADLE_PROJECT_VERSION=$(head -n 1 VERSION)" >> $GITHUB_ENV
311+
- run: echo "ORG_GRADLE_PROJECT_version=$(head -n 1 VERSION)" >> $GITHUB_ENV
308312
- name: "Install JDK 17"
309313
uses: actions/setup-java@v5
310314
with:
311315
distribution: "zulu"
312316
java-version: "17"
313317
cache: "gradle"
314318
- name: "Build Android Core"
315-
run: ./gradlew clean publishMavenPublicationToMavenLocal -PVERSION=$(head -n 1 VERSION)
319+
run: ./gradlew clean publishMavenPublicationToMavenLocal
316320
- name: "Test Kits"
317-
run: ./gradlew clean testRelease -c settings-kits.gradle
321+
run: ./gradlew clean testRelease -c settings-kits.gradle -Pmparticle.kit.mparticleFromMavenLocalOnly=true
318322
- name: "Test Isolated Kits (urbanairship-kit)"
319-
working-directory: kits/urbanairship/urbanairship-20
320-
run: ./gradlew clean testRelease
323+
run: ./gradlew -Pmparticle.kit.mparticleFromMavenLocalOnly=true -p kits/urbanairship/urbanairship-20 clean testRelease
321324

322325
semantic-release-dryrun:
323326
name: "Test Semantic Release - Dry Run"

.github/workflows/pull-request.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ jobs:
100100
steps:
101101
- name: "Checkout Branch"
102102
uses: actions/checkout@v6
103+
- run: echo "ORG_GRADLE_PROJECT_VERSION=$(head -n 1 VERSION)" >> $GITHUB_ENV
104+
- run: echo "ORG_GRADLE_PROJECT_version=$(head -n 1 VERSION)" >> $GITHUB_ENV
103105
- name: "Install JDK 17"
104106
uses: actions/setup-java@v5
105107
with:
@@ -108,9 +110,9 @@ jobs:
108110
- name: "Run Android Core SDK Lint"
109111
run: ./gradlew lint
110112
- name: "Setup Android Kit Lint"
111-
run: ./gradlew publishMavenPublicationToMavenLocal -PVERSION=$(head -n 1 VERSION)
113+
run: ./gradlew publishMavenPublicationToMavenLocal
112114
- name: "Run Android Kit Lint"
113-
run: ./gradlew -c settings-kits.gradle lint
115+
run: ./gradlew -c settings-kits.gradle -Pmparticle.kit.mparticleFromMavenLocalOnly=true lint
114116
- name: "Archive Lint Test Results"
115117
uses: actions/upload-artifact@v7
116118
if: always()
@@ -125,6 +127,8 @@ jobs:
125127
steps:
126128
- name: "Checkout Branch"
127129
uses: actions/checkout@v6
130+
- run: echo "ORG_GRADLE_PROJECT_VERSION=$(head -n 1 VERSION)" >> $GITHUB_ENV
131+
- run: echo "ORG_GRADLE_PROJECT_version=$(head -n 1 VERSION)" >> $GITHUB_ENV
128132
- name: "Install JDK 17"
129133
uses: actions/setup-java@v5
130134
with:
@@ -133,9 +137,9 @@ jobs:
133137
- name: "Run Android Core SDK Kotlin Lint"
134138
run: ./gradlew ktlintCheck
135139
- name: "Setup Android Kit Kotlin Lint"
136-
run: ./gradlew publishMavenPublicationToMavenLocal -PVERSION=$(head -n 1 VERSION)
140+
run: ./gradlew publishMavenPublicationToMavenLocal
137141
- name: "Run Android Kit Kotlin Lint"
138-
run: ./gradlew -c settings-kits.gradle ktlintCheck
142+
run: ./gradlew -c settings-kits.gradle -Pmparticle.kit.mparticleFromMavenLocalOnly=true ktlintCheck
139143
- name: "Archive Kotlin Lint Test Results"
140144
uses: actions/upload-artifact@v7
141145
if: always()
@@ -156,20 +160,21 @@ jobs:
156160
steps:
157161
- name: "Checkout Branch"
158162
uses: actions/checkout@v6
163+
- run: echo "ORG_GRADLE_PROJECT_VERSION=$(head -n 1 VERSION)" >> $GITHUB_ENV
164+
- run: echo "ORG_GRADLE_PROJECT_version=$(head -n 1 VERSION)" >> $GITHUB_ENV
159165
- name: "Install JDK 17"
160166
uses: actions/setup-java@v5
161167
with:
162168
distribution: "zulu"
163169
java-version: "17"
164170
- name: "Generate Core Release Build"
165-
run: ./gradlew publishMavenPublicationToMavenLocal -PVERSION=$(head -n 1 VERSION)
171+
run: ./gradlew publishMavenPublicationToMavenLocal
166172
- name: "Run Kit-Base Release Tests and Build"
167-
run: ./gradlew :android-kit-base:testRelease -PVERSION=$(head -n 1 VERSION)
173+
run: ./gradlew :android-kit-base:testRelease
168174
- name: "Run Kit Release Tests and Build"
169-
run: ./gradlew -p kits testRelease -c ../settings-kits.gradle -PVERSION=$(head -n 1 VERSION)
175+
run: ./gradlew -p kits testRelease -c ../settings-kits.gradle -Pmparticle.kit.mparticleFromMavenLocalOnly=true
170176
- name: "Run Isolated Kit Compatibility Tests (urbanairship)"
171-
working-directory: kits/urbanairship/urbanairship-20
172-
run: ./gradlew -PisRelease=true testRelease
177+
run: ./gradlew -Pmparticle.kit.mparticleFromMavenLocalOnly=true -p kits/urbanairship/urbanairship-20 -PisRelease=true testRelease
173178

174179
automerge-dependabot:
175180
name: "Save PR Number for Dependabot Automerge"

.trunk/trunk.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ runtimes:
2727
lint:
2828
enabled:
2929
- actionlint@1.7.7
30-
- checkov@3.2.470
30+
- checkov@3.2.513
3131
- git-diff-check
3232
- ktlint@1.7.1
33-
- markdownlint@0.45.0
34-
- prettier@3.6.2
33+
- markdownlint@0.48.0
34+
- prettier@3.8.1
3535
- shellcheck@0.11.0
3636
- shfmt@3.6.0
3737
- trufflehog@3.90.6

android-kit-base/src/androidTest/kotlin/com/mparticle/kits/testkits/AttributeListenerTestKit.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.mparticle.kits.testkits
22

33
import com.mparticle.MParticle
4-
import com.mparticle.kits.KitIntegration
4+
import com.mparticle.kits.KitIntegration.AttributeListener
5+
import com.mparticle.kits.KitIntegration.LogoutListener
56
import com.mparticle.kits.ReportingMessage
67

78
open class AttributeListenerTestKit :
89
ListenerTestKit(),
9-
KitIntegration.AttributeListener {
10+
AttributeListener,
11+
LogoutListener {
1012
var setUserAttribute: ((attributeKey: String?, attributeValue: String?) -> Unit)? = null
1113
var setUserAttributeList: ((attributeKey: String?, attributeValueList: List<String?>?) -> Unit)? =
1214
null

android-kit-base/src/main/java/com/mparticle/kits/KitIntegration.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,21 @@ public interface SessionListener {
345345
List<ReportingMessage> onSessionEnd();
346346
}
347347

348+
/**
349+
* Kits may implement this interface to respond when the mParticle Identity API performs a logout.
350+
*/
351+
public interface LogoutListener {
352+
353+
/**
354+
* The mParticle SDK exposes a logout API, allowing developers to track an event
355+
* when a user logs out of their app/platform. Use this opportunity to perform the appropriate logic
356+
* as per your platforms logout paradigm, such as clearing user attributes.
357+
*
358+
* @return Kits should return a List of ReportingMessages indicating that the logout was processed one or more times, or null if it was not processed
359+
*/
360+
List<ReportingMessage> logout();
361+
}
362+
348363
/**
349364
* Kits should implement this interface when their underlying service has the notion
350365
* of a user with attributes.
@@ -374,15 +389,6 @@ public interface AttributeListener {
374389

375390
void removeUserIdentity(MParticle.IdentityType identityType);
376391

377-
/**
378-
* The mParticle SDK exposes a logout API, allowing developers to track an event
379-
* when a user logs out of their app/platform. Use this opportunity to perform the appropriate logic
380-
* as per your platforms logout paradigm, such as clearing user attributes.
381-
*
382-
* @return Kits should return a List of ReportingMessages indicating that the logout was processed one or more times, or null if it was not processed
383-
*/
384-
List<ReportingMessage> logout();
385-
386392
}
387393

388394
/**

android-kit-base/src/main/java/com/mparticle/kits/KitManagerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.mparticle.internal.Logger;
4040
import com.mparticle.internal.MPUtility;
4141
import com.mparticle.internal.ReportingManager;
42+
import com.mparticle.kits.KitIntegration.LogoutListener;
4243
import com.mparticle.kits.mappings.CustomMapping;
4344
import com.mparticle.rokt.RoktOptions;
4445

@@ -809,9 +810,8 @@ public void removeUserIdentity(MParticle.IdentityType identityType) {
809810
public void logout() {
810811
for (KitIntegration provider : providers.values()) {
811812
try {
812-
if (provider instanceof KitIntegration.AttributeListener && !provider.isDisabled()) {
813-
List<ReportingMessage> report = ((KitIntegration.AttributeListener) provider).logout();
814-
getReportingManager().logAll(report);
813+
if (provider instanceof LogoutListener listener && !provider.isDisabled()) {
814+
getReportingManager().logAll(listener.logout());
815815
}
816816
} catch (Exception e) {
817817
Logger.warning("Failed to call logout for kit: " + provider.getName() + ": " + e.getMessage());

kit-plugin/src/main/groovy/com/mparticle/kits/KitPlugin.groovy

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ package com.mparticle.kits
33
import com.android.build.gradle.LibraryExtension
44
import org.gradle.api.Plugin
55
import org.gradle.api.Project
6+
import org.gradle.api.artifacts.dsl.RepositoryHandler
67

78
class KitPlugin implements Plugin<Project> {
89
void apply(Project target) {
910

1011
//formerly in kit-common.gradle
1112
target.apply(plugin: 'com.android.library')
1213
target.group = 'com.mparticle'
13-
target.buildscript.repositories.add(target.repositories.mavenLocal())
14-
target.buildscript.repositories.add(target.repositories.google())
15-
target.buildscript.repositories.add(target.repositories.mavenCentral())
16-
target.repositories.add(target.repositories.mavenLocal())
17-
target.repositories.add(target.repositories.google())
18-
target.repositories.add(target.repositories.mavenCentral())
14+
boolean mparticleFromMavenLocalOnly = resolveMparticleFromMavenLocalOnly(target)
15+
configureRepositories(target.buildscript.repositories, mparticleFromMavenLocalOnly)
16+
configureRepositories(target.repositories, mparticleFromMavenLocalOnly)
1917
target.configurations.create('deployerJars')
20-
def kitBaseVersion = target.findProperty('VERSION') ?: '+'
18+
// VERSION from CI is often set only on the root project (e.g. ORG_GRADLE_PROJECT_VERSION); kit
19+
// subprojects do not always inherit it, which would fall back to '+' and unstable resolution.
20+
def kitBaseVersion =
21+
target.findProperty('VERSION') ?: target.rootProject.findProperty('VERSION') ?: '+'
2122
target.dependencies.add('api', 'com.mparticle:android-kit-base:' + kitBaseVersion)
2223
target.dependencies.add('testImplementation', 'junit:junit:4.13.2')
2324
target.dependencies.add('testImplementation', 'org.mockito:mockito-core:1.10.19')
@@ -57,5 +58,47 @@ class KitPlugin implements Plugin<Project> {
5758
// no-op: publish plugin unavailable outside monorepo
5859
}
5960
}
61+
62+
/**
63+
* When true, {@code com.mparticle} artifacts (e.g. android-kit-base, android-kit-plugin) resolve
64+
* only from {@code mavenLocal()}; Maven Central / Google are not queried for that group.
65+
* Use after {@code publishMavenPublicationToMavenLocal} so CI and monorepo kit builds use the
66+
* freshly published local artifacts. Enable with {@code -Pmparticle.kit.mparticleFromMavenLocalOnly=true}
67+
* or env {@code MPARTICLE_KIT_FROM_MAVEN_LOCAL_ONLY=true}.
68+
*/
69+
private static boolean resolveMparticleFromMavenLocalOnly(Project target) {
70+
String prop = target.findProperty('mparticle.kit.mparticleFromMavenLocalOnly')?.toString()
71+
if (prop != null && Boolean.parseBoolean(prop)) {
72+
return true
73+
}
74+
String env = System.getenv('MPARTICLE_KIT_FROM_MAVEN_LOCAL_ONLY')
75+
return env != null && 'true'.equalsIgnoreCase(env)
76+
}
77+
78+
private static void configureRepositories(RepositoryHandler repositories, boolean mparticleFromMavenLocalOnly) {
79+
if (mparticleFromMavenLocalOnly) {
80+
// Root build scripts may have already attached unfiltered repos. Rebuild this
81+
// project's repository chain so com.mparticle cannot resolve outside mavenLocal().
82+
def existingRepos = repositories.toList()
83+
existingRepos.each { repo ->
84+
repositories.remove(repo)
85+
}
86+
repositories.mavenLocal {
87+
content {
88+
includeGroup 'com.mparticle'
89+
}
90+
}
91+
repositories.google()
92+
repositories.mavenCentral {
93+
content {
94+
excludeGroup 'com.mparticle'
95+
}
96+
}
97+
} else {
98+
repositories.mavenLocal()
99+
repositories.google()
100+
repositories.mavenCentral()
101+
}
102+
}
60103
}
61104

kits/adobe/adobe-5/src/main/kotlin/com/mparticle/kits/AdobeKitBase.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.mparticle.internal.MPUtility
77
import com.mparticle.internal.MPUtility.AdIdInfo
88
import com.mparticle.kits.KitIntegration.ApplicationStateListener
99
import com.mparticle.kits.KitIntegration.AttributeListener
10+
import com.mparticle.kits.KitIntegration.LogoutListener
1011
import com.mparticle.kits.KitIntegration.PushListener
1112
import org.json.JSONException
1213
import org.json.JSONObject
@@ -16,6 +17,7 @@ import java.net.URL
1617
abstract class AdobeKitBase :
1718
KitIntegration(),
1819
AttributeListener,
20+
LogoutListener,
1921
PushListener,
2022
ApplicationStateListener {
2123
private val dVer = "2"
@@ -138,7 +140,7 @@ abstract class AdobeKitBase :
138140
dcsRegion,
139141
pushId,
140142
gaid,
141-
userIdentities,
143+
currentUser?.userIdentities ?: emptyMap(),
142144
)
143145
}
144146

kits/adobemedia/adobemedia-5/src/main/kotlin/com/mparticle/kits/AdobeKit.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.mparticle.MParticle
2020
import com.mparticle.kits.KitIntegration.ApplicationStateListener
2121
import com.mparticle.kits.KitIntegration.AttributeListener
2222
import com.mparticle.kits.KitIntegration.EventListener
23+
import com.mparticle.kits.KitIntegration.LogoutListener
2324
import com.mparticle.kits.KitIntegration.PushListener
2425
import com.mparticle.media.events.ContentType
2526
import com.mparticle.media.events.EventAttributes
@@ -36,6 +37,7 @@ open class AdobeKit :
3637
KitIntegration(),
3738
EventListener,
3839
AttributeListener,
40+
LogoutListener,
3941
PushListener,
4042
ApplicationStateListener {
4143
companion object {

kits/appsflyer/appsflyer-6/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ import com.mparticle.commerce.Product
3131
import com.mparticle.consent.ConsentState
3232
import com.mparticle.internal.Logger
3333
import com.mparticle.internal.MPUtility
34+
import com.mparticle.kits.KitIntegration.LogoutListener
3435
import org.json.JSONArray
3536
import org.json.JSONException
3637
import org.json.JSONObject
3738
import java.math.BigDecimal
3839
import java.util.LinkedList
40+
import com.mparticle.kits.KitIntegration.AttributeListener
3941

4042
/**
4143
* mParticle Kit wrapper for the AppsFlyer SDK
4244
*/
4345
class AppsFlyerKit :
4446
KitIntegration(),
4547
KitIntegration.EventListener,
46-
KitIntegration.AttributeListener,
48+
AttributeListener,
49+
LogoutListener,
4750
KitIntegration.CommerceListener,
4851
AppsFlyerConversionListener,
4952
KitIntegration.ActivityListener,

0 commit comments

Comments
 (0)