diff --git a/python/tools/intellij.python.tools.iml b/python/tools/intellij.python.tools.iml
index cc5e3d30a367..4d5867cd1d34 100644
--- a/python/tools/intellij.python.tools.iml
+++ b/python/tools/intellij.python.tools.iml
@@ -16,5 +16,6 @@
+
\ No newline at end of file
diff --git a/python/tools/src/com/jetbrains/python/tools/PyPrebuiltIndicesGenerator.kt b/python/tools/src/com/jetbrains/python/tools/PyPrebuiltIndicesGenerator.kt
index f394609e3fb7..f51b74ae05ca 100644
--- a/python/tools/src/com/jetbrains/python/tools/PyPrebuiltIndicesGenerator.kt
+++ b/python/tools/src/com/jetbrains/python/tools/PyPrebuiltIndicesGenerator.kt
@@ -1,6 +1,7 @@
// Copyright 2000-2017 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.ide.BootstrapClassLoaderUtil
import com.intellij.idea.IdeaTestApplication
import com.intellij.index.PrebuiltIndexAwareIdIndexer
import com.intellij.openapi.application.PathManager
@@ -14,67 +15,60 @@ import com.intellij.util.io.ZipUtil
import com.intellij.util.ui.UIUtil
import com.jetbrains.python.psi.impl.stubs.PyPrebuiltStubsProvider
import org.jetbrains.index.id.IdIndexGenerator
-import org.jetbrains.index.stubs.StubGeneratorBootstrap
-import org.jetbrains.index.stubs.bootstrapAndRun
import java.io.File
import java.util.*
fun main(args: Array) {
- bootstrapAndRun(args, PyPrebuiltIndicesGeneratorBootstrap::class.java.name)
+ buildIndices(args[0], "${args[1]}/${PyPrebuiltStubsProvider.NAME}")
}
-class PyPrebuiltIndicesGeneratorBootstrap : StubGeneratorBootstrap {
- override fun run(args: Array) {
- buildIndices(args[0], "${args[1]}/${PyPrebuiltStubsProvider.NAME}")
+fun buildIndices(root: String, outputPath: String) {
+ val app = createApp()
+ try {
+ FileUtil.delete(File(outputPath))
+
+ val roots = unzipArchivesToRoots(root)
+
+ val rootFiles = ArrayList(roots.map { it -> LocalFileSystem.getInstance().findFileByIoFile(it)!! })
+
+ PyStubsGenerator("$outputPath/${PrebuiltStubsProviderBase.SDK_STUBS_STORAGE_NAME}").buildStubsForRoots(rootFiles)
+
+ IdIndexGenerator("$outputPath/${PrebuiltIndexAwareIdIndexer.ID_INDEX_FILE_NAME}").buildIdIndexForRoots(rootFiles)
}
-
- private fun buildIndices(root: String, outputPath: String) {
- val app = createApp()
- try {
- FileUtil.delete(File(outputPath))
-
- val roots = unzipArchivesToRoots(root)
-
- val rootFiles = ArrayList(roots.map { it -> LocalFileSystem.getInstance().findFileByIoFile(it)!! })
-
- PyStubsGenerator("$outputPath/${PrebuiltStubsProviderBase.SDK_STUBS_STORAGE_NAME}").buildStubsForRoots(rootFiles)
-
- IdIndexGenerator("$outputPath/${PrebuiltIndexAwareIdIndexer.ID_INDEX_FILE_NAME}").buildIdIndexForRoots(rootFiles)
- }
- catch (e: Throwable) {
- e.printStackTrace()
- }
- finally {
- UIUtil.invokeAndWaitIfNeeded(Runnable {
- WriteAction.run {
- app.dispose()
- }
- })
- FileUtil.delete(File(System.getProperty(PathManager.PROPERTY_PLUGINS_PATH)))
- FileUtil.delete(File(System.getProperty(PathManager.PROPERTY_SYSTEM_PATH)))
- System.exit(0)
- }
+ catch (e: Throwable) {
+ e.printStackTrace()
}
-
- private fun unzipArchivesToRoots(root: String): List {
- val dir = File(root)
- if (!dir.exists() || !dir.isDirectory) {
- throw IllegalStateException("$root doesn't exist or isn't a directory")
- }
- return dir.listFiles { _, name -> name.endsWith(".zip") }.map { zip ->
- val unzipRoot = File(root, zip.nameWithoutExtension)
- println("Extracting $zip")
- ZipUtil.extract(zip, unzipRoot, null)
- unzipRoot
- }
- }
-
- private fun createApp(): IdeaTestApplication {
- val candidates = ReflectionUtil.getField(PlatformTestCase::class.java, null, Array::class.java, "PREFIX_CANDIDATES")
- candidates[0] = "PyCharm"
- 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)
- return IdeaTestApplication.getInstance()
+ finally {
+ UIUtil.invokeAndWaitIfNeeded(Runnable {
+ WriteAction.run {
+ app.dispose()
+ }
+ })
+ FileUtil.delete(File(System.getProperty(PathManager.PROPERTY_PLUGINS_PATH)))
+ FileUtil.delete(File(System.getProperty(PathManager.PROPERTY_SYSTEM_PATH)))
+ System.exit(0)
}
}
+
+fun unzipArchivesToRoots(root: String): List {
+ val dir = File(root)
+ if (!dir.exists() || !dir.isDirectory) {
+ throw IllegalStateException("$root doesn't exist or isn't a directory")
+ }
+ return dir.listFiles { _, name -> name.endsWith(".zip") }.map { zip ->
+ val unzipRoot = File(root, zip.nameWithoutExtension)
+ println("Extracting $zip")
+ ZipUtil.extract(zip, unzipRoot, null)
+ unzipRoot
+ }
+}
+
+private fun createApp(): IdeaTestApplication {
+ val candidates = ReflectionUtil.getField(PlatformTestCase::class.java, null, Array::class.java, "PREFIX_CANDIDATES")
+ candidates[0] = "PyCharm"
+ 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()
+ return IdeaTestApplication.getInstance()
+}
diff --git a/tools/index-tools/intellij.tools.index.iml b/tools/index-tools/intellij.tools.index.iml
index 3143a4ec7304..9ca2e6102922 100644
--- a/tools/index-tools/intellij.tools.index.iml
+++ b/tools/index-tools/intellij.tools.index.iml
@@ -11,6 +11,5 @@
-
\ No newline at end of file
diff --git a/tools/index-tools/src/org/jetbrains/index/stubs/StubGeneratorBootstrap.kt b/tools/index-tools/src/org/jetbrains/index/stubs/StubGeneratorBootstrap.kt
deleted file mode 100644
index 7cc1433d2067..000000000000
--- a/tools/index-tools/src/org/jetbrains/index/stubs/StubGeneratorBootstrap.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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.
-package org.jetbrains.index.stubs
-
-import com.intellij.ide.BootstrapClassLoaderUtil
-
-interface StubGeneratorBootstrap {
- fun run(args: Array)
- fun Array.secondOrNull() = if (size < 2) null else this[1]
-}
-
-fun bootstrapAndRun(args: Array, className: String?) {
- val newClassLoader = BootstrapClassLoaderUtil.initClassLoader()
- Thread.currentThread().contextClassLoader = newClassLoader
-
- val klass = Class.forName(className, true, newClassLoader)
- val instance = klass.newInstance()
- val method = klass.getDeclaredMethod("run", Array::class.java)
- method.invoke(instance, args)
-}