Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GT-2455 provide a Scarlet.Builder extension method to force the default platform #2173

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a package private Java class to hide it from the public API for library consumers

/** @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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuntimePlatform is a Kotlin internal class in another library, we can still access it from Java to create the instance we need.

}
}
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we wrap the package-private java RuntimePlatformInternals.Default() in an internal Kotlin function, this allows us to access it from other packages in this module without exposing it on the public API

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only new thing exposed on the public API of this module