@@ -23,7 +23,7 @@ class ResourcesTaskTests {
23
23
val buildFile = projectDir.resolve(" build.gradle" )
24
24
val taskSetupIndented = taskSetup.prependIndent(" " .repeat(2 ))
25
25
val buildFileText = """
26
- $PLUGINS_BLOCK
26
+ ${pluginsBlock()}
27
27
28
28
tasks {
29
29
$JUPYTER_RESOURCES_TASK_NAME {
@@ -34,12 +34,15 @@ class ResourcesTaskTests {
34
34
buildFile.writeText(buildFileText)
35
35
}
36
36
37
- private fun runResourcesTask (args : Array <String >? = null): BuildResult {
37
+ private fun runResourcesTask (args : Array <String >? = null, type : String = "" ): BuildResult {
38
38
val arguments = args?.toMutableList() ? : mutableListOf (
39
39
" -Pkotlin.jupyter.add.api=false" ,
40
- " -Pkotlin.jupyter.add.scanner=false"
40
+ " -Pkotlin.jupyter.add.scanner=false" ,
41
+ " --stacktrace" ,
42
+ " --info"
41
43
)
42
- arguments.add(0 , RESOURCES_TASK_NAME )
44
+ val taskName = RESOURCES_TASK_NAME .withPrefix(type)
45
+ arguments.add(0 , taskName)
43
46
44
47
return GradleRunner .create()
45
48
.withProjectDir(projectDir)
@@ -49,8 +52,8 @@ class ResourcesTaskTests {
49
52
.build()
50
53
}
51
54
52
- private fun assertLibrariesJsonContents (expected : LibrariesScanResult ) {
53
- val librariesJsonText = projectDir.resolve(BUILD_LIBRARIES_JSON_PATH ).readText()
55
+ private fun assertLibrariesJsonContents (expected : LibrariesScanResult , type : String = "" ) {
56
+ val librariesJsonText = projectDir.resolve(buildLibrariesJsonPath(type) ).readText()
54
57
val libraryInfo = Json .decodeFromString<LibrariesScanResult >(librariesJsonText)
55
58
56
59
assertEquals(expected, libraryInfo)
@@ -111,7 +114,7 @@ class ResourcesTaskTests {
111
114
val apiAnnotations = jarFile(" api-annotations" )
112
115
buildFile.writeText(
113
116
"""
114
- $PLUGINS_BLOCK
117
+ ${pluginsBlock()}
115
118
116
119
dependencies {
117
120
implementation(files("$apiJar "))
@@ -149,6 +152,89 @@ class ResourcesTaskTests {
149
152
)
150
153
}
151
154
155
+ @Test
156
+ fun `check annotations in MPP` () {
157
+ val version = ClassLoader .getSystemClassLoader().getResource(" VERSION" )?.readText().orEmpty()
158
+
159
+ val propertiesFile = projectDir.resolve(" properties.gradle" )
160
+ propertiesFile.writeText(
161
+ """
162
+ kapt.verbose=true
163
+ """ .trimIndent()
164
+ )
165
+
166
+ val buildFile = projectDir.resolve(" build.gradle.kts" )
167
+
168
+ fun jarFile (name : String ): String {
169
+ return File (" ../$name /build/libs/$name -$version .jar" ).canonicalFile.absolutePath.replace(" \\ " , " /" )
170
+ }
171
+
172
+ val apiJar = jarFile(" api" )
173
+ val apiAnnotations = jarFile(" api-annotations" )
174
+ buildFile.writeText(
175
+ """
176
+ plugins {
177
+ kotlin("multiplatform") version "$KOTLIN_VERSION "
178
+ id("org.jetbrains.kotlin.jupyter.api")
179
+ }
180
+
181
+ kotlin {
182
+ jvm {
183
+ compilations.all {
184
+ kotlinOptions.jvmTarget = "11"
185
+ }
186
+ }
187
+ js(LEGACY) {
188
+ binaries.executable()
189
+ browser()
190
+ }
191
+ sourceSets {
192
+ val commonMain by getting
193
+ val commonTest by getting
194
+ val jvmMain by getting {
195
+ dependencies {
196
+ implementation(files("$apiJar "))
197
+ implementation(files("$apiAnnotations "))
198
+ }
199
+ dependencies.add("kapt", files("$apiAnnotations "))
200
+ }
201
+ val jvmTest by getting
202
+ val jsMain by getting
203
+ val jsTest by getting
204
+ }
205
+ }
206
+ """ .trimIndent()
207
+ )
208
+
209
+ val srcDir = projectDir.resolve(" src/jvmMain/kotlin" )
210
+ srcDir.mkdirs()
211
+
212
+ val integrationKt = srcDir.resolve(" pack" ).resolve(" Integration.kt" )
213
+ integrationKt.parentFile.mkdirs()
214
+ integrationKt.writeText(
215
+ """
216
+ package pack
217
+
218
+ import org.jetbrains.kotlinx.jupyter.api.annotations.JupyterLibrary
219
+ import org.jetbrains.kotlinx.jupyter.api.*
220
+ import org.jetbrains.kotlinx.jupyter.api.libraries.*
221
+
222
+ @JupyterLibrary
223
+ class Integration : JupyterIntegration({
224
+ import("org.my.lib.*")
225
+ })
226
+ """ .trimIndent()
227
+ )
228
+ runResourcesTask(type = " jvm" )
229
+
230
+ assertLibrariesJsonContents(
231
+ LibrariesScanResult (
232
+ producers = listOf (" pack.Integration" ).map(::LibrariesProducerDeclaration )
233
+ ),
234
+ " jvm"
235
+ )
236
+ }
237
+
152
238
@Test
153
239
fun `check extension` () {
154
240
val version = " 0.8.3.202"
@@ -157,7 +243,7 @@ class ResourcesTaskTests {
157
243
158
244
buildFile.writeText(
159
245
"""
160
- $PLUGINS_BLOCK
246
+ ${pluginsBlock()}
161
247
162
248
kotlinJupyter {
163
249
addApiDependency("$version ")
@@ -195,17 +281,27 @@ class ResourcesTaskTests {
195
281
}
196
282
197
283
companion object {
284
+ private const val KOTLIN_VERSION = " 1.5.20"
198
285
private const val RESOURCES_TASK_NAME = " processResources"
199
286
private const val JUPYTER_RESOURCES_TASK_NAME = " processJupyterApiResources"
200
287
201
- private const val MAIN_SOURCE_SET_BUILD_RESOURCES_PATH = " build/resources/main"
202
- private const val BUILD_LIBRARIES_JSON_PATH = " $MAIN_SOURCE_SET_BUILD_RESOURCES_PATH /$KOTLIN_JUPYTER_RESOURCES_PATH /$KOTLIN_JUPYTER_LIBRARIES_FILE_NAME "
288
+ private fun mainSourceSetBuildResourcesPath (type : String = ""): String {
289
+ return if (type.isEmpty()) {
290
+ " build/resources/main"
291
+ } else {
292
+ " build/processedResources/$type /main"
293
+ }
294
+ }
295
+ private fun buildLibrariesJsonPath (type : String = "") = " ${mainSourceSetBuildResourcesPath(type)} /$KOTLIN_JUPYTER_RESOURCES_PATH /$KOTLIN_JUPYTER_LIBRARIES_FILE_NAME "
203
296
204
- private val PLUGINS_BLOCK = """
297
+ private fun pluginsBlock ( ktPluginId : String = "jvm") = """
205
298
plugins {
206
- id 'org.jetbrains.kotlin.jvm ' version '1.4.20 '
299
+ id 'org.jetbrains.kotlin.$ktPluginId ' version '$KOTLIN_VERSION '
207
300
id 'org.jetbrains.kotlin.jupyter.api'
208
301
}
209
302
""" .trimIndent()
303
+
304
+ private fun String.withPrefix (prefix : String ) =
305
+ if (prefix.isEmpty()) this else prefix + capitalize()
210
306
}
211
307
}
0 commit comments