All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gitlab.arturbosch.detekt.internal.ClassLoaderCache.kt Maven / Gradle / Ivy

There is a newer version: 1.23.7
Show newest version
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