Skip to content

Commit 6353e74

Browse files
committed
Update after review
1 parent 855955b commit 6353e74

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

gradle-module-plugin/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repositories {
2020
}
2121

2222
group = "io.ia.sdk"
23-
version = "0.4.1"
23+
version = "0.5.0-SNAPSHOT"
2424

2525
configurations {
2626
val functionalTestImplementation by registering {
@@ -61,7 +61,6 @@ dependencies {
6161
implementation(libs.kotlinXmlBuilder)
6262
api(libs.moduleSigner)
6363
testImplementation(libs.kotlinTestJunit)
64-
testImplementation(libs.junit.jupiter.api)
6564
testImplementation("io.ia.sdk.tools.module.gen:generator-core")
6665
}
6766

gradle-module-plugin/gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
[versions]
22
kotlin = "1.7.10"
33
moshi = "1.9.3"
4-
junit-jupiter = "5.11.4"
54

65
[libraries]
76
# Dependencies referencable in buildscripts. Note that dashes are replaced by periods in the buildscript reference.
87
guava = { module = "com.google.guava:guava", version = "30.1.1-jre" }
98
kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
109
kotlinTestJunit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
1110
kotlinXmlBuilder = { module = "org.redundent:kotlin-xml-builder", version = "1.7.2" }
12-
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" }
1311
moshi = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" }
1412
moshiCodegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "moshi" }
1513
moduleSigner = { module = "com.inductiveautomation.ignitionsdk:module-signer", version = "0.0.1.ia" }

gradle-module-plugin/src/functionalTest/kotlin/io/ia/sdk/gradle/modl/task/ZipModuleTests.kt

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,61 @@ import org.gradle.api.Project
77
import org.gradle.api.internal.project.DefaultProject
88
import org.gradle.api.tasks.TaskExecutionException
99
import org.gradle.testfixtures.ProjectBuilder
10-
import org.junit.jupiter.api.Assertions.assertThrows
11-
import org.junit.jupiter.api.Assertions.assertTrue
12-
import org.junit.jupiter.api.BeforeEach
13-
import org.junit.jupiter.api.Test
14-
import org.junit.jupiter.api.io.TempDir
10+
import kotlin.io.path.createTempDirectory
11+
import kotlin.test.BeforeTest
12+
import kotlin.test.AfterTest
13+
import kotlin.test.Test
14+
import kotlin.test.assertTrue
15+
import kotlin.test.assertFailsWith
1516
import java.io.File
1617

1718
class ZipModuleTests : BaseTest() {
1819

19-
@TempDir
20-
lateinit var testProjectDir: File
20+
private lateinit var tempDir: File
2121
private lateinit var project: Project
2222
private lateinit var task: ZipModule
2323

24-
@BeforeEach
24+
@BeforeTest
2525
fun setup() {
26-
project = ProjectBuilder.builder().withProjectDir(testProjectDir).build() as DefaultProject
26+
tempDir = createTempDirectory().toFile()
27+
project = ProjectBuilder.builder().withProjectDir(tempDir).build() as DefaultProject
2728
task = project.tasks.create("testTask", ZipModule::class.java)
2829

29-
// Set up the task properties with the test directory
30-
task.content.set(project.objects.directoryProperty().fileValue(File(testProjectDir, "content")))
31-
task.unsignedModule.set(project.objects.fileProperty().fileValue(File(testProjectDir, "output.modl")))
30+
// Set up the task properties with the temp directory
31+
task.content.set(project.objects.directoryProperty().fileValue(File(tempDir, "content")))
32+
task.unsignedModule.set(project.objects.fileProperty().fileValue(File(tempDir, "output.modl")))
33+
}
34+
35+
@AfterTest
36+
fun cleanup() {
37+
tempDir.deleteRecursively()
3238
}
3339

3440
@Test
3541
fun `task succeeds when no duplicate jars exist`() {
3642
// Arrange
37-
val contentDir = File(testProjectDir, "content").apply { mkdirs() }
43+
val contentDir = task.content.asFile.get().apply { mkdirs() }
3844
File(contentDir, "my-lib-1.0.jar").createNewFile()
3945
File(contentDir, "another-lib-2.0.jar").createNewFile()
4046

41-
// Act & Assert: The task should not throw an exception
47+
// Act: The task should not throw an exception
4248
task.execute()
4349
}
4450

4551
@Test
4652
fun `task fails when duplicate jars with different versions exist`() {
4753
// Arrange
48-
val contentDir = File(testProjectDir, "content").apply { mkdirs() }
54+
val contentDir = task.content.asFile.get().apply { mkdirs() }
4955
File(contentDir, "my-lib-1.0.jar").createNewFile()
5056
File(contentDir, "my-lib-2.0.jar").createNewFile() // This is the duplicate
5157

52-
// Act & Assert: The task should throw a TaskExecutionException
53-
val exception = assertThrows(TaskExecutionException::class.java) {
58+
// Act & Assert: The task should throw a IllegalArgumentException
59+
val exception = assertFailsWith<IllegalArgumentException>{
5460
task.execute()
5561
}
5662

5763
// Verify the exception message
58-
val expectedMessage = "Jar with 'my-lib' has multiple versions presented"
64+
val expectedMessage = "Library 'my-lib' exists in multiple versions"
5965
assertTrue(exception.message!!.contains(expectedMessage))
6066
}
6167

gradle-module-plugin/src/main/kotlin/io/ia/sdk/gradle/modl/task/ZipModule.kt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,26 @@ open class ZipModule @Inject constructor(objects: ObjectFactory) : DefaultTask()
5858
}
5959

6060
/**
61-
* Try to detect jars in contentDir with the same name but have multiple
62-
* versions existed. Fail the build when it's found.
61+
* Fail the build when jars in the contentDir with the same name has
62+
* multiple versions detected.
6363
**/
6464
fun checkDuplicateJars(contentDir: File) {
6565
project.logger.info("Parsing file name in: ${contentDir.absolutePath}")
6666

67-
val fileMap = mutableMapOf<String, String>()
68-
val regex = "^(.+?)-(\\d+.*)(?:\\.jar)".toRegex()
67+
val fileSet = mutableSetOf<String>()
68+
val regex = "^(.+?)-(?:\\d+.*)(?:\\.jar)".toRegex()
6969

7070
contentDir.walk().filter { it.isFile }.forEach { file ->
7171
val matchResult = regex.find(file.name) // Match all the jar files
7272

7373
if (matchResult != null) {
7474
val name = matchResult.groupValues[1]
75-
val version = matchResult.groupValues[2]
7675

77-
if (fileMap.containsKey(name)) {
78-
throw TaskExecutionException(
79-
this,
80-
IllegalArgumentException(
81-
"""Jar with '$name' has multiple versions presented in ${contentDir.absolutePath}
82-
Please ensure only one version exist (preferably the highest) and update lib.version.toml file if needed.
83-
""".trimIndent()
84-
)
85-
)
76+
if (fileSet.contains(name)) {
77+
throw IllegalArgumentException(
78+
"Library '$name' exists in multiple versions in ${contentDir.absolutePath}")
8679
} else {
87-
fileMap[name] = version
80+
fileSet.add(name)
8881
}
8982
}
9083
}

0 commit comments

Comments
 (0)