Convert KotlinPaths to kotlin

This commit is contained in:
Ilya Chernikov
2019-02-07 11:01:59 +01:00
parent d1da1dd410
commit b0c86647ed
4 changed files with 67 additions and 144 deletions
@@ -96,13 +96,13 @@ fun CompilerConfiguration.configureStandardLibs(paths: KotlinPaths?, arguments:
} }
if (!arguments.noStdlib) { if (!arguments.noStdlib) {
addRoot("kotlin.stdlib", PathUtil.KOTLIN_JAVA_STDLIB_JAR, KotlinPaths::getStdlibPath, "'-no-stdlib'") addRoot("kotlin.stdlib", PathUtil.KOTLIN_JAVA_STDLIB_JAR, KotlinPaths::stdlibPath, "'-no-stdlib'")
addRoot("kotlin.script.runtime", PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, KotlinPaths::getScriptRuntimePath, "'-no-stdlib'") addRoot("kotlin.script.runtime", PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, KotlinPaths::scriptRuntimePath, "'-no-stdlib'")
} }
// "-no-stdlib" implies "-no-reflect": otherwise we would be able to transitively read stdlib classes through kotlin-reflect, // "-no-stdlib" implies "-no-reflect": otherwise we would be able to transitively read stdlib classes through kotlin-reflect,
// which is likely not what user wants since s/he manually provided "-no-stdlib" // which is likely not what user wants since s/he manually provided "-no-stdlib"
if (!arguments.noReflect && !arguments.noStdlib) { if (!arguments.noReflect && !arguments.noStdlib) {
addRoot("kotlin.reflect", PathUtil.KOTLIN_JAVA_REFLECT_JAR, KotlinPaths::getReflectPath, "'-no-reflect' or '-no-stdlib'") addRoot("kotlin.reflect", PathUtil.KOTLIN_JAVA_REFLECT_JAR, { it.reflectPath }, "'-no-reflect' or '-no-stdlib'")
} }
} }
@@ -14,60 +14,41 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.utils; package org.jetbrains.kotlin.utils
import org.jetbrains.annotations.NotNull; import java.io.File
import java.io.File; interface KotlinPaths {
import java.util.List; val homePath: File
public interface KotlinPaths { val libPath: File
@NotNull
File getHomePath();
@NotNull val stdlibPath: File
File getLibPath();
@NotNull val reflectPath: File
File getStdlibPath();
@NotNull val scriptRuntimePath: File
File getReflectPath();
@NotNull val kotlinTestPath: File
File getScriptRuntimePath();
@NotNull val stdlibSourcesPath: File
File getKotlinTestPath();
@NotNull val jsStdLibJarPath: File
File getStdlibSourcesPath();
@NotNull val jsStdLibSrcJarPath: File
File getJsStdLibJarPath();
@NotNull val jsKotlinTestJarPath: File
File getJsStdLibSrcJarPath();
@NotNull val allOpenPluginJarPath: File
File getJsKotlinTestJarPath();
@NotNull val noArgPluginJarPath: File
File getAllOpenPluginJarPath();
@NotNull val samWithReceiverJarPath: File
File getNoArgPluginJarPath();
@NotNull val trove4jJarPath: File
File getSamWithReceiverJarPath();
@NotNull val compilerClasspath: List<File>
File getTrove4jJarPath();
@NotNull val compilerPath: File
List<File> getCompilerClasspath();
@NotNull
File getCompilerPath();
} }
@@ -14,120 +14,62 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.utils; package org.jetbrains.kotlin.utils
import kotlin.collections.CollectionsKt; import kotlin.collections.*
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File
import java.util.List;
public class KotlinPathsFromHomeDir implements KotlinPaths { class KotlinPathsFromHomeDir(
// kotlinc directory override val homePath: File // kotlinc directory
private final File homePath; ) : KotlinPaths {
public KotlinPathsFromHomeDir(@NotNull File homePath) { override val libPath: File
this.homePath = homePath; get() = File(homePath, "lib")
}
@Override override val stdlibPath: File
@NotNull get() = getLibraryFile(PathUtil.KOTLIN_JAVA_STDLIB_JAR)
public File getHomePath() {
return homePath;
}
@Override override val reflectPath: File
@NotNull get() = getLibraryFile(PathUtil.KOTLIN_JAVA_REFLECT_JAR)
public File getLibPath() {
return new File(homePath, "lib");
}
@NotNull override val scriptRuntimePath: File
@Override get() = getLibraryFile(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR)
public File getStdlibPath() {
return getLibraryFile(PathUtil.KOTLIN_JAVA_STDLIB_JAR);
}
@NotNull override val kotlinTestPath: File
@Override get() = getLibraryFile(PathUtil.KOTLIN_TEST_JAR)
public File getReflectPath() {
return getLibraryFile(PathUtil.KOTLIN_JAVA_REFLECT_JAR);
}
@Override override val stdlibSourcesPath: File
@NotNull get() = getLibraryFile(PathUtil.KOTLIN_JAVA_STDLIB_SRC_JAR)
public File getScriptRuntimePath() {
return getLibraryFile(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR);
}
@NotNull override val jsStdLibJarPath: File
@Override get() = getLibraryFile(PathUtil.JS_LIB_JAR_NAME)
public File getKotlinTestPath() {
return getLibraryFile(PathUtil.KOTLIN_TEST_JAR);
}
@NotNull override val jsStdLibSrcJarPath: File
@Override get() = getLibraryFile(PathUtil.JS_LIB_SRC_JAR_NAME)
public File getStdlibSourcesPath() {
return getLibraryFile(PathUtil.KOTLIN_JAVA_STDLIB_SRC_JAR);
}
@Override override val jsKotlinTestJarPath: File
@NotNull get() = getLibraryFile(PathUtil.KOTLIN_TEST_JS_JAR)
public File getJsStdLibJarPath() {
return getLibraryFile(PathUtil.JS_LIB_JAR_NAME);
}
@Override override val allOpenPluginJarPath: File
@NotNull get() = getLibraryFile(PathUtil.ALLOPEN_PLUGIN_JAR_NAME)
public File getJsStdLibSrcJarPath() {
return getLibraryFile(PathUtil.JS_LIB_SRC_JAR_NAME);
}
@NotNull override val noArgPluginJarPath: File
@Override get() = getLibraryFile(PathUtil.NOARG_PLUGIN_JAR_NAME)
public File getJsKotlinTestJarPath() {
return getLibraryFile(PathUtil.KOTLIN_TEST_JS_JAR);
}
@NotNull override val samWithReceiverJarPath: File
@Override get() = getLibraryFile(PathUtil.SAM_WITH_RECEIVER_PLUGIN_JAR_NAME)
public File getAllOpenPluginJarPath() {
return getLibraryFile(PathUtil.ALLOPEN_PLUGIN_JAR_NAME);
}
@NotNull override val trove4jJarPath: File
@Override get() = getLibraryFile(PathUtil.TROVE4J_NAME)
public File getNoArgPluginJarPath() {
return getLibraryFile(PathUtil.NOARG_PLUGIN_JAR_NAME);
}
@NotNull override val compilerClasspath: List<File>
@Override get() = listOf(stdlibPath, reflectPath, scriptRuntimePath, trove4jJarPath)
public File getSamWithReceiverJarPath() {
return getLibraryFile(PathUtil.SAM_WITH_RECEIVER_PLUGIN_JAR_NAME);
}
@NotNull override val compilerPath: File
@Override get() = getLibraryFile(PathUtil.KOTLIN_COMPILER_JAR)
public File getTrove4jJarPath() {
return getLibraryFile(PathUtil.TROVE4J_NAME);
}
@NotNull private fun getLibraryFile(fileName: String): File {
@Override return File(libPath, fileName)
public List<File> getCompilerClasspath() {
return CollectionsKt.listOf(getStdlibPath(), getReflectPath(), getScriptRuntimePath(), getTrove4jJarPath());
}
@NotNull
@Override
public File getCompilerPath() {
return getLibraryFile(PathUtil.KOTLIN_COMPILER_JAR);
}
@NotNull
private File getLibraryFile(@NotNull String fileName) {
return new File(getLibPath(), fileName);
} }
} }
@@ -89,16 +89,16 @@ enum class LibraryJarDescriptor(
val shouldExist: Boolean, val shouldExist: Boolean,
val getPath: (KotlinPaths) -> File = { paths -> File(paths.libPath, jarName) } val getPath: (KotlinPaths) -> File = { paths -> File(paths.libPath, jarName) }
) { ) {
RUNTIME_JAR(PathUtil.KOTLIN_JAVA_STDLIB_JAR, OrderRootType.CLASSES, true, KotlinPaths::getStdlibPath) { RUNTIME_JAR(PathUtil.KOTLIN_JAVA_STDLIB_JAR, OrderRootType.CLASSES, true, { it.stdlibPath }) {
override fun findExistingJar(library: Library): VirtualFile? { override fun findExistingJar(library: Library): VirtualFile? {
if (isExternalLibrary(library)) return null if (isExternalLibrary(library)) return null
return JavaRuntimeDetectionUtil.getRuntimeJar(Arrays.asList(*library.getFiles(OrderRootType.CLASSES))) return JavaRuntimeDetectionUtil.getRuntimeJar(Arrays.asList(*library.getFiles(OrderRootType.CLASSES)))
} }
}, },
REFLECT_JAR(PathUtil.KOTLIN_JAVA_REFLECT_JAR, OrderRootType.CLASSES, false, KotlinPaths::getReflectPath), REFLECT_JAR(PathUtil.KOTLIN_JAVA_REFLECT_JAR, OrderRootType.CLASSES, false, { it.reflectPath }),
SCRIPT_RUNTIME_JAR(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, OrderRootType.CLASSES, true, KotlinPaths::getScriptRuntimePath), SCRIPT_RUNTIME_JAR(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, OrderRootType.CLASSES, true, { it.scriptRuntimePath }),
TEST_JAR(PathUtil.KOTLIN_TEST_JAR, OrderRootType.CLASSES, false, KotlinPaths::getKotlinTestPath), TEST_JAR(PathUtil.KOTLIN_TEST_JAR, OrderRootType.CLASSES, false, { it.kotlinTestPath }),
@Deprecated("RUNTIME_JDK7_JAR should be used since 1.2") @Deprecated("RUNTIME_JDK7_JAR should be used since 1.2")
RUNTIME_JRE7_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_JAR, OrderRootType.CLASSES, false), RUNTIME_JRE7_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_JAR, OrderRootType.CLASSES, false),
@@ -116,7 +116,7 @@ enum class LibraryJarDescriptor(
RUNTIME_JRE8_SOURCES_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_SRC_JAR, OrderRootType.SOURCES, false), RUNTIME_JRE8_SOURCES_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_SRC_JAR, OrderRootType.SOURCES, false),
RUNTIME_JDK8_SOURCES_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_SRC_JAR, OrderRootType.SOURCES, false), RUNTIME_JDK8_SOURCES_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_SRC_JAR, OrderRootType.SOURCES, false),
RUNTIME_SRC_JAR(PathUtil.KOTLIN_JAVA_STDLIB_SRC_JAR, OrderRootType.SOURCES, false, KotlinPaths::getStdlibSourcesPath) { RUNTIME_SRC_JAR(PathUtil.KOTLIN_JAVA_STDLIB_SRC_JAR, OrderRootType.SOURCES, false, { it.stdlibSourcesPath }) {
override fun findExistingJar(library: Library): VirtualFile? { override fun findExistingJar(library: Library): VirtualFile? {
return super.findExistingJar(library) ?: LibraryUtils.getJarFile( return super.findExistingJar(library) ?: LibraryUtils.getJarFile(
library.getFiles(orderRootType).toList(), library.getFiles(orderRootType).toList(),
@@ -127,8 +127,8 @@ enum class LibraryJarDescriptor(
REFLECT_SRC_JAR(PathUtil.KOTLIN_REFLECT_SRC_JAR, OrderRootType.SOURCES, false), REFLECT_SRC_JAR(PathUtil.KOTLIN_REFLECT_SRC_JAR, OrderRootType.SOURCES, false),
TEST_SRC_JAR(PathUtil.KOTLIN_TEST_SRC_JAR, OrderRootType.SOURCES, false), TEST_SRC_JAR(PathUtil.KOTLIN_TEST_SRC_JAR, OrderRootType.SOURCES, false),
JS_STDLIB_JAR(PathUtil.JS_LIB_JAR_NAME, OrderRootType.CLASSES, true, KotlinPaths::getJsStdLibJarPath), JS_STDLIB_JAR(PathUtil.JS_LIB_JAR_NAME, OrderRootType.CLASSES, true, { it.jsStdLibJarPath }),
JS_STDLIB_SRC_JAR(PathUtil.JS_LIB_SRC_JAR_NAME, OrderRootType.SOURCES, false, KotlinPaths::getJsStdLibSrcJarPath); JS_STDLIB_SRC_JAR(PathUtil.JS_LIB_SRC_JAR_NAME, OrderRootType.SOURCES, false, { it.jsStdLibSrcJarPath });
open fun findExistingJar(library: Library): VirtualFile? { open fun findExistingJar(library: Library): VirtualFile? {
if (isExternalLibrary(library)) return null if (isExternalLibrary(library)) return null