Replaced jdk-headers with jdk-annotations everywhere.

This commit is contained in:
Evgeny Gerashchenko
2012-07-02 23:48:27 +04:00
parent 53cdbe486d
commit 77df57c150
20 changed files with 143 additions and 145 deletions
@@ -57,17 +57,17 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
protected ExitCode doExecute(K2JVMCompilerArguments arguments, PrintingMessageCollector messageCollector, Disposable rootDisposable) {
CompilerSpecialMode mode = parseCompilerSpecialMode(arguments);
File jdkHeadersJar;
if (mode.includeJdkHeaders()) {
if (arguments.jdkHeaders != null) {
jdkHeadersJar = new File(arguments.jdkHeaders);
File jdkAnnotationsJar;
if (mode.includeJdkAnnotations()) {
if (arguments.jdkAnnotations != null) {
jdkAnnotationsJar = new File(arguments.jdkAnnotations);
}
else {
jdkHeadersJar = PathUtil.getAltHeadersPath();
jdkAnnotationsJar = PathUtil.getJdkAnnotationsPath();
}
}
else {
jdkHeadersJar = null;
jdkAnnotationsJar = null;
}
File runtimeJar;
@@ -83,7 +83,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
runtimeJar = null;
}
CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), jdkHeadersJar, runtimeJar);
CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), jdkAnnotationsJar, runtimeJar);
final List<String> argumentsSourceDirs = arguments.getSourceDirs();
if (!arguments.script &&
@@ -57,8 +57,8 @@ public class K2JVMCompilerArguments extends CompilerArguments {
@Argument(value = "stdlib", description = "Path to the stdlib.jar")
public String stdlib;
@Argument(value = "jdkHeaders", description = "Path to the kotlin-jdk-headers.jar")
public String jdkHeaders;
@Argument(value = "jdkAnnotations", description = "Path to the kotlin-jdk-annotations.jar")
public String jdkAnnotations;
@Argument(value = "mode", description = "Special compiler modes: stubs or jdkHeaders")
public String mode;
@@ -90,9 +90,9 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
}
annotationsProvider = new CoreAnnotationsProvider();
if (compilerSpecialMode.includeJdkHeaders()) {
for (VirtualFile root : compilerDependencies.getJdkHeaderRoots()) {
addLibraryRoot(root);
if (compilerSpecialMode.includeJdkAnnotations()) {
for (VirtualFile root : compilerDependencies.getJdkAnnotationsRoots()) {
annotationsProvider.addExternalAnnotationsRoot(root);
}
}
@@ -1,3 +1,4 @@
/*
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
@@ -35,14 +36,14 @@ public class CompilerDependencies {
@Nullable
private final File jdkJar;
@Nullable
private final File jdkHeadersJar;
private final File jdkAnnotationsJar;
@Nullable
private final File runtimeJar;
public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkJar, @Nullable File jdkHeadersJar, @Nullable File runtimeJar) {
public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkJar, @Nullable File jdkAnnotationsJar, @Nullable File runtimeJar) {
this.compilerSpecialMode = compilerSpecialMode;
this.jdkJar = jdkJar;
this.jdkHeadersJar = jdkHeadersJar;
this.jdkAnnotationsJar = jdkAnnotationsJar;
this.runtimeJar = runtimeJar;
if (compilerSpecialMode.includeJdk()) {
@@ -50,9 +51,9 @@ public class CompilerDependencies {
throw new IllegalArgumentException("jdk must be included for mode " + compilerSpecialMode);
}
}
if (compilerSpecialMode.includeJdkHeaders()) {
if (jdkHeadersJar == null) {
throw new IllegalArgumentException("jdkHeaders must be included for mode " + compilerSpecialMode);
if (compilerSpecialMode.includeJdkAnnotations()) {
if (jdkAnnotationsJar == null) {
throw new IllegalArgumentException("jdkAnnotations must be included for mode " + compilerSpecialMode);
}
}
if (compilerSpecialMode.includeKotlinRuntime()) {
@@ -72,20 +73,15 @@ public class CompilerDependencies {
return jdkJar;
}
@Nullable
public File getJdkHeadersJar() {
return jdkHeadersJar;
}
@Nullable
public File getRuntimeJar() {
return runtimeJar;
}
@NotNull
public List<VirtualFile> getJdkHeaderRoots() {
if (compilerSpecialMode.includeJdkHeaders()) {
return Collections.singletonList(PathUtil.jarFileOrDirectoryToVirtualFile(jdkHeadersJar));
public List<VirtualFile> getJdkAnnotationsRoots() {
if (compilerSpecialMode.includeJdkAnnotations()) {
return Collections.singletonList(PathUtil.jarFileOrDirectoryToVirtualFile(jdkAnnotationsJar));
}
else {
return Collections.emptyList();
@@ -107,7 +103,7 @@ public class CompilerDependencies {
return new CompilerDependencies(
compilerSpecialMode,
compilerSpecialMode.includeJdk() ? findRtJar() : null,
compilerSpecialMode.includeJdkHeaders() ? PathUtil.getAltHeadersPath() : null,
compilerSpecialMode.includeJdkAnnotations() ? PathUtil.getJdkAnnotationsPath() : null,
compilerSpecialMode.includeKotlinRuntime() ? PathUtil.getDefaultRuntimePath() : null);
}
@@ -28,7 +28,7 @@ public enum CompilerSpecialMode {
JS,
;
public boolean includeJdkHeaders() {
public boolean includeJdkAnnotations() {
return this == REGULAR || this == STDLIB || this == IDEA;
}
@@ -59,7 +59,7 @@ public class PsiClassFinderForJvm implements PsiClassFinder {
@PostConstruct
public void initialize() {
this.altClassFinder = new AltClassFinder(project, compilerDependencies.getJdkHeaderRoots());
this.altClassFinder = new AltClassFinder(project, compilerDependencies.getJdkAnnotationsRoots());
this.javaSearchScope = new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
@Override
public boolean contains(VirtualFile file) {
+1 -1
View File
@@ -5,7 +5,7 @@ Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
-annotations [String] paths to external annotations
-includeRuntime [flag]
-stdlib [String] Path to the stdlib.jar
-jdkHeaders [String] Path to the kotlin-jdk-headers.jar
-jdkAnnotations [String] Path to the kotlin-jdk-annotations.jar
-mode [String] Special compiler modes: stubs or jdkHeaders
-output [String] output directory
-module [String] module to compile
@@ -50,7 +50,7 @@ fun test6() : Boolean {
return true
}
// ArrayList without jdk-headers cannot be used in these tests
// ArrayList without jdk-annotations cannot be used in these tests
class MyArrayList<T>() {
private var value17: T? = null
private var value39: T? = null
@@ -1,4 +1,3 @@
package kotlin1
import java.util.*
@@ -1,4 +1,3 @@
package kotlin1
import java.util.*
@@ -6,6 +5,6 @@ import java.util.*
fun main(args : Array<String>) {
val al : ArrayList<Int> = ArrayList<Int>()
// A type mismatch on this line means that alt-headers were not loaded
// A type mismatch on this line means that jdk-annotations were not loaded
al.toArray(Array<Int>(3, {1})) : Array<Int>
}
@@ -18,11 +18,10 @@ package org.jetbrains.jet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileBuiltins;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileJdkHeaders;
import org.jetbrains.jet.codegen.forTestCompile.ForTestPackJdkAnnotations;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.utils.PathUtil;
import org.junit.Test;
/**
@@ -36,8 +35,8 @@ public class CompileCompilerDependenciesTest {
}
@Test
public void compileJdkHeaders() {
ForTestCompileJdkHeaders.jdkHeadersForTests();
public void packJdkAnnotations() {
ForTestPackJdkAnnotations.jdkAnnotationsForTests();
}
@Test
@@ -53,7 +52,7 @@ public class CompileCompilerDependenciesTest {
return new CompilerDependencies(
compilerSpecialMode,
compilerSpecialMode.includeJdk() ? (mockJdk ? JetTestUtils.findMockJdkRtJar() : CompilerDependencies.findRtJar()) : null,
compilerSpecialMode.includeJdkHeaders() ? ForTestCompileJdkHeaders.jdkHeadersForTests() : null,
compilerSpecialMode.includeJdkAnnotations() ? ForTestPackJdkAnnotations.jdkAnnotationsForTests() : null,
compilerSpecialMode.includeKotlinRuntime() ? ForTestCompileRuntime.runtimeJarForTests() : null);
}
}
@@ -1,55 +0,0 @@
/*
* 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.codegen.forTestCompile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import java.io.File;
/**
* @author Stepan Koltsov
*/
public class ForTestCompileJdkHeaders {
private ForTestCompileJdkHeaders() {
}
private static class JdkHeaders extends ForTestCompileSomething {
JdkHeaders() {
super("jdkHeaders");
}
@Override
protected void doCompile(@NotNull File classesDir) throws Exception {
ExitCode exitCode = new K2JVMCompiler().exec(
System.err, "-output", classesDir.getPath(), "-src", "./jdk-headers/src", "-mode", "jdkHeaders");
if (exitCode != ExitCode.OK) {
throw new IllegalStateException("jdk headers compilation failed: " + exitCode);
}
}
private static final JdkHeaders jdkHeaders = new JdkHeaders();
}
@NotNull
public static File jdkHeadersForTests() {
return ForTestCompileSomething.ACTUALLY_COMPILE ? JdkHeaders.jdkHeaders.getJarFile() : new File("dist/kotlinc/lib/alt/kotlin-jdk-headers.jar");
}
}
@@ -80,7 +80,7 @@ abstract class ForTestCompileSomething {
}
}
private static void copyToJar(File root, JarOutputStream os) throws IOException {
static void copyToJar(File root, JarOutputStream os) throws IOException {
Stack<Pair<String, File>> toCopy = new Stack<Pair<String, File>>();
toCopy.add(new Pair<String, File>("", root));
while (!toCopy.empty()) {
@@ -0,0 +1,72 @@
/*
* 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.codegen.forTestCompile;
import com.google.common.io.Files;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Stack;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
/**
* @author Stepan Koltsov
*/
public class ForTestPackJdkAnnotations {
private ForTestPackJdkAnnotations() {
}
private static File jarFile = null;
private static File getJarFile() {
if (jarFile == null) {
try {
File tmpDir = JetTestUtils.tmpDir("runtimejar");
jarFile = new File(tmpDir, "runtime.jar");
FileOutputStream annotationsJar = new FileOutputStream(jarFile);
try {
JarOutputStream jarOutputStream = new JarOutputStream(new BufferedOutputStream(annotationsJar));
try {
ForTestCompileSomething.copyToJar(new File("./jdk-annotations"), jarOutputStream);
}
finally {
jarOutputStream.close();
}
}
finally {
annotationsJar.close();
}
}
catch (IOException e) {
throw new AssertionError(e);
}
}
return jarFile;
}
@NotNull
public static File jdkAnnotationsForTests() {
return ForTestCompileSomething.ACTUALLY_COMPILE ? getJarFile() : new File("dist/kotlinc/lib/alt/kotlin-jdk-annotations.jar");
}
}
@@ -20,7 +20,7 @@ import com.intellij.openapi.util.io.FileUtil;
import junit.framework.TestCase;
import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileJdkHeaders;
import org.jetbrains.jet.codegen.forTestCompile.ForTestPackJdkAnnotations;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.jet.parsing.JetParsingTest;
import org.junit.Assert;
@@ -44,13 +44,13 @@ public class CompileEnvironmentTest extends TestCase {
try {
File stdlib = ForTestCompileRuntime.runtimeJarForTests();
File jdkHeaders = ForTestCompileJdkHeaders.jdkHeadersForTests();
File jdkAnnotations = ForTestPackJdkAnnotations.jdkAnnotationsForTests();
File resultJar = new File(tempDir, "result.jar");
ExitCode rv = new K2JVMCompiler().exec(System.out,
"-module", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts",
"-jar", resultJar.getAbsolutePath(),
"-stdlib", stdlib.getAbsolutePath(),
"-jdkHeaders", jdkHeaders.getAbsolutePath());
"-module", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts",
"-jar", resultJar.getAbsolutePath(),
"-stdlib", stdlib.getAbsolutePath(),
"-jdkAnnotations", jdkAnnotations.getAbsolutePath());
Assert.assertEquals("compilation completed with non-zero code", ExitCode.OK, rv);
FileInputStream fileInputStream = new FileInputStream(resultJar);
try {
@@ -78,10 +78,10 @@ public class CompileEnvironmentTest extends TestCase {
try {
File out = new File(tempDir, "out");
File stdlib = ForTestCompileRuntime.runtimeJarForTests();
File jdkHeaders = ForTestCompileJdkHeaders.jdkHeadersForTests();
File jdkAnnotations = ForTestPackJdkAnnotations.jdkAnnotationsForTests();
ExitCode exitCode = new K2JVMCompiler()
.exec(System.out, "-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt", "-output",
out.getAbsolutePath(), "-stdlib", stdlib.getAbsolutePath(), "-jdkHeaders", jdkHeaders.getAbsolutePath());
out.getAbsolutePath(), "-stdlib", stdlib.getAbsolutePath(), "-jdkAnnotations", jdkAnnotations.getAbsolutePath());
Assert.assertEquals(ExitCode.OK, exitCode);
assertEquals(1, out.listFiles().length);
assertEquals(1, out.listFiles()[0].listFiles().length);
@@ -19,7 +19,7 @@ package org.jetbrains.jet.jvm.compiler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileJdkHeaders;
import org.jetbrains.jet.codegen.forTestCompile.ForTestPackJdkAnnotations;
import org.jetbrains.jet.di.InjectorForJavaSemanticServices;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
@@ -36,7 +36,6 @@ import org.junit.Assert;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;
/**
* @author Stepan Koltsov
@@ -80,7 +79,8 @@ public class JavaDescriptorResolverTest extends TestCaseWithTmpdir {
}
public void testResolveJdkHeaderClassWithoutJdk() {
JetCoreEnvironment jetCoreEnvironment = new JetCoreEnvironment(myTestRootDisposable, new CompilerDependencies(CompilerSpecialMode.IDEA, null, ForTestCompileJdkHeaders.jdkHeadersForTests(), null));
JetCoreEnvironment jetCoreEnvironment = new JetCoreEnvironment(myTestRootDisposable, new CompilerDependencies(CompilerSpecialMode.IDEA, null, ForTestPackJdkAnnotations
.jdkAnnotationsForTests(), null));
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
jetCoreEnvironment.getCompilerDependencies(), jetCoreEnvironment.getProject());
@@ -94,8 +94,8 @@ public class PathUtil {
}
@Nullable
public static File getAltHeadersPath() {
return getFilePackedIntoLib("alt/kotlin-jdk-headers.jar");
public static File getJdkAnnotationsPath() {
return getFilePackedIntoLib("alt/kotlin-jdk-annotations.jar");
}
@NotNull