J2K PathUtil: convert and prettify

This commit is contained in:
Alexander Udalov
2017-07-05 19:24:37 +03:00
parent 3beb6a86f7
commit 46a01ec131
28 changed files with 158 additions and 178 deletions
@@ -62,7 +62,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
val paths = if (arguments.kotlinHome != null) val paths = if (arguments.kotlinHome != null)
KotlinPathsFromHomeDir(File(arguments.kotlinHome)) KotlinPathsFromHomeDir(File(arguments.kotlinHome))
else else
PathUtil.getKotlinPathsForCompiler() PathUtil.kotlinPathsForCompiler
messageCollector.report(LOGGING, "Using Kotlin home directory ${paths.homePath}") messageCollector.report(LOGGING, "Using Kotlin home directory ${paths.homePath}")
PerformanceCounter.setTimeCounterEnabled(arguments.reportPerf) PerformanceCounter.setTimeCounterEnabled(arguments.reportPerf)
@@ -477,7 +477,7 @@ class KotlinCoreEnvironment private constructor(
var pluginRoot = var pluginRoot =
configuration.get(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT)?.let(::File) configuration.get(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT)?.let(::File)
?: configuration.get(CLIConfigurationKeys.COMPILER_JAR_LOCATOR)?.compilerJar ?: configuration.get(CLIConfigurationKeys.COMPILER_JAR_LOCATOR)?.compilerJar
?: PathUtil.getPathUtilJar() ?: PathUtil.pathUtilJar
val app = ApplicationManager.getApplication() val app = ApplicationManager.getApplication()
val parentFile = pluginRoot.parentFile val parentFile = pluginRoot.parentFile
@@ -51,7 +51,7 @@ open class KotlinJvmReplService(
protected val configuration = CompilerConfiguration().apply { protected val configuration = CompilerConfiguration().apply {
addJvmClasspathRoots(PathUtil.getJdkClassesRootsFromCurrentJre()) addJvmClasspathRoots(PathUtil.getJdkClassesRootsFromCurrentJre())
addJvmClasspathRoots(PathUtil.getKotlinPathsForCompiler().let { listOf(it.stdlibPath, it.reflectPath, it.scriptRuntimePath) }) addJvmClasspathRoots(PathUtil.kotlinPathsForCompiler.let { listOf(it.stdlibPath, it.reflectPath, it.scriptRuntimePath) })
addJvmClasspathRoots(templateClasspath) addJvmClasspathRoots(templateClasspath)
put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script") put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script")
languageVersionSettings = LanguageVersionSettingsImpl( languageVersionSettings = LanguageVersionSettingsImpl(
@@ -214,7 +214,7 @@ object MockLibraryUtil {
@Synchronized @Synchronized
private fun createCompilerClassLoader(): ClassLoader { private fun createCompilerClassLoader(): ClassLoader {
return ClassPreloadingUtils.preloadClasses( return ClassPreloadingUtils.preloadClasses(
listOf(PathUtil.getKotlinPathsForDistDirectory().compilerPath), listOf(PathUtil.kotlinPathsForDistDirectory.compilerPath),
Preloader.DEFAULT_CLASS_NUMBER_ESTIMATE, null, null Preloader.DEFAULT_CLASS_NUMBER_ESTIMATE, null, null
) )
} }
@@ -20,7 +20,6 @@ import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.util.ExecUtil import com.intellij.execution.util.ExecUtil
import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TestCaseWithTmpdir import org.jetbrains.kotlin.test.TestCaseWithTmpdir
import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.kotlin.utils.PathUtil
@@ -36,7 +35,7 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
workDirectory: File? = null workDirectory: File? = null
) { ) {
val executableFileName = if (SystemInfo.isWindows) "$executableName.bat" else executableName val executableFileName = if (SystemInfo.isWindows) "$executableName.bat" else executableName
val launcherFile = File(PathUtil.getKotlinPathsForDistDirectory().homePath, "bin/$executableFileName") val launcherFile = File(PathUtil.kotlinPathsForDistDirectory.homePath, "bin/$executableFileName")
assertTrue("Launcher script not found, run 'ant dist': ${launcherFile.absolutePath}", launcherFile.exists()) assertTrue("Launcher script not found, run 'ant dist': ${launcherFile.absolutePath}", launcherFile.exists())
val cmd = GeneralCommandLine(launcherFile.absolutePath, *args) val cmd = GeneralCommandLine(launcherFile.absolutePath, *args)
@@ -398,7 +398,7 @@ private fun classpathFromClassloader(): List<File> =
open class TestKotlinScriptDependenciesResolver : TestKotlinScriptDummyDependenciesResolver() { open class TestKotlinScriptDependenciesResolver : TestKotlinScriptDummyDependenciesResolver() {
private val kotlinPaths by lazy { PathUtil.getKotlinPathsForCompiler() } private val kotlinPaths by lazy { PathUtil.kotlinPathsForCompiler }
@AcceptedAnnotations(DependsOn::class, DependsOnTwo::class) @AcceptedAnnotations(DependsOn::class, DependsOnTwo::class)
override fun resolve(scriptContents: ScriptContents, override fun resolve(scriptContents: ScriptContents,
@@ -14,163 +14,144 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.utils; package org.jetbrains.kotlin.utils
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PathManager
import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.java.impl.JavaSdkUtil
import org.jetbrains.jps.model.java.impl.JavaSdkUtil;
import java.io.File; import java.io.File
import java.util.List; import java.util.regex.Pattern
import java.util.regex.Pattern;
public class PathUtil { object PathUtil {
const val JPS_KOTLIN_HOME_PROPERTY = "jps.kotlin.home"
public static final String JPS_KOTLIN_HOME_PROPERTY = "jps.kotlin.home"; const val JS_LIB_JAR_NAME = "kotlin-stdlib-js.jar"
const val JS_LIB_10_JAR_NAME = "kotlin-jslib.jar"
const val ALLOPEN_PLUGIN_JAR_NAME = "allopen-compiler-plugin.jar"
const val NOARG_PLUGIN_JAR_NAME = "noarg-compiler-plugin.jar"
const val SAM_WITH_RECEIVER_PLUGIN_JAR_NAME = "sam-with-receiver-compiler-plugin.jar"
const val JS_LIB_SRC_JAR_NAME = "kotlin-stdlib-js-sources.jar"
const val KOTLIN_JAVA_RUNTIME_JAR = "kotlin-runtime.jar"
const val KOTLIN_JAVA_RUNTIME_JRE7_JAR = "kotlin-stdlib-jre7.jar"
const val KOTLIN_JAVA_RUNTIME_JRE8_JAR = "kotlin-stdlib-jre8.jar"
const val KOTLIN_JAVA_RUNTIME_JRE7_SRC_JAR = "kotlin-stdlib-jre7-sources.jar"
const val KOTLIN_JAVA_RUNTIME_JRE8_SRC_JAR = "kotlin-stdlib-jre8-sources.jar"
const val KOTLIN_JAVA_STDLIB_JAR = "kotlin-stdlib.jar"
const val KOTLIN_JAVA_REFLECT_JAR = "kotlin-reflect.jar"
const val KOTLIN_JAVA_SCRIPT_RUNTIME_JAR = "kotlin-script-runtime.jar"
const val KOTLIN_TEST_JAR = "kotlin-test.jar"
const val KOTLIN_TEST_JS_JAR = "kotlin-test-js.jar"
const val KOTLIN_JAVA_STDLIB_SRC_JAR = "kotlin-stdlib-sources.jar"
const val KOTLIN_JAVA_STDLIB_SRC_JAR_OLD = "kotlin-runtime-sources.jar"
const val KOTLIN_REFLECT_SRC_JAR = "kotlin-reflect-sources.jar"
const val KOTLIN_TEST_SRC_JAR = "kotlin-test-sources.jar"
const val KOTLIN_COMPILER_JAR = "kotlin-compiler.jar"
public static final String JS_LIB_JAR_NAME = "kotlin-stdlib-js.jar"; @JvmField
public static final String JS_LIB_10_JAR_NAME = "kotlin-jslib.jar"; val KOTLIN_RUNTIME_JAR_PATTERN: Pattern = Pattern.compile("kotlin-(stdlib|runtime)(-\\d[\\d.]+(-.+)?)?\\.jar")
public static final String ALLOPEN_PLUGIN_JAR_NAME = "allopen-compiler-plugin.jar"; val KOTLIN_STDLIB_JS_JAR_PATTERN: Pattern = Pattern.compile("kotlin-stdlib-js.*\\.jar")
public static final String NOARG_PLUGIN_JAR_NAME = "noarg-compiler-plugin.jar"; val KOTLIN_JS_LIBRARY_JAR_PATTERN: Pattern = Pattern.compile("kotlin-js-library.*\\.jar")
public static final String SAM_WITH_RECEIVER_PLUGIN_JAR_NAME = "sam-with-receiver-compiler-plugin.jar";
public static final String JS_LIB_SRC_JAR_NAME = "kotlin-stdlib-js-sources.jar";
public static final String KOTLIN_JAVA_RUNTIME_JAR = "kotlin-runtime.jar";
public static final String KOTLIN_JAVA_RUNTIME_JRE7_JAR = "kotlin-stdlib-jre7.jar";
public static final String KOTLIN_JAVA_RUNTIME_JRE8_JAR = "kotlin-stdlib-jre8.jar";
public static final String KOTLIN_JAVA_RUNTIME_JRE7_SRC_JAR = "kotlin-stdlib-jre7-sources.jar";
public static final String KOTLIN_JAVA_RUNTIME_JRE8_SRC_JAR = "kotlin-stdlib-jre8-sources.jar";
public static final String KOTLIN_JAVA_STDLIB_JAR = "kotlin-stdlib.jar";
public static final String KOTLIN_JAVA_REFLECT_JAR = "kotlin-reflect.jar";
public static final String KOTLIN_JAVA_SCRIPT_RUNTIME_JAR = "kotlin-script-runtime.jar";
public static final String KOTLIN_TEST_JAR = "kotlin-test.jar";
public static final String KOTLIN_TEST_JS_JAR = "kotlin-test-js.jar";
public static final String KOTLIN_JAVA_STDLIB_SRC_JAR = "kotlin-stdlib-sources.jar";
public static final String KOTLIN_JAVA_STDLIB_SRC_JAR_OLD = "kotlin-runtime-sources.jar";
public static final String KOTLIN_REFLECT_SRC_JAR = "kotlin-reflect-sources.jar";
public static final String KOTLIN_TEST_SRC_JAR = "kotlin-test-sources.jar";
public static final String KOTLIN_COMPILER_JAR = "kotlin-compiler.jar";
public static final Pattern KOTLIN_RUNTIME_JAR_PATTERN = Pattern.compile("kotlin-(stdlib|runtime)(-\\d[\\d.]+(-.+)?)?\\.jar"); private const val HOME_FOLDER_NAME = "kotlinc"
public static final Pattern KOTLIN_STDLIB_JS_JAR_PATTERN = Pattern.compile("kotlin-stdlib-js.*\\.jar"); private val NO_PATH = File("<no_path>")
public static final Pattern KOTLIN_JS_LIBRARY_JAR_PATTERN = Pattern.compile("kotlin-js-library.*\\.jar");
public static final String HOME_FOLDER_NAME = "kotlinc"; @JvmStatic
private static final File NO_PATH = new File("<no_path>"); val kotlinPathsForIdeaPlugin: KotlinPaths
get() = if (ApplicationManager.getApplication().isUnitTestMode)
kotlinPathsForDistDirectory
else
KotlinPathsFromHomeDir(compilerPathForIdeaPlugin)
private PathUtil() {} // When JPS is run on TeamCity, it can not rely on Kotlin plugin layout,
// so the path to Kotlin is specified in a system property
@NotNull private val kotlinPathsForJpsPlugin: KotlinPaths
public static KotlinPaths getKotlinPathsForIdeaPlugin() { get() {
return ApplicationManager.getApplication().isUnitTestMode() val jpsKotlinHome = System.getProperty(JPS_KOTLIN_HOME_PROPERTY)
? getKotlinPathsForDistDirectory() return if (jpsKotlinHome != null) {
: new KotlinPathsFromHomeDir(getCompilerPathForIdeaPlugin()); KotlinPathsFromHomeDir(File(jpsKotlinHome))
} }
else KotlinPathsFromHomeDir(compilerPathForJpsPlugin)
@NotNull
public static KotlinPaths getKotlinPathsForJpsPlugin() {
// When JPS is run on TeamCity, it can not rely on Kotlin plugin layout,
// so the path to Kotlin is specified in a system property
String jpsKotlinHome = System.getProperty(JPS_KOTLIN_HOME_PROPERTY);
if (jpsKotlinHome != null) {
return new KotlinPathsFromHomeDir(new File(jpsKotlinHome));
} }
return new KotlinPathsFromHomeDir(getCompilerPathForJpsPlugin());
}
@NotNull val kotlinPathsForJpsPluginOrJpsTests: KotlinPaths
public static KotlinPaths getKotlinPathsForJpsPluginOrJpsTests() { get() = if ("true".equals(System.getProperty("kotlin.jps.tests"), ignoreCase = true)) {
if ("true".equalsIgnoreCase(System.getProperty("kotlin.jps.tests"))) { kotlinPathsForDistDirectory
return getKotlinPathsForDistDirectory();
} }
return getKotlinPathsForJpsPlugin(); else kotlinPathsForJpsPlugin
}
@NotNull @JvmStatic
public static KotlinPaths getKotlinPathsForCompiler() { val kotlinPathsForCompiler: KotlinPaths
if (!getPathUtilJar().isFile()) { get() = if (!pathUtilJar.isFile) {
// Not running from a jar, i.e. it is it must be a unit test // Not running from a jar, i.e. it is it must be a unit test
return getKotlinPathsForDistDirectory(); kotlinPathsForDistDirectory
} }
return new KotlinPathsFromHomeDir(getCompilerPathForCompilerJar()); else KotlinPathsFromHomeDir(compilerPathForCompilerJar)
}
@NotNull @JvmStatic
public static KotlinPaths getKotlinPathsForDistDirectory() { val kotlinPathsForDistDirectory: KotlinPaths
return new KotlinPathsFromHomeDir(new File("dist", HOME_FOLDER_NAME)); get() = KotlinPathsFromHomeDir(File("dist", HOME_FOLDER_NAME))
}
@NotNull private val compilerPathForCompilerJar: File
private static File getCompilerPathForCompilerJar() { get() {
File jar = getPathUtilJar(); val jar = pathUtilJar
if (!jar.exists()) return NO_PATH
if (!jar.exists()) return NO_PATH; if (jar.name == KOTLIN_COMPILER_JAR) {
val lib = jar.parentFile
return lib.parentFile
}
if (jar.getName().equals(KOTLIN_COMPILER_JAR)) { return NO_PATH
File lib = jar.getParentFile();
return lib.getParentFile();
} }
return NO_PATH; private val compilerPathForJpsPlugin: File
} get() {
val jar = pathUtilJar
if (!jar.exists()) return NO_PATH
@NotNull if (jar.name == "kotlin-jps-plugin.jar") {
private static File getCompilerPathForJpsPlugin() { val pluginHome = jar.parentFile.parentFile.parentFile
File jar = getPathUtilJar(); return File(pluginHome, HOME_FOLDER_NAME)
}
if (!jar.exists()) return NO_PATH; return NO_PATH
if (jar.getName().equals("kotlin-jps-plugin.jar")) {
File pluginHome = jar.getParentFile().getParentFile().getParentFile();
return new File(pluginHome, HOME_FOLDER_NAME);
} }
return NO_PATH; private val compilerPathForIdeaPlugin: File
} get() {
val jar = pathUtilJar
if (!jar.exists()) return NO_PATH
@NotNull if (jar.name == "kotlin-plugin.jar") {
private static File getCompilerPathForIdeaPlugin() { val lib = jar.parentFile
File jar = getPathUtilJar(); val pluginHome = lib.parentFile
if (!jar.exists()) return NO_PATH; return File(pluginHome, HOME_FOLDER_NAME)
}
if (jar.getName().equals("kotlin-plugin.jar")) { return NO_PATH
File lib = jar.getParentFile();
File pluginHome = lib.getParentFile();
return new File(pluginHome, HOME_FOLDER_NAME);
} }
return NO_PATH; val pathUtilJar: File
get() = getResourcePathForClass(PathUtil::class.java)
@JvmStatic
fun getResourcePathForClass(aClass: Class<*>): File {
val path = "/" + aClass.name.replace('.', '/') + ".class"
val resourceRoot = PathManager.getResourceRoot(aClass, path) ?: throw IllegalStateException("Resource not found: $path")
return File(resourceRoot).absoluteFile
} }
@NotNull @JvmStatic
public static File getPathUtilJar() { fun getJdkClassesRootsFromCurrentJre(): List<File> =
return getResourcePathForClass(PathUtil.class); getJdkClassesRootsFromJre(System.getProperty("java.home"))
}
@NotNull @JvmStatic
public static File getResourcePathForClass(@NotNull Class aClass) { fun getJdkClassesRootsFromJre(javaHome: String): List<File> =
String path = "/" + aClass.getName().replace('.', '/') + ".class"; JavaSdkUtil.getJdkClassesRoots(File(javaHome), true)
String resourceRoot = PathManager.getResourceRoot(aClass, path);
if (resourceRoot == null) {
throw new IllegalStateException("Resource not found: " + path);
}
return new File(resourceRoot).getAbsoluteFile();
}
@NotNull @JvmStatic
public static List<File> getJdkClassesRootsFromCurrentJre() { fun getJdkClassesRoots(jdkHome: File): List<File> =
return getJdkClassesRootsFromJre(System.getProperty("java.home")); JavaSdkUtil.getJdkClassesRoots(jdkHome, false)
}
@NotNull
public static List<File> getJdkClassesRootsFromJre(@NotNull String javaHome) {
return JavaSdkUtil.getJdkClassesRoots(new File(javaHome), true);
}
@NotNull
public static List<File> getJdkClassesRoots(@NotNull File jdkHome) {
return JavaSdkUtil.getJdkClassesRoots(jdkHome, false);
}
} }
@@ -24,7 +24,6 @@ import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.module.Module import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.JavaSdkType import com.intellij.openapi.projectRoots.JavaSdkType
import com.intellij.openapi.projectRoots.JdkUtil
import com.intellij.openapi.projectRoots.SimpleJavaSdkType import com.intellij.openapi.projectRoots.SimpleJavaSdkType
import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.OrderEnumerator import com.intellij.openapi.roots.OrderEnumerator
@@ -68,7 +67,7 @@ class KotlinConsoleKeeper(val project: Project) {
// use to debug repl process // use to debug repl process
//paramList.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005") //paramList.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
val kotlinPaths = PathUtil.getKotlinPathsForIdeaPlugin() val kotlinPaths = PathUtil.kotlinPathsForIdeaPlugin
val replClassPath = listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.stdlibPath, kotlinPaths.scriptRuntimePath) val replClassPath = listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.stdlibPath, kotlinPaths.scriptRuntimePath)
.joinToString(File.pathSeparator) { it.absolutePath } .joinToString(File.pathSeparator) { it.absolutePath }
@@ -44,7 +44,7 @@ class KotlinJsr223JvmScriptEngine4Idea(
) : KotlinJsr223JvmScriptEngineBase(factory) { ) : KotlinJsr223JvmScriptEngineBase(factory) {
private val daemon by lazy { private val daemon by lazy {
val path = PathUtil.getKotlinPathsForIdeaPlugin().compilerPath val path = PathUtil.kotlinPathsForIdeaPlugin.compilerPath
assert(path.exists()) assert(path.exists())
val compilerId = CompilerId.makeCompilerId(path) val compilerId = CompilerId.makeCompilerId(path)
val daemonOptions = configureDaemonOptions() val daemonOptions = configureDaemonOptions()
@@ -58,7 +58,7 @@ fun classpathFromClassloader(classLoader: ClassLoader): List<File>? =
private val kotlinCompilerJar: File by lazy { private val kotlinCompilerJar: File by lazy {
// highest prio - explicit property // highest prio - explicit property
System.getProperty("kotlin.compiler.jar")?.let(::File)?.takeIf(File::exists) System.getProperty("kotlin.compiler.jar")?.let(::File)?.takeIf(File::exists)
?: PathUtil.getKotlinPathsForIdeaPlugin().compilerPath ?: PathUtil.kotlinPathsForIdeaPlugin.compilerPath
?: throw FileNotFoundException("Cannot find kotlin compiler jar, set kotlin.compiler.jar property to proper location") ?: throw FileNotFoundException("Cannot find kotlin compiler jar, set kotlin.compiler.jar property to proper location")
} }
@@ -59,15 +59,13 @@ object ConfigLibraryUtil {
fun configureKotlinJsRuntimeAndSdk(module: Module, sdk: Sdk) { fun configureKotlinJsRuntimeAndSdk(module: Module, sdk: Sdk) {
configureSdk(module, sdk) configureSdk(module, sdk)
addLibrary(getKotlinRuntimeLibEditor(DEFAULT_KOTLIN_JS_STDLIB_NAME, addLibrary(getKotlinRuntimeLibEditor(DEFAULT_KOTLIN_JS_STDLIB_NAME,
PathUtil.getKotlinPathsForDistDirectory().jsStdLibJarPath), module, PathUtil.kotlinPathsForDistDirectory.jsStdLibJarPath), module,
JSLibraryKind) JSLibraryKind)
} }
fun configureKotlinRuntime(module: Module) { fun configureKotlinRuntime(module: Module) {
addLibrary(getKotlinRuntimeLibEditor(DEFAULT_JAVA_RUNTIME_LIB_NAME, PathUtil.getKotlinPathsForDistDirectory().stdlibPath), addLibrary(getKotlinRuntimeLibEditor(DEFAULT_JAVA_RUNTIME_LIB_NAME, PathUtil.kotlinPathsForDistDirectory.stdlibPath), module)
module) addLibrary(getKotlinRuntimeLibEditor(DEFAULT_KOTLIN_TEST_LIB_NAME, PathUtil.kotlinPathsForDistDirectory.kotlinTestPath), module)
addLibrary(getKotlinRuntimeLibEditor(DEFAULT_KOTLIN_TEST_LIB_NAME, PathUtil.getKotlinPathsForDistDirectory().kotlinTestPath),
module)
} }
fun unConfigureKotlinRuntime(module: Module) { fun unConfigureKotlinRuntime(module: Module) {
@@ -191,7 +191,7 @@ private class ScriptCommandLineState(
val scriptVFile = LocalFileSystem.getInstance().findFileByIoFile(File(filePath)) ?: val scriptVFile = LocalFileSystem.getInstance().findFileByIoFile(File(filePath)) ?:
throw CantRunException("Script file was not found in project") throw CantRunException("Script file was not found in project")
params.classPath.add(PathUtil.getKotlinPathsForIdeaPlugin().compilerPath) params.classPath.add(PathUtil.kotlinPathsForIdeaPlugin.compilerPath)
val scriptClasspath = ScriptDependenciesManager.getInstance(environment.project).getScriptClasspath(scriptVFile) val scriptClasspath = ScriptDependenciesManager.getInstance(environment.project).getScriptClasspath(scriptVFile)
scriptClasspath.forEach { scriptClasspath.forEach {
@@ -60,7 +60,7 @@ class BundledKotlinScriptDependenciesResolver : DependenciesResolver {
val javaHome = environment.get("sdk") as String? val javaHome = environment.get("sdk") as String?
val dependencies = ScriptDependencies( val dependencies = ScriptDependencies(
javaHome = javaHome?.let(::File), javaHome = javaHome?.let(::File),
classpath = with(PathUtil.getKotlinPathsForIdeaPlugin()) { classpath = with(PathUtil.kotlinPathsForIdeaPlugin) {
listOf( listOf(
reflectPath, reflectPath,
stdlibPath, stdlibPath,
@@ -198,7 +198,7 @@ enum class LibraryJarDescriptor(val jarName: String,
return LibraryUtils.getJarFile(Arrays.asList(*library.getFiles(orderRootType)), jarName) return LibraryUtils.getJarFile(Arrays.asList(*library.getFiles(orderRootType)), jarName)
} }
fun getPathInPlugin() = getPath(PathUtil.getKotlinPathsForIdeaPlugin()) fun getPathInPlugin() = getPath(PathUtil.kotlinPathsForIdeaPlugin)
} }
fun bundledRuntimeVersion(): String { fun bundledRuntimeVersion(): String {
@@ -206,7 +206,7 @@ fun bundledRuntimeVersion(): String {
} }
private val bundledRuntimeBuildNumber: String? by lazy { private val bundledRuntimeBuildNumber: String? by lazy {
val file = PathUtil.getKotlinPathsForIdeaPlugin().buildNumberFile val file = PathUtil.kotlinPathsForIdeaPlugin.buildNumberFile
if (file.exists()) file.readText().trim() else null if (file.exists()) file.readText().trim() else null
} }
@@ -190,10 +190,10 @@ abstract class AbstractConfigureKotlinTest : PlatformTestCase() {
} }
private val pathToExistentRuntimeJar: String private val pathToExistentRuntimeJar: String
get() = PathUtil.getKotlinPathsForDistDirectory().stdlibPath.parent get() = PathUtil.kotlinPathsForDistDirectory.stdlibPath.parent
private val pathToExistentJsJar: String private val pathToExistentJsJar: String
get() = PathUtil.getKotlinPathsForDistDirectory().jsStdLibJarPath.parent get() = PathUtil.kotlinPathsForDistDirectory.jsStdLibJarPath.parent
protected fun assertNotConfigured(module: Module, configurator: KotlinWithLibraryConfigurator) { protected fun assertNotConfigured(module: Module, configurator: KotlinWithLibraryConfigurator) {
TestCase.assertFalse( TestCase.assertFalse(
@@ -73,7 +73,7 @@ abstract class AbstractScriptConfigurationTest : AbstractPsiCheckerTest() {
protected fun configureScriptEnvironment(path: String) { protected fun configureScriptEnvironment(path: String) {
val templateOutDir = compileLibToDir( val templateOutDir = compileLibToDir(
File("${path}template"), File("${path}template"),
PathUtil.getKotlinPathsForDistDirectory().scriptRuntimePath.path PathUtil.kotlinPathsForDistDirectory.scriptRuntimePath.path
) )
val libSrcDir = File("${path}lib") val libSrcDir = File("${path}lib")
@@ -333,7 +333,7 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
fun testKotlinJavaScriptProjectWithDirectoryAsStdlib() { fun testKotlinJavaScriptProjectWithDirectoryAsStdlib() {
initProject() initProject()
val jslibJar = PathUtil.getKotlinPathsForDistDirectory().jsStdLibJarPath val jslibJar = PathUtil.kotlinPathsForDistDirectory.jsStdLibJarPath
val jslibDir = File(workDir, "KotlinJavaScript") val jslibDir = File(workDir, "KotlinJavaScript")
try { try {
ZipUtil.extract(jslibJar, jslibDir, null) ZipUtil.extract(jslibJar, jslibDir, null)
@@ -45,7 +45,7 @@ class ClasspathOrderTest : TestCaseWithTmpdir() {
File(tmpdir, "output").absolutePath, File(tmpdir, "output").absolutePath,
listOf(sourceDir), listOf(sourceDir),
listOf(JvmSourceRoot(sourceDir)), listOf(JvmSourceRoot(sourceDir)),
listOf(PathUtil.getKotlinPathsForDistDirectory().runtimePath), listOf(PathUtil.kotlinPathsForDistDirectory.runtimePath),
null, null,
JavaModuleBuildTargetType.PRODUCTION.typeId, JavaModuleBuildTargetType.PRODUCTION.typeId,
JavaModuleBuildTargetType.PRODUCTION.isTests, JavaModuleBuildTargetType.PRODUCTION.isTests,
@@ -51,8 +51,11 @@ import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollector import org.jetbrains.kotlin.compilerRunner.OutputItemsCollector
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.CompilerRunnerConstants
import org.jetbrains.kotlin.config.CompilerRunnerConstants.INTERNAL_ERROR_PREFIX import org.jetbrains.kotlin.config.CompilerRunnerConstants.INTERNAL_ERROR_PREFIX
import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.daemon.common.isDaemonEnabled import org.jetbrains.kotlin.daemon.common.isDaemonEnabled
import org.jetbrains.kotlin.incremental.* import org.jetbrains.kotlin.incremental.*
import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.incremental.components.LookupTracker
@@ -469,7 +472,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
} }
return JpsCompilerEnvironment( return JpsCompilerEnvironment(
PathUtil.getKotlinPathsForJpsPluginOrJpsTests(), PathUtil.kotlinPathsForJpsPluginOrJpsTests,
compilerServices, compilerServices,
ClassCondition { className -> ClassCondition { className ->
className.startsWith("org.jetbrains.kotlin.load.kotlin.incremental.components.") className.startsWith("org.jetbrains.kotlin.load.kotlin.incremental.components.")
@@ -25,7 +25,7 @@ class AllOpenGradleProjectImportHandler : AbstractGradleImportHandler() {
override val pluginName = "allopen" override val pluginName = "allopen"
override val annotationOptionName = AllOpenCommandLineProcessor.ANNOTATION_OPTION.name override val annotationOptionName = AllOpenCommandLineProcessor.ANNOTATION_OPTION.name
override val dataStorageTaskName = "allOpenDataStorageTask" override val dataStorageTaskName = "allOpenDataStorageTask"
override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().allOpenPluginJarPath override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.allOpenPluginJarPath
override fun getAnnotationsForPreset(presetName: String): List<String> { override fun getAnnotationsForPreset(presetName: String): List<String> {
for ((name, annotations) in AllOpenCommandLineProcessor.SUPPORTED_PRESETS.entries) { for ((name, annotations) in AllOpenCommandLineProcessor.SUPPORTED_PRESETS.entries) {
@@ -29,7 +29,7 @@ class AllOpenMavenProjectImportHandler : AbstractMavenImportHandler() {
override val pluginName = "allopen" override val pluginName = "allopen"
override val annotationOptionName = AllOpenCommandLineProcessor.ANNOTATION_OPTION.name override val annotationOptionName = AllOpenCommandLineProcessor.ANNOTATION_OPTION.name
override val mavenPluginArtifactName = "kotlin-maven-allopen" override val mavenPluginArtifactName = "kotlin-maven-allopen"
override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().allOpenPluginJarPath override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.allOpenPluginJarPath
override fun getAnnotations(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<String>? { override fun getAnnotations(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<String>? {
if ("all-open" !in enabledCompilerPlugins && "spring" !in enabledCompilerPlugins) { if ("all-open" !in enabledCompilerPlugins && "spring" !in enabledCompilerPlugins) {
@@ -151,7 +151,7 @@ abstract class AbstractKotlinKapt3IntegrationTest : CodegenTestCase() {
options: Map<String, String>, options: Map<String, String>,
stubsOutputDir: File, stubsOutputDir: File,
incrementalDataOutputDir: File incrementalDataOutputDir: File
) : AbstractKapt3Extension(PathUtil.getJdkClassesRootsFromCurrentJre() + PathUtil.getKotlinPathsForIdeaPlugin().stdlibPath, ) : AbstractKapt3Extension(PathUtil.getJdkClassesRootsFromCurrentJre() + PathUtil.kotlinPathsForIdeaPlugin.stdlibPath,
emptyList(), javaSourceRoots, outputDir, outputDir, emptyList(), javaSourceRoots, outputDir, outputDir,
stubsOutputDir, incrementalDataOutputDir, options, emptyMap(), "", STUBS_AND_APT, System.currentTimeMillis(), stubsOutputDir, incrementalDataOutputDir, options, emptyMap(), "", STUBS_AND_APT, System.currentTimeMillis(),
KaptLogger(true), correctErrorTypes = true, compilerConfiguration = CompilerConfiguration.EMPTY KaptLogger(true), correctErrorTypes = true, compilerConfiguration = CompilerConfiguration.EMPTY
@@ -124,10 +124,10 @@ abstract class AbstractKotlinKaptContextTest : AbstractKotlinKapt3Test() {
val sourceOutputDir = Files.createTempDirectory("kaptRunner").toFile() val sourceOutputDir = Files.createTempDirectory("kaptRunner").toFile()
try { try {
kaptContext.doAnnotationProcessing(emptyList(), listOf(JavaKaptContextTest.simpleProcessor()), kaptContext.doAnnotationProcessing(emptyList(), listOf(JavaKaptContextTest.simpleProcessor()),
compileClasspath = PathUtil.getJdkClassesRootsFromCurrentJre() + PathUtil.getKotlinPathsForIdeaPlugin().stdlibPath, compileClasspath = PathUtil.getJdkClassesRootsFromCurrentJre() + PathUtil.kotlinPathsForIdeaPlugin.stdlibPath,
annotationProcessingClasspath = emptyList(), annotationProcessors = "", annotationProcessingClasspath = emptyList(), annotationProcessors = "",
sourcesOutputDir = sourceOutputDir, classesOutputDir = sourceOutputDir, sourcesOutputDir = sourceOutputDir, classesOutputDir = sourceOutputDir,
additionalSources = compilationUnits, withJdk = true) additionalSources = compilationUnits, withJdk = true)
val javaFiles = sourceOutputDir.walkTopDown().filter { it.isFile && it.extension == "java" } val javaFiles = sourceOutputDir.walkTopDown().filter { it.isFile && it.extension == "java" }
val actualRaw = javaFiles.sortedBy { it.name }.joinToString(FILE_SEPARATOR) { it.name + ":\n\n" + it.readText() } val actualRaw = javaFiles.sortedBy { it.name }.joinToString(FILE_SEPARATOR) { it.name + ":\n\n" + it.readText() }
@@ -16,8 +16,8 @@
package org.jetbrains.kotlin.noarg.ide package org.jetbrains.kotlin.noarg.ide
import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor
import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler
import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor
import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.kotlin.utils.PathUtil
class NoArgGradleProjectImportHandler : AbstractGradleImportHandler() { class NoArgGradleProjectImportHandler : AbstractGradleImportHandler() {
@@ -25,7 +25,7 @@ class NoArgGradleProjectImportHandler : AbstractGradleImportHandler() {
override val pluginName = "noarg" override val pluginName = "noarg"
override val annotationOptionName = NoArgCommandLineProcessor.ANNOTATION_OPTION.name override val annotationOptionName = NoArgCommandLineProcessor.ANNOTATION_OPTION.name
override val dataStorageTaskName = "noArgDataStorageTask" override val dataStorageTaskName = "noArgDataStorageTask"
override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().noArgPluginJarPath override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.noArgPluginJarPath
override fun getAnnotationsForPreset(presetName: String): List<String> { override fun getAnnotationsForPreset(presetName: String): List<String> {
for ((name, annotations) in NoArgCommandLineProcessor.SUPPORTED_PRESETS.entries) { for ((name, annotations) in NoArgCommandLineProcessor.SUPPORTED_PRESETS.entries) {
@@ -16,8 +16,8 @@
package org.jetbrains.kotlin.noarg.ide package org.jetbrains.kotlin.noarg.ide
import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor
import org.jetbrains.kotlin.annotation.plugin.ide.AbstractMavenImportHandler import org.jetbrains.kotlin.annotation.plugin.ide.AbstractMavenImportHandler
import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor
import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.kotlin.utils.PathUtil
class NoArgMavenProjectImportHandler : AbstractMavenImportHandler() { class NoArgMavenProjectImportHandler : AbstractMavenImportHandler() {
@@ -29,7 +29,7 @@ class NoArgMavenProjectImportHandler : AbstractMavenImportHandler() {
override val pluginName = "noarg" override val pluginName = "noarg"
override val annotationOptionName = NoArgCommandLineProcessor.ANNOTATION_OPTION.name override val annotationOptionName = NoArgCommandLineProcessor.ANNOTATION_OPTION.name
override val mavenPluginArtifactName = "kotlin-maven-noarg" override val mavenPluginArtifactName = "kotlin-maven-noarg"
override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().noArgPluginJarPath override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.noArgPluginJarPath
override fun getAnnotations(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<String>? { override fun getAnnotations(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<String>? {
if ("no-arg" !in enabledCompilerPlugins && "jpa" !in enabledCompilerPlugins) { if ("no-arg" !in enabledCompilerPlugins && "jpa" !in enabledCompilerPlugins) {
@@ -25,7 +25,7 @@ class SamWithReceiverGradleProjectImportHandler : AbstractGradleImportHandler()
override val pluginName = "sam-with-receiver" override val pluginName = "sam-with-receiver"
override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name
override val dataStorageTaskName = "samWithReceiverDataStorageTask" override val dataStorageTaskName = "samWithReceiverDataStorageTask"
override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().allOpenPluginJarPath override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.allOpenPluginJarPath
override fun getAnnotationsForPreset(presetName: String): List<String> { override fun getAnnotationsForPreset(presetName: String): List<String> {
for ((name, annotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS.entries) { for ((name, annotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS.entries) {
@@ -29,7 +29,7 @@ class SamWithReceiverMavenProjectImportHandler : AbstractMavenImportHandler() {
override val pluginName = "samWithReceiver" override val pluginName = "samWithReceiver"
override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name
override val mavenPluginArtifactName = "kotlin-maven-sam-with-receiver" override val mavenPluginArtifactName = "kotlin-maven-sam-with-receiver"
override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().allOpenPluginJarPath override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.allOpenPluginJarPath
override fun getAnnotations(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<String>? { override fun getAnnotations(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<String>? {
if ("sam-with-receiver" !in enabledCompilerPlugins) { if ("sam-with-receiver" !in enabledCompilerPlugins) {
@@ -53,7 +53,7 @@ class SourceSectionsTest : TestCaseWithTmpdir() {
} }
private val kotlinPaths: KotlinPaths by lazy { private val kotlinPaths: KotlinPaths by lazy {
val paths = PathUtil.getKotlinPathsForDistDirectory() val paths = PathUtil.kotlinPathsForDistDirectory
TestCase.assertTrue("Lib directory doesn't exist. Run 'ant dist'", paths.libPath.absoluteFile.isDirectory) TestCase.assertTrue("Lib directory doesn't exist. Run 'ant dist'", paths.libPath.absoluteFile.isDirectory)
paths paths
} }