io.gitlab.arturbosch.detekt.internal.ClassLoaderCache.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of detekt-gradle-plugin Show documentation
Show all versions of detekt-gradle-plugin Show documentation
Static code analysis for Kotlin
package io.gitlab.arturbosch.detekt.internal
import org.gradle.api.file.FileCollection
import java.net.URLClassLoader
import java.util.concurrent.ConcurrentHashMap
fun interface ClassLoaderCache {
fun getOrCreate(classpath: FileCollection): URLClassLoader
}
internal class DefaultClassLoaderCache : ClassLoaderCache {
private val classpathFilesHashWithLoaders = ConcurrentHashMap()
override fun getOrCreate(classpath: FileCollection): URLClassLoader {
val classpathFiles = classpath.files
val classpathHashCode = HashSet(classpathFiles).hashCode()
return classpathFilesHashWithLoaders.getOrPut(classpathHashCode) {
URLClassLoader(
classpathFiles.map { it.toURI().toURL() }.toTypedArray(),
null /* isolate detekt environment */
)
}
}
}
object GlobalClassLoaderCache : ClassLoaderCache by DefaultClassLoaderCache()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy