diff --git a/idea/tests/org/jetbrains/kotlin/gradle/MultiplatformProjectImportingTest.kt b/idea/tests/org/jetbrains/kotlin/gradle/MultiplatformProjectImportingTest.kt new file mode 100644 index 00000000000..f2b2fda93a9 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/gradle/MultiplatformProjectImportingTest.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2016 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.kotlin.gradle + +import com.intellij.openapi.roots.DependencyScope +import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase +import org.junit.Test + +class MultiplatformProjectImportingTest : GradleImportingTestCase() { + @Test + fun testPlatformToCommonDependency() { + createProjectSubFile("settings.gradle", "include ':common', ':jvm', ':js'") + + val kotlinVersion = "1.1-M04" + val kotlinRepo = "maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' }" + + createProjectSubFile("build.gradle", """ + buildscript { + repositories { + $kotlinRepo + mavenCentral() + } + + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") + } + } + + project('common') { + apply plugin: 'kotlin-platform-common' + } + + project('jvm') { + apply plugin: 'kotlin-platform-jvm' + + dependencies { + implement project(':common') + } + } + + project('js') { + apply plugin: 'kotlin-platform-js' + + dependencies { + implement project(':common') + } + } + """) + + importProject() + assertModuleModuleDepScope("jvm_main", "common_main", DependencyScope.COMPILE) + assertModuleModuleDepScope("jvm_test", "common_test", DependencyScope.COMPILE) + assertModuleModuleDepScope("js_main", "common_main", DependencyScope.COMPILE) + assertModuleModuleDepScope("js_test", "common_test", DependencyScope.COMPILE) + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemImportingTestCase.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemImportingTestCase.java index cea72138f3f..08e1b430e0e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemImportingTestCase.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemImportingTestCase.java @@ -31,9 +31,14 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.externalSystem.util.ExternalSystemUtil; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.roots.DependencyScope; +import com.intellij.openapi.roots.ModuleOrderEntry; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtilRt; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -111,4 +116,49 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest protected abstract ExternalProjectSettings getCurrentExternalProjectSettings(); protected abstract ProjectSystemId getExternalSystemId(); + + protected void assertModuleModuleDepScope(String moduleName, String depName, DependencyScope... scopes) { + List deps = getModuleModuleDeps(moduleName, depName); + Set actualScopes = new HashSet(); + for (ModuleOrderEntry dep : deps) { + actualScopes.add(dep.getScope()); + } + HashSet expectedScopes = new HashSet(Arrays.asList(scopes)); + assertEquals("Dependency '" + depName + "' for module '" + moduleName + "' has unexpected scope", + expectedScopes, actualScopes); + } + + @NotNull + private List getModuleModuleDeps(@NotNull String moduleName, @NotNull String depName) { + return getModuleDep(moduleName, depName, ModuleOrderEntry.class); + } + + private ModuleRootManager getRootManager(String module) { + return ModuleRootManager.getInstance(getModule(module)); + } + + @NotNull + private List getModuleDep(@NotNull String moduleName, @NotNull String depName, @NotNull Class clazz) { + List deps = ContainerUtil.newArrayList(); + + for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) { + if (clazz.isInstance(e) && e.getPresentableName().equals(depName)) { + deps.add((T)e); + } + } + assertTrue("Dependency '" + depName + "' for module '" + moduleName + "' not found among: " + collectModuleDepsNames(moduleName, clazz), + !deps.isEmpty()); + return deps; + } + + private List collectModuleDepsNames(String moduleName, Class clazz) { + List actual = new ArrayList(); + + for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) { + if (clazz.isInstance(e)) { + actual.add(e.getPresentableName()); + } + } + return actual; + } }