Implement Java 9 module visibility checks

In this commit, only IDE tests are added, because we look for module
declarations in the IDE across the whole project, whereas in the
compiler we should do this on the module path only and that requires
separate work (KT-18599) which is done in the following commits.

(The change in Cache.kt is needed so that
JvmModuleAccessibilityChecker.ClassifierUsage, which is an inner class,
would be injected properly.)

 #KT-18598 In Progress
 #KT-18599 In Progress
This commit is contained in:
Alexander Udalov
2017-05-18 19:05:53 +03:00
parent 2275068c94
commit e32880d9a3
56 changed files with 678 additions and 36 deletions
@@ -501,7 +501,7 @@ public class KotlinTestUtils {
JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromJre(getJreHome(jdk6)));
}
else if (jdkKind == TestJdkKind.FULL_JDK_9) {
File home = getJre9HomeIfPossible();
File home = getJdk9HomeIfPossible();
if (home != null) {
configuration.put(JVMConfigurationKeys.JDK_HOME, home);
}
@@ -529,8 +529,11 @@ public class KotlinTestUtils {
}
@Nullable
public static File getJre9HomeIfPossible() {
public static File getJdk9HomeIfPossible() {
String jdk9 = System.getenv("JDK_19");
if (jdk9 == null) {
jdk9 = System.getenv("JDK_9");
}
if (jdk9 == null) {
// TODO: replace this with a failure as soon as Java 9 is installed on all TeamCity agents
System.err.println("Environment variable JDK_19 is not set, the test will be skipped");
@@ -46,11 +46,11 @@ object MockLibraryUtil {
jarName: String,
addSources: Boolean = false,
extraOptions: List<String> = emptyList(),
extraClasspath: List<String> = emptyList()
extraClasspath: List<String> = emptyList(),
useJava9: Boolean = false
): File {
return compileLibraryToJar(
sourcesPath, KotlinTestUtils.tmpDir("testLibrary-" + jarName), jarName, addSources, extraOptions, extraClasspath
)
return compileLibraryToJar(sourcesPath, KotlinTestUtils.tmpDir("testLibrary-" + jarName), jarName, addSources,
extraOptions, extraClasspath, useJava9)
}
@JvmStatic
@@ -61,7 +61,8 @@ object MockLibraryUtil {
jarName: String,
addSources: Boolean = false,
extraOptions: List<String> = emptyList(),
extraClasspath: List<String> = emptyList()
extraClasspath: List<String> = emptyList(),
useJava9: Boolean = false
): File {
val classesDir = File(contentDir, "classes")
@@ -91,7 +92,14 @@ object MockLibraryUtil {
"-d", classesDir.path
)
KotlinTestUtils.compileJavaFiles(javaFiles, options)
val compile =
if (useJava9) KotlinTestUtils::compileJavaFilesExternallyWithJava9
else KotlinTestUtils::compileJavaFiles
val success = compile(javaFiles, options)
if (!success) {
throw AssertionError("Java files are not compiled successfully")
}
}
return createJarFile(contentDir, classesDir, jarName, sourcesPath.takeIf { addSources })