Skip to content

Commit 136f7ae

Browse files
novalisdenahiz4kn4feinadams85
authored
Config v6 (#18)
* SDKKey validation updated to handle proxy and new key format * Comparators rework Removed:IS ONE OF, IS NOT ONE OF Changed: CONTAINS, DOES_NOT_CONTAIN Added: DATE_BEFORE, DATE_AFTER, HASHED_EQUALS, HASHED_NOT_EQUALS, HASHED_STARTS_WITH, HASHED_ENDS_WITH, HASHED_ARRAY_CONTAINS, HASHED_ARRAY_NOT_CONTAINS * Fix comparators names * Fix comparator names and add new comparator * v6 and models added * Implement evaluatePrerequisiteFlagCondition and added v6 tests * Fix comparator and other errors * Added segments impl and test * Rename ComparisonCondition to UserCondition * Added logs to new code * Evaluation logger * Evaluation logs and tests finished * Logs NumberFormat updated and DateUTC fixed * Remove TODOs * EvaluateLogger depends on LogLevel * v5 and v6 sdkKey updates * EvaluationLoggerTurnOffTest updated with LogLevel checks * Added attributeValueFrom user helper methods. (no date yet) * Format code * Fix matrix test v5vsV6. Add remoteJson to tests * Detekt fixes * Ktlint fixes * Add docs * Fix list truncation * Date double value format fix. Cannot convert to Long because it's not milliseconds * Fix JS test errors. Lint and detekt problems. * Added text comparators. Updated segments evaluation. Updated tests. * Unicode test and fixes added * Small fix and reduce logged info in tests * Evaluator warning fixes * Format * Fix failing JS tests * Remove println * Added tests and small fixes. CCUser handle Any values * JS number settingtype added to handle JS number conversion. * Fix JS Evaluation fails because of cache message * Update 1103 error message * Fix circular dependency missing remove. * Rename Comparator to USerComparator. Fix user attribute override. Set evaluateConditions default result to true. Fix variationIDTests json. Fix getKeyAndValue method to handle targetRule percentage options as well. * Fix getKeyAndValue targeting rule if. Add exception to evaluatePercentageOptions if sum is not 100%. * Move configSalt validation from deserialization. * update processHashedStartEndsWithCompare handle sliced String * Update trim and refactor process methods. * Accept NaN * Added extra segment and prerequisite tests * Error message fixes * SDK key validation LOCAL_ONLY fix * Code format * Fix httpEngine in test * klint fix * Added missing PrerequisiteFlag Override Test * Add trim test Fix user value version trim * Add trim test Fix user value version trim * Fix user toString use simple json. Fix comparatorsTests. * Fix Array and List convert to String to use json. * Add specialCharacter test * Refactor LogHelper * Platform based double format WIP * Set stringbuilder lineseparator as default * Lint fixes * Fixes after merge. Exclude native format test. * Change DataSource setting to config. Fix override test. Fix missing segment and configSalt mapping. * JS platform send agent and etag info in the request query params. * Remove expected NumberFormatter class. Now just the doubleToString method expected and implemented. * Fix date conversions * Fix log double format. Now only the native platform is different from the expected. * NSNumberFormatter added (not tested) * lint fix * fix imports * Added darwinTest module * Try to fix darwin number formatter * Type validation updated and some test added * lint fix * Try to fix formatter * Update NumberFormatter.kt * darwin test fix * darwin test fix * darwin test fix * Fix test after merge. Move EvaluateLogger to a new file. * Value type and setting type validation fixed. getAnyValue and getAnyValueDetails check allowed types. Missing hooks and error logging added. getAnyValue and getAnyValueDetails allow null defaultValue. Fix tests based on changes and add some type validation tests. * Fix tests * Fix darwin test * Update version to 3.0.0 * Fixes on model based on code review * Fixes based on code review * Fixes based on code review * Fix based on code review * Refactor getValue/getAnyValue and getValueDetails/getAnyValueDetails to have a consistent behavior with other SDKs (#27) * Hashed length trim added * Fixes based on review * Add analysis to PR checks * Detekt and lint fixes * SemVer fix. Lint fix * Added when fix * Add tests * klint fix * detekt fix * Add more test * Fix testGetValueDetailsValidTypes * Fix test error * Moved Utils method to internal object * Detekt fix * Lint fix * Rename Utils file to Constants and internal object Utils to Helpers * Added FlagValueSerializer tests * Update fetcher param test to check http/2 headers. * Added getKeyAndValue tests --------- Co-authored-by: Peter Csajtai <[email protected]> Co-authored-by: adams85 <[email protected]>
1 parent 3769a53 commit 136f7ae

File tree

113 files changed

+36370
-1022
lines changed

Some content is hidden

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

113 files changed

+36370
-1022
lines changed

.github/workflows/test.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,90 @@ jobs:
5050
uses: ./.github/actions/cache-gradle
5151
- name: Run format check
5252
run: ./gradlew ktlintCheck --stacktrace
53+
shell: bash
54+
55+
analysis:
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v4
59+
- name: Set up JDK
60+
uses: actions/setup-java@v4
61+
with:
62+
java-version: 17
63+
distribution: zulu
64+
- name: Cache Konan
65+
uses: ./.github/actions/cache-konan
66+
- name: Cache Gradle
67+
uses: ./.github/actions/cache-gradle
68+
- name: Run code analysis
69+
run: ./gradlew detekt --stacktrace
70+
shell: bash
71+
- name: Upload SARIF file
72+
uses: github/codeql-action/upload-sarif@v3
73+
with:
74+
sarif_file: build/reports/detekt/detekt.sarif
75+
- name: Upload analysis report
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: analysis-report
79+
path: build/reports/detekt
80+
81+
coverage:
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v4
85+
- name: Set up JDK
86+
uses: actions/setup-java@v4
87+
with:
88+
java-version: 11
89+
distribution: zulu
90+
- name: Cache Konan
91+
uses: ./.github/actions/cache-konan
92+
- name: Cache Gradle
93+
uses: ./.github/actions/cache-gradle
94+
- name: Calculate coverage
95+
run: ./gradlew koverXmlReport --stacktrace
96+
shell: bash
97+
- name: Upload coverage report
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: coverage-report
101+
path: build/reports/kover
102+
103+
upload-reports:
104+
needs: [ test, analysis, coverage, lint ]
105+
runs-on: ubuntu-latest
106+
env:
107+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
BUILD_NUMBER: ${{ github.run_number }}
110+
steps:
111+
- uses: actions/checkout@v4
112+
- name: Set up JDK
113+
uses: actions/setup-java@v4
114+
with:
115+
java-version: 17
116+
distribution: zulu
117+
- name: SonarCloud cache
118+
uses: actions/cache@v4
119+
with:
120+
path: ~/.sonar/cache
121+
key: ${{ runner.os }}-sonar
122+
restore-keys: ${{ runner.os }}-sonar
123+
- name: Cache Konan
124+
uses: ./.github/actions/cache-konan
125+
- name: Cache Gradle
126+
uses: ./.github/actions/cache-gradle
127+
- name: Download coverage report
128+
uses: actions/download-artifact@v4
129+
with:
130+
name: coverage-report
131+
path: build/reports/kover
132+
- name: Download analysis report
133+
uses: actions/download-artifact@v4
134+
with:
135+
name: analysis-report
136+
path: build/reports/detekt
137+
- name: Upload reports to SonarCloud
138+
run: ./gradlew sonarqube --stacktrace
53139
shell: bash

build.gradle.kts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ kotlin {
8383
nodejs {
8484
testTask {
8585
useMocha {
86-
timeout = "10000"
86+
timeout = "20000"
8787
}
8888
}
8989
}
@@ -176,6 +176,13 @@ kotlin {
176176
}
177177
}
178178

179+
val darwinTest by creating {
180+
dependsOn(commonTest)
181+
dependencies {
182+
implementation("io.ktor:ktor-client-darwin:$ktor_version")
183+
}
184+
}
185+
179186
val nativeMain by creating {
180187
dependsOn(commonMain)
181188
}
@@ -193,7 +200,11 @@ kotlin {
193200
}
194201

195202
configure(nativeTestSets) {
196-
dependsOn(nativeTest)
203+
if (this.name.isDarwin()) {
204+
dependsOn(darwinTest)
205+
} else {
206+
dependsOn(nativeTest)
207+
}
197208
}
198209
}
199210
}

detekt.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ style:
44
WildcardImport:
55
active: false
66
ReturnCount:
7-
max: 8
7+
max: 9
88
DestructuringDeclarationWithTooManyEntries:
99
maxDestructuringEntries: 5
1010

11-
1211
complexity:
1312
ComplexCondition:
14-
threshold: 5
13+
threshold: 11
1514
TooManyFunctions:
1615
thresholdInClasses: 22
1716
thresholdInInterfaces: 17
1817
LongMethod:
1918
threshold: 70
2019
LongParameterList:
2120
constructorThreshold: 10
21+
functionThreshold: 7
22+
CyclomaticComplexMethod:
23+
threshold: 17
24+
NestedBlockDepth:
25+
threshold: 10
2226

2327
exceptions:
2428
TooGenericExceptionCaught:

gradle.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group=com.configcat
2-
version=2.1.0
2+
version=3.0.0
33

44
ktor_version=2.0.3
55
kotlinx_serialization_version=1.4.1
@@ -17,4 +17,6 @@ kotlin.native.ignoreDisabledTargets=true
1717
kotlin.mpp.stability.nowarn=true
1818

1919
kotlin.native.binary.memoryModel=experimental
20-
org.gradle.jvmargs=-Xmx6g
20+
org.gradle.jvmargs=-Xmx6g
21+
22+
kotlin.ignore.tcsm.overflow=true

gradle/wrapper/gradle-wrapper.jar

935 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ set -- \
205205
org.gradle.wrapper.GradleWrapperMain \
206206
"$@"
207207

208+
# Stop when "xargs" is not available.
209+
if ! command -v xargs >/dev/null 2>&1
210+
then
211+
die "xargs is not available"
212+
fi
213+
208214
# Use "xargs" to parse quoted args.
209215
#
210216
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

gradlew.bat

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@rem limitations under the License.
1515
@rem
1616

17-
@if "%DEBUG%" == "" @echo off
17+
@if "%DEBUG%"=="" @echo off
1818
@rem ##########################################################################
1919
@rem
2020
@rem Gradle startup script for Windows
@@ -25,7 +25,7 @@
2525
if "%OS%"=="Windows_NT" setlocal
2626

2727
set DIRNAME=%~dp0
28-
if "%DIRNAME%" == "" set DIRNAME=.
28+
if "%DIRNAME%"=="" set DIRNAME=.
2929
set APP_BASE_NAME=%~n0
3030
set APP_HOME=%DIRNAME%
3131

@@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4040

4141
set JAVA_EXE=java.exe
4242
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
43+
if %ERRORLEVEL% equ 0 goto execute
4444

4545
echo.
4646
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7575

7676
:end
7777
@rem End local scope for the variables with windows NT shell
78-
if "%ERRORLEVEL%"=="0" goto mainEnd
78+
if %ERRORLEVEL% equ 0 goto mainEnd
7979

8080
:fail
8181
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
8282
rem the _cmd.exe /c_ return code!
83-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84-
exit /b 1
83+
set EXIT_CODE=%ERRORLEVEL%
84+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
85+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
86+
exit /b %EXIT_CODE%
8587

8688
:mainEnd
8789
if "%OS%"=="Windows_NT" endlocal

src/androidMain/kotlin/com/configcat/Cache.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public class SharedPreferencesCache(context: Context) : ConfigCache {
1414
private val sharedPreferences: SharedPreferences
1515

1616
init {
17-
sharedPreferences = context.applicationContext.getSharedPreferences("configcat_preferences", Context.MODE_PRIVATE)
17+
sharedPreferences =
18+
context.applicationContext.getSharedPreferences("configcat_preferences", Context.MODE_PRIVATE)
1819
}
1920

2021
override suspend fun read(key: String): String? = sharedPreferences.getString(key, null)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.configcat
2+
3+
import java.text.DecimalFormat
4+
import java.text.DecimalFormatSymbols
5+
import java.util.*
6+
import kotlin.math.abs
7+
8+
internal actual fun doubleToString(doubleToString: Double): String {
9+
// Handle Double.NaN, Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY
10+
if (doubleToString.isNaN() || doubleToString.isInfinite()) {
11+
return doubleToString.toString()
12+
}
13+
14+
// To get similar result between different SDKs the Double value format is modified.
15+
// Between 1e-6 and 1e21 we don't use scientific-notation. Over these limits scientific-notation used but the
16+
// ExponentSeparator replaced with "e" and "e+".
17+
// "." used as decimal separator in all cases.
18+
val abs = abs(doubleToString)
19+
val fmt =
20+
if (1e-6 <= abs && abs < 1e21) DecimalFormat("#.#################") else DecimalFormat("#.#################E0")
21+
val symbols = DecimalFormatSymbols.getInstance(Locale.UK)
22+
if (abs > 1) {
23+
symbols.exponentSeparator = "e+"
24+
} else {
25+
symbols.exponentSeparator = "e"
26+
}
27+
fmt.decimalFormatSymbols = symbols
28+
return fmt.format(doubleToString)
29+
}
30+
31+
internal actual fun formatDoubleForLog(doubleToFormat: Double): String {
32+
val decimalFormat = DecimalFormat("0.#####")
33+
decimalFormat.decimalFormatSymbols = DecimalFormatSymbols.getInstance(Locale.UK)
34+
return decimalFormat.format(doubleToFormat)
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.configcat.fetch
2+
3+
import io.ktor.client.request.*
4+
5+
internal actual fun httpRequestBuilder(
6+
configCatUserAgent: String,
7+
eTag: String
8+
): HttpRequestBuilder {
9+
return commonHttpRequestBuilder(configCatUserAgent, eTag)
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.configcat.override
2+
3+
import com.configcat.model.Setting
4+
5+
internal actual fun convertToSetting(value: Any): Setting {
6+
return commonConvertToSetting(value)
7+
}

0 commit comments

Comments
 (0)