Rewritten CompileTextTest so it doesn't add class path to already created configuration. Removed JetCoreEnvironment.addToClasspathFromClassLoader() method.
This commit is contained in:
@@ -159,20 +159,4 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||
public List<JetFile> getSourceFiles() {
|
||||
return sourceFiles;
|
||||
}
|
||||
|
||||
public void addToClasspathFromClassLoader(ClassLoader loader) {
|
||||
ClassLoader parent = loader.getParent();
|
||||
if (parent != null) {
|
||||
addToClasspathFromClassLoader(parent);
|
||||
}
|
||||
|
||||
if (loader instanceof URLClassLoader) {
|
||||
for (URL url : ((URLClassLoader) loader).getURLs()) {
|
||||
File file = new File(url.getPath());
|
||||
if (file.exists() && (!file.isFile() || file.getPath().endsWith(".jar"))) {
|
||||
addToClasspath(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,25 +17,57 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CompileTextTest extends CodegenTestCase {
|
||||
public void testMe() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations();
|
||||
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
|
||||
compilerConfiguration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClassPathFromClassLoaders(getClass().getClassLoader()));
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), compilerConfiguration);
|
||||
String text = "import org.jetbrains.jet.codegen.CompileTextTest; fun x() = CompileTextTest()";
|
||||
K2JVMCompileEnvironmentConfiguration configuration = new K2JVMCompileEnvironmentConfiguration(
|
||||
myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR, false, BuiltinsScopeExtensionMode.ALL, false,
|
||||
BuiltinToJavaTypesMapping.ENABLED);
|
||||
configuration.getEnvironment().addToClasspathFromClassLoader(getClass().getClassLoader());
|
||||
ClassLoader classLoader = KotlinToJVMBytecodeCompiler.compileText(configuration, text);
|
||||
Class<?> namespace = classLoader.loadClass("namespace");
|
||||
Method x = namespace.getDeclaredMethod("x");
|
||||
Object invoke = x.invoke(null);
|
||||
assertTrue(invoke instanceof CompileTextTest);
|
||||
}
|
||||
|
||||
private static List<File> getClassPathFromClassLoaders(ClassLoader loader) {
|
||||
List<File> list = new ArrayList<File>();
|
||||
addClassPathFromClassLoadersRecursively(loader, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private static void addClassPathFromClassLoadersRecursively(ClassLoader loader, List<File> list) {
|
||||
ClassLoader parent = loader.getParent();
|
||||
if (parent != null) {
|
||||
addClassPathFromClassLoadersRecursively(parent, list);
|
||||
}
|
||||
|
||||
if (loader instanceof URLClassLoader) {
|
||||
for (URL url : ((URLClassLoader) loader).getURLs()) {
|
||||
File file = new File(url.getPath());
|
||||
if (file.exists() && (!file.isFile() || file.getPath().endsWith(".jar"))) {
|
||||
list.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user