Add jdk jars to kotlin classpath

#KT-4214 Fixed
This commit is contained in:
Natalia Ukhorskaya
2013-12-23 18:29:30 +04:00
parent 4bc94e86c0
commit f2f1a1313d
36 changed files with 653 additions and 127 deletions
@@ -80,6 +80,8 @@ public class SpecialFiles {
excludedFiles.add("genericBackingFieldSignature.kt"); // Wrong signature after package renaming
excludedFiles.add("genericMethodSignature.kt"); // Wrong signature after package renaming
excludedFiles.add("classpath.kt"); // Some classes are not visible on android
}
private SpecialFiles() {
@@ -165,7 +165,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
private static List<File> getClasspath(@NotNull KotlinPaths paths, @NotNull K2JVMCompilerArguments arguments) {
List<File> classpath = Lists.newArrayList();
if (!arguments.noJdk) {
classpath.add(PathUtil.findRtJar());
classpath.addAll(PathUtil.getJdkClassesRoots());
}
if (!arguments.noStdlib) {
classpath.add(paths.getRuntimePath());
@@ -98,7 +98,7 @@ public class CompileEnvironmentUtil {
if (runtimePath.exists()) {
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, runtimePath);
}
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.findRtJar());
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.getJdkClassesRoots());
File jdkAnnotationsPath = paths.getJdkAnnotationsPath();
if (jdkAnnotationsPath.exists()) {
configuration.add(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, jdkAnnotationsPath);
@@ -85,6 +85,11 @@ public class AntTaskTest extends KotlinIntegrationTestBase {
doJvmAntTest();
}
@Test
public void jvmClasspath() throws Exception {
doJvmAntTest();
}
@Test
public void antTaskJvmManyRoots() throws Exception {
doJvmAntTest();
@@ -0,0 +1,11 @@
OUT:
Buildfile: [TestData]/build.xml
build:
[kotlinc] Compiling [[[TestData]/hello.kt]] => [[Temp]/hello.jar]
[kotlinc] WARNING: [TestData]/hello.kt: (15, 9) Variable 'result' is never used
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -0,0 +1,7 @@
<project name="Ant Task Test" default="build">
<taskdef resource="org/jetbrains/jet/buildtools/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
<target name="build">
<kotlinc src="${test.data}/hello.kt" output="${temp}/hello.jar"/>
</target>
</project>
@@ -0,0 +1,18 @@
package hello
import sun.nio.cs.SingleByte
import sun.net.spi.nameservice.dns.DNSNameService
import javax.crypto.Cipher
import com.sun.java.browser.plugin2.DOM
import com.sun.crypto.provider.AESCipher
fun main(args : Array<String>) {
val a = SingleByte() // charsets.jar
val c = DNSNameService() // dnsns.ajr
val e : Cipher? = null // jce.jar
val f : AESCipher? = null // sunjce_provider.jar
val j : DOM? = null // plugin.jar
val result = "$a$c$e$f$j"
println("OK")
}
@@ -0,0 +1,4 @@
OUT:
OK
Return code: 0
+4
View File
@@ -0,0 +1,4 @@
-src
$TESTDATA_DIR$/classpath.kt
-output
$TEMP_DIR$
+14
View File
@@ -0,0 +1,14 @@
import sun.nio.cs.SingleByte
import sun.net.spi.nameservice.dns.DNSNameService
import javax.crypto.Cipher
import com.sun.java.browser.plugin2.DOM
import com.sun.crypto.provider.AESCipher
fun box(): String {
val a = SingleByte() // charsets.jar
val c = DNSNameService() // dnsns.ajr
val e : Cipher? = null // jce.jar
val f : AESCipher? = null // sunjce_provider.jar
val j : DOM? = null // plugin.jar
return "OK"
}
+6
View File
@@ -0,0 +1,6 @@
WARNING: $TESTDATA_DIR$/classpath.kt: (8, 9) Variable 'a' is never used
WARNING: $TESTDATA_DIR$/classpath.kt: (9, 9) Variable 'c' is never used
WARNING: $TESTDATA_DIR$/classpath.kt: (10, 9) Variable 'e' is never used
WARNING: $TESTDATA_DIR$/classpath.kt: (11, 9) Variable 'f' is never used
WARNING: $TESTDATA_DIR$/classpath.kt: (12, 9) Variable 'j' is never used
OK
@@ -0,0 +1,14 @@
import sun.nio.cs.SingleByte
import sun.net.spi.nameservice.dns.DNSNameService
import javax.crypto.Cipher
import com.sun.java.browser.plugin2.DOM
import com.sun.crypto.provider.AESCipher
fun box() : String {
val a = SingleByte() // charsets.jar
val c = DNSNameService() // dnsns.ajr
val e : Cipher? = null // jce.jar
val f : AESCipher? = null // sunjce_provider.jar
val j : DOM? = null // plugin.jar
return "OK"
}
@@ -344,7 +344,12 @@ public class JetTestUtils {
@NotNull TestJdkKind jdkKind, @NotNull Collection<File> extraClasspath, @NotNull Collection<File> priorityClasspath) {
CompilerConfiguration configuration = new CompilerConfiguration();
configuration.addAll(CLASSPATH_KEY, priorityClasspath);
configuration.add(CLASSPATH_KEY, jdkKind == TestJdkKind.MOCK_JDK ? findMockJdkRtJar() : PathUtil.findRtJar());
if (jdkKind == TestJdkKind.MOCK_JDK) {
configuration.add(CLASSPATH_KEY, findMockJdkRtJar());
}
else {
configuration.addAll(CLASSPATH_KEY, PathUtil.getJdkClassesRoots());
}
if (configurationKind == ALL) {
configuration.add(CLASSPATH_KEY, ForTestCompileRuntime.runtimeJarForTests());
}
@@ -39,6 +39,11 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cli/jvm"), Pattern.compile("^(.+)\\.args$"), true);
}
@TestMetadata("classpath.args")
public void testClasspath() throws Exception {
doJvmTest("compiler/testData/cli/jvm/classpath.args");
}
@TestMetadata("diagnosticsOrder.args")
public void testDiagnosticsOrder() throws Exception {
doJvmTest("compiler/testData/cli/jvm/diagnosticsOrder.args");
@@ -480,6 +480,11 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/fullJdk"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("classpath.kt")
public void testClasspath() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/fullJdk/classpath.kt");
}
@TestMetadata("genericBackingFieldSignature.kt")
public void testGenericBackingFieldSignature() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/fullJdk/genericBackingFieldSignature.kt");
@@ -113,7 +113,7 @@ public class ResolveDescriptorsFromExternalLibraries {
System.out.println("Using file " + jar);
}
else {
jar = PathUtil.findRtJar();
jar = findRtJar();
System.out.println("Using rt.jar: " + jar);
}
@@ -138,6 +138,17 @@ public class ResolveDescriptorsFromExternalLibraries {
return hasErrors;
}
@NotNull
private static File findRtJar() {
List<File> roots = PathUtil.getJdkClassesRoots();
for (File root : roots) {
if (root.getName().equals("rt.jar") || root.getName().equals("classes.jar")) {
return root;
}
}
throw new IllegalArgumentException("No rt.jar/classes.jar found under " + System.getProperty("java.home"));
}
private boolean parseLibraryFileChunk(File jar, String libDescription, ZipInputStream zip, int classesPerChunk) throws IOException {
Disposable junk = new Disposable() {
@Override
@@ -153,8 +164,8 @@ public class ResolveDescriptorsFromExternalLibraries {
CompilerConfiguration configuration =
JetTestUtils.compilerConfigurationForTests(ConfigurationKind.JDK_AND_ANNOTATIONS, TestJdkKind.FULL_JDK);
jetCoreEnvironment = JetCoreEnvironment.createForTests(junk, configuration);
if (!PathUtil.findRtJar().equals(jar)) {
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + PathUtil.findRtJar());
if (!findRtJar().equals(jar)) {
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + findRtJar());
}
}
@@ -18,13 +18,14 @@ package org.jetbrains.jet.utils;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.java.impl.JavaSdkUtil;
import java.io.File;
import java.util.List;
public class PathUtil {
@@ -153,26 +154,7 @@ public class PathUtil {
}
@NotNull
public static File findRtJar() {
return findRtJar(System.getProperty("java.home"));
}
private static File findRtJar(String javaHome) {
if (SystemInfo.isMac && !SystemInfo.isJavaVersionAtLeast("1.7")) {
File classesJar = new File(new File(javaHome).getParentFile(), "Classes/classes.jar");
if (classesJar.exists()) {
return classesJar;
}
throw new IllegalArgumentException("No classes.jar found under " + classesJar.getParent());
}
else {
File rtJar = new File(javaHome, "lib/rt.jar");
if (rtJar.exists()) {
return rtJar;
}
throw new IllegalArgumentException("No rt.jar found under " + rtJar.getParent());
}
public static List<File> getJdkClassesRoots() {
return JavaSdkUtil.getJdkClassesRoots(new File(System.getProperty("java.home")), true);
}
}
+1
View File
@@ -11,6 +11,7 @@
<orderEntry type="module" module-name="util.runtime" exported="" />
<orderEntry type="module" module-name="Kotlin" exported="" />
<orderEntry type="library" exported="" name="kotlin-runtime" level="project" />
<orderEntry type="library" name="jps-model" level="project" />
</component>
</module>