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

Make supported locales lazily computed providers #1139

Merged
merged 1 commit into from
Dec 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class foundry/gradle/properties/PropertyResolver {
public final fun optionalStringValue (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
public static synthetic fun optionalStringValue$default (Lfoundry/gradle/properties/PropertyResolver;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
public final fun providerFor (Ljava/lang/String;)Lorg/gradle/api/provider/Provider;
public final fun requiredStringProvider (Ljava/lang/String;)Lorg/gradle/api/provider/Provider;
public final fun stringValue (Ljava/lang/String;)Ljava/lang/String;
public final fun stringValue (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ public class PropertyResolver(
?: error("No property for '$key' found and no default value was provided.")
}

public fun requiredStringProvider(key: String): Provider<String> {
return optionalStringProvider(key)
.orElse(
providers.provider {
error("No property for '$key' found and no default value was provided.")
}
)
}

public fun optionalStringValue(key: String, defaultValue: String? = null): String? {
return providerFor(key).orNull ?: defaultValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ internal fun robolectricJars(gradleUserHomeDir: File, createDirsIfMissing: Boole
}
}

public fun Project.supportedLanguages(supportedLanguages: SupportedLanguagesEnum): List<String> {
public fun Project.supportedLanguages(
supportedLanguages: SupportedLanguagesEnum
): Provider<List<String>> {
val foundryProperties = project.foundryProperties
val gaLanguages = foundryProperties.supportedLanguages.split(",")
val gaLanguages = foundryProperties.supportedLanguages.map { it.split(",") }

val internalLanguages = foundryProperties.supportedLanguagesInternal.split(",")
val internalLanguages = foundryProperties.supportedLanguagesInternal.map { it.split(",") }

val betaLanguages = foundryProperties.supportedLanguagesBeta.split(",")
val betaLanguages = foundryProperties.supportedLanguagesBeta.map { it.split(",") }

return when (supportedLanguages) {
SupportedLanguagesEnum.GA -> gaLanguages.toList().filter { it.isNotBlank() }
SupportedLanguagesEnum.INTERNAL ->
internalLanguages.union(gaLanguages).toList().filter { it.isNotBlank() }
SupportedLanguagesEnum.BETA ->
betaLanguages.union(gaLanguages).toList().filter { it.isNotBlank() }
}
SupportedLanguagesEnum.GA -> gaLanguages
SupportedLanguagesEnum.INTERNAL -> internalLanguages.zip(gaLanguages, List<String>::union)
SupportedLanguagesEnum.BETA -> betaLanguages.zip(gaLanguages, List<String>::union)
}.map { it.filter { it.isNotBlank() } }
}

public enum class SupportedLanguagesEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ internal constructor(
get() = booleanProperty("foundry.config.noPlatform")

/** Property corresponding to the supported languages in GA builds */
public val supportedLanguages: String
get() = stringProperty("foundry.android.supportedLanguages")
public val supportedLanguages: Provider<String>
get() = resolver.requiredStringProvider("foundry.android.supportedLanguages")

/** Property corresponding to the supported languages in Internal builds */
public val supportedLanguagesInternal: String
get() = stringProperty("foundry.android.supportedLanguagesInternal")
public val supportedLanguagesInternal: Provider<String>
get() = resolver.requiredStringProvider("foundry.android.supportedLanguagesInternal")

/** Property corresponding to the supported languages in Beta builds */
public val supportedLanguagesBeta: String
get() = stringProperty("foundry.android.supportedLanguagesBeta")
public val supportedLanguagesBeta: Provider<String>
get() = resolver.requiredStringProvider("foundry.android.supportedLanguagesBeta")

/**
* Property corresponding to the file path of a custom versions.json file for use with
Expand Down
Loading