Skip to content

Commit 10732cd

Browse files
authored
Merge pull request #859
Metadata in events
2 parents c37e0b3 + 141e298 commit 10732cd

178 files changed

Lines changed: 11356 additions & 784 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/sonarqube.yml

Lines changed: 83 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: SonarCloud Analysis
22

33
on:
4+
push:
5+
branches:
6+
- master
7+
- development
8+
- '*_baseline'
49
pull_request:
510
branches:
611
- '*'
@@ -38,114 +43,101 @@ jobs:
3843
- name: Build project and run tests with coverage
3944
run: |
4045
# Build the project
41-
./gradlew assembleDebug --stacktrace
42-
43-
# Run tests with coverage - allow test failures
44-
./gradlew testDebugUnitTest jacocoTestReport --stacktrace
45-
TEST_RESULT=$?
46-
if [ $TEST_RESULT -ne 0 ]; then
47-
echo "Some tests failed, but continuing to check for coverage data..."
48-
# Even if tests fail, JaCoCo should generate a report with partial coverage
49-
# from the tests that did pass
50-
fi
51-
52-
- name: Prepare class files for SonarQube analysis
53-
run: |
54-
echo "Searching for compiled class files..."
55-
56-
# Create the target directory
57-
mkdir -p build/intermediates/runtime_library_classes_dir/debug
58-
59-
# Find all directories containing class files with better patterns
60-
CLASS_DIRS=$(find build -name "*.class" -type f -exec dirname {} \; | sort -u | grep -E "(javac|kotlin-classes|runtime_library)" | head -10)
61-
62-
if [ -z "$CLASS_DIRS" ]; then
63-
echo "WARNING: No class files found in the build directory!"
64-
echo "Searching in all build subdirectories..."
65-
find build -name "*.class" -type f | head -20
46+
./gradlew assembleDebug
47+
48+
# Run tests - continue even if some tests fail
49+
./gradlew testDebugUnitTest || echo "Some tests failed, but continuing to generate coverage report..."
50+
51+
# Generate JaCoCo aggregate report separately (ensures it runs even if tests failed)
52+
./gradlew jacocoRootReport
53+
54+
# Log report location for debugging
55+
REPORT_PATH="build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
56+
if [ -f "$REPORT_PATH" ]; then
57+
echo "✓ JaCoCo report generated at: $REPORT_PATH ($(wc -c < "$REPORT_PATH") bytes)"
6658
else
67-
echo "Found class files in the following directories:"
68-
echo "$CLASS_DIRS"
69-
70-
# Copy classes from all relevant directories, not just the first one
71-
for CLASS_DIR in $CLASS_DIRS; do
72-
if [ -d "$CLASS_DIR" ] && [ "$(find "$CLASS_DIR" -name "*.class" | wc -l)" -gt 0 ]; then
73-
echo "Copying classes from $CLASS_DIR"
74-
cp -r "$CLASS_DIR"/* build/intermediates/runtime_library_classes_dir/debug/ 2>/dev/null || echo "Failed to copy from $CLASS_DIR"
75-
fi
76-
done
77-
78-
# Verify the target directory now has class files
79-
CLASS_COUNT=$(find build/intermediates/runtime_library_classes_dir/debug -name "*.class" | wc -l)
80-
echo "Target directory now contains $CLASS_COUNT class files"
59+
echo "✗ JaCoCo report was NOT generated at: $REPORT_PATH"
8160
fi
8261
83-
# Update sonar-project.properties with all found class directories
84-
echo "" >> sonar-project.properties
85-
echo "# Additional binary paths found during build" >> sonar-project.properties
86-
if [ -n "$CLASS_DIRS" ]; then
87-
# Convert newlines to commas for sonar.java.binaries
88-
BINARY_PATHS=$(echo "$CLASS_DIRS" | tr '\n' ',' | sed 's/,$//')
89-
echo "sonar.java.binaries=build/intermediates/runtime_library_classes_dir/debug,$BINARY_PATHS" >> sonar-project.properties
62+
- name: Verify class files and coverage data for SonarQube analysis
63+
run: |
64+
echo "=== Verifying Build Artifacts for SonarQube ==="
65+
echo ""
66+
67+
# Dynamically get modules from settings.gradle (extract module names from "include ':modulename'" lines)
68+
MODULES=$(grep "^include" settings.gradle | cut -d"'" -f2 | cut -d":" -f2 | tr '\n' ' ')
69+
echo "Detected modules: $MODULES"
70+
echo ""
71+
72+
echo "Checking compiled class files for each module:"
73+
for module in $MODULES; do
74+
MODULE_CLASSES_DIR="${module}/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes"
75+
if [ -d "$MODULE_CLASSES_DIR" ]; then
76+
CLASS_COUNT=$(find "$MODULE_CLASSES_DIR" -name "*.class" | wc -l)
77+
echo " ✓ ${module}: Found $CLASS_COUNT class files in $MODULE_CLASSES_DIR"
78+
else
79+
echo " ✗ ${module}: Class directory not found: $MODULE_CLASSES_DIR"
80+
fi
81+
done
82+
83+
echo ""
84+
echo "Checking JaCoCo coverage report:"
85+
if [ -f build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml ]; then
86+
REPORT_SIZE=$(wc -c < build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml)
87+
PACKAGE_COUNT=$(grep -c "<package" build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0")
88+
CLASS_COUNT=$(grep -c "<class" build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0")
89+
LINE_COUNT=$(grep -c "<line" build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0")
90+
COVERED_LINES=$(grep -c 'ci="1"' build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml || echo "0")
91+
92+
echo " ✓ JaCoCo report found: build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
93+
echo " - Size: $REPORT_SIZE bytes"
94+
echo " - Packages: $PACKAGE_COUNT"
95+
echo " - Classes: $CLASS_COUNT"
96+
echo " - Lines: $LINE_COUNT"
97+
echo " - Covered lines: $COVERED_LINES"
98+
99+
# Check if events module coverage is present
100+
if grep -q 'package name="io/harness/events"' build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml; then
101+
echo " ✓ Events module (io/harness/events) coverage found in report"
102+
else
103+
echo " ✗ WARNING: Events module coverage NOT found in report"
104+
fi
90105
else
91-
echo "sonar.java.binaries=build/intermediates/runtime_library_classes_dir/debug" >> sonar-project.properties
106+
echo " ✗ JaCoCo report file not found"
92107
fi
93-
94-
echo "Checking for JaCoCo report files..."
95-
find build -name "*.xml" | grep jacoco || echo "No JaCoCo XML files found"
96-
find build -name "*.exec" | grep jacoco || echo "No JaCoCo exec files found"
97-
98-
echo "Contents of JaCoCo report directory:"
99-
ls -la build/reports/jacoco/jacocoTestReport/ || echo "Directory not found"
100-
108+
109+
echo ""
110+
echo "Checking JaCoCo execution data for each module:"
111+
for module in $MODULES; do
112+
EXEC_FILE="${module}/build/jacoco/testDebugUnitTest.exec"
113+
if [ -f "$EXEC_FILE" ]; then
114+
EXEC_SIZE=$(wc -c < "$EXEC_FILE")
115+
echo " ✓ ${module}: Found execution data ($EXEC_SIZE bytes) in $EXEC_FILE"
116+
else
117+
echo " ✗ ${module}: Execution data not found: $EXEC_FILE"
118+
fi
119+
done
120+
101121
echo ""
102-
echo "Checking test execution results:"
122+
echo "Test execution summary:"
103123
TEST_RESULT_FILES=$(find build -name "TEST-*.xml" 2>/dev/null)
104124
if [ -n "$TEST_RESULT_FILES" ]; then
105-
echo "Found test result files:"
106-
echo "$TEST_RESULT_FILES"
107-
# Count total tests, failures, errors
108125
TOTAL_TESTS=$(cat $TEST_RESULT_FILES | grep -o 'tests="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}')
109126
TOTAL_FAILURES=$(cat $TEST_RESULT_FILES | grep -o 'failures="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}')
110127
TOTAL_ERRORS=$(cat $TEST_RESULT_FILES | grep -o 'errors="[0-9]*"' | cut -d'"' -f2 | awk '{sum+=$1} END {print sum}')
111-
echo "Test summary: $TOTAL_TESTS tests, $TOTAL_FAILURES failures, $TOTAL_ERRORS errors"
112-
else
113-
echo "No test result files found"
114-
fi
115-
116-
echo ""
117-
echo "Checking JaCoCo report content:"
118-
if [ -f build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml ]; then
119-
echo "Report file size: $(wc -c < build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml) bytes"
120-
echo "First 500 chars of report:"
121-
head -c 500 build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
122-
echo ""
123-
echo ""
124-
echo "Counting coverage elements:"
125-
grep -c "<package" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No packages found"
126-
grep -c "<class" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No classes found"
127-
grep -c "<method" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No methods found"
128-
grep -c "<line" build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No lines found"
129-
grep -c 'ci="1"' build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml || echo "No covered lines found"
128+
echo " Tests: $TOTAL_TESTS | Failures: $TOTAL_FAILURES | Errors: $TOTAL_ERRORS"
130129
else
131-
echo "JaCoCo report file not found"
130+
echo " No test result files found"
132131
fi
133-
134-
echo ""
135-
echo "Checking binary directories specified in sonar-project.properties:"
136-
echo "build/intermediates/runtime_library_classes_dir/debug:"
137-
ls -la build/intermediates/runtime_library_classes_dir/debug || echo "Directory not found"
138-
132+
139133
echo ""
140-
echo "Checking all available class directories:"
141-
find build -path "*/build/*" -name "*.class" | head -n 10 || echo "No class files found"
142-
143-
echo ""
144-
echo "Final sonar-project.properties content:"
134+
echo "SonarQube configuration (sonar-project.properties):"
145135
cat sonar-project.properties
136+
echo ""
137+
echo "=== Verification Complete ==="
146138
147139
- name: SonarCloud Scan
148-
uses: SonarSource/sonarqube-scan-action@v6
140+
uses: SonarSource/sonarqube-scan-action@v7
149141
env:
150142
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
151143
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}

api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

api/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# API module
2+
3+
This module contains the public API interfaces and types exposed to consumers of the Split SDK.
4+
5+
Classes in this module are part of the public API contract and should maintain backwards compatibility.

api/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id 'com.android.library'
3+
}
4+
5+
apply from: "$rootDir/gradle/common-android-library.gradle"
6+
7+
android {
8+
namespace 'io.split.android.client.api'
9+
10+
compileOptions {
11+
sourceCompatibility JavaVersion.VERSION_1_8
12+
targetCompatibility JavaVersion.VERSION_1_8
13+
}
14+
}
15+
16+
dependencies {
17+
implementation libs.annotation
18+
19+
testImplementation libs.junit4
20+
testImplementation libs.mockitoCore
21+
}
22+

api/consumer-rules.pro

Whitespace-only changes.

api/proguard-rules.pro

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
22+

api/src/androidTest/java/.gitkeep

Whitespace-only changes.

api/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>
5+

main/src/main/java/io/split/android/client/EvaluationOptions.java renamed to api/src/main/java/io/split/android/client/EvaluationOptions.java

File renamed without changes.

main/src/main/java/io/split/android/client/SplitClient.java renamed to api/src/main/java/io/split/android/client/SplitClient.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Map;
88

99
import io.split.android.client.attributes.AttributesManager;
10+
import io.split.android.client.events.SplitEventListener;
1011
import io.split.android.client.events.SplitEvent;
1112
import io.split.android.client.events.SplitEventTask;
1213

@@ -179,6 +180,42 @@ public interface SplitClient extends AttributesManager {
179180

180181
void on(SplitEvent event, SplitEventTask task);
181182

183+
/**
184+
* Registers an event listener for SDK events that provide typed metadata.
185+
* <p>
186+
* This method provides type-safe callbacks for SDK_READY, SDK_UPDATE, and SDK_READY_FROM_CACHE events.
187+
* Override the methods you need in the listener.
188+
* <p>
189+
* Multiple listeners can be registered. Each listener will be invoked once per event.
190+
* <p>
191+
* Example usage:
192+
* <pre>{@code
193+
* client.addEventListener(new SdkEventListener() {
194+
* @Override
195+
* public void onReady(SplitClient client, SdkReadyMetadata metadata) {
196+
* Boolean initialCacheLoad = metadata.isInitialCacheLoad();
197+
* // Handle SDK ready on background thread
198+
* }
199+
*
200+
* @Override
201+
* public void onUpdate(SplitClient client, SdkUpdateMetadata metadata) {
202+
* SdkUpdateMetadata.Type type = metadata.getType(); // FLAGS_UPDATE or SEGMENTS_UPDATE
203+
* List<String> names = metadata.getNames(); // updated flag/segment names
204+
* // Handle on background thread
205+
* }
206+
*
207+
* @Override
208+
* public void onReadyFromCacheView(SplitClient client, SdkReadyMetadata metadata) {
209+
* // Handle on main/UI thread
210+
* Boolean initialCacheLoad = metadata.isInitialCacheLoad();
211+
* }
212+
* });
213+
* }</pre>
214+
*
215+
* @param listener the event listener to register. Must not be null.
216+
*/
217+
void addEventListener(@NonNull SplitEventListener listener);
218+
182219
/**
183220
* Enqueue a new event to be sent to Split data collection services.
184221
* <p>

0 commit comments

Comments
 (0)