diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.kt b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.kt index 4777a10c8a4..487927520a9 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.kt @@ -23,32 +23,103 @@ interface KotlinPaths { val libPath: File +// TODO: uncomment deprecation and fix usages in the whole project +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.StdLib)")) val stdlibPath: File + get() = jar(Jar.StdLib) +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.reflect)")) val reflectPath: File + get() = jar(Jar.Reflect) +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.scriptRuntime)")) val scriptRuntimePath: File + get() = jar(Jar.ScriptRuntime) +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.kotlinTest)")) val kotlinTestPath: File + get() = jar(Jar.KotlinTest) +// @Deprecated("Obsolete API", ReplaceWith("sourcesJar(KotlinPaths.Jars.stdLib)!!")) val stdlibSourcesPath: File + get() = sourcesJar(Jar.StdLib)!! +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.jsStdLib)")) val jsStdLibJarPath: File + get() = jar(Jar.JsStdLib) +// @Deprecated("Obsolete API", ReplaceWith("sourcesJar(KotlinPaths.Jars.JsStdLib)!!")) val jsStdLibSrcJarPath: File + get() = sourcesJar(Jar.JsStdLib)!! +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.jsKotlinTest)")) val jsKotlinTestJarPath: File + get() = jar(Jar.JsKotlinTest) +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.allOpenPlugin)")) val allOpenPluginJarPath: File + get() = jar(Jar.AllOpenPlugin) +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.noArgPlugin)")) val noArgPluginJarPath: File + get() = jar(Jar.NoArgPlugin) +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.samWithReceiver)")) val samWithReceiverJarPath: File + get() = jar(Jar.SamWithReceiver) +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.trove4j)")) val trove4jJarPath: File + get() = jar(Jar.Trove4j) +// @Deprecated("Obsolete API", ReplaceWith("classPath(KotlinPaths.ClassPaths.Compiler)")) val compilerClasspath: List + get() = classPath(ClassPaths.Compiler) +// @Deprecated("Obsolete API", ReplaceWith("jar(KotlinPaths.Jars.compiler)")) val compilerPath: File + get() = jar(Jar.Compiler) + enum class Jar(val baseName: String) { + StdLib(PathUtil.KOTLIN_JAVA_STDLIB_NAME), + Reflect(PathUtil.KOTLIN_JAVA_REFLECT_NAME), + ScriptRuntime(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_NAME), + KotlinTest(PathUtil.KOTLIN_TEST_NAME), + JsStdLib(PathUtil.JS_LIB_NAME), + JsKotlinTest(PathUtil.KOTLIN_TEST_JS_NAME), + AllOpenPlugin(PathUtil.ALLOPEN_PLUGIN_NAME), + NoArgPlugin(PathUtil.NOARG_PLUGIN_NAME), + SamWithReceiver(PathUtil.SAM_WITH_RECEIVER_PLUGIN_NAME), + Trove4j(PathUtil.TROVE4J_NAME), + Compiler(PathUtil.KOTLIN_COMPILER_NAME), + } + + enum class ClassPaths(val contents: List = emptyList()) { + Empty(), + Compiler(Jars.Compiler, Jars.StdLib, Jars.Reflect, Jars.ScriptRuntime, Jars.Trove4j), + ; + + constructor(vararg jars: Jar) : this(jars.asList()) + constructor(baseClassPath: ClassPaths, vararg jars: Jar) : this(baseClassPath.contents + jars) + } + + fun jar(jar: Jar): File + + fun sourcesJar(jar: Jar): File? + + fun classPath(jars: Sequence): List = jars.map(this::jar).toList() + + fun classPath(base: ClassPaths, vararg additionalJars: Jar): List = classPath(base.contents.asSequence() + additionalJars) + + fun classPath(vararg jars: Jar): List = classPath(jars.asSequence()) } + +abstract class KotlinPathsFromBaseDirectory(val basePath: File) : KotlinPaths { + + override val libPath: File + get() = basePath + + override fun jar(jar: KotlinPaths.Jar): File = basePath.resolve(jar.baseName + ".jar") + + override fun sourcesJar(jar: KotlinPaths.Jar): File? = basePath.resolve(jar.baseName + "-sources.jar") +} \ No newline at end of file diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.kt b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.kt index 884475ca577..29c4c7da03e 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.kt @@ -22,54 +22,10 @@ import java.io.File class KotlinPathsFromHomeDir( override val homePath: File // kotlinc directory -) : KotlinPaths { +) : KotlinPathsFromBaseDirectory(File(homePath, "lib")) { - override val libPath: File - get() = File(homePath, "lib") + // TODO: extend when needed + val libsWithSources = setOf(KotlinPaths.Jar.StdLib, KotlinPaths.Jar.JsStdLib) - override val stdlibPath: File - get() = getLibraryFile(PathUtil.KOTLIN_JAVA_STDLIB_JAR) - - override val reflectPath: File - get() = getLibraryFile(PathUtil.KOTLIN_JAVA_REFLECT_JAR) - - override val scriptRuntimePath: File - get() = getLibraryFile(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR) - - override val kotlinTestPath: File - get() = getLibraryFile(PathUtil.KOTLIN_TEST_JAR) - - override val stdlibSourcesPath: File - get() = getLibraryFile(PathUtil.KOTLIN_JAVA_STDLIB_SRC_JAR) - - override val jsStdLibJarPath: File - get() = getLibraryFile(PathUtil.JS_LIB_JAR_NAME) - - override val jsStdLibSrcJarPath: File - get() = getLibraryFile(PathUtil.JS_LIB_SRC_JAR_NAME) - - override val jsKotlinTestJarPath: File - get() = getLibraryFile(PathUtil.KOTLIN_TEST_JS_JAR) - - override val allOpenPluginJarPath: File - get() = getLibraryFile(PathUtil.ALLOPEN_PLUGIN_JAR_NAME) - - override val noArgPluginJarPath: File - get() = getLibraryFile(PathUtil.NOARG_PLUGIN_JAR_NAME) - - override val samWithReceiverJarPath: File - get() = getLibraryFile(PathUtil.SAM_WITH_RECEIVER_PLUGIN_JAR_NAME) - - override val trove4jJarPath: File - get() = getLibraryFile(PathUtil.TROVE4J_NAME) - - override val compilerClasspath: List - get() = listOf(stdlibPath, reflectPath, scriptRuntimePath, trove4jJarPath) - - override val compilerPath: File - get() = getLibraryFile(PathUtil.KOTLIN_COMPILER_JAR) - - private fun getLibraryFile(fileName: String): File { - return File(libPath, fileName) - } + override fun sourcesJar(jar: KotlinPaths.Jar): File? = if (jar in libsWithSources) super.sourcesJar(jar) else null } diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt index f1c9247f65e..1aa23746730 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt @@ -27,9 +27,12 @@ object PathUtil { const val JS_LIB_JAR_NAME = "$JS_LIB_NAME.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 ALLOPEN_PLUGIN_NAME = "allopen-compiler-plugin" + const val ALLOPEN_PLUGIN_JAR_NAME = "$ALLOPEN_PLUGIN_NAME.jar" + const val NOARG_PLUGIN_NAME = "noarg-compiler-plugin" + const val NOARG_PLUGIN_JAR_NAME = "$NOARG_PLUGIN_NAME.jar" + const val SAM_WITH_RECEIVER_PLUGIN_NAME = ".jar" + const val SAM_WITH_RECEIVER_PLUGIN_JAR_NAME = "$SAM_WITH_RECEIVER_PLUGIN_NAME.jar" const val JS_LIB_SRC_JAR_NAME = "kotlin-stdlib-js-sources.jar" const val KOTLIN_JAVA_RUNTIME_JRE7_NAME = "kotlin-stdlib-jre7" @@ -56,9 +59,12 @@ object PathUtil { const val KOTLIN_JAVA_REFLECT_JAR = "$KOTLIN_JAVA_REFLECT_NAME.jar" const val KOTLIN_REFLECT_SRC_JAR = "$KOTLIN_JAVA_REFLECT_NAME-sources.jar" - const val KOTLIN_JAVA_SCRIPT_RUNTIME_JAR = "kotlin-script-runtime.jar" - const val KOTLIN_SCRIPTING_COMMON_JAR = "kotlin-scripting-common.jar" - const val KOTLIN_SCRIPTING_JVM_JAR = "kotlin-scripting-jvm.jar" + const val KOTLIN_JAVA_SCRIPT_RUNTIME_NAME = "kotlin-script-runtime" + const val KOTLIN_JAVA_SCRIPT_RUNTIME_JAR = "$KOTLIN_JAVA_SCRIPT_RUNTIME_NAME.jar" + const val KOTLIN_SCRIPTING_COMMON_NAME = "kotlin-scripting-common" + const val KOTLIN_SCRIPTING_COMMON_JAR = "$KOTLIN_SCRIPTING_COMMON_NAME.jar" + const val KOTLIN_SCRIPTING_JVM_NAME = "kotlin-scripting-jvm" + const val KOTLIN_SCRIPTING_JVM_JAR = "$KOTLIN_SCRIPTING_JVM_NAME.jar" const val KOTLIN_SCRIPTING_COMPILER_PLUGIN_NAME = "kotlin-scripting-compiler" const val KOTLIN_SCRIPTING_COMPILER_PLUGIN_JAR = "$KOTLIN_SCRIPTING_COMPILER_PLUGIN_NAME.jar"