Skip to content

Commit

Permalink
provide a Scarlet.Builder extension method to force the default platform
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Sep 25, 2024
1 parent dd15a60 commit 03de060
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions gto-support-scarlet/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ dependencies {
api(libs.scarlet.core)
compileOnly(libs.scarlet)

implementation(project(":gto-support-util"))
implementation(libs.okio)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.tinder.scarlet.internal.utils;

import androidx.annotation.NonNull;

class RuntimePlatformInternals {

Check warning on line 5 in gto-support-scarlet/src/main/java/com/tinder/scarlet/internal/utils/RuntimePlatformInternals.java

View check run for this annotation

Codecov / codecov/patch

gto-support-scarlet/src/main/java/com/tinder/scarlet/internal/utils/RuntimePlatformInternals.java#L5

Added line #L5 was not covered by tests
/** @noinspection KotlinInternalInJava*/
@NonNull
@SuppressWarnings("MethodName")
static RuntimePlatform Default() {
return new RuntimePlatform.Default();

Check warning on line 10 in gto-support-scarlet/src/main/java/com/tinder/scarlet/internal/utils/RuntimePlatformInternals.java

View check run for this annotation

Codecov / codecov/patch

gto-support-scarlet/src/main/java/com/tinder/scarlet/internal/utils/RuntimePlatformInternals.java#L10

Added line #L10 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.tinder.scarlet

import org.ccci.gto.android.common.util.getDeclaredFieldOrNull
import org.ccci.gto.android.common.util.getOrNull

private val platformField = getDeclaredFieldOrNull<Scarlet.Builder>("platform")

Check warning on line 6 in gto-support-scarlet/src/main/kotlin/com/tinder/scarlet/ScarletBuilderInternals.kt

View check run for this annotation

Codecov / codecov/patch

gto-support-scarlet/src/main/kotlin/com/tinder/scarlet/ScarletBuilderInternals.kt#L6

Added line #L6 was not covered by tests

internal var Scarlet.Builder.platform: Any?
get() = platformField?.getOrNull(this)
set(value) {
platformField?.set(this, requireNotNull(value))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.tinder.scarlet.internal.utils

internal fun defaultPlatform() = RuntimePlatformInternals.Default()

Check warning on line 3 in gto-support-scarlet/src/main/kotlin/com/tinder/scarlet/internal/utils/RuntimePlatformInternals.kt

View check run for this annotation

Codecov / codecov/patch

gto-support-scarlet/src/main/kotlin/com/tinder/scarlet/internal/utils/RuntimePlatformInternals.kt#L3

Added line #L3 was not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.ccci.gto.android.common.scarlet

import com.tinder.scarlet.Scarlet
import com.tinder.scarlet.internal.utils.defaultPlatform
import com.tinder.scarlet.platform

/**
* Scarlet improperly detects desugared Android apps as the Java 8 runtime.
* This method will force the default platform for Scarlet to be used.
*
* See:
* https://github.com/Tinder/Scarlet/issues/235
* https://issuetracker.google.com/issues/342419066
*/
fun Scarlet.Builder.forceDefaultPlatform() = apply { platform = defaultPlatform() }

Check warning on line 15 in gto-support-scarlet/src/main/kotlin/org/ccci/gto/android/common/scarlet/ScarletBuilder.kt

View check run for this annotation

Codecov / codecov/patch

gto-support-scarlet/src/main/kotlin/org/ccci/gto/android/common/scarlet/ScarletBuilder.kt#L15

Added line #L15 was not covered by tests

0 comments on commit 03de060

Please sign in to comment.