Introduce HighlightingWithDependentLibrariesTest
This tests that LibraryInfo dependencies affect source files highlighting
This commit is contained in:
@@ -18,7 +18,6 @@ package org.jetbrains.jet;
|
|||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
|
||||||
import com.intellij.util.io.ZipUtil;
|
import com.intellij.util.io.ZipUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.cli.common.ExitCode;
|
import org.jetbrains.jet.cli.common.ExitCode;
|
||||||
@@ -32,7 +31,9 @@ import java.lang.reflect.Method;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
@@ -43,35 +44,43 @@ public class MockLibraryUtil {
|
|||||||
|
|
||||||
private static Class<?> compilerClass = null;
|
private static Class<?> compilerClass = null;
|
||||||
|
|
||||||
public static File compileLibraryToJar(String sourcesPath, boolean addSources) {
|
@NotNull
|
||||||
|
public static File compileLibraryToJar(
|
||||||
|
@NotNull String sourcesPath,
|
||||||
|
@NotNull String jarName,
|
||||||
|
boolean addSources,
|
||||||
|
@NotNull String... extraClasspath
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
File contentDir = JetTestUtils.tmpDir("lib-content");
|
File contentDir = JetTestUtils.tmpDir("testLibrary-" + jarName);
|
||||||
|
|
||||||
File classesDir = new File(contentDir, "classes");
|
File classesDir = new File(contentDir, "classes");
|
||||||
compileKotlin(sourcesPath, classesDir);
|
compileKotlin(sourcesPath, classesDir, extraClasspath);
|
||||||
|
|
||||||
List<File> javaFiles = FileUtil.findFilesByMask(Pattern.compile(".*\\.java"), new File(sourcesPath));
|
List<File> javaFiles = FileUtil.findFilesByMask(Pattern.compile(".*\\.java"), new File(sourcesPath));
|
||||||
if (!javaFiles.isEmpty()) {
|
if (!javaFiles.isEmpty()) {
|
||||||
List<String> classPath = ContainerUtil.list(ForTestCompileRuntime.runtimeJarForTests().getPath(),
|
List<String> classpath = new ArrayList<String>();
|
||||||
JetTestUtils.getAnnotationsJar().getPath());
|
classpath.add(ForTestCompileRuntime.runtimeJarForTests().getPath());
|
||||||
|
classpath.add(JetTestUtils.getAnnotationsJar().getPath());
|
||||||
|
Collections.addAll(classpath, extraClasspath);
|
||||||
|
|
||||||
// Probably no kotlin files were present, so dir might not have been created after kotlin compiler
|
// Probably no kotlin files were present, so dir might not have been created after kotlin compiler
|
||||||
if (classesDir.exists()) {
|
if (classesDir.exists()) {
|
||||||
classPath.add(classesDir.getPath());
|
classpath.add(classesDir.getPath());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FileUtil.createDirectory(classesDir);
|
FileUtil.createDirectory(classesDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> options = Arrays.asList(
|
List<String> options = Arrays.asList(
|
||||||
"-classpath", StringUtil.join(classPath, File.pathSeparator),
|
"-classpath", StringUtil.join(classpath, File.pathSeparator),
|
||||||
"-d", classesDir.getPath()
|
"-d", classesDir.getPath()
|
||||||
);
|
);
|
||||||
|
|
||||||
JetTestUtils.compileJavaFiles(javaFiles, options);
|
JetTestUtils.compileJavaFiles(javaFiles, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
File jarFile = new File(contentDir, "library.jar");
|
File jarFile = new File(contentDir, jarName + ".jar");
|
||||||
|
|
||||||
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(jarFile));
|
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(jarFile));
|
||||||
ZipUtil.addDirToZipRecursively(zip, jarFile, classesDir, "", null, null);
|
ZipUtil.addDirToZipRecursively(zip, jarFile, classesDir, "", null, null);
|
||||||
@@ -88,18 +97,17 @@ public class MockLibraryUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Runs compiler in custom class loader to avoid effects caused by replacing Application with another one created in compiler.
|
// Runs compiler in custom class loader to avoid effects caused by replacing Application with another one created in compiler.
|
||||||
public static void compileKotlin(@NotNull String sourcesPath, @NotNull File outDir) {
|
public static void compileKotlin(@NotNull String sourcesPath, @NotNull File outDir, @NotNull String... extraClasspath) {
|
||||||
compileKotlin(sourcesPath, outDir, sourcesPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void compileKotlin(@NotNull String sourcesPath, @NotNull File outDir, @NotNull String classpath) {
|
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||||
Class<?> compilerClass = getCompilerClass();
|
Class<?> compilerClass = getCompilerClass();
|
||||||
Object compilerObject = compilerClass.newInstance();
|
Object compilerObject = compilerClass.newInstance();
|
||||||
Method execMethod = compilerClass.getMethod("exec", PrintStream.class, String[].class);
|
Method execMethod = compilerClass.getMethod("exec", PrintStream.class, String[].class);
|
||||||
|
|
||||||
String newClasspath = classpath.contains(sourcesPath) ? classpath : classpath + File.pathSeparator + sourcesPath;
|
List<String> classpath = new ArrayList<String>();
|
||||||
|
classpath.add(sourcesPath);
|
||||||
|
Collections.addAll(classpath, extraClasspath);
|
||||||
|
String newClasspath = StringUtil.join(classpath, File.pathSeparator);
|
||||||
|
|
||||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||||
Enum<?> invocationResult = (Enum<?>) execMethod.invoke(
|
Enum<?> invocationResult = (Enum<?>) execMethod.invoke(
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public abstract class AbstractTopLevelMembersInvocationTest extends AbstractByte
|
|||||||
|
|
||||||
File library = new File(root, LIBRARY);
|
File library = new File(root, LIBRARY);
|
||||||
List<File> classPath = library.exists() ?
|
List<File> classPath = library.exists() ?
|
||||||
Collections.singletonList(MockLibraryUtil.compileLibraryToJar(library.getPath(), false)) :
|
Collections.singletonList(MockLibraryUtil.compileLibraryToJar(library.getPath(), LIBRARY, false)) :
|
||||||
Collections.<File>emptyList();
|
Collections.<File>emptyList();
|
||||||
|
|
||||||
assert !sourceFiles.isEmpty() : getTestName(true) + " should contain at least one .kt file";
|
assert !sourceFiles.isEmpty() : getTestName(true) + " should contain at least one .kt file";
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private File compileLibrary(@NotNull String sourcePath) {
|
private File compileLibrary(@NotNull String sourcePath) {
|
||||||
return MockLibraryUtil.compileLibraryToJar(new File(getTestDataDirectory(), sourcePath).getPath(), false);
|
return MockLibraryUtil.compileLibraryToJar(new File(getTestDataDirectory(), sourcePath).getPath(), "customKotlinLib", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestWithTxt(@NotNull File... extraClassPath) throws Exception {
|
private void doTestWithTxt(@NotNull File... extraClassPath) throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package lib1
|
||||||
|
|
||||||
|
public open class Base {
|
||||||
|
public open fun baseFun() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun acceptBase(b: Base) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package lib2
|
||||||
|
|
||||||
|
import lib1.*
|
||||||
|
|
||||||
|
public class Derived(): Base() {
|
||||||
|
public fun derivedFun() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun acceptBase(b: Base) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun returnBase(): Base = Base()
|
||||||
|
|
||||||
|
public fun Base.extendBase(): Unit {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package using.libs
|
||||||
|
|
||||||
|
import lib2.extendBase
|
||||||
|
|
||||||
|
//check that references to lib1 entities obtained through lib2 are valid
|
||||||
|
fun main() {
|
||||||
|
lib1.acceptBase(lib1.Base())
|
||||||
|
lib2.acceptBase(lib1.Base())
|
||||||
|
lib2.acceptBase(lib2.Derived())
|
||||||
|
lib1.acceptBase(lib2.Derived())
|
||||||
|
lib1.acceptBase(lib2.returnBase())
|
||||||
|
lib1.Base().extendBase()
|
||||||
|
lib1.Base().baseFun()
|
||||||
|
lib2.Derived().baseFun()
|
||||||
|
lib2.Derived().derivedFun()
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ public class JdkAndMockLibraryProjectDescriptor extends JetLightProjectDescripto
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
|
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
|
||||||
File libraryJar = MockLibraryUtil.compileLibraryToJar(sourcesPath, withSources);
|
File libraryJar = MockLibraryUtil.compileLibraryToJar(sourcesPath, "myKotlinLib,", withSources);
|
||||||
String jarUrl = "jar://" + FileUtilRt.toSystemIndependentName(libraryJar.getAbsolutePath()) + "!/";
|
String jarUrl = "jar://" + FileUtilRt.toSystemIndependentName(libraryJar.getAbsolutePath()) + "!/";
|
||||||
|
|
||||||
Library.ModifiableModel libraryModel = model.getModuleLibraryTable().getModifiableModel().createLibrary("myKotlinLib").getModifiableModel();
|
Library.ModifiableModel libraryModel = model.getModuleLibraryTable().getModifiableModel().createLibrary("myKotlinLib").getModifiableModel();
|
||||||
|
|||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.plugin.caches.resolve
|
||||||
|
|
||||||
|
import org.jetbrains.jet.plugin.PluginTestCaseBase
|
||||||
|
import org.jetbrains.jet.MockLibraryUtil
|
||||||
|
import com.intellij.openapi.roots.libraries.Library
|
||||||
|
import com.intellij.openapi.command.WriteCommandAction
|
||||||
|
import java.io.File
|
||||||
|
import com.intellij.openapi.roots.OrderRootType
|
||||||
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
|
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
|
||||||
|
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar
|
||||||
|
import org.jetbrains.jet.plugin.JetLightProjectDescriptor
|
||||||
|
import com.intellij.openapi.module.Module
|
||||||
|
import com.intellij.openapi.roots.ModifiableRootModel
|
||||||
|
import com.intellij.openapi.roots.ContentEntry
|
||||||
|
|
||||||
|
public class HighlightingWithDependentLibrariesTest : JetLightCodeInsightFixtureTestCase() {
|
||||||
|
private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/highlightingWithDependentLibraries"
|
||||||
|
|
||||||
|
override fun getProjectDescriptor() = object : JetLightProjectDescriptor() {
|
||||||
|
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry?) {
|
||||||
|
val compiledJar1 = MockLibraryUtil.compileLibraryToJar("$TEST_DATA_PATH/lib1", "lib1", false)
|
||||||
|
val compiledJar2 = MockLibraryUtil.compileLibraryToJar("$TEST_DATA_PATH/lib2", "lib2", false, compiledJar1.canonicalPath)
|
||||||
|
|
||||||
|
model.addLibraryEntry(createLibrary(compiledJar1, "baseLibrary"))
|
||||||
|
model.addLibraryEntry(createLibrary(compiledJar2, "dependentLibrary"))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createLibrary(jarFile: File, name: String): Library {
|
||||||
|
val library = LibraryTablesRegistrar.getInstance()!!.getLibraryTable(getProject()).createLibrary(name)!!
|
||||||
|
val model = library.getModifiableModel()
|
||||||
|
model.addRoot(VfsUtil.getUrlForLibraryRoot(jarFile), OrderRootType.CLASSES)
|
||||||
|
model.commit()
|
||||||
|
return library
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun testHighlightingWithDependentLibraries() {
|
||||||
|
myFixture.configureByFile("$TEST_DATA_PATH/module/usingLibs.kt")
|
||||||
|
myFixture.checkHighlighting(false, false, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -124,7 +124,7 @@ public abstract class KotlinDebuggerTestCase extends DescriptorTestCase {
|
|||||||
if (!IS_TINY_APP_COMPILED) {
|
if (!IS_TINY_APP_COMPILED) {
|
||||||
String modulePath = getTestAppPath();
|
String modulePath = getTestAppPath();
|
||||||
|
|
||||||
CUSTOM_LIBRARY_JAR = MockLibraryUtil.compileLibraryToJar(CUSTOM_LIBRARY_SOURCES.getPath(), true);
|
CUSTOM_LIBRARY_JAR = MockLibraryUtil.compileLibraryToJar(CUSTOM_LIBRARY_SOURCES.getPath(), "debuggerCustomLibrary", true);
|
||||||
|
|
||||||
String outputDir = modulePath + File.separator + "classes";
|
String outputDir = modulePath + File.separator + "classes";
|
||||||
String sourcesDir = modulePath + File.separator + "src";
|
String sourcesDir = modulePath + File.separator + "src";
|
||||||
|
|||||||
Reference in New Issue
Block a user