diff --git a/alchemist-incarnation-collektive/src/main/kotlin/it/unibo/alchemist/CollektiveIncarnation.kt b/alchemist-incarnation-collektive/src/main/kotlin/it/unibo/alchemist/CollektiveIncarnation.kt index 92afcad05..69263ca9e 100644 --- a/alchemist-incarnation-collektive/src/main/kotlin/it/unibo/alchemist/CollektiveIncarnation.kt +++ b/alchemist-incarnation-collektive/src/main/kotlin/it/unibo/alchemist/CollektiveIncarnation.kt @@ -26,8 +26,6 @@ import it.unibo.alchemist.util.RandomGenerators.nextDouble import it.unibo.collektive.aggregate.api.Aggregate import it.unibo.collektive.compiler.CollektiveK2JVMCompiler import it.unibo.collektive.compiler.logging.CollectingMessageCollector -import it.unibo.collektive.compiler.util.md5 -import it.unibo.collektive.compiler.util.toBase32 import org.apache.commons.math3.random.RandomGenerator import org.danilopianini.util.ListSet import org.jetbrains.kotlin.cli.common.ExitCode @@ -42,6 +40,7 @@ import org.slf4j.LoggerFactory import java.io.File import java.lang.reflect.Method import java.net.URLClassLoader +import java.security.MessageDigest import javax.script.ScriptEngineManager import kotlin.io.path.absolutePathString import kotlin.io.path.createTempDirectory @@ -117,7 +116,7 @@ class CollektiveIncarnation

: Incarnation where P : Position

{ val code: String = parameters["code"]?.toString().orEmpty() val sourceSets: List = parameters["source-sets"].toFiles() val classpath = sourceSets.joinToString(separator = File.pathSeparator) { it.absolutePath } - val internalIdentifier = "$classpath$code$entrypoint".md5().toBase32() + val internalIdentifier = "$classpath$code$entrypoint".md5() val (name: String, methodName: String) = when (val nameFromParameters = parameters["name"]) { null -> "collektive$internalIdentifier".let { it to it } @@ -222,6 +221,11 @@ class CollektiveIncarnation

: Incarnation where P : Position

{ ?: error("No script engine with ${property.name} found.") } + private fun String.md5(): String = + MessageDigest.getInstance("MD5").digest(toByteArray()).joinToString("") { + "%02x".format(it) + } + private val findPackage = Regex("""package\s+((\w+\.)*\w+)(\s|;|/|$)""", RegexOption.MULTILINE) private val validName = Regex("^[a-zA-Z_][a-zA-Z0-9_]*$", RegexOption.MULTILINE) private val logger = LoggerFactory.getLogger(CollektiveIncarnation::class.java) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5e71e3c47..aed30a395 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,12 +8,15 @@ kotlin = "2.1.0" [libraries] alchemist-api = { module = "it.unibo.alchemist:alchemist-api", version.ref = "alchemist" } alchemist = { module = "it.unibo.alchemist:alchemist", version.ref = "alchemist" } -apache-commons-codec = "commons-codec:commons-codec:1.17.2" + caffeine = "com.github.ben-manes.caffeine:caffeine:3.2.0" + javap = "com.perfma.wrapped:com.sun.tools:1.8.0_jdk8u275-b01_linux_x64" + kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" } kotest-runner-junit5-jvm = { module = "io.kotest:kotest-runner-junit5-jvm", version.ref = "kotest" } + kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" } kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } kotlin-scripting-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable", version.ref = "kotlin" } @@ -22,6 +25,7 @@ kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotl kotlin-test-common = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlin" } kotlin-test-annotations-common = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" } kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } + kotlinpoet = "com.squareup:kotlinpoet:2.0.0" slf4j = "org.slf4j:slf4j-api:2.0.16" subjekt = "io.github.freshmag:subjekt-api:1.1.5"