Skip to content

Commit fc61704

Browse files
Fix issue #290 (#291)
* Fix issue #290 * Updated changelog and version * Fix local publication
1 parent 279d72f commit fc61704

File tree

8 files changed

+166
-46
lines changed

8 files changed

+166
-46
lines changed

compiler-plugin/build.gradle.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ buildConfig {
4040

4141
publishing {
4242
publications {
43-
if (System.getenv("RELEASE_COMPILER_PLUGIN").toBoolean()) {
44-
create<MavenPublication>("kotlin") {
45-
from(components["java"])
46-
artifactId = "mappie-compiler-plugin"
47-
mappiePom(name = "tech.mappie:mappie-compiler-plugin")
48-
}
43+
create<MavenPublication>("kotlin") {
44+
from(components["java"])
45+
artifactId = "mappie-compiler-plugin"
46+
mappiePom(name = "tech.mappie:mappie-compiler-plugin")
4947
}
5048
}
5149

52-
repositories {
53-
maven {
54-
url = uri(rootProject.layout.buildDirectory.file("staging-deploy"))
50+
if (System.getenv("RELEASE_COMPILER_PLUGIN").toBoolean()) {
51+
repositories {
52+
maven {
53+
url = uri(rootProject.layout.buildDirectory.file("staging-deploy"))
54+
}
5555
}
5656
}
5757
}

compiler-plugin/src/main/kotlin/tech/mappie/ir/generation/classes/ObjectMappieCodeGenerator.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
1111
import org.jetbrains.kotlin.ir.types.IrSimpleType
1212
import org.jetbrains.kotlin.ir.types.makeNotNull
1313
import org.jetbrains.kotlin.ir.types.typeOrFail
14+
import org.jetbrains.kotlin.ir.types.typeOrNull
1415
import org.jetbrains.kotlin.ir.util.getKFunctionType
1516
import tech.mappie.exceptions.MappiePanicException.Companion.panic
1617
import tech.mappie.ir.generation.ClassMappieCodeGenerationModel
@@ -46,7 +47,9 @@ class ObjectMappieCodeGenerator(private val context: CodeGenerationContext, priv
4647
private fun IrBlockBodyBuilder.content() {
4748
val constructor = model.constructor.symbol
4849
val regularParameters = model.declaration.parameters.filter { it.kind == IrParameterKind.Regular }
49-
val call = irCallConstructor(constructor, emptyList()).apply {
50+
val typeArguments = (model.declaration.returnType.type as IrSimpleType).arguments.map { it.typeOrNull ?: context.irBuiltIns.anyType }
51+
52+
val call = irCallConstructor(constructor, typeArguments).apply {
5053
model.mappings.forEach { (target, source) ->
5154
if (target is ValueParameterTarget) {
5255
constructArgument(source, regularParameters)?.let { argument ->
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package tech.mappie.testing.scenarios
2+
3+
import org.assertj.core.api.Assertions.assertThat
4+
import org.junit.jupiter.api.Test
5+
import tech.mappie.testing.MappieTestCase
6+
import java.time.Instant
7+
8+
class PaginationTest : MappieTestCase() {
9+
10+
data class GetProjectListResult (
11+
val items: List<GetProjectListResultItem>,
12+
val totalCount: Int,
13+
val page: Int,
14+
val pageSize: Int,
15+
val totalPages: Int,
16+
val hasNextPage: Boolean,
17+
val hasPreviousPage: Boolean
18+
)
19+
20+
data class GetProjectListResultItem (
21+
val createdAt: Instant,
22+
val lastModifiedAt: Instant? = null,
23+
val id: String,
24+
val number: String
25+
)
26+
27+
data class PaginationInfo<T>(
28+
val pageKey: Int,
29+
val totalPages: Int,
30+
val isLastPage: Boolean,
31+
val items: List<T>,
32+
val totalItems: Int,
33+
) {
34+
val nextPageKey: Int
35+
get() = pageKey + 1
36+
}
37+
38+
data class ProjectListItem(
39+
val id: String,
40+
val number: String,
41+
val date: Instant
42+
)
43+
44+
@Test
45+
fun `mapper without pagination`() {
46+
compile {
47+
file("Test.kt",
48+
"""
49+
import tech.mappie.api.ObjectMappie
50+
import tech.mappie.testing.scenarios.PaginationTest.*
51+
52+
class ProjectListItemMapper: ObjectMappie<GetProjectListResultItem, ProjectListItem>() {
53+
override fun map(from: GetProjectListResultItem): ProjectListItem = mapping {
54+
to::date fromProperty from::createdAt
55+
}
56+
}
57+
58+
""")
59+
} satisfies {
60+
isOk()
61+
hasNoWarningsOrErrors()
62+
63+
val mapper = objectMappie<GetProjectListResultItem, ProjectListItem>("ProjectListItemMapper")
64+
65+
assertThat(mapper.map(GetProjectListResultItem(Instant.MIN, null, "id", "number")))
66+
.isEqualTo(ProjectListItem("id", "number", Instant.MIN))
67+
}
68+
}
69+
70+
@Test
71+
fun `mapper with pagination`() {
72+
compile {
73+
file("Test.kt",
74+
"""
75+
import tech.mappie.api.ObjectMappie
76+
import tech.mappie.testing.scenarios.PaginationTest.*
77+
78+
class GetProjectListResultMapper: ObjectMappie<GetProjectListResult, PaginationInfo<ProjectListItem>>() {
79+
override fun map(from: GetProjectListResult) = mapping {
80+
to::pageKey fromProperty from::page
81+
to::isLastPage fromValue !from.hasNextPage
82+
to::totalItems fromProperty from::totalPages
83+
}
84+
}
85+
86+
object ProjectListItemMapper: ObjectMappie<GetProjectListResultItem, ProjectListItem>() {
87+
override fun map(from: GetProjectListResultItem): ProjectListItem = mapping {
88+
to::date fromProperty from::createdAt
89+
}
90+
}
91+
92+
""")
93+
} satisfies {
94+
isOk()
95+
hasNoWarningsOrErrors()
96+
97+
val mapper = objectMappie<GetProjectListResult, PaginationInfo<ProjectListItem>>("GetProjectListResultMapper")
98+
99+
val input = GetProjectListResult(
100+
listOf(GetProjectListResultItem(Instant.MIN, null, "id", "number")),
101+
1,
102+
2,
103+
3,
104+
4,
105+
false,
106+
false
107+
)
108+
109+
assertThat(mapper.map(input))
110+
.isEqualTo(PaginationInfo(2, 4, true, listOf(ProjectListItem("id", "number", Instant.MIN)), 4))
111+
}
112+
}
113+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=2.2.20-1.6.0
1+
version=2.2.20-1.6.1
22

33
org.gradle.configuration-cache=true
44
org.gradle.configuration-cache.parallel=true

mappie-api/build.gradle.kts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ kotlin {
5252
}
5353

5454
publishing {
55-
if (System.getenv("RELEASE_API").toBoolean()) {
56-
publications.configureEach {
57-
if (this is MavenPublication) {
58-
artifact(tasks["javadocJar"])
59-
// jreleaser workaround
60-
if (name != "jvm" && name != "kotlinMultiplatform") {
61-
artifact(tasks["emptyJar"])
62-
}
63-
mappiePom(name = "tech.mappie:mappie-api")
55+
publications.configureEach {
56+
if (this is MavenPublication) {
57+
artifact(tasks["javadocJar"])
58+
// jreleaser workaround
59+
if (name != "jvm" && name != "kotlinMultiplatform") {
60+
artifact(tasks["emptyJar"])
6461
}
62+
mappiePom(name = "tech.mappie:mappie-api")
6563
}
6664
}
6765

68-
repositories {
69-
maven {
70-
url = uri(rootProject.layout.buildDirectory.file("staging-deploy"))
66+
if (System.getenv("RELEASE_API").toBoolean()) {
67+
repositories {
68+
maven {
69+
url = uri(rootProject.layout.buildDirectory.file("staging-deploy"))
70+
}
7171
}
7272
}
7373
}

maven-plugin/build.gradle.kts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ java {
3333
}
3434

3535
publishing {
36-
if (System.getenv("RELEASE_MAVEN_PLUGIN").toBoolean()) {
37-
publications {
38-
create<MavenPublication>("java-maven-plugin") {
39-
artifactId = "mappie-maven-plugin"
40-
from(components["java"])
41-
mappiePom(name = "tech.mappie:maven-plugin")
42-
}
36+
publications {
37+
create<MavenPublication>("java-maven-plugin") {
38+
artifactId = "mappie-maven-plugin"
39+
from(components["java"])
40+
mappiePom(name = "tech.mappie:maven-plugin")
4341
}
4442
}
4543

46-
repositories {
47-
maven {
48-
url = uri(rootProject.layout.buildDirectory.file("staging-deploy"))
44+
if (System.getenv("RELEASE_MAVEN_PLUGIN").toBoolean()) {
45+
repositories {
46+
maven {
47+
url = uri(rootProject.layout.buildDirectory.file("staging-deploy"))
48+
}
4949
}
5050
}
5151
}

modules/kotlinx-datetime/build.gradle.kts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ kotlin {
3131
}
3232

3333
publishing {
34-
if (System.getenv("RELEASE_MODULE_KOTLINX_DATETIME").toBoolean()) {
35-
publications.configureEach {
36-
if (this is MavenPublication) {
37-
artifactId = artifactId.replace("kotlinx-datetime", "module-kotlinx-datetime")
38-
artifact(tasks["javadocJar"])
39-
// jreleaser workaround
40-
if (name != "jvm" && name != "kotlinMultiplatform") {
41-
artifact(tasks["emptyJar"])
42-
}
43-
mappiePom(name = "tech.mappie:module-kotlinx-datetime")
34+
publications.configureEach {
35+
if (this is MavenPublication) {
36+
artifactId = artifactId.replace("kotlinx-datetime", "module-kotlinx-datetime")
37+
artifact(tasks["javadocJar"])
38+
// jreleaser workaround
39+
if (name != "jvm" && name != "kotlinMultiplatform") {
40+
artifact(tasks["emptyJar"])
4441
}
42+
mappiePom(name = "tech.mappie:module-kotlinx-datetime")
4543
}
4644
}
4745

48-
repositories {
49-
maven {
50-
url = uri(rootProject.layout.buildDirectory.file("staging-deploy"))
46+
if (System.getenv("RELEASE_MODULE_KOTLINX_DATETIME").toBoolean()) {
47+
repositories {
48+
maven {
49+
url = uri(rootProject.layout.buildDirectory.file("staging-deploy"))
50+
}
5151
}
5252
}
5353
}

website/src/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
title: "Changelog"
33
layout: "layouts/changelog.html"
44
changelog:
5+
- date: "2025-10-22"
6+
title: "v2.2.20-1.6.1"
7+
items:
8+
- "[#290](https://github.com/Mr-Mappie/mappie/issues/290) Fix IndexOutOfBoundsException with generic target type."
59
- date: "2025-10-12"
610
title: "v2.2.20-1.6.0"
711
items:

0 commit comments

Comments
 (0)