JPS: don't consider that the module is not Kotlin JS until check all libraries.

#KT-14082 Fixed
This commit is contained in:
Zalim Bashorov
2016-09-29 14:28:03 +03:00
parent 9797a1c35c
commit 797f7ab28e
2 changed files with 28 additions and 29 deletions
@@ -189,11 +189,17 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
}
}
annotation class WorkingDir(val name: String)
override fun setUp() {
super.setUp()
val sourceFilesRoot = File(AbstractKotlinJpsBuildTestCase.TEST_DATA_PATH + "general/" + getTestName(false))
val currentTestMethod = this::class.members.firstOrNull { it.name == "test" + getTestName(false) }
val workingDirFromAnnotation = currentTestMethod?.annotations?.filterIsInstance<WorkingDir>()?.firstOrNull()?.name
val sourceFilesRoot = File(AbstractKotlinJpsBuildTestCase.TEST_DATA_PATH + "general/" + (workingDirFromAnnotation ?: getTestName(false)))
workDir = AbstractKotlinJpsBuildTestCase.copyTestDataToTmpDir(sourceFilesRoot)
orCreateProjectDir
JpsUtils.resetCaches()
}
override fun tearDown() {
@@ -276,6 +282,15 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
checkWhen(arrayOf(touch("src/test1.kt"), touch("module2/src/module2.kt")), null, k2jsOutput(PROJECT_NAME, ADDITIONAL_MODULE_NAME))
}
@WorkingDir("KotlinJavaScriptProjectWithTwoModules")
fun testKotlinJavaScriptProjectWithTwoModulesAndWithLibrary() {
initProject()
createKotlinJavaScriptLibraryArchive()
addKotlinJavaScriptDependency(KOTLIN_JS_LIBRARY, File(workDir, KOTLIN_JS_LIBRARY_JAR))
addKotlinJavaScriptStdlibDependency()
makeAll().assertSuccessful()
}
fun testKotlinJavaScriptProjectWithDirectoryAsStdlib() {
initProject()
val jslibJar = PathUtil.getKotlinPathsForDistDirectory().jsStdLibJarPath
@@ -839,7 +854,7 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
private fun assertCanceled(buildResult: BuildResult) {
val list = buildResult.getMessages(BuildMessage.Kind.INFO)
assertTrue("The build has been canceled".equals(list.last().messageText))
assertTrue("The build has been canceled" == list.last().messageText)
}
private fun generateLongKotlinFile(filePath: String, packagename: String, className: String) {
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.jps.build;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jps.incremental.ModuleBuildTarget;
import org.jetbrains.jps.model.java.JpsJavaClasspathKind;
import org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator;
@@ -27,8 +28,6 @@ import org.jetbrains.jps.model.library.JpsOrderRootType;
import org.jetbrains.jps.util.JpsPathUtil;
import org.jetbrains.kotlin.utils.LibraryUtils;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -36,8 +35,8 @@ import java.util.concurrent.ConcurrentHashMap;
class JpsUtils {
private JpsUtils() {}
private static final Map<ModuleBuildTarget, Boolean> IS_KOTLIN_JS_MODULE_CACHE = createMapForCaching();
private static final Map<String, Boolean> IS_KOTLIN_JS_STDLIB_JAR_CACHE = createMapForCaching();
private static final Map<ModuleBuildTarget, Boolean> IS_KOTLIN_JS_MODULE_CACHE = new ConcurrentHashMap<ModuleBuildTarget, Boolean>();
private static final Map<String, Boolean> IS_KOTLIN_JS_STDLIB_JAR_CACHE = new ConcurrentHashMap<String, Boolean>();
@NotNull
static JpsJavaDependenciesEnumerator getAllDependencies(@NotNull ModuleBuildTarget target) {
@@ -62,7 +61,10 @@ class JpsUtils {
String url = root.getUrl();
Boolean cachedValue = IS_KOTLIN_JS_STDLIB_JAR_CACHE.get(url);
if (cachedValue != null) return cachedValue;
if (cachedValue != null) {
if (cachedValue.booleanValue()) return true;
else continue;
}
boolean isKotlinJavascriptStdLibrary = LibraryUtils.isKotlinJavascriptStdLibrary(JpsPathUtil.urlToFile(url));
IS_KOTLIN_JS_STDLIB_JAR_CACHE.put(url, isKotlinJavascriptStdLibrary);
@@ -72,27 +74,9 @@ class JpsUtils {
return false;
}
private static <K, V> Map<K,V> createMapForCaching() {
if ("true".equalsIgnoreCase(System.getProperty("kotlin.jps.tests"))) {
return new AbstractMap<K, V>() {
@Override
public V put(K key, V value) {
return null;
}
@Override
public V get(Object key) {
return null;
}
@NotNull
@Override
public Set<Entry<K, V>> entrySet() {
return Collections.emptySet();
}
};
}
return new ConcurrentHashMap<K, V>();
@TestOnly
static void resetCaches() {
IS_KOTLIN_JS_MODULE_CACHE.clear();
IS_KOTLIN_JS_STDLIB_JAR_CACHE.clear();
}
}