[project structure tests] optimization: reuse the 'processModuleProductionOutput' function in ApiCheckTest

If the module output is packed in a JAR, it's better to close the FileSystem instance after use to close the corresponding ZIP file.
Also, this simplifies code.

GitOrigin-RevId: 6e1896864cdd61b555d64b5b3b4a2b84df2052d5
This commit is contained in:
Nikolay Chashnikov
2025-08-04 14:16:53 +00:00
committed by intellij-monorepo-bot
parent 2c51563ba0
commit b4c7e14379
2 changed files with 5 additions and 29 deletions
@@ -1,7 +1,7 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.platform.testFramework.monorepo.api
import com.intellij.openapi.application.PathManager
import com.intellij.platform.testFramework.monorepo.processModuleProductionOutput
import com.intellij.tools.apiDump.API
import com.intellij.tools.apiDump.api
import com.intellij.tools.apiDump.emptyApiIndex
@@ -13,13 +13,9 @@ import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.fold
import kotlinx.coroutines.launch
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.jps.ProjectPaths
import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.jps.model.module.JpsModule
import org.junit.jupiter.api.fail
import java.nio.file.Path
import java.util.concurrent.ConcurrentHashMap
import kotlin.io.path.name
@ApiStatus.Internal
class ModuleApi(private val cs: CoroutineScope) {
@@ -57,14 +53,8 @@ class ModuleApi(private val cs: CoroutineScope) {
acc + item
}
var outputDir = ProjectPaths.getModuleOutputDir(module, false)?.toPath()
?: fail("'${module.name}' has no out directory")
val mapping = PathManager.getArchivedCompiledClassesMapping()
if (mapping != null) {
// path is absolute, mapping contains only the last two path elements
outputDir = mapping[outputDir.parent.name + "/" + outputDir.name]?.let { Path.of(it) } ?: outputDir
return processModuleProductionOutput(module) { outputRoot ->
api(dependencyIndex, outputRoot)
}
return api(dependencyIndex, outputDir)
}
}
+2 -16
View File
@@ -10,9 +10,6 @@ import kotlinx.validation.api.*
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.AnnotationNode
import java.net.URI
import java.nio.file.FileSystemAlreadyExistsException
import java.nio.file.FileSystems
import java.nio.file.Path
import kotlin.io.path.*
import kotlin.metadata.jvm.JvmFieldSignature
@@ -310,22 +307,11 @@ private fun stableAndExperimentalApi(classSignatures: List<ApiClass>): Pair<List
@OptIn(ExperimentalPathApi::class)
private fun classFilePaths(classRoot: Path): Sequence<Path> {
var root = classRoot
if (root.isRegularFile() && root.extension == "jar") {
val uri = URI("jar:${classRoot.toUri()}!/")
val fs = try {
FileSystems.newFileSystem(uri, emptyMap<String, Any>())
}
catch (ignored: FileSystemAlreadyExistsException) {
FileSystems.getFileSystem(uri)
}
root = fs.rootDirectories.single()
}
return root
return classRoot
.walk()
.filter { path ->
path.extension == "class" &&
!root.relativize(path).startsWith("META-INF/")
!classRoot.relativize(path).startsWith("META-INF/")
}
}