[TEST] Introduce test-infrastructure-utils module and extract common test utilities here
This commit is contained in:
+2
-2
@@ -6,13 +6,13 @@
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
|
||||
abstract class AbstractCompileKotlinAgainstKotlinJdk15Test : AbstractCompileKotlinAgainstKotlinTest() {
|
||||
override fun invokeBox(className: String) {
|
||||
runJvmInstance(
|
||||
KotlinTestUtils.getJdk15Home(),
|
||||
KtTestUtil.getJdk15Home(),
|
||||
additionalArgs = listOf("--enable-preview"),
|
||||
classPath = listOfNotNull(
|
||||
aDir, bDir, ForTestCompileRuntime.runtimeJarForTests(),
|
||||
|
||||
+6
-5
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
|
||||
import java.io.File;
|
||||
@@ -44,8 +45,8 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
||||
tmpdir = KotlinTestUtils.tmpDirForTest(this);
|
||||
aDir = new File(tmpdir, "a");
|
||||
bDir = new File(tmpdir, "b");
|
||||
KotlinTestUtils.mkdirs(aDir);
|
||||
KotlinTestUtils.mkdirs(bDir);
|
||||
KtTestUtil.mkdirs(aDir);
|
||||
KtTestUtil.mkdirs(bDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,7 +116,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
||||
Disposable compileDisposable = createDisposable("compileA");
|
||||
CompilerConfiguration configuration = createConfiguration(
|
||||
ConfigurationKind.ALL, getTestJdkKind(files), getBackendA(),
|
||||
Collections.singletonList(KotlinTestUtils.getAnnotationsJar()),
|
||||
Collections.singletonList(KtTestUtil.getAnnotationsJar()),
|
||||
Collections.emptyList(), Collections.singletonList(testFile)
|
||||
);
|
||||
|
||||
@@ -138,7 +139,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
||||
String commonHeader = StringsKt.substringBefore(files.get(0).content, "FILE:", "");
|
||||
CompilerConfiguration configuration = createConfiguration(
|
||||
ConfigurationKind.ALL, getTestJdkKind(files), getBackendB(),
|
||||
Arrays.asList(KotlinTestUtils.getAnnotationsJar(), aDir),
|
||||
Arrays.asList(KtTestUtil.getAnnotationsJar(), aDir),
|
||||
Collections.emptyList(), Arrays.asList(testFile, new TestFile("header", commonHeader))
|
||||
);
|
||||
|
||||
@@ -167,7 +168,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends CodegenTest
|
||||
) {
|
||||
|
||||
List<KtFile> ktFiles =
|
||||
files.stream().map(file -> KotlinTestUtils.createFile(file.name, file.content, environment.getProject()))
|
||||
files.stream().map(file -> KtTestUtil.createFile(file.name, file.content, environment.getProject()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
ModuleVisibilityManager.SERVICE.getInstance(environment.getProject()).addModule(
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@@ -18,7 +19,7 @@ abstract class AbstractCustomJDKBlackBoxCodegenTest : AbstractBlackBoxCodegenTes
|
||||
override fun doTest(filePath: String) {
|
||||
val file = File(filePath)
|
||||
val expectedText =
|
||||
KotlinTestUtils.doLoadFile(file) +
|
||||
KtTestUtil.doLoadFile(file) +
|
||||
"\n" +
|
||||
"""
|
||||
fun main() {
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader;
|
||||
import org.jetbrains.org.objectweb.asm.ClassVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
@@ -49,7 +50,7 @@ abstract public class AbstractGenerateNotNullAssertionsTest extends CodegenTestC
|
||||
}
|
||||
|
||||
private void loadSource(@NotNull String fileName) {
|
||||
loadFileByFullPath(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName);
|
||||
loadFileByFullPath(KtTestUtil.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName);
|
||||
}
|
||||
|
||||
protected void doTestNoAssertionsForKotlinFromBinary(String binaryDependencyFilename, String testFilename) {
|
||||
|
||||
+2
-2
@@ -5,13 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractJdk15BlackBoxCodegenTest : AbstractCustomJDKBlackBoxCodegenTest() {
|
||||
override fun getTestJdkKind(): TestJdkKind = TestJdkKind.FULL_JDK_15
|
||||
override fun getJdkHome(): File = KotlinTestUtils.getJdk15Home()
|
||||
override fun getJdkHome(): File = KtTestUtil.getJdk15Home()
|
||||
override fun getPrefix(): String = "java15/box"
|
||||
|
||||
override fun getAdditionalJvmArgs(): List<String> = listOf("--enable-preview")
|
||||
|
||||
+3
-3
@@ -5,12 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractJdk9BlackBoxCodegenTest : AbstractCustomJDKBlackBoxCodegenTest() {
|
||||
override fun getTestJdkKind(): TestJdkKind = TestJdkKind.FULL_JDK_9
|
||||
override fun getJdkHome(): File = KotlinTestUtils.getJdk9Home()
|
||||
override fun getJdkHome(): File = KtTestUtil.getJdk9Home()
|
||||
override fun getPrefix(): String = "java9/box"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil.getAnnotationsJar
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||
import java.io.File
|
||||
|
||||
|
||||
+3
-2
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.test.*;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
@@ -51,13 +52,13 @@ public abstract class AbstractTopLevelMembersInvocationTest extends AbstractByte
|
||||
getTestRootDisposable(),
|
||||
KotlinTestUtils.newConfiguration(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK,
|
||||
CollectionsKt.plus(classPath, KotlinTestUtils.getAnnotationsJar()), Collections.emptyList()
|
||||
CollectionsKt.plus(classPath, KtTestUtil.getAnnotationsJar()), Collections.emptyList()
|
||||
),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
|
||||
loadFiles(ArrayUtil.toStringArray(sourceFiles));
|
||||
|
||||
List<OccurrenceInfo> expected = readExpectedOccurrences(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + sourceFiles.get(0));
|
||||
List<OccurrenceInfo> expected = readExpectedOccurrences(KtTestUtil.getTestDataPathBase() + "/codegen/" + sourceFiles.get(0));
|
||||
String actual = generateToText();
|
||||
Companion.checkGeneratedTextAgainstExpectedOccurrences(actual, expected, TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.scripting.definitions.ScriptDependenciesProvider;
|
||||
import org.jetbrains.kotlin.scripting.resolve.ScriptCompilationConfigurationWrapper;
|
||||
import org.jetbrains.kotlin.test.*;
|
||||
import org.jetbrains.kotlin.test.clientserver.TestProxy;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.jetbrains.org.objectweb.asm.ClassReader;
|
||||
import org.jetbrains.org.objectweb.asm.tree.ClassNode;
|
||||
@@ -63,8 +64,8 @@ import java.util.stream.Collectors;
|
||||
import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
|
||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
|
||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.*;
|
||||
import static org.jetbrains.kotlin.test.util.KtTestUtil.getAnnotationsJar;
|
||||
|
||||
public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.TestFile> {
|
||||
private static final String DEFAULT_TEST_FILE_NAME = "a_test";
|
||||
@@ -134,7 +135,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
|
||||
@NotNull
|
||||
protected String loadFile(@NotNull @TestDataFile String name) {
|
||||
return loadFileByFullPath(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + name);
|
||||
return loadFileByFullPath(KtTestUtil.getTestDataPathBase() + "/codegen/" + name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -172,7 +173,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
if (file.name.endsWith(".kt") || file.name.endsWith(".kts")) {
|
||||
// `rangesToDiagnosticNames` parameter is not-null only for diagnostic tests, it's using for lazy diagnostics
|
||||
String content = CheckerTestUtil.INSTANCE.parseDiagnosedRanges(file.content, new ArrayList<>(0), null);
|
||||
ktFiles.add(KotlinTestUtils.createFile(file.name, content, project));
|
||||
ktFiles.add(KtTestUtil.createFile(file.name, content, project));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,7 +609,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
protected void doTest(@NotNull String filePath) throws Exception {
|
||||
File file = new File(filePath);
|
||||
|
||||
String expectedText = KotlinTestUtils.doLoadFile(file);
|
||||
String expectedText = KtTestUtil.doLoadFile(file);
|
||||
List<TestFile> testFiles = createTestFilesFromFile(file, expectedText);
|
||||
|
||||
doMultiFileTest(file, testFiles);
|
||||
@@ -659,7 +660,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
@NotNull
|
||||
private static File createTempDirectory(String prefix) {
|
||||
try {
|
||||
return KotlinTestUtils.tmpDir(prefix);
|
||||
return KtTestUtil.tmpDir(prefix);
|
||||
} catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
@@ -674,7 +675,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
|
||||
for (TestFile testFile : javaFiles) {
|
||||
File file = new File(dir, testFile.name);
|
||||
KotlinTestUtils.mkdirs(file.getParentFile());
|
||||
KtTestUtil.mkdirs(file.getParentFile());
|
||||
FilesKt.writeText(file, testFile.content, Charsets.UTF_8);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -81,15 +81,15 @@ public class CodegenTestFiles {
|
||||
}
|
||||
|
||||
public static CodegenTestFiles create(Project project, String[] names) {
|
||||
return create(project, names, KotlinTestUtils.getTestDataPathBase());
|
||||
return create(project, names, KtTestUtil.getTestDataPathBase());
|
||||
}
|
||||
|
||||
public static CodegenTestFiles create(Project project, String[] names, String testDataPath) {
|
||||
List<KtFile> files = new ArrayList<>(names.length);
|
||||
for (String name : names) {
|
||||
try {
|
||||
String content = KotlinTestUtils.doLoadFile(testDataPath + "/codegen/", name);
|
||||
KtFile file = KotlinTestUtils.createFile(name, content, project);
|
||||
String content = KtTestUtil.doLoadFile(testDataPath + "/codegen/", name);
|
||||
KtFile file = KtTestUtil.createFile(name, content, project);
|
||||
files.add(file);
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -103,7 +103,7 @@ public class CodegenTestFiles {
|
||||
public static CodegenTestFiles create(@NotNull String fileName, @NotNull String contentWithDiagnosticMarkup, @NotNull Project project) {
|
||||
// `rangesToDiagnosticNames` parameter is not-null only for diagnostic tests, it's using for lazy diagnostics
|
||||
String content = CheckerTestUtil.INSTANCE.parseDiagnosedRanges(contentWithDiagnosticMarkup, new ArrayList<>(), null);
|
||||
KtFile file = KotlinTestUtils.createFile(fileName, content, project);
|
||||
KtFile file = KtTestUtil.createFile(fileName, content, project);
|
||||
List<PsiErrorElement> ranges = AnalyzingUtils.getSyntaxErrorRanges(file);
|
||||
assert ranges.isEmpty() : "Syntax errors found in " + file + ": " + ranges;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.jetbrains.kotlin.utils.StringsKt;
|
||||
|
||||
@@ -85,7 +86,7 @@ public class CodegenTestUtil {
|
||||
@NotNull List<String> additionalOptions
|
||||
) {
|
||||
try {
|
||||
File directory = KotlinTestUtils.tmpDir("java-classes");
|
||||
File directory = KtTestUtil.tmpDir("java-classes");
|
||||
compileJava(fileNames, additionalClasspath, additionalOptions, directory);
|
||||
return directory;
|
||||
}
|
||||
@@ -118,7 +119,7 @@ public class CodegenTestUtil {
|
||||
List<String> classpath = new ArrayList<>();
|
||||
classpath.add(ForTestCompileRuntime.runtimeJarForTests().getPath());
|
||||
classpath.add(ForTestCompileRuntime.reflectJarForTests().getPath());
|
||||
classpath.add(KotlinTestUtils.getAnnotationsJar().getPath());
|
||||
classpath.add(KtTestUtil.getAnnotationsJar().getPath());
|
||||
classpath.addAll(additionalClasspath);
|
||||
|
||||
List<String> options = new ArrayList<>(Arrays.asList(
|
||||
|
||||
+3
-3
@@ -25,10 +25,10 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.clientserver.TestProcessServer
|
||||
import org.jetbrains.kotlin.test.clientserver.TestProxy
|
||||
import org.jetbrains.kotlin.test.clientserver.getGeneratedClass
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import java.io.File
|
||||
import java.lang.IllegalStateException
|
||||
import java.net.URLClassLoader
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
@@ -158,7 +158,7 @@ abstract class AbstractDebugTest : CodegenTestCase() {
|
||||
GenerationUtils.compileFiles(myFiles.psiFiles, myEnvironment, classBuilderFactory)
|
||||
classFileFactory = generationState.factory
|
||||
|
||||
val tempDirForTest = KotlinTestUtils.tmpDir("debuggerTest")
|
||||
val tempDirForTest = KtTestUtil.tmpDir("debuggerTest")
|
||||
val classesDir = File(tempDirForTest, "classes")
|
||||
try {
|
||||
classFileFactory.writeAllTo(classesDir)
|
||||
@@ -298,4 +298,4 @@ abstract class AbstractDebugTest : CodegenTestCase() {
|
||||
abstract fun storeStep(loggedItems: ArrayList<Any>, event: Event)
|
||||
|
||||
abstract fun checkResult(wholeFile: File, loggedItems: List<Any>)
|
||||
}
|
||||
}
|
||||
|
||||
-149
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen.forTestCompile;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ForTestCompileRuntime {
|
||||
private static volatile SoftReference<ClassLoader> reflectJarClassLoader = new SoftReference<>(null);
|
||||
private static volatile SoftReference<ClassLoader> runtimeJarClassLoader = new SoftReference<>(null);
|
||||
|
||||
@NotNull
|
||||
public static File runtimeJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-stdlib.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File runtimeJarForTestsWithJdk8() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-stdlib-jdk8.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File minimalRuntimeJarForTests() {
|
||||
return assertExists(new File("dist/kotlin-stdlib-minimal-for-test.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File kotlinTestJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-test.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File kotlinTestJUnitJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-test-junit.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File kotlinTestJsJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-test-js.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File reflectJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-reflect.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File scriptRuntimeJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-script-runtime.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File runtimeSourcesJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-stdlib-sources.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File stdlibMavenSourcesJarForTests() {
|
||||
return assertExists(new File("dist/maven/kotlin-stdlib-sources.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File stdlibCommonForTests() {
|
||||
return assertExists(new File("dist/common/kotlin-stdlib-common.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File stdlibCommonSourcesForTests() {
|
||||
return assertExists(new File("dist/common/kotlin-stdlib-common-sources.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File stdlibJsForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-stdlib-js.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File jetbrainsAnnotationsForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/annotations-13.0.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File jvmAnnotationsForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-annotations-jvm.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File androidAnnotationsForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-annotations-android.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File coroutinesCompatForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-coroutines-experimental-compat.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File assertExists(@NotNull File file) {
|
||||
if (!file.exists()) {
|
||||
throw new IllegalStateException(file + " does not exist. Run 'gradlew dist'");
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static synchronized ClassLoader runtimeAndReflectJarClassLoader() {
|
||||
ClassLoader loader = reflectJarClassLoader.get();
|
||||
if (loader == null) {
|
||||
loader = createClassLoader(runtimeJarForTests(), reflectJarForTests(), scriptRuntimeJarForTests(), kotlinTestJarForTests());
|
||||
reflectJarClassLoader = new SoftReference<>(loader);
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static synchronized ClassLoader runtimeJarClassLoader() {
|
||||
ClassLoader loader = runtimeJarClassLoader.get();
|
||||
if (loader == null) {
|
||||
loader = createClassLoader(runtimeJarForTests(), scriptRuntimeJarForTests(), kotlinTestJarForTests());
|
||||
runtimeJarClassLoader = new SoftReference<>(loader);
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ClassLoader createClassLoader(@NotNull File... files) {
|
||||
try {
|
||||
List<URL> urls = new ArrayList<>(2);
|
||||
for (File file : files) {
|
||||
urls.add(file.toURI().toURL());
|
||||
}
|
||||
return new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user