Environment creation unified everywhere.

JDK Kind turned into enum for clarity
This commit is contained in:
Andrey Breslav
2012-07-11 13:40:50 +04:00
parent fe6fa5dfaa
commit 207c75b956
7 changed files with 51 additions and 25 deletions
@@ -52,9 +52,9 @@ public class CompileCompilerDependenciesTest {
ForTestCompileRuntime.runtimeJarForTests();
}
public static CompilerConfiguration compilerConfigurationForTests(@NotNull ConfigurationKind configurationKind, boolean mockJdk) {
public static CompilerConfiguration compilerConfigurationForTests(@NotNull ConfigurationKind configurationKind, @NotNull TestJdkKind jdkKind) {
List<File> classpath = new ArrayList<File>();
classpath.add(mockJdk ? JetTestUtils.findMockJdkRtJar() : PathUtil.findRtJar());
classpath.add(jdkKind == TestJdkKind.MOCK_JDK ? JetTestUtils.findMockJdkRtJar() : PathUtil.findRtJar());
if (configurationKind == ALL) {
classpath.add(ForTestCompileRuntime.runtimeJarForTests());
}
@@ -178,13 +178,27 @@ public class JetTestUtils {
builtinsScopeExtensionMode);
}
public static JetCoreEnvironment createEnvironmentWithFullJdk(Disposable disposable) {
return createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(disposable,
ConfigurationKind.ALL, TestJdkKind.FULL_JDK);
}
public static JetCoreEnvironment createEnvironmentWithMockJdkAndIdeaAnnotations(Disposable disposable) {
return createEnvironmentWithMockJdkAndIdeaAnnotations(disposable, ConfigurationKind.ALL);
}
public static JetCoreEnvironment createEnvironmentWithMockJdkAndIdeaAnnotations(Disposable disposable, @NotNull ConfigurationKind configurationKind) {
return createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(disposable, configurationKind, TestJdkKind.MOCK_JDK);
}
public static JetCoreEnvironment createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(
@NotNull Disposable disposable,
@NotNull ConfigurationKind configurationKind,
@NotNull TestJdkKind jdkKind
) {
JetCoreEnvironment environment = new JetCoreEnvironment(disposable,
CompileCompilerDependenciesTest.compilerConfigurationForTests(configurationKind, true)
CompileCompilerDependenciesTest
.compilerConfigurationForTests(configurationKind, jdkKind)
);
environment.addToClasspath(getAnnotationsJar());
return environment;
@@ -198,7 +212,6 @@ public class JetTestUtils {
return new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/annotations.jar");
}
public static void mkdirs(File file) throws IOException {
if (file.isDirectory()) {
return;
@@ -255,12 +268,6 @@ public class JetTestUtils {
public static final Pattern FILE_PATTERN = Pattern.compile("//\\s*FILE:\\s*(.*)$", Pattern.MULTILINE);
public static JetCoreEnvironment createEnvironmentWithFullJdk(Disposable disposable) {
return new JetCoreEnvironment(disposable,
CompileCompilerDependenciesTest.compilerConfigurationForTests(ConfigurationKind.ALL, false)
);
}
public static PsiFile createFile(@NonNls String name, String text, @NotNull Project project) {
LightVirtualFile virtualFile = new LightVirtualFile(name, JetLanguage.INSTANCE, text);
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
@@ -29,15 +29,10 @@ public abstract class KotlinTestWithEnvironmentManagement extends UsefulTestCase
}
protected JetCoreEnvironment createEnvironmentWithMockJdk(@NotNull ConfigurationKind configurationKind) {
return createEnvironmentWithJdk(configurationKind, true);
return createEnvironmentWithJdk(configurationKind, TestJdkKind.MOCK_JDK);
}
protected JetCoreEnvironment createEnvironmentWithJdk(@NotNull ConfigurationKind configurationKind, boolean mockJdk) {
JetCoreEnvironment environment = new JetCoreEnvironment(getTestRootDisposable(),
CompileCompilerDependenciesTest
.compilerConfigurationForTests(configurationKind, mockJdk)
);
environment.addToClasspath(JetTestUtils.getAnnotationsJar());
return environment;
protected JetCoreEnvironment createEnvironmentWithJdk(@NotNull ConfigurationKind configurationKind, @NotNull TestJdkKind jdkKind) {
return JetTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(getTestRootDisposable(), configurationKind, jdkKind);
}
}
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet;
/**
* @author abreslav
*/
public enum TestJdkKind {
MOCK_JDK,
FULL_JDK,
}
@@ -26,10 +26,7 @@ import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.CompileCompilerDependenciesTest;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.TimeUtils;
import org.jetbrains.jet.*;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.di.InjectorForJavaSemanticServices;
@@ -151,7 +148,7 @@ public class ResolveDescriptorsFromExternalLibraries {
}
else {
CompilerConfiguration configuration =
CompileCompilerDependenciesTest.compilerConfigurationForTests(ConfigurationKind.JDK_AND_ANNOTATIONS, false);
CompileCompilerDependenciesTest.compilerConfigurationForTests(ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.FULL_JDK);
jetCoreEnvironment = JetCoreEnvironment.createCoreEnvironmentForJVM(junk, configuration);
if (!PathUtil.findRtJar().equals(jar)) {
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + PathUtil.findRtJar());
@@ -25,6 +25,7 @@ import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.KotlinTestWithEnvironmentManagement;
import org.jetbrains.jet.TestJdkKind;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.jvm.compiler.NamespaceComparator;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
@@ -48,7 +49,7 @@ public class LazyResolveStdlibLoadingTest extends KotlinTestWithEnvironmentManag
@Override
protected void setUp() throws Exception {
super.setUp();
stdlibEnvironment = createEnvironmentWithJdk(ConfigurationKind.JDK_AND_ANNOTATIONS, false);
stdlibEnvironment = createEnvironmentWithJdk(ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.FULL_JDK);
}
protected void doTestForGivenFiles(
@@ -23,6 +23,7 @@ import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.CompileCompilerDependenciesTest;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.TestJdkKind;
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
import org.jetbrains.jet.cli.jvm.repl.ReplInterpreter;
import org.jetbrains.jet.config.CompilerConfiguration;
@@ -54,7 +55,7 @@ public class ReplInterpreterTest {
private void testFile(@NotNull String relativePath) {
CompilerConfiguration configuration =
CompileCompilerDependenciesTest.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, false);
CompileCompilerDependenciesTest.compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.FULL_JDK);
File[] classpath = configuration.getUserData(JVMConfigurationKeys.CLASSPATH_KEY);
assert classpath != null;
configuration.putUserData(JVMConfigurationKeys.CLASSPATH_KEY, ArrayUtil.append(classpath, new File("out/production/runtime")));