Skip to content

Commit

Permalink
Merge pull request #44 from Skeptick/rc/release-1.2.2
Browse files Browse the repository at this point in the history
Release 1.2.2
  • Loading branch information
Skeptick authored Dec 4, 2023
2 parents 0715aa2 + d99ed05 commit 4e0b76d
Show file tree
Hide file tree
Showing 42 changed files with 107 additions and 117 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources generation in Kotlin Multiplatform.

buildscript {
dependencies {
classpath("io.github.skeptick.libres:gradle-plugin:1.2.1")
classpath("io.github.skeptick.libres:gradle-plugin:1.2.2")
}
}
```
Expand Down Expand Up @@ -37,7 +37,7 @@ libres {
kotlin {
commonMain {
dependencies {
implementation("io.github.skeptick.libres:libres-compose:1.2.1")
implementation("io.github.skeptick.libres:libres-compose:1.2.2")
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
@file:Suppress("UnstableApiUsage")

enableFeaturePreview("VERSION_CATALOGS")

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
Expand Down
3 changes: 1 addition & 2 deletions buildSrc/src/main/kotlin/android-setup-plugin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ plugins {
}

android {
compileSdk = 33
compileSdk = 34

defaultConfig {
minSdk = 16
targetSdk = 33
}

buildFeatures {
Expand Down
36 changes: 6 additions & 30 deletions buildSrc/src/main/kotlin/multiplatform-setup.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
id("com.android.library")
kotlin("multiplatform")
}

kotlin {
jvm()
android {
androidTarget {
publishAllLibraryVariants()
}
js(IR) {
Expand All @@ -16,35 +17,10 @@ kotlin {
macosArm64()
macosX64()

sourceSets {
val commonMain by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val macosArm64Main by getting
val macosX64Main by getting

val macosMain by creating {
dependsOn(commonMain)
macosArm64Main.dependsOn(this)
macosX64Main.dependsOn(this)
}

val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}

val appleMain by creating {
dependsOn(commonMain)
macosMain.dependsOn(this)
iosMain.dependsOn(this)
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs += "-Xexpect-actual-classes"
}
}
}
23 changes: 9 additions & 14 deletions gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ plugins {
id("com.vanniktech.maven.publish")
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
version = property("VERSION_NAME").toString()

kotlin {
jvmToolchain(11)
}

dependencies {
Expand All @@ -31,16 +32,12 @@ gradlePlugin {
}
}

sourceSets {
getByName("main").java.srcDir("generated")
}

tasks.register("libresVersion") {
val libresVersion = tasks.register("libresVersion") {
val outputDir = file("generated")
inputs.property("version", version)
outputs.dir(outputDir)

doLast {
doFirst {
val text = """
// Generated file. Do not edit!
package io.github.skeptick.libres
Expand All @@ -54,8 +51,6 @@ tasks.register("libresVersion") {
}
}

afterEvaluate {
tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile::class.java).configureEach {
dependsOn("libresVersion")
}
}
sourceSets.main.configure {
kotlin.srcDir(libresVersion)
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class ResourcesPlugin : Plugin<Project> {
}

private fun Project.fetchSourceSets() {
val outputDirectory = File(project.buildDir, "generated/libres")
val buildDir = layout.buildDirectory.asFile.get()
val outputDirectory = File(buildDir, "generated/libres")
val kotlinExtension = project.extensions.getByType(KotlinProjectExtension::class.java)
val commonSourceSet = kotlinExtension.sourceSets.findByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME)
val androidExtension = project.extensions.findByName("android") as BaseExtension?
Expand Down Expand Up @@ -120,7 +121,6 @@ class ResourcesPlugin : Plugin<Project> {
}
}

@Suppress("UnstableApiUsage")
private fun Project.registerGeneratorsTasks() {
val stringsInputDirectory = File(inputDirectory, "strings")
val imagesInputDirectory = File(inputDirectory, "images")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ internal fun KotlinSourceSet.createKotlinSourceSet(
return SourceSet(rootDir = rootDir, sourcesDir = sourcesDirectory, resourcesDir = resourcesDirectory, platform)
}

@Suppress("UnstableApiUsage")
internal fun KotlinSourceSet.createAndroidSourceSet(
outputDirectory: File,
androidMainSourceSet: AndroidSourceSet
Expand Down Expand Up @@ -89,7 +88,7 @@ internal val KotlinTarget.platform: KotlinPlatform?
is KotlinJvmTarget, is KotlinWithJavaTarget<*, *> -> KotlinPlatform.Jvm
is KotlinJsIrTarget -> KotlinPlatform.Js
is KotlinNativeTarget -> when (konanTarget.family) {
Family.IOS, Family.OSX -> KotlinPlatform.Apple
Family.IOS, Family.OSX, Family.TVOS -> KotlinPlatform.Apple
else -> null
}
else -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import kotlin.io.path.pathString
internal const val appleBundlesDirectory = "generated/libres/apple/libres-bundles"

internal fun Project.appendAppleBundles(currentResources: String): String {
File(buildDir, appleBundlesDirectory).mkdirs()
val path = "'${buildDir.relativeTo(projectDir).path}/$appleBundlesDirectory'"
File(buildDirectory, appleBundlesDirectory).mkdirs()
val path = "'${buildDirectory.relativeTo(projectDir).path}/$appleBundlesDirectory'"
if (currentResources.isBlank() || currentResources.trim().matches(Regex("^\\[\\s*]$"))) return "[$path]"
val existPaths = currentResources.substringAfter('[').substringBeforeLast(']')
return "[$existPaths, $path]"
}

internal fun createBundlesSymLinks(rootProject: Project, exportedProjects: List<Project>) {
val rootBundlesDir = Path(rootProject.buildDir.absolutePath, appleBundlesDirectory)
val rootBundlesDir = Path(rootProject.buildDirectory.absolutePath, appleBundlesDirectory)
val rootBundleName = rootProject.appleBundleName
val rootBundle = Path(rootProject.buildDir.absolutePath, appleBundlesDirectory, "${rootBundleName}.bundle")
val rootBundle = Path(rootProject.buildDirectory.absolutePath, appleBundlesDirectory, "${rootBundleName}.bundle")
if (!Files.exists(rootBundle)) Files.createDirectories(rootBundle)
exportedProjects.forEach { rootBundlesDir.addSymlinkToBundle(it) }
}
Expand All @@ -32,8 +32,10 @@ internal val Project.appleBundleName: String

private fun Path.addSymlinkToBundle(project: Project) {
val bundleName = project.appleBundleName
val target = Path(project.buildDir.absolutePath, appleBundlesDirectory, "${bundleName}.bundle")
val target = Path(project.buildDirectory.absolutePath, appleBundlesDirectory, "${bundleName}.bundle")
val link = Path(pathString, "${bundleName}.bundle")
if (!Files.exists(target)) Files.createDirectories(target)
if (!Files.exists(link)) Files.createSymbolicLink(link, target)
}
}

private val Project.buildDirectory: File get() = layout.buildDirectory.asFile.get()
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private fun TypeSpec.Builder.appendAppleBundleProperty(bundleName: String): Type
return addProperty(
PropertySpec.builder("bundle", NSBundle)
.addModifiers(KModifier.PRIVATE)
.initializer("NSBundle.bundleWithName(%S)", bundleName)
.delegate("lazy { NSBundle.bundleWithName(%S) }", bundleName)
.build()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class StringTypeSpecsBuilder(
stringsInterface.addTextResourceToInterface(resourceName, type)
baseLocalizedObject.addTextResourceToLocalizedObject(resourceName, formattedResource, type, baseLanguageCode)
stringObject.addTextResourceToStringsObject(resourceName, type, camelCaseForApple)
if (generateNamedArguments && baseParameters.isNotEmpty()) customClasses += CustomFormattedTextResourceClass(baseResource)
if (generateNamedArguments && baseParameters.isNotEmpty()) customClasses += CustomFormattedTextResourceClass(type, baseResource)
}

fun save(outputDirectory: File) {
Expand Down Expand Up @@ -68,12 +68,12 @@ private fun TextResource.fetchClass(packageName: String, hasParameters: Boolean,
when (this) {
is StringResource -> when {
!hasParameters -> String::class.asTypeName()
generateNamedArguments -> ClassName(packageName, name.snakeCaseToCamelCase())
generateNamedArguments -> ClassName(packageName, "LibresFormat" + name.snakeCaseToCamelCase())
else -> VoidFormattedString::class.asTypeName()
}
is PluralsResource -> when {
!hasParameters -> VoidPluralString::class.asTypeName()
generateNamedArguments -> ClassName(packageName, name.snakeCaseToCamelCase())
generateNamedArguments -> ClassName(packageName, "LibresFormat" + name.snakeCaseToCamelCase())
else -> VoidFormattedPluralString::class.asTypeName()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ internal fun EmptyStringObject(name: String): TypeSpec.Builder {
return TypeSpec.objectBuilder("${name}Strings")
}

internal fun CustomFormattedTextResourceClass(resource: TextResource): TypeSpec.Builder {
internal fun CustomFormattedTextResourceClass(type: ClassName, resource: TextResource): TypeSpec.Builder {
return when (resource) {
is StringResource -> CustomFormattedStringClass(resource)
is PluralsResource -> CustomFormattedPluralStringClass(resource)
is StringResource -> CustomFormattedStringClass(type, resource)
is PluralsResource -> CustomFormattedPluralStringClass(type, resource)
}
}

Expand All @@ -82,9 +82,9 @@ internal fun CustomFormattedTextResourceClass(resource: TextResource): TypeSpec.
* }
* }
*/
private fun CustomFormattedStringClass(resource: StringResource): TypeSpec.Builder {
private fun CustomFormattedStringClass(type: ClassName, resource: StringResource): TypeSpec.Builder {
val parameters = resource.parameters.map { it.snakeCaseToCamelCase(startWithLower = true) }.toSet()
return TypeSpec.classBuilder(resource.name.snakeCaseToCamelCase(startWithLower = false))
return TypeSpec.classBuilder(type.simpleName)
.primaryConstructor(
FunSpec.constructorBuilder().addParameter("value", String::class).build()
).addProperty(
Expand All @@ -105,9 +105,9 @@ private fun CustomFormattedStringClass(resource: StringResource): TypeSpec.Build
* }
* }
*/
private fun CustomFormattedPluralStringClass(resource: PluralsResource): TypeSpec.Builder {
private fun CustomFormattedPluralStringClass(type: ClassName, resource: PluralsResource): TypeSpec.Builder {
val parameters = resource.parameters.map { it.snakeCaseToCamelCase(startWithLower = true) }.toSet()
return TypeSpec.classBuilder(resource.name.snakeCaseToCamelCase(startWithLower = false))
return TypeSpec.classBuilder(type.simpleName)
.primaryConstructor(
FunSpec.constructorBuilder()
.addParameter("forms", PluralForms::class.asClassName())
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ android.useAndroidX=true
org.jetbrains.compose.experimental.uikit.enabled=true
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
android.disableAutomaticComponentCreation=true
kotlin.mpp.androidSourceSetLayoutVersion=2

GROUP=io.github.skeptick.libres
VERSION_NAME=1.2.1
VERSION_NAME=1.2.2

SONATYPE_HOST=S01

Expand Down
20 changes: 10 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[versions]
plugin-android = "7.3.0"
plugin-publish-maven = "0.22.0"
plugin-multiplatform-compose = "1.3.1"
plugin-android = "8.1.2"
plugin-publish-maven = "0.25.3"
plugin-multiplatform-compose = "1.5.10"

kotlin = "1.8.10"
androidx-core = "1.9.0"
kotlin = "1.9.20"
androidx-core = "1.12.0"
robovm = "1.0.0"
icu4j = "70.1"
jackson = "2.14.0"
kotlinpoet = "1.12.0"
javacv = "1.5.7"
android-sdk-tools = "30.3.1"
icu4j = "74.1"
jackson = "2.16.0"
kotlinpoet = "1.15.2"
javacv = "1.5.9"
android-sdk-tools = "31.2.0"

junit = "4.13.2"

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion libres-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kotlin {
commonMain {
dependencies {
api(projects.libresCore)
compileOnly(compose.ui)
implementation(compose.ui)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:OptIn(ExperimentalForeignApi::class)

package io.github.skeptick.libres.compose

import androidx.compose.ui.unit.IntSize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
@file:OptIn(ExperimentalForeignApi::class)

package io.github.skeptick.libres.compose

import androidx.compose.ui.unit.IntSize
import io.github.skeptick.libres.images.Image
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.MemScope
import platform.CoreGraphics.*
import platform.UIKit.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
@file:OptIn(ExperimentalForeignApi::class)

package io.github.skeptick.libres.compose

import androidx.compose.ui.unit.IntSize
import io.github.skeptick.libres.images.Image
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.MemScope
import platform.AppKit.NSImageRep
import platform.CoreGraphics.CGImageRef
Expand Down
Loading

0 comments on commit 4e0b76d

Please sign in to comment.