Skip to content

Commit

Permalink
Add Kopy
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierSegoviaCordoba committed Sep 8, 2024
1 parent f715a41 commit 267abaf
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 19 deletions.
2 changes: 2 additions & 0 deletions gradle/hubdle.libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ javiersc-gradle-extensions = "1.0.0-alpha.34"
javiersc-hubdle = "0.7.10"
javiersc-kotlin = "0.1.0-alpha.16"
javiersc-kotlin-compiler-extensions = "0.4.2+2.0.20"
javiersc-kotlin-kopy = "0.11.0+2.0.20"
javiersc-kotlinx-coroutines = "0.1.0-rc.1"
javiersc-mokoki = "0.2.0-alpha.1"
javiersc-mokoki-serialization = "0.2.0-alpha.1"
Expand Down Expand Up @@ -301,6 +302,7 @@ gradle-develocity = { id = "com.gradle.develocity", version.ref = "gradle-develo
gradle-plugin-publish = { id = "com.gradle.plugin-publish", version.ref = "gradle-plugin-publish" }
gradle-test-retry = { id = "org.gradle.test-retry", version.ref = "gradle-test-retry" }
javiersc-hubdle = { id = "com.javiersc.hubdle", version.ref = "javiersc-hubdle" } # {{ version.ref = "javiersc-hubdle" }}
javiersc-kotlin-kopy = { id = "com.javiersc.kotlin.kopy", version.ref = "javiersc-kotlin-kopy" }
javiersc-semver = { id = "com.javiersc.semver", version.ref = "javiersc-semver" }
jetbrains-changelog = { id = "org.jetbrains.changelog", version.ref = "jetbrains-changelog" }
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jetbrains-compose" }
Expand Down
52 changes: 48 additions & 4 deletions hubdle-gradle-plugin/api/hubdle-gradle-plugin.api

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions hubdle-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ hubdle {
api(hubdle.plugins.gradle.develocity.artifact)
api(hubdle.plugins.gradle.plugin.publish.artifact)
api(hubdle.plugins.gradle.test.retry.artifact)
api(hubdle.plugins.javiersc.kotlin.kopy.artifact)
api(hubdle.plugins.javiersc.semver.artifact)
api(hubdle.plugins.jetbrains.changelog.artifact)
api(hubdle.plugins.jetbrains.compose.artifact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotli
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinContextReceiversFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinCoroutinesFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinExtendedStdlibFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKopyFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKotestFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinMoleculeFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinSerializationFeatureExtension
Expand Down Expand Up @@ -82,6 +83,7 @@ private fun HubdleState.createKotlinFeatureExtensions() {
createExtension<HubdleKotlinContextReceiversFeatureExtension>()
createExtension<HubdleKotlinCoroutinesFeatureExtension>()
createExtension<HubdleKotlinExtendedStdlibFeatureExtension>()
createExtension<HubdleKotlinKopyFeatureExtension>()
createExtension<HubdleKotlinKotestFeatureExtension>()
createExtension<HubdleKotlinMoleculeFeatureExtension>()
createExtension<HubdleKotlinSerializationFeatureExtension>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotli
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinComposeDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinCoroutinesDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinExtendedStdlibDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKopyDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKotestDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinMoleculeDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinSerializationDelegateFeatureExtension
Expand All @@ -35,17 +36,18 @@ constructor(project: Project) :
}

public interface HubdleKotlinAndroidApplicationDelegateFeaturesExtension :
HubdleJavaVersionDelegateFeatureExtension,
HubdleJvmToolchainDelegateFeatureExtension,
HubdleKotlinAtomicfuDelegateFeatureExtension,
HubdleKotlinBuildKonfigDelegateFeatureExtension,
HubdleKotlinComposeDelegateFeatureExtension,
HubdleKotlinCoroutinesDelegateFeatureExtension,
HubdleKotlinExtendedStdlibDelegateFeatureExtension,
HubdleJavaVersionDelegateFeatureExtension,
HubdleKotlinKopyDelegateFeatureExtension,
HubdleKotlinKotestDelegateFeatureExtension,
HubdleKotlinMoleculeDelegateFeatureExtension,
HubdleKotlinSerializationDelegateFeatureExtension,
HubdleKotlinSqlDelightDelegateFeatureExtension,
HubdleJvmToolchainDelegateFeatureExtension
HubdleKotlinSqlDelightDelegateFeatureExtension

internal val HubdleEnableableExtension.hubdleAndroidApplicationFeatures:
HubdleKotlinAndroidApplicationFeaturesExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotli
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinComposeDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinCoroutinesDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinExtendedStdlibDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKopyDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKotestDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinMoleculeDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinSerializationDelegateFeatureExtension
Expand All @@ -36,17 +37,18 @@ constructor(project: Project) :
}

public interface HubdleKotlinAndroidLibraryDelegateFeaturesExtension :
HubdleJavaVersionDelegateFeatureExtension,
HubdleJvmToolchainDelegateFeatureExtension,
HubdleKotlinAtomicfuDelegateFeatureExtension,
HubdleKotlinBuildKonfigDelegateFeatureExtension,
HubdleKotlinComposeDelegateFeatureExtension,
HubdleKotlinCoroutinesDelegateFeatureExtension,
HubdleKotlinExtendedStdlibDelegateFeatureExtension,
HubdleJavaVersionDelegateFeatureExtension,
HubdleKotlinKopyDelegateFeatureExtension,
HubdleKotlinKotestDelegateFeatureExtension,
HubdleKotlinMoleculeDelegateFeatureExtension,
HubdleKotlinSerializationDelegateFeatureExtension,
HubdleKotlinSqlDelightDelegateFeatureExtension,
HubdleJvmToolchainDelegateFeatureExtension
HubdleKotlinSqlDelightDelegateFeatureExtension

internal val HubdleEnableableExtension.hubdleAndroidLibraryFeatures:
HubdleKotlinAndroidLibraryExtension
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.javiersc.hubdle.project.extensions.kotlin.features.shared

import com.javiersc.hubdle.project.extensions.HubdleDslMarker
import com.javiersc.hubdle.project.extensions._internal.ApplicablePlugin.Scope
import com.javiersc.hubdle.project.extensions._internal.fallbackAction
import com.javiersc.hubdle.project.extensions._internal.getHubdleExtension
import com.javiersc.hubdle.project.extensions.apis.BaseHubdleExtension
import com.javiersc.hubdle.project.extensions.apis.HubdleConfigurableExtension
import com.javiersc.hubdle.project.extensions.apis.HubdleEnableableExtension
import com.javiersc.hubdle.project.extensions.apis.enableAndExecute
import com.javiersc.hubdle.project.extensions.kotlin.hubdleKotlinAny
import com.javiersc.hubdle.project.extensions.shared.PluginId
import com.javiersc.kotlin.kopy.args.KopyFunctions
import com.javiersc.kotlin.kopy.args.KopyVisibility
import com.javiersc.kotlin.kopy.gradle.plugin.KopyExtension
import javax.inject.Inject
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.provider.Property

public open class HubdleKotlinKopyFeatureExtension @Inject constructor(project: Project) :
HubdleConfigurableExtension(project) {

override val isEnabled: Property<Boolean> = property { false }

override val oneOfExtensions: Set<HubdleEnableableExtension>
get() = hubdleKotlinAny

public val functions: Property<KopyFunctions> = property { KopyFunctions.All }

@HubdleDslMarker
public fun functions(functions: KopyFunctions = KopyFunctions.All) {
this.functions.set(functions)
}

public val visibility: Property<KopyVisibility> = property { KopyVisibility.Auto }

@HubdleDslMarker
public fun visibility(visibility: KopyVisibility = KopyVisibility.Auto) {
this.visibility.set(visibility)
}

@HubdleDslMarker
public fun kopy(action: Action<KopyExtension> = Action {}): Unit = fallbackAction(action)

override fun Project.defaultConfiguration() {
applicablePlugin(
scope = Scope.CurrentProject,
pluginId = PluginId.JavierscKotlinKopyGradlePlugin,
)
applicablePlugin(scope = Scope.CurrentProject, pluginId = PluginId.JetbrainsKotlinAtomicfu)

withPlugin(PluginId.JavierscKotlinKopyGradlePlugin) {
configure<KopyExtension> {
functions.set(this@HubdleKotlinKopyFeatureExtension.functions)
visibility.set(this@HubdleKotlinKopyFeatureExtension.visibility)
}
}
}
}

public interface HubdleKotlinKopyDelegateFeatureExtension : BaseHubdleExtension {

public val kopy: HubdleKotlinKopyFeatureExtension
get() = project.getHubdleExtension()

@HubdleDslMarker
public fun kopy(action: Action<HubdleKotlinKopyFeatureExtension> = Action {}) {
kopy.enableAndExecute(action)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotli
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinContextReceiversDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinCoroutinesDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinExtendedStdlibDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKopyDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKotestDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinMoleculeDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinSerializationDelegateFeatureExtension
Expand Down Expand Up @@ -37,22 +38,23 @@ public open class HubdleKotlinJvmFeaturesExtension @Inject constructor(project:
}

public interface HubdleKotlinJvmDelegateFeaturesExtension :
HubdleKotlinAtomicfuDelegateFeatureExtension,
HubdleKotlinBuildKonfigDelegateFeatureExtension,
HubdleGradleDelegateFeatureExtension,
HubdleIntellijDelegateFeatureExtension,
HubdleJavaApplicationDelegateFeatureExtension,
HubdleJavaVersionDelegateFeatureExtension,
HubdleJvmToolchainDelegateFeatureExtension,
HubdleKotlinAtomicfuDelegateFeatureExtension,
HubdleKotlinBuildKonfigDelegateFeatureExtension,
HubdleKotlinCompilerPluginDelegateFeatureExtension,
HubdleKotlinComposeDelegateFeatureExtension,
HubdleKotlinContextReceiversDelegateFeatureExtension,
HubdleKotlinCoroutinesDelegateFeatureExtension,
HubdleKotlinExtendedStdlibDelegateFeatureExtension,
HubdleJavaVersionDelegateFeatureExtension,
HubdleKotlinKopyDelegateFeatureExtension,
HubdleKotlinKotestDelegateFeatureExtension,
HubdleKotlinMoleculeDelegateFeatureExtension,
HubdleKotlinSerializationDelegateFeatureExtension,
HubdleKotlinSqlDelightDelegateFeatureExtension,
HubdleJvmToolchainDelegateFeatureExtension
HubdleKotlinSqlDelightDelegateFeatureExtension

internal val HubdleEnableableExtension.hubdleKotlinJvmFeatures: HubdleKotlinJvmFeaturesExtension
get() = getHubdleExtension()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotli
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinComposeDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinCoroutinesDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinExtendedStdlibDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKopyDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinKotestDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinMoleculeDelegateFeatureExtension
import com.javiersc.hubdle.project.extensions.kotlin.features.shared.HubdleKotlinSerializationDelegateFeatureExtension
Expand All @@ -33,18 +34,19 @@ public open class HubdleKotlinMultiplatformFeaturesExtension @Inject constructor
}

public interface HubdleKotlinMultiplatformDelegateFeaturesExtension :
HubdleKotlinMultiplatformMinimumTargetPerOsDelegateFeatureExtension,
HubdleJavaVersionDelegateFeatureExtension,
HubdleJvmToolchainDelegateFeatureExtension,
HubdleKotlinAtomicfuDelegateFeatureExtension,
HubdleKotlinBuildKonfigDelegateFeatureExtension,
HubdleKotlinComposeDelegateFeatureExtension,
HubdleKotlinCoroutinesDelegateFeatureExtension,
HubdleKotlinExtendedStdlibDelegateFeatureExtension,
HubdleJavaVersionDelegateFeatureExtension,
HubdleKotlinKopyDelegateFeatureExtension,
HubdleKotlinKotestDelegateFeatureExtension,
HubdleKotlinMoleculeDelegateFeatureExtension,
HubdleKotlinMultiplatformMinimumTargetPerOsDelegateFeatureExtension,
HubdleKotlinSerializationDelegateFeatureExtension,
HubdleKotlinSqlDelightDelegateFeatureExtension,
HubdleJvmToolchainDelegateFeatureExtension
HubdleKotlinSqlDelightDelegateFeatureExtension

internal val HubdleEnableableExtension.hubdleKotlinMultiplatformFeatures:
HubdleKotlinMultiplatformFeaturesExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum class PluginId(public val id: String) {
JavaGradlePlugin("java-gradle-plugin"),
JavaTestFixtures("java-test-fixtures"),
JavierscHubdle("com.javiersc.hubdle"),
JavierscKotlinKopyGradlePlugin("com.javiersc.kotlin.kopy"),
JavierscSemverGradlePlugin("com.javiersc.semver"),
JetbrainsChangelog("org.jetbrains.changelog"),
JetbrainsCompose("org.jetbrains.compose"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.javiersc.hubdle.project.kotlin.jvm.features

import com.javiersc.gradle.testkit.test.extensions.GradleTestKitTest
import com.javiersc.hubdle.hubdle.gradle.plugin.HubdleGradlePluginProjectData
import com.javiersc.hubdle.project.fixtures.KotlinVersionEnv
import com.javiersc.hubdle.project.fixtures.KotlinVersionRegexOrEmptyOrNull
import io.kotest.matchers.string.shouldContain
import java.io.File
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS

internal class KotlinJvmKopyFeatureTest : GradleTestKitTest() {

@Test
@EnabledOnOs(value = [OS.LINUX, OS.MAC, OS.WINDOWS])
@EnabledIfSystemProperty(named = KotlinVersionEnv, matches = KotlinVersionRegexOrEmptyOrNull)
fun `kopy feature`() {
gradleTestKitTest("kotlin/jvm/features/kopy") {
val hubdleTomlDestination =
projectDir.resolve("gradle/hubdle.libs.versions.toml").apply {
parentFile.mkdirs()
createNewFile()
}
File(HubdleGradlePluginProjectData.RootDirAbsolutePath)
.resolve("gradle/hubdle.libs.versions.toml")
.copyTo(target = hubdleTomlDestination, overwrite = true)
withArguments("run", "--no-scan").build().outputTrimmed.apply {
shouldContain("A(b=B(c=Hello world))")
shouldContain("A(b=B(c=Hello, World!))")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@file:Suppress("PackageDirectoryMismatch")

plugins {
id("com.javiersc.hubdle")
}

hubdle {
config {
versioning {
isEnabled.set(false)
}
}

kotlin {
jvm {
features {
application {
mainClass.set("com.javiersc.kotlin.jvm.kopy.MainKt")
}
kopy()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
####################################################################################################
### CONFIGURATION ###
####################################################################################################
root.project.name=sandbox-project
project.group=com.kotlin.jvm
main.project.name=bar.baz
####################################################################################################
### CODE ANALYSIS ###
####################################################################################################
analysis.sonar.organization=javiersc
####################################################################################################
### POM ###
####################################################################################################
pom.name=Sandbox name
pom.description=Sandbox description
pom.url=https://github.com/JavierSegoviaCordoba/sandbox-project
pom.license.name=The Apache License, Version 2.0
pom.license.url=https://www.apache.org/licenses/LICENSE-2.0.txt
pom.developer.id=JavierSegoviaCordoba
pom.developer.name=Javier Segovia Cordoba
pom.developer.email=[email protected]
pom.scm.url=https://github.com/JavierSegoviaCordoba/sandbox-project
pom.scm.connection=scm:git:[email protected]:JavierSegoviaCordoba/sandbox-project.git
pom.scm.developerConnection=scm:git:[email protected]:JavierSegoviaCordoba/sandbox-project.git
####################################################################################################
### Gradle ###
####################################################################################################
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@file:Suppress("PackageDirectoryMismatch")

package com.javiersc.kotlin.jvm.kopy

import com.javiersc.kotlin.kopy.Kopy

fun main() {
val a1 = A(b = B(c = "Hello world"))
val a2 = a1.copy {
b.c = "Hello, World!"
}

check(a1.b.c == "Hello world")
check(a2.b.c == "Hello, World!")

println(a1)
println(a2)
}

@Kopy data class A(val b: B)
@Kopy data class B(val c: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@file:Suppress("PackageDirectoryMismatch")

pluginManagement {
repositories {
google {
mavenContent {
includeGroupByRegex("androidx.*")
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
}
}
gradlePluginPortal()
mavenCentral()
}
}

plugins { //
id("com.javiersc.hubdle")
}

hubdleSettings {
catalog { //
isEnabled.set(false)
}
}

dependencyResolutionManagement {
versionCatalogs {
register("hubdle") { //
from(files("gradle/hubdle.libs.versions.toml"))
}
}
repositories { //
mavenLocalTest()
}
}

0 comments on commit 267abaf

Please sign in to comment.