Skip to content

Commit

Permalink
Commonize
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmb13 committed May 10, 2024
1 parent 57505e9 commit 3928a28
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 99 deletions.
4 changes: 2 additions & 2 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ dependencies {

gradlePlugin {
plugins {
register("androidLibrary") {
register("library") {
id = "co.zsmb.requirektx.library"
implementationClass = "AndroidLibraryConventionPlugin"
implementationClass = "KmpLibraryConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class AndroidLibraryConventionPlugin : Plugin<Project> {
class KmpLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
Expand All @@ -27,6 +27,29 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
}
}

if (target.isNotJustAndroid()) {
jvm()
iosArm64()
iosSimulatorArm64()
iosX64()
js {
browser()
nodejs()
}
linuxArm64()
linuxX64()
macosArm64()
macosX64()
tvosArm64()
tvosSimulatorArm64()
tvosX64()
wasmJs()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
watchosX64()
}

explicitApi()

@OptIn(ExperimentalKotlinGradlePluginApi::class)
Expand Down Expand Up @@ -79,3 +102,5 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
}
}
}

private fun Project.isNotJustAndroid() = hasProperty("android-only").not()
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ kotlin.code.style=official

# Publishing
group=co.zsmb
version=1.3.0
version=2.0.0-alpha02
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ androidTools = "31.4.0"
appcompat = "1.6.1"
constraintlayout = "2.1.4"
core-ktx = "1.13.1"
core-bundle = "1.0.0-rc01"
junit = "4.13.2"
junit-jupiter-api = "5.9.2"
kotlin = "1.9.24"
material = "1.12.0"
maven-publish = "0.28.0"
navigation-runtime = "2.7.7"
navigation-runtime = "2.7.0-alpha04"
robolectric = "4.12.1"
work-runtime = "2.9.0"

Expand All @@ -18,6 +19,7 @@ android-gradle-plugin = { group = "com.android.tools.build", name = "gradle", ve
android-tools-common = { group = "com.android.tools", name = "common", version.ref = "androidTools" }
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
core-bundle = { module = "org.jetbrains.androidx.core:core-bundle", version.ref = "core-bundle" }
core-ktx = { module = "androidx.core:core-ktx", version.ref = "core-ktx" }
junit = { module = "junit:junit", version.ref = "junit" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter-api" }
Expand All @@ -27,7 +29,7 @@ kotlin-gradle-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-p
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
material = { module = "com.google.android.material:material", version.ref = "material" }
maven-publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish" }
navigation-runtime = { module = "androidx.navigation:navigation-runtime", version.ref = "navigation-runtime" }
navigation-runtime = { module = "org.jetbrains.androidx.navigation:navigation-runtime", version.ref = "navigation-runtime" }
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
work-runtime = { module = "androidx.work:work-runtime", version.ref = "work-runtime" }

Expand Down
2 changes: 1 addition & 1 deletion requirektx-bundle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android.namespace = "co.zsmb.requirektx.bundle"
kotlin {
sourceSets {
commonMain.dependencies {
api("org.jetbrains.androidx.core:core-bundle:1.0.0-rc01")
api(libs.core.bundle)
}
commonTest.dependencies {
implementation(libs.kotlin.test)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@file:Suppress("NOTHING_TO_INLINE")

package co.zsmb.requirektx

import androidx.core.bundle.Bundle
import android.os.Parcelable

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireParcelableArrayList(key: String): ArrayList<Parcelable> = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getParcelableArrayListOrNull(key: String): ArrayList<Parcelable>? = getOrNullImpl(key)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@file:Suppress("NOTHING_TO_INLINE")

package co.zsmb.requirektx

import android.os.Parcelable
import android.util.SparseArray
import androidx.core.bundle.Bundle

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireParcelableArray(key: String): Array<Parcelable> = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getParcelableArrayOrNull(key: String): Array<Parcelable>? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun <reified T : Parcelable> Bundle.requireSparseParcelableArray(key: String): SparseArray<T> = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun <reified T : Parcelable> Bundle.getSparseParcelableArrayOrNull(key: String): SparseArray<T>? = getOrNullImpl(key)
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,12 @@
package co.zsmb.requirektx

import android.os.Binder
import androidx.core.bundle.Bundle
import android.os.Parcelable
import android.util.Size
import android.util.SizeF
import androidx.core.bundle.Bundle
import java.io.Serializable

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireString(key: String): String = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getStringOrNull(key: String): String? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireCharSequence(key: String): CharSequence = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getCharSequenceOrNull(key: String): CharSequence? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
Expand Down Expand Up @@ -106,18 +78,3 @@ public inline fun Bundle.requireBinder(key: String): Binder = requireImpl(key)
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getBinderOrNull(key: String): Binder? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireBundle(key: String): Bundle = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getBundleOrNull(key: String): Bundle? = getOrNullImpl(key)

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package co.zsmb.requirektx

import androidx.core.bundle.Bundle
import android.os.Parcelable

/**
* Returns the value associated with the given key.
Expand All @@ -19,20 +18,6 @@ public inline fun Bundle.requireIntegerArrayList(key: String): ArrayList<Int> =
*/
public inline fun Bundle.getIntegerArrayListOrNull(key: String): ArrayList<Int>? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireParcelableArrayList(key: String): ArrayList<Parcelable> = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getParcelableArrayListOrNull(key: String): ArrayList<Parcelable>? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

package co.zsmb.requirektx

import android.os.Parcelable
import android.util.SparseArray
import androidx.core.bundle.Bundle

/**
Expand Down Expand Up @@ -145,31 +143,3 @@ public inline fun Bundle.requireCharSequenceArray(key: String): Array<CharSequen
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getCharSequenceArrayOrNull(key: String): Array<CharSequence>? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireParcelableArray(key: String): Array<Parcelable> = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getParcelableArrayOrNull(key: String): Array<Parcelable>? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun <reified T : Parcelable> Bundle.requireSparseParcelableArray(key: String): SparseArray<T> = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun <reified T : Parcelable> Bundle.getSparseParcelableArrayOrNull(key: String): SparseArray<T>? = getOrNullImpl(key)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@file:Suppress("NOTHING_TO_INLINE")

package co.zsmb.requirektx

import androidx.core.bundle.Bundle

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireString(key: String): String = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getStringOrNull(key: String): String? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireCharSequence(key: String): CharSequence = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getCharSequenceOrNull(key: String): CharSequence? = getOrNullImpl(key)

/**
* Returns the value associated with the given key.
*
* @throws IllegalArgumentException if the key does not exist.
* @throws IllegalStateException if the stored value is of the wrong type.
*/
public inline fun Bundle.requireBundle(key: String): Bundle = requireImpl(key)

/**
* Returns the value associated with the given key, or null if the key doesn't exist,
* or the stored value is of the wrong type.
*/
public inline fun Bundle.getBundleOrNull(key: String): Bundle? = getOrNullImpl(key)

1 change: 1 addition & 0 deletions requirektx-intent/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
android-only=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package co.zsmb.requirektx

4 changes: 1 addition & 3 deletions requirektx-navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ kotlin {
sourceSets {
commonMain.dependencies {
api(project(":requirektx-bundle"))
implementation(libs.navigation.runtime)
}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
androidMain.dependencies {
implementation(libs.navigation.runtime)
}
val androidUnitTest by getting {
dependencies {
implementation(libs.robolectric)
Expand Down
1 change: 1 addition & 0 deletions requirektx-work/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
android-only=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package co.zsmb.requirektx

0 comments on commit 3928a28

Please sign in to comment.