Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,24 @@ class ZipFileSystemCacheableAccessor(private val cacheLimit: Int) : ZipFileSyste
}

override fun <T> withZipFileSystem(zipFile: File, action: (FileSystem) -> T): T {
val fileSystem = openedFileSystems.getOrPut(zipFile) { zipFile.zipFileSystem() }
val fileSystem = synchronized(openedFileSystems) {
openedFileSystems.getOrPut(zipFile) { zipFile.zipFileSystem() }
}
return action(fileSystem)
}

fun reset() {
var lastException: Exception? = null
for (fileSystem in openedFileSystems.values) {
try {
fileSystem.close()
} catch (e: Exception) {
lastException = e
synchronized(openedFileSystems) {
for (fileSystem in openedFileSystems.values) {
try {
fileSystem.close()
} catch (e: Exception) {
lastException = e
}
}
openedFileSystems.clear()
}
openedFileSystems.clear()

lastException?.let {
throw it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ class KotlinLibraryResolverImpl<L : KotlinLibrary> internal constructor(
noEndorsedLibs: Boolean,
): List<KotlinLibrary> {

val userProvidedLibraries = unresolvedLibraries.asSequence()
.mapNotNull { searchPathResolver.resolve(it) }
.toList()
val userProvidedLibraries = unresolvedLibraries
.parallelStream()
.map { searchPathResolver.resolve(it) }
.filter { it != null }
.map { it!! }
.collect(java.util.stream.Collectors.toList())

val defaultLibraries = searchPathResolver.defaultLinks(noStdLib, noDefaultLibs, noEndorsedLibs)

Expand Down Expand Up @@ -126,28 +129,31 @@ class KotlinLibraryResolverImpl<L : KotlinLibrary> internal constructor(
// constructed from the very beginning as well.
val result = KotlinLibraryResolverResultImpl(rootLibraries)

val cache = mutableMapOf<Any, KotlinResolvedLibrary>()
val cache = java.util.concurrent.ConcurrentHashMap<Any, KotlinResolvedLibrary>()
cache.putAll(rootLibraries.map { it.library.libraryFile.fileKey to it })

val processingQueue = ArrayDeque(rootLibraries)
while(processingQueue.isNotEmpty()) {
val currentLibrary = processingQueue.removeFirst()
currentLibrary.library.unresolvedDependencies(resolveManifestDependenciesLenient)
.forEach { unresolvedDependency ->
if (!searchPathResolver.isProvidedByDefault(unresolvedDependency)) {
searchPathResolver.resolve(unresolvedDependency)?.let { resolvedDependencyLibrary ->
val fileKey = resolvedDependencyLibrary.libraryFile.fileKey
if (fileKey in cache) {
currentLibrary.addDependency(cache[fileKey]!!)
} else {
val newlyResolved = KotlinResolvedLibraryImpl(resolvedDependencyLibrary)
cache[fileKey] = newlyResolved
currentLibrary.addDependency(newlyResolved)
processingQueue.add(newlyResolved)
var currentLevel: List<KotlinResolvedLibraryImpl> = rootLibraries
while (currentLevel.isNotEmpty()) {
val nextLevel = java.util.concurrent.ConcurrentLinkedQueue<KotlinResolvedLibraryImpl>()

currentLevel.parallelStream().forEach { currentLibrary ->
currentLibrary.library.unresolvedDependencies(resolveManifestDependenciesLenient)
.parallelStream()
.forEach { unresolvedDependency ->
if (!searchPathResolver.isProvidedByDefault(unresolvedDependency)) {
searchPathResolver.resolve(unresolvedDependency)?.let { resolvedDependencyLibrary ->
val fileKey = resolvedDependencyLibrary.libraryFile.fileKey
val resolvedLibrary = cache.computeIfAbsent(fileKey) {
val newLib = KotlinResolvedLibraryImpl(resolvedDependencyLibrary)
nextLevel.add(newLib)
newLib
}
currentLibrary.addDependency(resolvedLibrary)
}
}
}
}
}
currentLevel = nextLevel.toList()
}
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.jetbrains.kotlin.library.metadata.resolver.KotlinResolvedLibrary

class KotlinResolvedLibraryImpl(override val library: KotlinLibrary) : KotlinResolvedLibrary {

private val _resolvedDependencies = mutableListOf<KotlinResolvedLibrary>()
private val _resolvedDependencies = java.util.Collections.synchronizedList(mutableListOf<KotlinResolvedLibrary>())
private val _emptyPackages by lazy { parseModuleHeader(library.metadata.moduleHeaderData).emptyPackageList }

override val resolvedDependencies: List<KotlinResolvedLibrary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
// Store already resolved libraries.
private inner class ResolvedLibrary(val library: L?)

private val resolvedLibraries = HashMap<UnresolvedLibrary, ResolvedLibrary>()
private val resolvedLibraries = java.util.concurrent.ConcurrentHashMap<UnresolvedLibrary, ResolvedLibrary>()

private fun resolveOrNull(unresolved: UnresolvedLibrary): L? {
return resolvedLibraries.getOrPut(unresolved) {
Expand Down