From ad79717fcbd2e5aebcf4470f0825478de26bc70d Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 6 Dec 2019 07:29:21 +0100 Subject: [PATCH] use Path GitOrigin-RevId: c01f511df4039673f1fe0f378c758957c656d592 --- .../src/com/intellij/util/io/ZipUtil.java | 2 +- .../jetbrains/python/tools/IndicesBuilder.kt | 5 +- .../jetbrains/python/tools/PyGeneratorBase.kt | 62 ++++++++++--------- .../tools/PythonUniversalStubsBuilder.kt | 2 +- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/platform/util/src/com/intellij/util/io/ZipUtil.java b/platform/util/src/com/intellij/util/io/ZipUtil.java index 2a2312f64844..3e578c063285 100644 --- a/platform/util/src/com/intellij/util/io/ZipUtil.java +++ b/platform/util/src/com/intellij/util/io/ZipUtil.java @@ -131,7 +131,7 @@ public class ZipUtil { } private static class FileFilterAdapter implements Condition { - private static FileFilterAdapter wrap(File outputDir, FilenameFilter filter) { + private static FileFilterAdapter wrap(File outputDir, @Nullable FilenameFilter filter) { return filter == null ? null : new FileFilterAdapter(outputDir, filter); } diff --git a/python/tools/src/com/jetbrains/python/tools/IndicesBuilder.kt b/python/tools/src/com/jetbrains/python/tools/IndicesBuilder.kt index c86e90222731..8f6effdcaa8d 100644 --- a/python/tools/src/com/jetbrains/python/tools/IndicesBuilder.kt +++ b/python/tools/src/com/jetbrains/python/tools/IndicesBuilder.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.tools import com.intellij.index.PrebuiltIndexAwareIdIndexer @@ -6,7 +6,6 @@ import com.jetbrains.python.psi.impl.stubs.PyPrebuiltStubsProvider import org.jetbrains.index.id.IdIndexGenerator import kotlin.system.exitProcess - /** * @author Aleksey.Rostovskiy */ @@ -24,7 +23,7 @@ fun main(args: Array) { } } -object IndicesBuilder: PyGeneratorBase() { +private object IndicesBuilder: PyGeneratorBase() { fun build(root: String, outputPath: String) { try { app diff --git a/python/tools/src/com/jetbrains/python/tools/PyGeneratorBase.kt b/python/tools/src/com/jetbrains/python/tools/PyGeneratorBase.kt index 975b6aa34a85..f8a1993f4d28 100644 --- a/python/tools/src/com/jetbrains/python/tools/PyGeneratorBase.kt +++ b/python/tools/src/com/jetbrains/python/tools/PyGeneratorBase.kt @@ -7,52 +7,54 @@ import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile import com.intellij.testFramework.TestApplicationManager import com.intellij.util.PlatformUtils -import com.intellij.util.io.ZipUtil -import java.io.File +import com.intellij.util.io.Decompressor +import java.nio.file.Files +import java.nio.file.Paths /** * @author Aleksey.Rostovskiy */ open class PyGeneratorBase { + @Suppress("SpellCheckingInspection") + private val tempDir = Files.createTempDirectory("pystubs").toAbsolutePath() + protected val app by lazy { System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, PlatformUtils.PYCHARM_CE_PREFIX) - System.setProperty(PathManager.PROPERTY_PLUGINS_PATH, FileUtil.createTempDirectory("pystubs", "plugins").absolutePath) - System.setProperty(PathManager.PROPERTY_SYSTEM_PATH, FileUtil.createTempDirectory("pystubs", "system").absolutePath) - System.setProperty(PathManager.PROPERTY_CONFIG_PATH, FileUtil.createTempDirectory("pystubs", "config").absolutePath) - //Thread.currentThread().contextClassLoader = BootstrapClassLoaderUtil.initClassLoader() + + val dir = FileUtil.toSystemIndependentName(tempDir.toString()) + System.setProperty(PathManager.PROPERTY_PLUGINS_PATH, "$dir/plugins") + System.setProperty(PathManager.PROPERTY_SYSTEM_PATH, "$dir/system") + System.setProperty(PathManager.PROPERTY_CONFIG_PATH, "$dir/config") TestApplicationManager.getInstance() } - protected fun rootFiles(root: String): ArrayList{ - val dir = File(root) - if (!dir.exists() || !dir.isDirectory) { - throw IllegalStateException("$root doesn't exist or isn't a directory") + protected fun rootFiles(root: String): List { + val dir = Paths.get(root) + return Files.newDirectoryStream(dir).use { children -> + children.map { + LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(it.toString()))!! + } } - - return ArrayList(dir.listFiles().map { it-> - LocalFileSystem.getInstance().findFileByIoFile(it)!! - }) } - protected fun unzipArchivesToRoots(root: String): ArrayList { - val dir = File(root) - if (!dir.exists() || !dir.isDirectory) { - throw IllegalStateException("$root doesn't exist or isn't a directory") + protected fun unzipArchivesToRoots(root: String): List { + val rootDir = Paths.get(root) + return Files.newDirectoryStream(rootDir).use { children -> + children.mapNotNull { path -> + val fileName = path.fileName.toString() + if (!fileName.endsWith(".zip")) { + return@mapNotNull null + } + + val unzipRoot = rootDir.resolve(FileUtil.getNameWithoutExtension(fileName)) + println("Extracting $path") + Decompressor.Zip(path.toFile()).extract(unzipRoot.toFile()) + LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(unzipRoot.toString()))!! + } } - val files = dir.listFiles { _, name -> name.endsWith(".zip") }.map { zip -> - val unzipRoot = File(root, zip.nameWithoutExtension) - println("Extracting $zip") - ZipUtil.extract(zip, unzipRoot, null) - unzipRoot - } - return ArrayList(files.map { it -> - LocalFileSystem.getInstance().findFileByIoFile(it)!! - }) } protected fun tearDown() { - app.dispose() - FileUtil.delete(File(System.getProperty(PathManager.PROPERTY_PLUGINS_PATH))) - FileUtil.delete(File(System.getProperty(PathManager.PROPERTY_SYSTEM_PATH))) + FileUtil.delete(tempDir) } } \ No newline at end of file diff --git a/python/tools/src/com/jetbrains/python/tools/PythonUniversalStubsBuilder.kt b/python/tools/src/com/jetbrains/python/tools/PythonUniversalStubsBuilder.kt index cd6522c028de..b88ca41aece3 100644 --- a/python/tools/src/com/jetbrains/python/tools/PythonUniversalStubsBuilder.kt +++ b/python/tools/src/com/jetbrains/python/tools/PythonUniversalStubsBuilder.kt @@ -34,7 +34,7 @@ fun main(args: Array) { } } -object PythonUniversalStubsBuilder : PyGeneratorBase() { +private object PythonUniversalStubsBuilder : PyGeneratorBase() { fun generateStubs(root: String, outputPath: String) { try { app