Skip to content

Commit

Permalink
refactor: use jdk md5 hashing removing apache commons from dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasfara committed Jan 19, 2025
1 parent 5f82f3f commit 9602772
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -117,7 +116,7 @@ class CollektiveIncarnation<P> : Incarnation<Any?, P> where P : Position<P> {
val code: String = parameters["code"]?.toString().orEmpty()
val sourceSets: List<File> = 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 }
Expand Down Expand Up @@ -222,6 +221,11 @@ class CollektiveIncarnation<P> : Incarnation<Any?, P> where P : Position<P> {
?: 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)
Expand Down
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"
Expand Down

0 comments on commit 9602772

Please sign in to comment.