Reformat: idea-gradle module

This commit is contained in:
Nikolay Krasko
2018-03-06 15:03:01 +03:00
parent cff88a3f8b
commit 9004cdfa45
32 changed files with 1708 additions and 1388 deletions
+18 -3
View File
@@ -1,4 +1,3 @@
apply { plugin("kotlin") } apply { plugin("kotlin") }
apply { plugin("jps-compatible") } apply { plugin("jps-compatible") }
@@ -16,14 +15,30 @@ dependencies {
compile(project(":js:js.frontend")) compile(project(":js:js.frontend"))
compileOnly(intellijDep()) { includeJars("openapi", "idea", "external-system-rt", "forms_rt", "extensions", "jdom", "util") } compileOnly(intellijDep()) { includeJars("openapi", "idea", "external-system-rt", "forms_rt", "extensions", "jdom", "util") }
compileOnly(intellijPluginDep("gradle")) { includeJars("gradle-tooling-api", "gradle", "gradle-base-services", rootProject = rootProject) } compileOnly(intellijPluginDep("gradle")) {
includeJars(
"gradle-tooling-api",
"gradle",
"gradle-base-services",
rootProject = rootProject
)
}
compileOnly(intellijPluginDep("Groovy")) { includeJars("Groovy") } compileOnly(intellijPluginDep("Groovy")) { includeJars("Groovy") }
compileOnly(intellijPluginDep("junit")) { includeJars("idea-junit") } compileOnly(intellijPluginDep("junit")) { includeJars("idea-junit") }
testCompile(projectTests(":idea")) testCompile(projectTests(":idea"))
testCompile(projectTests(":idea:idea-test-framework")) testCompile(projectTests(":idea:idea-test-framework"))
testCompile(intellijPluginDep("gradle")) { includeJars("gradle-wrapper", "gradle-base-services", "gradle-tooling-extension-impl", "gradle-tooling-api", "gradle", rootProject = rootProject) } testCompile(intellijPluginDep("gradle")) {
includeJars(
"gradle-wrapper",
"gradle-base-services",
"gradle-tooling-extension-impl",
"gradle-tooling-api",
"gradle",
rootProject = rootProject
)
}
testCompileOnly(intellijPluginDep("Groovy")) { includeJars("Groovy") } testCompileOnly(intellijPluginDep("Groovy")) { includeJars("Groovy") }
testCompileOnly(intellijDep()) { includeJars("groovy-all", "idea_rt", rootProject = rootProject) } testCompileOnly(intellijDep()) { includeJars("groovy-all", "idea_rt", rootProject = rootProject) }
@@ -23,10 +23,12 @@ import com.intellij.psi.PsiElement
interface GradleBuildScriptManipulator { interface GradleBuildScriptManipulator {
fun isConfigured(kotlinPluginName: String): Boolean fun isConfigured(kotlinPluginName: String): Boolean
fun configureModuleBuildScript(kotlinPluginName: String, fun configureModuleBuildScript(
kotlinPluginName: String,
stdlibArtifactName: String, stdlibArtifactName: String,
version: String, version: String,
jvmTarget: String?): Boolean jvmTarget: String?
): Boolean
fun configureProjectBuildScript(version: String): Boolean fun configureProjectBuildScript(version: String): Boolean
@@ -39,7 +41,8 @@ interface GradleBuildScriptManipulator {
fun addKotlinLibraryToModuleBuildScript( fun addKotlinLibraryToModuleBuildScript(
scope: DependencyScope, scope: DependencyScope,
libraryDescriptor: ExternalLibraryDescriptor, libraryDescriptor: ExternalLibraryDescriptor,
isAndroidModule: Boolean) isAndroidModule: Boolean
)
fun getKotlinStdlibVersion(): String? fun getKotlinStdlibVersion(): String?
} }
@@ -32,9 +32,11 @@ import javax.swing.Icon
import javax.swing.JComponent import javax.swing.JComponent
import javax.swing.JLabel import javax.swing.JLabel
abstract class GradleKotlinFrameworkSupportProvider(val frameworkTypeId: String, abstract class GradleKotlinFrameworkSupportProvider(
val frameworkTypeId: String,
val displayName: String, val displayName: String,
val frameworkIcon: Icon) : GradleFrameworkSupportProvider() { val frameworkIcon: Icon
) : GradleFrameworkSupportProvider() {
override fun getFrameworkType(): FrameworkTypeEx = object : FrameworkTypeEx(frameworkTypeId) { override fun getFrameworkType(): FrameworkTypeEx = object : FrameworkTypeEx(frameworkTypeId) {
override fun getIcon(): Icon = frameworkIcon override fun getIcon(): Icon = frameworkIcon
@@ -54,10 +56,12 @@ abstract class GradleKotlinFrameworkSupportProvider(val frameworkTypeId: String,
} }
} }
override fun addSupport(module: Module, override fun addSupport(
module: Module,
rootModel: ModifiableRootModel, rootModel: ModifiableRootModel,
modifiableModelsProvider: ModifiableModelsProvider, modifiableModelsProvider: ModifiableModelsProvider,
buildScriptData: BuildScriptDataBuilder) { buildScriptData: BuildScriptDataBuilder
) {
addSupport(buildScriptData, rootModel.sdk) addSupport(buildScriptData, rootModel.sdk)
} }
@@ -106,9 +110,10 @@ abstract class GradleKotlinFrameworkSupportProvider(val frameworkTypeId: String,
protected abstract fun getDescription(): String protected abstract fun getDescription(): String
} }
open class GradleKotlinJavaFrameworkSupportProvider(frameworkTypeId: String = "KOTLIN", open class GradleKotlinJavaFrameworkSupportProvider(
displayName: String = "Kotlin (Java)") frameworkTypeId: String = "KOTLIN",
: GradleKotlinFrameworkSupportProvider(frameworkTypeId, displayName, KotlinIcons.SMALL_LOGO) { displayName: String = "Kotlin (Java)"
) : GradleKotlinFrameworkSupportProvider(frameworkTypeId, displayName, KotlinIcons.SMALL_LOGO) {
override fun getPluginId() = KotlinGradleModuleConfigurator.KOTLIN override fun getPluginId() = KotlinGradleModuleConfigurator.KOTLIN
@@ -127,9 +132,10 @@ open class GradleKotlinJavaFrameworkSupportProvider(frameworkTypeId: String = "K
override fun getDescription() = "A Kotlin library or application targeting the JVM" override fun getDescription() = "A Kotlin library or application targeting the JVM"
} }
open class GradleKotlinJSFrameworkSupportProvider(frameworkTypeId: String = "KOTLIN_JS", open class GradleKotlinJSFrameworkSupportProvider(
displayName: String = "Kotlin (JavaScript)") frameworkTypeId: String = "KOTLIN_JS",
: GradleKotlinFrameworkSupportProvider(frameworkTypeId, displayName, KotlinIcons.JS) { displayName: String = "Kotlin (JavaScript)"
) : GradleKotlinFrameworkSupportProvider(frameworkTypeId, displayName, KotlinIcons.JS) {
override fun getPluginId() = KotlinJsGradleModuleConfigurator.KOTLIN_JS override fun getPluginId() = KotlinJsGradleModuleConfigurator.KOTLIN_JS
@@ -53,13 +53,11 @@ class GroovyBuildScriptManipulator(private val groovyScript: GroovyFile) : Gradl
val applyStatement = getApplyStatement(groovyScript) val applyStatement = getApplyStatement(groovyScript)
if (applyStatement != null) { if (applyStatement != null) {
groovyScript.addAfter(apply, applyStatement) groovyScript.addAfter(apply, applyStatement)
} } else {
else {
val buildScriptBlock = groovyScript.getBlockByName("buildscript") val buildScriptBlock = groovyScript.getBlockByName("buildscript")
if (buildScriptBlock != null) { if (buildScriptBlock != null) {
groovyScript.addAfter(apply, buildScriptBlock.parent) groovyScript.addAfter(apply, buildScriptBlock.parent)
} } else {
else {
groovyScript.addAfter(apply, groovyScript.statements.lastOrNull() ?: groovyScript.firstChild) groovyScript.addAfter(apply, groovyScript.statements.lastOrNull() ?: groovyScript.firstChild)
} }
} }
@@ -130,7 +128,8 @@ class GroovyBuildScriptManipulator(private val groovyScript: GroovyFile) : Gradl
scope.toGradleCompileScope(isAndroidModule), scope.toGradleCompileScope(isAndroidModule),
libraryDescriptor.libraryGroupId, libraryDescriptor.libraryGroupId,
libraryDescriptor.libraryArtifactId, libraryDescriptor.libraryArtifactId,
libraryDescriptor.maxVersion) libraryDescriptor.maxVersion
)
groovyScript.getDependenciesBlock().apply { groovyScript.getDependenciesBlock().apply {
addLastExpressionInBlockIfNeeded(dependencyString) addLastExpressionInBlockIfNeeded(dependencyString)
@@ -262,8 +261,7 @@ class GroovyBuildScriptManipulator(private val groovyScript: GroovyFile) : Gradl
if (lastStatement != null) { if (lastStatement != null) {
addAfter(newStatement, lastStatement) addAfter(newStatement, lastStatement)
} }
} } else {
else {
if (firstChild != null) { if (firstChild != null) {
addAfter(newStatement, firstChild) addAfter(newStatement, firstChild)
} }
@@ -96,7 +96,9 @@ class KotlinBuildScriptManipulator(private val kotlinScript: KtFile) : GradleBui
libraryDescriptor.libraryGroupId, libraryDescriptor.libraryGroupId,
libraryDescriptor.libraryArtifactId, libraryDescriptor.libraryArtifactId,
scope.toGradleCompileScope(isAndroidModule), scope.toGradleCompileScope(isAndroidModule),
kotlinLibraryVersion)) kotlinLibraryVersion
)
)
} }
} }
@@ -183,8 +185,7 @@ class KotlinBuildScriptManipulator(private val kotlinScript: KtFile) : GradleBui
val statement = kotlinBlock.statements.find { it.text.startsWith("experimental.coroutines") } val statement = kotlinBlock.statements.find { it.text.startsWith("experimental.coroutines") }
return if (statement != null) { return if (statement != null) {
statement.replace(psiFactory.createExpression(snippet)) statement.replace(psiFactory.createExpression(snippet))
} } else {
else {
kotlinBlock.add(psiFactory.createExpression(snippet)).apply { addNewLinesIfNeeded() } kotlinBlock.add(psiFactory.createExpression(snippet)).apply { addNewLinesIfNeeded() }
} }
} }
@@ -199,12 +200,10 @@ class KotlinBuildScriptManipulator(private val kotlinScript: KtFile) : GradleBui
} }
if (assignment != null) { if (assignment != null) {
assignment.replace(psiFactory.createExpression(snippet)) assignment.replace(psiFactory.createExpression(snippet))
} } else {
else {
optionsBlock.addExpressionIfMissing(snippet) optionsBlock.addExpressionIfMissing(snippet)
} }
} } else {
else {
addImportIfMissing("org.jetbrains.kotlin.gradle.tasks.KotlinCompile") addImportIfMissing("org.jetbrains.kotlin.gradle.tasks.KotlinCompile")
script?.blockExpression?.addDeclarationIfMissing("val $taskName: KotlinCompile by tasks") script?.blockExpression?.addDeclarationIfMissing("val $taskName: KotlinCompile by tasks")
addTopLevelBlock("$taskName.kotlinOptions")?.addExpressionIfMissing(snippet) addTopLevelBlock("$taskName.kotlinOptions")?.addExpressionIfMissing(snippet)
@@ -275,8 +274,13 @@ class KotlinBuildScriptManipulator(private val kotlinScript: KtFile) : GradleBui
if (first) script?.blockExpression?.addAfter(element, null) else script?.blockExpression?.add(element) if (first) script?.blockExpression?.addAfter(element, null) else script?.blockExpression?.add(element)
private fun KtFile.addImportIfMissing(path: String): KtImportDirective = private fun KtFile.addImportIfMissing(path: String): KtImportDirective =
importDirectives.find { it.importPath?.pathStr == path } ?: importDirectives.find { it.importPath?.pathStr == path } ?: importList?.add(
importList?.add(psiFactory.createImportDirective(ImportPath.fromString(path))) as KtImportDirective psiFactory.createImportDirective(
ImportPath.fromString(
path
)
)
) as KtImportDirective
private fun KtBlockExpression.addExpressionAfterIfMissing(text: String, after: PsiElement): KtExpression = addStatementIfMissing(text) { private fun KtBlockExpression.addExpressionAfterIfMissing(text: String, after: PsiElement): KtExpression = addStatementIfMissing(text) {
psiFactory.createExpression(it).let { created -> psiFactory.createExpression(it).let { created ->
@@ -286,19 +290,21 @@ class KotlinBuildScriptManipulator(private val kotlinScript: KtFile) : GradleBui
private fun KtBlockExpression.addExpressionIfMissing(text: String, first: Boolean = false): KtExpression = addStatementIfMissing(text) { private fun KtBlockExpression.addExpressionIfMissing(text: String, first: Boolean = false): KtExpression = addStatementIfMissing(text) {
psiFactory.createExpression(it).let { created -> psiFactory.createExpression(it).let { created ->
if(first) addAfter(created, null) else add(created) if (first) addAfter(created, null) else add(created)
} }
} }
private fun KtBlockExpression.addDeclarationIfMissing(text: String, first: Boolean = false): KtDeclaration = addStatementIfMissing(text) { private fun KtBlockExpression.addDeclarationIfMissing(text: String, first: Boolean = false): KtDeclaration =
addStatementIfMissing(text) {
psiFactory.createDeclaration<KtDeclaration>(it).let { created -> psiFactory.createDeclaration<KtDeclaration>(it).let { created ->
if(first) addAfter(created, null) else add(created) if (first) addAfter(created, null) else add(created)
} }
} }
private inline fun <reified T: PsiElement> KtBlockExpression.addStatementIfMissing( private inline fun <reified T : PsiElement> KtBlockExpression.addStatementIfMissing(
text: String, text: String,
crossinline factory: (String) -> PsiElement): T { crossinline factory: (String) -> PsiElement
): T {
statements.find { it.text == text }?.let { statements.find { it.text == text }?.let {
return it as T return it as T
} }
@@ -321,7 +327,12 @@ class KotlinBuildScriptManipulator(private val kotlinScript: KtFile) : GradleBui
fun getKotlinModuleDependencySnippet(artifactId: String, version: String? = null): String = fun getKotlinModuleDependencySnippet(artifactId: String, version: String? = null): String =
"kotlinModule(\"${artifactId.removePrefix("kotlin-")}\", ${version?.let { "\"$it\"" } ?: GSK_KOTLIN_VERSION_PROPERTY_NAME})" "kotlinModule(\"${artifactId.removePrefix("kotlin-")}\", ${version?.let { "\"$it\"" } ?: GSK_KOTLIN_VERSION_PROPERTY_NAME})"
fun getCompileDependencySnippet(groupId: String, artifactId: String, compileScope: String = "compile", version: String? = null): String = fun getCompileDependencySnippet(
groupId: String,
artifactId: String,
compileScope: String = "compile",
version: String? = null
): String =
if (groupId == KOTLIN_GROUP_ID) if (groupId == KOTLIN_GROUP_ID)
"$compileScope(${Companion.getKotlinModuleDependencySnippet(artifactId, version)})" "$compileScope(${Companion.getKotlinModuleDependencySnippet(artifactId, version)})"
else else
@@ -42,11 +42,13 @@ abstract class KotlinDslGradleKotlinFrameworkSupportProvider(
override fun createProvider(): FrameworkSupportInModuleProvider = this@KotlinDslGradleKotlinFrameworkSupportProvider override fun createProvider(): FrameworkSupportInModuleProvider = this@KotlinDslGradleKotlinFrameworkSupportProvider
} }
override fun addSupport(projectId: ProjectId, override fun addSupport(
projectId: ProjectId,
module: Module, module: Module,
rootModel: ModifiableRootModel, rootModel: ModifiableRootModel,
modifiableModelsProvider: ModifiableModelsProvider, modifiableModelsProvider: ModifiableModelsProvider,
buildScriptData: BuildScriptDataBuilder) { buildScriptData: BuildScriptDataBuilder
) {
var kotlinVersion = bundledRuntimeVersion() var kotlinVersion = bundledRuntimeVersion()
val additionalRepository = getRepositoryForVersion(kotlinVersion) val additionalRepository = getRepositoryForVersion(kotlinVersion)
if (isSnapshot(bundledRuntimeVersion())) { if (isSnapshot(bundledRuntimeVersion())) {
@@ -53,7 +53,9 @@ class KotlinGradleMultiplatformModuleBuilder : GradleModuleBuilder() {
super.createWizardSteps(wizardContext, modulesProvider) // initializes GradleModuleBuilder.myWizardContext super.createWizardSteps(wizardContext, modulesProvider) // initializes GradleModuleBuilder.myWizardContext
return arrayOf( return arrayOf(
KotlinGradleMultiplatformWizardStep(this, wizardContext), KotlinGradleMultiplatformWizardStep(this, wizardContext),
ExternalModuleSettingsStep(wizardContext, this, GradleProjectSettingsControl(externalProjectSettings)) ExternalModuleSettingsStep(
wizardContext, this, GradleProjectSettingsControl(externalProjectSettings)
)
) )
} }
@@ -96,6 +98,7 @@ class KotlinGradleMultiplatformModuleBuilder : GradleModuleBuilder() {
extendScript: (BuildScriptDataBuilder, Sdk?) -> Unit = { _, _ -> } extendScript: (BuildScriptDataBuilder, Sdk?) -> Unit = { _, _ -> }
) { ) {
if (childModuleName.isNullOrEmpty()) return if (childModuleName.isNullOrEmpty()) return
val moduleDir = contentRoot.createChildDirectory(this, childModuleName!!) val moduleDir = contentRoot.createChildDirectory(this, childModuleName!!)
val buildGradle = moduleDir.createChildData(null, "build.gradle") val buildGradle = moduleDir.createChildData(null, "build.gradle")
val buildScriptData = BuildScriptDataBuilder(buildGradle) val buildScriptData = BuildScriptDataBuilder(buildGradle)
@@ -71,9 +71,11 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
return resolverCtx.isResolveModulePerSourceSet return resolverCtx.isResolveModulePerSourceSet
} }
override fun populateModuleDependencies(gradleModule: IdeaModule, override fun populateModuleDependencies(
gradleModule: IdeaModule,
ideModule: DataNode<ModuleData>, ideModule: DataNode<ModuleData>,
ideProject: DataNode<ProjectData>) { ideProject: DataNode<ProjectData>
) {
val outputToSourceSet = ideProject.getUserData(GradleProjectResolver.MODULES_OUTPUTS) val outputToSourceSet = ideProject.getUserData(GradleProjectResolver.MODULES_OUTPUTS)
val sourceSetByName = ideProject.getUserData(GradleProjectResolver.RESOLVED_SOURCE_SETS) val sourceSetByName = ideProject.getUserData(GradleProjectResolver.RESOLVED_SOURCE_SETS)
@@ -92,7 +94,8 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
val targetModuleNode = ExternalSystemApiUtil.findFirstRecursively(ideProject) { val targetModuleNode = ExternalSystemApiUtil.findFirstRecursively(ideProject) {
(it.data as? ModuleData)?.id == dependency.projectPath (it.data as? ModuleData)?.id == dependency.projectPath
} as DataNode<ModuleData>? ?: return@mapNotNullTo null } as DataNode<ModuleData>? ?: return@mapNotNullTo null
ExternalSystemApiUtil.findAll(targetModuleNode, GradleSourceSetData.KEY).firstOrNull { it.sourceSetName == "main" } ExternalSystemApiUtil.findAll(targetModuleNode, GradleSourceSetData.KEY)
.firstOrNull { it.sourceSetName == "main" }
} }
is FileCollectionDependency -> { is FileCollectionDependency -> {
dependency.files dependency.files
@@ -114,8 +117,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
fun addTransitiveDependenciesOnImplementedModules() { fun addTransitiveDependenciesOnImplementedModules() {
val moduleNodesToProcess = if (useModulePerSourceSet()) { val moduleNodesToProcess = if (useModulePerSourceSet()) {
ExternalSystemApiUtil.findAll(ideModule, GradleSourceSetData.KEY) ExternalSystemApiUtil.findAll(ideModule, GradleSourceSetData.KEY)
} } else listOf(ideModule)
else listOf(ideModule)
for (currentModuleNode in moduleNodesToProcess) { for (currentModuleNode in moduleNodesToProcess) {
val toProcess = LinkedList<DataNode<out ModuleData>>() val toProcess = LinkedList<DataNode<out ModuleData>>()
@@ -128,18 +130,17 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
val moduleNodeForGradleModel = if (useModulePerSourceSet()) { val moduleNodeForGradleModel = if (useModulePerSourceSet()) {
ExternalSystemApiUtil.findParent(moduleNode, ProjectKeys.MODULE) ExternalSystemApiUtil.findParent(moduleNode, ProjectKeys.MODULE)
} } else moduleNode
else moduleNode
val ideaModule = if (moduleNodeForGradleModel != ideModule) { val ideaModule = if (moduleNodeForGradleModel != ideModule) {
gradleIdeaProject.modules.firstOrNull { it.gradleProject.path == moduleNodeForGradleModel?.data?.id } gradleIdeaProject.modules.firstOrNull { it.gradleProject.path == moduleNodeForGradleModel?.data?.id }
} } else gradleModule
else gradleModule
val implementsModuleIds = resolverCtx.getExtraProject(ideaModule, KotlinGradleModel::class.java)?.implements val implementsModuleIds = resolverCtx.getExtraProject(ideaModule, KotlinGradleModel::class.java)?.implements
?: emptyList() ?: emptyList()
for (implementsModuleId in implementsModuleIds) { for (implementsModuleId in implementsModuleIds) {
val compositePrefix = if (resolverCtx.models.ideaProject != gradleModule.project val compositePrefix = if (resolverCtx.models.ideaProject != gradleModule.project
&& implementsModuleId.startsWith(":")) { && implementsModuleId.startsWith(":")
) {
gradleModule.project.name gradleModule.project.name
} else { } else {
"" ""
@@ -159,8 +160,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
if (currentModuleNode.sourceSetName == "test" && targetMainSourceSet != targetSourceSet) { if (currentModuleNode.sourceSetName == "test" && targetMainSourceSet != targetSourceSet) {
addDependency(currentModuleNode, targetMainSourceSet) addDependency(currentModuleNode, targetMainSourceSet)
} }
} } else {
else {
addDependency(currentModuleNode, targetModule) addDependency(currentModuleNode, targetModule)
} }
} }
@@ -27,7 +27,6 @@ import com.intellij.psi.PsiManager
import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.CoroutineSupport import org.jetbrains.kotlin.config.CoroutineSupport
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.idea.KotlinPluginUtil
import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion
import org.jetbrains.kotlin.idea.quickfix.ChangeCoroutineSupportFix import org.jetbrains.kotlin.idea.quickfix.ChangeCoroutineSupportFix
@@ -103,10 +102,12 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
} }
} }
fun configureWithVersion(project: Project, fun configureWithVersion(
project: Project,
modulesToConfigure: List<Module>, modulesToConfigure: List<Module>,
kotlinVersion: String, kotlinVersion: String,
collector: NotificationMessageCollector): HashSet<PsiFile> { collector: NotificationMessageCollector
): HashSet<PsiFile> {
val filesToOpen = HashSet<PsiFile>() val filesToOpen = HashSet<PsiFile>()
val buildScript = project.getTopLevelBuildScriptPsiFile() val buildScript = project.getTopLevelBuildScriptPsiFile()
if (buildScript != null && canConfigureFile(buildScript)) { if (buildScript != null && canConfigureFile(buildScript)) {
@@ -120,8 +121,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
val file = module.getBuildScriptPsiFile() val file = module.getBuildScriptPsiFile()
if (file != null && canConfigureFile(file)) { if (file != null && canConfigureFile(file)) {
configureModule(module, file, false, kotlinVersion, collector, filesToOpen) configureModule(module, file, false, kotlinVersion, collector, filesToOpen)
} } else {
else {
showErrorMessage(project, "Cannot find build.gradle file for module " + module.name) showErrorMessage(project, "Cannot find build.gradle file for module " + module.name)
} }
} }
@@ -149,7 +149,8 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
kotlinPluginName, kotlinPluginName,
getStdlibArtifactName(sdk, version), getStdlibArtifactName(sdk, version),
version, version,
jvmTarget) jvmTarget
)
} }
protected open fun getStdlibArtifactName(sdk: Sdk?, version: String) = getStdlibArtifactId(sdk, version) protected open fun getStdlibArtifactName(sdk: Sdk?, version: String) = getStdlibArtifactId(sdk, version)
@@ -203,10 +204,12 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
} ?: false } ?: false
if (runtimeUpdateRequired) { if (runtimeUpdateRequired) {
Messages.showErrorDialog(module.project, Messages.showErrorDialog(
module.project,
"This language feature requires version $requiredStdlibVersion or later of the Kotlin runtime library. " + "This language feature requires version $requiredStdlibVersion or later of the Kotlin runtime library. " +
"Please update the version in your build script.", "Please update the version in your build script.",
"Update Language Version") "Update Language Version"
)
return return
} }
@@ -222,10 +225,12 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
(getRuntimeLibraryVersion(module)?.startsWith("1.0") ?: false) (getRuntimeLibraryVersion(module)?.startsWith("1.0") ?: false)
if (runtimeUpdateRequired) { if (runtimeUpdateRequired) {
Messages.showErrorDialog(module.project, Messages.showErrorDialog(
module.project,
"Coroutines support requires version 1.1 or later of the Kotlin runtime library. " + "Coroutines support requires version 1.1 or later of the Kotlin runtime library. " +
"Please update the version in your build script.", "Please update the version in your build script.",
ChangeCoroutineSupportFix.getFixText(state)) ChangeCoroutineSupportFix.getFixText(state)
)
return return
} }
@@ -235,7 +240,12 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
} }
} }
override fun addLibraryDependency(module: Module, element: PsiElement, library: ExternalLibraryDescriptor, libraryJarDescriptors: List<LibraryJarDescriptor>) { override fun addLibraryDependency(
module: Module,
element: PsiElement,
library: ExternalLibraryDescriptor,
libraryJarDescriptors: List<LibraryJarDescriptor>
) {
val scope = OrderEntryFix.suggestScopeByLocation(module, element) val scope = OrderEntryFix.suggestScopeByLocation(module, element)
KotlinWithGradleConfigurator.addKotlinLibraryToModule(module, scope, library) KotlinWithGradleConfigurator.addKotlinLibraryToModule(module, scope, library)
} }
@@ -340,19 +350,21 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
} }
private fun findBuildGradleFile(path: String): File? = private fun findBuildGradleFile(path: String): File? =
File(path + "/" + GradleConstants.DEFAULT_SCRIPT_NAME).takeIf { it.exists() } ?: File(path + "/" + GradleConstants.DEFAULT_SCRIPT_NAME).takeIf { it.exists() }
File(path + "/" + KOTLIN_BUILD_SCRIPT_NAME).takeIf { it.exists() } ?: File(path + "/" + KOTLIN_BUILD_SCRIPT_NAME).takeIf { it.exists() }
private fun File.getPsiFile(project: Project) = VfsUtil.findFileByIoFile(this, true)?.let { private fun File.getPsiFile(project: Project) = VfsUtil.findFileByIoFile(this, true)?.let {
PsiManager.getInstance(project).findFile(it) PsiManager.getInstance(project).findFile(it)
} }
private fun showErrorMessage(project: Project, message: String?) { private fun showErrorMessage(project: Project, message: String?) {
Messages.showErrorDialog(project, Messages.showErrorDialog(
project,
"<html>Couldn't configure kotlin-gradle plugin automatically.<br/>" + "<html>Couldn't configure kotlin-gradle plugin automatically.<br/>" +
(if (message != null) message + "<br/>" else "") + (if (message != null) message + "<br/>" else "") +
"<br/>See manual installation instructions <a href=\"https://kotlinlang.org/docs/reference/using-gradle.html\">here</a>.</html>", "<br/>See manual installation instructions <a href=\"https://kotlinlang.org/docs/reference/using-gradle.html\">here</a>.</html>",
"Configure Kotlin-Gradle Plugin") "Configure Kotlin-Gradle Plugin"
)
} }
} }
} }
@@ -43,7 +43,7 @@ import kotlin.script.dependencies.Environment
import kotlin.script.experimental.dependencies.ScriptDependencies import kotlin.script.experimental.dependencies.ScriptDependencies
class GradleScriptDefinitionsContributor(private val project: Project): ScriptDefinitionContributor { class GradleScriptDefinitionsContributor(private val project: Project) : ScriptDefinitionContributor {
override val id: String = "Gradle Kotlin DSL" override val id: String = "Gradle Kotlin DSL"
private val failedToLoad = AtomicBoolean(false) private val failedToLoad = AtomicBoolean(false)
@@ -134,8 +134,7 @@ class GradleScriptDefinitionsContributor(private val project: Project): ScriptDe
additionalResolverClasspath: (gradleLibDir: File) -> List<File> additionalResolverClasspath: (gradleLibDir: File) -> List<File>
): List<KotlinScriptDefinition> = try { ): List<KotlinScriptDefinition> = try {
doLoadGradleTemplates(templateClass, dependencySelector, additionalResolverClasspath) doLoadGradleTemplates(templateClass, dependencySelector, additionalResolverClasspath)
} } catch (t: Throwable) {
catch (t: Throwable) {
// TODO: review exception handling // TODO: review exception handling
failedToLoad.set(true) failedToLoad.set(true)
emptyList() emptyList()
@@ -171,12 +170,14 @@ class GradleScriptDefinitionsContributor(private val project: Project): ScriptDe
val gradleSettings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID) val gradleSettings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID)
if (gradleSettings.getLinkedProjectsSettings().isEmpty()) return emptyList() if (gradleSettings.getLinkedProjectsSettings().isEmpty()) return emptyList()
val projectSettings = gradleSettings.getLinkedProjectsSettings().filterIsInstance<GradleProjectSettings>().firstOrNull() ?: return emptyList() val projectSettings =
gradleSettings.getLinkedProjectsSettings().filterIsInstance<GradleProjectSettings>().firstOrNull() ?: return emptyList()
val gradleExeSettings = ExternalSystemApiUtil.getExecutionSettings<GradleExecutionSettings>( val gradleExeSettings = ExternalSystemApiUtil.getExecutionSettings<GradleExecutionSettings>(
project, project,
projectSettings.externalProjectPath, projectSettings.externalProjectPath,
GradleConstants.SYSTEM_ID) GradleConstants.SYSTEM_ID
)
val gradleHome = gradleExeSettings.gradleHome ?: error("Unable to get Gradle home directory") val gradleHome = gradleExeSettings.gradleHome ?: error("Unable to get Gradle home directory")
@@ -25,9 +25,9 @@ import com.intellij.util.text.VersionComparatorUtil
import org.jetbrains.kotlin.idea.configuration.allModules import org.jetbrains.kotlin.idea.configuration.allModules
import org.jetbrains.kotlin.idea.configuration.getWholeModuleGroup import org.jetbrains.kotlin.idea.configuration.getWholeModuleGroup
import org.jetbrains.kotlin.idea.inspections.ReplaceStringInDocumentFix import org.jetbrains.kotlin.idea.inspections.ReplaceStringInDocumentFix
import org.jetbrains.kotlin.idea.versions.LibInfo
import org.jetbrains.kotlin.idea.versions.DEPRECATED_LIBRARIES_INFORMATION import org.jetbrains.kotlin.idea.versions.DEPRECATED_LIBRARIES_INFORMATION
import org.jetbrains.kotlin.idea.versions.DeprecatedLibInfo import org.jetbrains.kotlin.idea.versions.DeprecatedLibInfo
import org.jetbrains.kotlin.idea.versions.LibInfo
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.plugins.gradle.codeInspection.GradleBaseInspection import org.jetbrains.plugins.gradle.codeInspection.GradleBaseInspection
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor
@@ -62,17 +62,22 @@ class DeprecatedGradleDependencyInspection : GradleBaseInspection() {
// Should be generified for any library, not exactly Kotlin stdlib // Should be generified for any library, not exactly Kotlin stdlib
val libVersion = val libVersion =
DifferentStdlibGradleVersionInspection.getResolvedKotlinStdlibVersion( DifferentStdlibGradleVersionInspection.getResolvedKotlinStdlibVersion(
dependencyStatement.containingFile, listOf(outdatedInfo.old.name)) ?: dependencyStatement.containingFile, listOf(outdatedInfo.old.name)
libraryVersionFromOrderEntry(dependencyStatement.containingFile, outdatedInfo.old.name) ) ?: libraryVersionFromOrderEntry(dependencyStatement.containingFile, outdatedInfo.old.name)
if (libVersion != null && VersionComparatorUtil.COMPARATOR.compare(libVersion, outdatedInfo.outdatedAfterVersion) >= 0) { if (libVersion != null && VersionComparatorUtil.COMPARATOR.compare(
libVersion,
outdatedInfo.outdatedAfterVersion
) >= 0
) {
val reportOnElement = reportOnElement(dependencyStatement, outdatedInfo) val reportOnElement = reportOnElement(dependencyStatement, outdatedInfo)
registerError( registerError(
reportOnElement, outdatedInfo.message, reportOnElement, outdatedInfo.message,
arrayOf(ReplaceStringInDocumentFix(reportOnElement, outdatedInfo.old.name, outdatedInfo.new.name)), arrayOf(ReplaceStringInDocumentFix(reportOnElement, outdatedInfo.old.name, outdatedInfo.new.name)),
ProblemHighlightType.LIKE_DEPRECATED) ProblemHighlightType.LIKE_DEPRECATED
)
break break
} }
@@ -29,7 +29,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlo
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression
class DifferentKotlinGradleVersionInspection : GradleBaseInspection(), PluginVersionDependentInspection{ class DifferentKotlinGradleVersionInspection : GradleBaseInspection(), PluginVersionDependentInspection {
override var testVersionMessage: String? = null override var testVersionMessage: String? = null
@TestOnly set @TestOnly set
@@ -58,15 +58,15 @@ class DifferentKotlinGradleVersionInspection : GradleBaseInspection(), PluginVer
} ?: return } ?: return
val kotlinPluginVersion = val kotlinPluginVersion =
GradleHeuristicHelper.getHeuristicVersionInBuildScriptDependency(kotlinPluginStatement) ?: GradleHeuristicHelper.getHeuristicVersionInBuildScriptDependency(kotlinPluginStatement) ?: getResolvedKotlinGradleVersion(
getResolvedKotlinGradleVersion(closure.containingFile) ?: closure.containingFile
return ) ?: return
onFound(kotlinPluginVersion, kotlinPluginStatement) onFound(kotlinPluginVersion, kotlinPluginStatement)
} }
} }
private inner class MyVisitor: VersionFinder() { private inner class MyVisitor : VersionFinder() {
private val idePluginVersion by lazy { bundledRuntimeVersion() } private val idePluginVersion by lazy { bundledRuntimeVersion() }
override fun onFound(kotlinPluginVersion: String, kotlinPluginStatement: GrCallExpression) { override fun onFound(kotlinPluginVersion: String, kotlinPluginStatement: GrCallExpression) {
@@ -35,7 +35,8 @@ import java.util.*
class DifferentStdlibGradleVersionInspection : GradleBaseInspection() { class DifferentStdlibGradleVersionInspection : GradleBaseInspection() {
override fun buildVisitor(): BaseInspectionVisitor = MyVisitor( override fun buildVisitor(): BaseInspectionVisitor = MyVisitor(
listOf(MAVEN_STDLIB_ID, MAVEN_STDLIB_ID_JRE7, MAVEN_STDLIB_ID_JDK7, MAVEN_STDLIB_ID_JRE8, MAVEN_STDLIB_ID_JDK8)) listOf(MAVEN_STDLIB_ID, MAVEN_STDLIB_ID_JRE7, MAVEN_STDLIB_ID_JDK7, MAVEN_STDLIB_ID_JRE8, MAVEN_STDLIB_ID_JDK8)
)
override fun buildErrorString(vararg args: Any) = override fun buildErrorString(vararg args: Any) =
"Plugin version (${args[0]}) is not the same as library version (${args[1]})" "Plugin version (${args[0]}) is not the same as library version (${args[1]})"
@@ -58,7 +59,7 @@ class DifferentStdlibGradleVersionInspection : GradleBaseInspection() {
} }
} }
private inner class MyVisitor(libraryIds: List<String>): VersionFinder(libraryIds) { private inner class MyVisitor(libraryIds: List<String>) : VersionFinder(libraryIds) {
override fun onFound(stdlibVersion: String, stdlibStatement: GrCallExpression) { override fun onFound(stdlibVersion: String, stdlibStatement: GrCallExpression) {
val gradlePluginVersion = getResolvedKotlinGradleVersion(stdlibStatement.containingFile) val gradlePluginVersion = getResolvedKotlinGradleVersion(stdlibStatement.containingFile)
@@ -78,7 +78,8 @@ internal fun findKotlinPluginVersion(classpathData: BuildScriptClasspathData): S
return versionSubstring return versionSubstring
} }
} else if (uniformedPath.contains(KOTLIN_PLUGIN_PATH_MARKER_FOR_MAVEN_LOCAL_REPO)) { } else if (uniformedPath.contains(KOTLIN_PLUGIN_PATH_MARKER_FOR_MAVEN_LOCAL_REPO)) {
val versionSubstring = uniformedPath.substringAfter(KOTLIN_PLUGIN_PATH_MARKER_FOR_MAVEN_LOCAL_REPO).substringBefore('/', "<error>") val versionSubstring =
uniformedPath.substringAfter(KOTLIN_PLUGIN_PATH_MARKER_FOR_MAVEN_LOCAL_REPO).substringBefore('/', "<error>")
if (versionSubstring != "<error>") { if (versionSubstring != "<error>") {
return versionSubstring return versionSubstring
} }
@@ -91,7 +92,7 @@ internal fun findKotlinPluginVersion(classpathData: BuildScriptClasspathData): S
class NodeWithData<T>(val node: DataNode<*>, val data: T) class NodeWithData<T>(val node: DataNode<*>, val data: T)
fun <T: Any> DataNode<*>.findAll(key: Key<T>): List<NodeWithData<T>> { fun <T : Any> DataNode<*>.findAll(key: Key<T>): List<NodeWithData<T>> {
val nodes = ExternalSystemApiUtil.findAll(this, key) val nodes = ExternalSystemApiUtil.findAll(this, key)
return nodes.mapNotNull { return nodes.mapNotNull {
val data = it.getData(key) ?: return@mapNotNull null val data = it.getData(key) ?: return@mapNotNull null
@@ -49,7 +49,8 @@ class DefaultGradleModelFacade : KotlinGradleModelFacade {
override fun getDependencyModules(ideModule: DataNode<ModuleData>, gradleIdeaProject: IdeaProject): Collection<DataNode<ModuleData>> { override fun getDependencyModules(ideModule: DataNode<ModuleData>, gradleIdeaProject: IdeaProject): Collection<DataNode<ModuleData>> {
val ideProject = ideModule.parent as DataNode<ProjectData> val ideProject = ideModule.parent as DataNode<ProjectData>
val dependencyModuleNames = ExternalSystemApiUtil.getChildren(ideModule, ProjectKeys.MODULE_DEPENDENCY).map { it.data.target.externalName }.toHashSet() val dependencyModuleNames =
ExternalSystemApiUtil.getChildren(ideModule, ProjectKeys.MODULE_DEPENDENCY).map { it.data.target.externalName }.toHashSet()
return findModulesByNames(dependencyModuleNames, gradleIdeaProject, ideProject) return findModulesByNames(dependencyModuleNames, gradleIdeaProject, ideProject)
} }
} }
@@ -64,7 +65,11 @@ fun getDependencyModules(moduleData: DataNode<ModuleData>, gradleIdeaProject: Id
return emptyList() return emptyList()
} }
fun findModulesByNames(dependencyModuleNames: Set<String>, gradleIdeaProject: IdeaProject, ideProject: DataNode<ProjectData>): LinkedHashSet<DataNode<ModuleData>> { fun findModulesByNames(
dependencyModuleNames: Set<String>,
gradleIdeaProject: IdeaProject,
ideProject: DataNode<ProjectData>
): LinkedHashSet<DataNode<ModuleData>> {
val modules = ExternalSystemApiUtil.getChildren(ideProject, ProjectKeys.MODULE) val modules = ExternalSystemApiUtil.getChildren(ideProject, ProjectKeys.MODULE)
return modules.filterTo(LinkedHashSet()) { it.data.externalName in dependencyModuleNames } return modules.filterTo(LinkedHashSet()) { it.data.externalName in dependencyModuleNames }
} }
@@ -31,9 +31,11 @@ import org.jetbrains.plugins.gradle.util.GradleConstants
class KotlinTestClassGradleConfigurationProducer : TestClassGradleConfigurationProducer() { class KotlinTestClassGradleConfigurationProducer : TestClassGradleConfigurationProducer() {
override fun doSetupConfigurationFromContext(configuration: ExternalSystemRunConfiguration, override fun doSetupConfigurationFromContext(
configuration: ExternalSystemRunConfiguration,
context: ConfigurationContext, context: ConfigurationContext,
sourceElement: Ref<PsiElement>): Boolean { sourceElement: Ref<PsiElement>
): Boolean {
val contextLocation = context.location ?: return false val contextLocation = context.location ?: return false
val module = context.module ?: return false val module = context.module ?: return false
@@ -93,9 +95,11 @@ class KotlinTestClassGradleConfigurationProducer : TestClassGradleConfigurationP
class KotlinTestMethodGradleConfigurationProducer class KotlinTestMethodGradleConfigurationProducer
: TestMethodGradleConfigurationProducer() { : TestMethodGradleConfigurationProducer() {
override fun doSetupConfigurationFromContext(configuration: ExternalSystemRunConfiguration, override fun doSetupConfigurationFromContext(
configuration: ExternalSystemRunConfiguration,
context: ConfigurationContext, context: ConfigurationContext,
sourceElement: Ref<PsiElement>): Boolean { sourceElement: Ref<PsiElement>
): Boolean {
val contextLocation = context.location ?: return false val contextLocation = context.location ?: return false
if (context.module == null) return false if (context.module == null) return false
@@ -142,10 +146,12 @@ class KotlinTestMethodGradleConfigurationProducer
return scriptParameters.contains(testFilter!!) return scriptParameters.contains(testFilter!!)
} }
private fun applyTestMethodConfiguration(configuration: ExternalSystemRunConfiguration, private fun applyTestMethodConfiguration(
configuration: ExternalSystemRunConfiguration,
context: ConfigurationContext, context: ConfigurationContext,
psiMethod: PsiMethod, psiMethod: PsiMethod,
vararg containingClasses: PsiClass): Boolean { vararg containingClasses: PsiClass
): Boolean {
val module = context.module ?: return false val module = context.module ?: return false
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) return false if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) return false
@@ -56,8 +56,7 @@ class MultiplatformGradleProjectTaskRunner : GradleProjectTaskRunner() {
val runProfile = projectTask.runProfile val runProfile = projectTask.runProfile
if (runProfile is ModuleBasedConfiguration<*>) { if (runProfile is ModuleBasedConfiguration<*>) {
runProfile.configurationModule.module?.isMultiplatformModule() == true runProfile.configurationModule.module?.isMultiplatformModule() == true
} } else {
else {
false false
} }
} }
@@ -74,7 +73,8 @@ class MultiplatformGradleProjectTaskRunner : GradleProjectTaskRunner() {
) { ) {
val configuration = context.runConfiguration val configuration = context.runConfiguration
if (configuration is ModuleBasedConfiguration<*> && if (configuration is ModuleBasedConfiguration<*> &&
(configuration.configurationModule is JavaRunConfigurationModule || configuration is KotlinRunConfiguration)) { (configuration.configurationModule is JavaRunConfigurationModule || configuration is KotlinRunConfiguration)
) {
val module = configuration.configurationModule.module val module = configuration.configurationModule.module
if (module?.targetPlatform == TargetPlatformKind.Common) { if (module?.targetPlatform == TargetPlatformKind.Common) {
@@ -104,8 +104,15 @@ class MultiplatformGradleProjectTaskRunner : GradleProjectTaskRunner() {
} }
} }
class MultiplatformGradleOrderEnumeratorHandler(val factory: MultiplatformGradleOrderEnumeratorHandler.FactoryImpl) : OrderEnumerationHandler() { class MultiplatformGradleOrderEnumeratorHandler(val factory: MultiplatformGradleOrderEnumeratorHandler.FactoryImpl) :
override fun addCustomModuleRoots(type: OrderRootType, rootModel: ModuleRootModel, result: MutableCollection<String>, includeProduction: Boolean, includeTests: Boolean): Boolean { OrderEnumerationHandler() {
override fun addCustomModuleRoots(
type: OrderRootType,
rootModel: ModuleRootModel,
result: MutableCollection<String>,
includeProduction: Boolean,
includeTests: Boolean
): Boolean {
if (factory.isEnumerating(rootModel.module)) return false if (factory.isEnumerating(rootModel.module)) return false
factory.startEnumerating(rootModel.module) factory.startEnumerating(rootModel.module)
try { try {
@@ -113,10 +120,13 @@ class MultiplatformGradleOrderEnumeratorHandler(val factory: MultiplatformGradle
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, rootModel.module)) return false if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, rootModel.module)) return false
if (!GradleSystemRunningSettings.getInstance().isUseGradleAwareMake) { if (!GradleSystemRunningSettings.getInstance().isUseGradleAwareMake) {
val gradleProjectPath = ExternalSystemModulePropertyManager.getInstance(rootModel.module).getRootProjectPath() ?: return false val gradleProjectPath =
ExternalSystemModulePropertyManager.getInstance(rootModel.module).getRootProjectPath() ?: return false
val externalProjectDataCache = ExternalProjectDataCache.getInstance(rootModel.module.project)!! val externalProjectDataCache = ExternalProjectDataCache.getInstance(rootModel.module.project)!!
val externalRootProject = externalProjectDataCache.getRootExternalProject(GradleConstants.SYSTEM_ID, val externalRootProject = externalProjectDataCache.getRootExternalProject(
File(gradleProjectPath)) ?: return false GradleConstants.SYSTEM_ID,
File(gradleProjectPath)
) ?: return false
val externalSourceSets = externalProjectDataCache.findExternalProject(externalRootProject, rootModel.module) val externalSourceSets = externalProjectDataCache.findExternalProject(externalRootProject, rootModel.module)
@@ -31,7 +31,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.1.0" val kotlinVersion = "1.1.0"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -61,7 +62,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
implement project(':common') implement project(':common')
} }
} }
""") """
)
importProject() importProject()
assertModuleModuleDepScope("jvm_main", "common_main", DependencyScope.COMPILE) assertModuleModuleDepScope("jvm_main", "common_main", DependencyScope.COMPILE)
@@ -76,7 +78,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.2.40-dev-610" val kotlinVersion = "1.2.40-dev-610"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -112,7 +115,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
expectedBy project(':common1') expectedBy project(':common1')
} }
} }
""") """
)
importProject() importProject()
assertModuleModuleDepScope("jvm_main", "common1_main", DependencyScope.COMPILE) assertModuleModuleDepScope("jvm_main", "common1_main", DependencyScope.COMPILE)
@@ -131,7 +135,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.2.0-beta-74" val kotlinVersion = "1.2.0-beta-74"
createProjectSubFile("toInclude/build.gradle", """ createProjectSubFile(
"toInclude/build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -162,10 +167,12 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
expectedBy project(':common') expectedBy project(':common')
} }
} }
""") """
)
createProjectSubFile("settings.gradle", "includeBuild('toInclude')") createProjectSubFile("settings.gradle", "includeBuild('toInclude')")
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -178,7 +185,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
} }
apply plugin: 'kotlin' apply plugin: 'kotlin'
""".trimIndent()) """.trimIndent()
)
importProject() importProject()
assertModuleModuleDepScope("jvm_main", "common_main", DependencyScope.COMPILE) assertModuleModuleDepScope("jvm_main", "common_main", DependencyScope.COMPILE)
@@ -193,7 +201,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.1.0" val kotlinVersion = "1.1.0"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -221,7 +230,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
implement project(':') implement project(':')
} }
} }
""") """
)
importProject() importProject()
assertModuleModuleDepScope("jvm_main", "foo_main", DependencyScope.COMPILE) assertModuleModuleDepScope("jvm_main", "foo_main", DependencyScope.COMPILE)
@@ -236,7 +246,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.1.0" val kotlinVersion = "1.1.0"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -292,7 +303,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
compile project(':js-lib') compile project(':js-lib')
} }
} }
""") """
)
importProject() importProject()
@@ -314,7 +326,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.1.0" val kotlinVersion = "1.1.0"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -357,7 +370,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
compile project(':jvm-lib2') compile project(':jvm-lib2')
} }
} }
""") """
)
importProject() importProject()
@@ -381,7 +395,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.1.51" val kotlinVersion = "1.1.51"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -434,7 +449,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
testCompile(project(':project2').sourceSets.test.output) testCompile(project(':project2').sourceSets.test.output)
} }
} }
""") """
)
val isResolveModulePerSourceSet = getCurrentExternalProjectSettings().isResolveModulePerSourceSet val isResolveModulePerSourceSet = getCurrentExternalProjectSettings().isResolveModulePerSourceSet
@@ -484,7 +500,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.1.51" val kotlinVersion = "1.1.51"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -552,10 +569,13 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
testCompile(project(':project2').sourceSets.test.output) testCompile(project(':project2').sourceSets.test.output)
} }
} }
""") """
createProjectSubFile("local.properties", """ )
createProjectSubFile(
"local.properties", """
sdk.dir=/${KotlinTestUtils.getAndroidSdkSystemIndependentPath()} sdk.dir=/${KotlinTestUtils.getAndroidSdkSystemIndependentPath()}
""") """
)
importProject() importProject()
@@ -574,7 +594,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.1.51" val kotlinVersion = "1.1.51"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -602,17 +623,18 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
implement project(':project1') implement project(':project1')
} }
} }
""") """
)
importProject() importProject()
TestCase.assertEquals( TestCase.assertEquals(
projectPath + "/project2/build/classes/test/project2_test.js", projectPath + "/project2/build/classes/test/project2_test.js",
PathUtil.toSystemIndependentName(KotlinFacet.get (getModule("project2_main"))!!.configuration.settings.testOutputPath) PathUtil.toSystemIndependentName(KotlinFacet.get(getModule("project2_main"))!!.configuration.settings.testOutputPath)
) )
TestCase.assertEquals( TestCase.assertEquals(
projectPath + "/project2/build/classes/test/project2_test.js", projectPath + "/project2/build/classes/test/project2_test.js",
PathUtil.toSystemIndependentName(KotlinFacet.get (getModule("project2_test"))!!.configuration.settings.testOutputPath) PathUtil.toSystemIndependentName(KotlinFacet.get(getModule("project2_test"))!!.configuration.settings.testOutputPath)
) )
} }
@@ -625,7 +647,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.1.51" val kotlinVersion = "1.1.51"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -653,17 +676,18 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
implement project(':project1') implement project(':project1')
} }
} }
""") """
)
importProject() importProject()
TestCase.assertEquals( TestCase.assertEquals(
projectPath + "/project2/build/classes/main/project2.js", projectPath + "/project2/build/classes/main/project2.js",
PathUtil.toSystemIndependentName(KotlinFacet.get (getModule("project2_main"))!!.configuration.settings.productionOutputPath) PathUtil.toSystemIndependentName(KotlinFacet.get(getModule("project2_main"))!!.configuration.settings.productionOutputPath)
) )
TestCase.assertEquals( TestCase.assertEquals(
projectPath + "/project2/build/classes/main/project2.js", projectPath + "/project2/build/classes/main/project2.js",
PathUtil.toSystemIndependentName(KotlinFacet.get (getModule("project2_test"))!!.configuration.settings.productionOutputPath) PathUtil.toSystemIndependentName(KotlinFacet.get(getModule("project2_test"))!!.configuration.settings.productionOutputPath)
) )
} }
@@ -676,7 +700,8 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
val kotlinVersion = "1.1.51" val kotlinVersion = "1.1.51"
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -730,16 +755,19 @@ class MultiplatformProjectImportingTest : GradleImportingTestCase() {
} }
} }
} }
""") """
createProjectSubFile("local.properties", """ )
createProjectSubFile(
"local.properties", """
sdk.dir=/${KotlinTestUtils.getAndroidSdkSystemIndependentPath()} sdk.dir=/${KotlinTestUtils.getAndroidSdkSystemIndependentPath()}
""") """
)
importProject() importProject()
TestCase.assertEquals( TestCase.assertEquals(
projectPath + "/project2/build/classes/test/project2_test.js", projectPath + "/project2/build/classes/test/project2_test.js",
PathUtil.toSystemIndependentName(KotlinFacet.get (getModule("project2"))!!.configuration.settings.testOutputPath) PathUtil.toSystemIndependentName(KotlinFacet.get(getModule("project2"))!!.configuration.settings.testOutputPath)
) )
} }
} }
@@ -60,7 +60,7 @@ import static org.junit.Assume.assumeThat;
@RunWith(value = Parameterized.class) @RunWith(value = Parameterized.class)
public abstract class AbstractModelBuilderTest { public abstract class AbstractModelBuilderTest {
public static final Object[][] SUPPORTED_GRADLE_VERSIONS = { {"3.5"} }; public static final Object[][] SUPPORTED_GRADLE_VERSIONS = {{"3.5"}};
private static final Pattern TEST_METHOD_NAME_PATTERN = Pattern.compile("(.*)\\[(\\d*: with Gradle-.*)\\]"); private static final Pattern TEST_METHOD_NAME_PATTERN = Pattern.compile("(.*)\\[(\\d*: with Gradle-.*)\\]");
@@ -112,13 +112,14 @@ public abstract class AbstractModelBuilderTest {
InputStream settingsStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME); InputStream settingsStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME);
try { try {
if(settingsStream != null) { if (settingsStream != null) {
FileUtil.writeToFile( FileUtil.writeToFile(
new File(testDir, GradleConstants.SETTINGS_FILE_NAME), new File(testDir, GradleConstants.SETTINGS_FILE_NAME),
FileUtil.loadTextAndClose(settingsStream) FileUtil.loadTextAndClose(settingsStream)
); );
} }
} finally { }
finally {
StreamUtil.closeStream(settingsStream); StreamUtil.closeStream(settingsStream);
} }
@@ -131,9 +132,10 @@ public abstract class AbstractModelBuilderTest {
try { try {
daemonMaxIdleTime = Integer.parseInt(System.getProperty("gradleDaemonMaxIdleTime", "10")); daemonMaxIdleTime = Integer.parseInt(System.getProperty("gradleDaemonMaxIdleTime", "10"));
} }
catch (NumberFormatException ignore) {} catch (NumberFormatException ignore) {
}
((DefaultGradleConnector)connector).daemonMaxIdleTime(daemonMaxIdleTime, TimeUnit.SECONDS); ((DefaultGradleConnector) connector).daemonMaxIdleTime(daemonMaxIdleTime, TimeUnit.SECONDS);
ProjectConnection connection = connector.connect(); ProjectConnection connection = connector.connect();
try { try {
@@ -145,10 +147,12 @@ public abstract class AbstractModelBuilderTest {
String jdkHome = IdeaTestUtil.requireRealJdkHome(); String jdkHome = IdeaTestUtil.requireRealJdkHome();
buildActionExecutor.setJavaHome(new File(jdkHome)); buildActionExecutor.setJavaHome(new File(jdkHome));
buildActionExecutor.setJvmArguments("-Xmx128m", "-XX:MaxPermSize=64m"); buildActionExecutor.setJvmArguments("-Xmx128m", "-XX:MaxPermSize=64m");
buildActionExecutor.withArguments("--info", "--recompile-scripts", GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath()); buildActionExecutor
.withArguments("--info", "--recompile-scripts", GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath());
allModels = buildActionExecutor.run(); allModels = buildActionExecutor.run();
assertNotNull(allModels); assertNotNull(allModels);
} finally { }
finally {
connection.close(); connection.close();
} }
} }
@@ -237,10 +241,12 @@ public abstract class AbstractModelBuilderTest {
return version.isSnapshot() ? mySnapshotRepoUrl : myReleaseRepoUrl; return version.isSnapshot() ? mySnapshotRepoUrl : myReleaseRepoUrl;
} }
private static URI getDistribution(@NotNull String repositoryUrl, private static URI getDistribution(
@NotNull String repositoryUrl,
@NotNull GradleVersion version, @NotNull GradleVersion version,
@NotNull String archiveName, @NotNull String archiveName,
@NotNull String archiveClassifier) throws URISyntaxException { @NotNull String archiveClassifier
) throws URISyntaxException {
return new URI(String.format("%s/%s-%s-%s.zip", repositoryUrl, archiveName, version.getVersion(), archiveClassifier)); return new URI(String.format("%s/%s-%s-%s.zip", repositoryUrl, archiveName, version.getVersion(), archiveClassifier));
} }
@@ -75,7 +75,8 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest
AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId()); AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId());
ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings(); ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
projectSettings.setExternalProjectPath(getProjectPath()); projectSettings.setExternalProjectPath(getProjectPath());
@SuppressWarnings("unchecked") Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings()); @SuppressWarnings("unchecked") Set<ExternalProjectSettings> projects =
ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
projects.remove(projectSettings); projects.remove(projectSettings);
projects.add(projectSettings); projects.add(projectSettings);
//noinspection unchecked //noinspection unchecked
@@ -144,7 +145,12 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest
@NotNull @NotNull
private <T> List<T> getModuleDep(@NotNull String moduleName, @NotNull String depName, @NotNull Class<T> clazz) { private <T> List<T> getModuleDep(@NotNull String moduleName, @NotNull String depName, @NotNull Class<T> clazz) {
List<T> deps = collectModuleDeps(moduleName, depName, clazz); List<T> deps = collectModuleDeps(moduleName, depName, clazz);
assertTrue("Dependency '" + depName + "' for module '" + moduleName + "' not found among: " + collectModuleDepsNames(moduleName, clazz), assertTrue("Dependency '" +
depName +
"' for module '" +
moduleName +
"' not found among: " +
collectModuleDepsNames(moduleName, clazz),
!deps.isEmpty()); !deps.isEmpty());
return deps; return deps;
} }
@@ -155,7 +161,7 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest
for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) { for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) {
if (clazz.isInstance(e) && e.getPresentableName().equals(depName)) { if (clazz.isInstance(e) && e.getPresentableName().equals(depName)) {
deps.add((T)e); deps.add((T) e);
} }
} }
@@ -266,7 +266,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase {
FileUtil.ensureExists(f.getParentFile()); FileUtil.ensureExists(f.getParentFile());
FileUtil.ensureCanCreateFile(f); FileUtil.ensureCanCreateFile(f);
boolean created = f.createNewFile(); boolean created = f.createNewFile();
if(!created) { if (!created) {
throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath()); throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath());
} }
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f); return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
@@ -23,7 +23,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
@Test @Test
fun testProjectWithModule() { fun testProjectWithModule() {
createProjectSubFile("settings.gradle", "include ':app'") createProjectSubFile("settings.gradle", "include ':app'")
createProjectSubFile("app/build.gradle", """ createProjectSubFile(
"app/build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -39,7 +40,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-0.0" // intentionally invalid version compile "org.jetbrains.kotlin:kotlin-stdlib-0.0" // intentionally invalid version
} }
""".trimIndent()) """.trimIndent()
)
importProject() importProject()
@@ -62,14 +64,16 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
@Test @Test
fun testConfigure10() { fun testConfigure10() {
createProjectSubFile("settings.gradle", "include ':app'") createProjectSubFile("settings.gradle", "include ':app'")
val file = createProjectSubFile("app/build.gradle", """ val file = createProjectSubFile(
"app/build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
mavenCentral() mavenCentral()
} }
} }
""".trimIndent()) """.trimIndent()
)
importProject() importProject()
@@ -82,7 +86,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
FileDocumentManager.getInstance().saveAllDocuments() FileDocumentManager.getInstance().saveAllDocuments()
val content = LoadTextUtil.loadText(file).toString() val content = LoadTextUtil.loadText(file).toString()
assertEquals(""" assertEquals(
"""
buildscript { buildscript {
ext.kotlin_version = '1.0.6' ext.kotlin_version = '1.0.6'
repositories { repositories {
@@ -100,28 +105,35 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:${"$"}kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib:${"$"}kotlin_version"
} }
""".trimIndent(), content) """.trimIndent(), content
)
} }
} }
} }
private fun findGradleModuleConfigurator() = Extensions.findExtension(KotlinProjectConfigurator.EP_NAME, private fun findGradleModuleConfigurator() = Extensions.findExtension(
KotlinGradleModuleConfigurator::class.java) KotlinProjectConfigurator.EP_NAME,
KotlinGradleModuleConfigurator::class.java
)
private fun findJsGradleModuleConfigurator() = Extensions.findExtension(KotlinProjectConfigurator.EP_NAME, private fun findJsGradleModuleConfigurator() = Extensions.findExtension(
KotlinJsGradleModuleConfigurator::class.java) KotlinProjectConfigurator.EP_NAME,
KotlinJsGradleModuleConfigurator::class.java
)
@Test @Test
fun testConfigureGSK() { fun testConfigureGSK() {
createProjectSubFile("settings.gradle", "include ':app'") createProjectSubFile("settings.gradle", "include ':app'")
val file = createProjectSubFile("app/build.gradle.kts", """ val file = createProjectSubFile(
"app/build.gradle.kts", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
mavenCentral() mavenCentral()
} }
} }
""".trimIndent()) """.trimIndent()
)
importProject() importProject()
@@ -134,7 +146,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
FileDocumentManager.getInstance().saveAllDocuments() FileDocumentManager.getInstance().saveAllDocuments()
val content = LoadTextUtil.loadText(file).toString() val content = LoadTextUtil.loadText(file).toString()
assertEquals(""" assertEquals(
"""
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val kotlin_version: String by extra val kotlin_version: String by extra
@@ -166,7 +179,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
compileTestKotlin.kotlinOptions { compileTestKotlin.kotlinOptions {
jvmTarget = "1.8" jvmTarget = "1.8"
} }
""".trimIndent(), content) """.trimIndent(), content
)
} }
} }
} }
@@ -174,7 +188,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
@Test @Test
fun testListNonConfiguredModules() { fun testListNonConfiguredModules() {
createProjectSubFile("settings.gradle", "include ':app'") createProjectSubFile("settings.gradle", "include ':app'")
createProjectSubFile("app/build.gradle", """ createProjectSubFile(
"app/build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -183,7 +198,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
} }
apply plugin: 'java' apply plugin: 'java'
""".trimIndent()) """.trimIndent()
)
createProjectSubFile("app/src/main/java/foo.kt", "") createProjectSubFile("app/src/main/java/foo.kt", "")
importProject() importProject()
@@ -208,7 +224,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
@Test @Test
fun testListNonConfiguredModules_Configured() { fun testListNonConfiguredModules_Configured() {
createProjectSubFile("settings.gradle", "include ':app'") createProjectSubFile("settings.gradle", "include ':app'")
createProjectSubFile("app/build.gradle", """ createProjectSubFile(
"app/build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -226,7 +243,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.3" compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.3"
} }
""".trimIndent()) """.trimIndent()
)
createProjectSubFile("app/src/main/java/foo.kt", "") createProjectSubFile("app/src/main/java/foo.kt", "")
importProject() importProject()
@@ -239,7 +257,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
@Test @Test
fun testListNonConfiguredModules_ConfiguredOnlyTest() { fun testListNonConfiguredModules_ConfiguredOnlyTest() {
createProjectSubFile("settings.gradle", "include ':app'") createProjectSubFile("settings.gradle", "include ':app'")
createProjectSubFile("app/build.gradle", """ createProjectSubFile(
"app/build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -257,7 +276,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
dependencies { dependencies {
testCompile "org.jetbrains.kotlin:kotlin-stdlib:1.1.3" testCompile "org.jetbrains.kotlin:kotlin-stdlib:1.1.3"
} }
""".trimIndent()) """.trimIndent()
)
createProjectSubFile("app/src/test/java/foo.kt", "") createProjectSubFile("app/src/test/java/foo.kt", "")
importProject() importProject()
@@ -269,13 +289,15 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
@Test @Test
fun testAddNonKotlinLibraryGSK() { fun testAddNonKotlinLibraryGSK() {
val buildScript = createProjectSubFile("build.gradle.kts", val buildScript = createProjectSubFile(
"build.gradle.kts",
""" """
|dependencies { |dependencies {
| testCompile("junit:junit:4.12") | testCompile("junit:junit:4.12")
| compile(kotlinModule("stdlib-jre8")) | compile(kotlinModule("stdlib-jre8"))
|} |}
|""".trimMargin("|")) |""".trimMargin("|")
)
importProject() importProject()
@@ -284,7 +306,7 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
KotlinWithGradleConfigurator.addKotlinLibraryToModule( KotlinWithGradleConfigurator.addKotlinLibraryToModule(
myTestFixture.module, myTestFixture.module,
DependencyScope.COMPILE, DependencyScope.COMPILE,
object: ExternalLibraryDescriptor("org.a.b", "lib", "1.0.0", "1.0.0") { object : ExternalLibraryDescriptor("org.a.b", "lib", "1.0.0", "1.0.0") {
override fun getLibraryClassesRoots() = emptyList<String>() override fun getLibraryClassesRoots() = emptyList<String>()
}) })
} }
@@ -300,19 +322,22 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
| compile("org.a.b:lib:1.0.0") | compile("org.a.b:lib:1.0.0")
|} |}
|""".trimMargin("|"), |""".trimMargin("|"),
LoadTextUtil.loadText(buildScript).toString()) LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testAddLibraryGSK_WithKotlinVersion() { fun testAddLibraryGSK_WithKotlinVersion() {
val buildScript = createProjectSubFile("build.gradle.kts", val buildScript = createProjectSubFile(
"build.gradle.kts",
""" """
|val kotlin_version: String by extra |val kotlin_version: String by extra
|dependencies { |dependencies {
| testCompile("junit:junit:4.12") | testCompile("junit:junit:4.12")
| compile(kotlinModule("stdlib-jre8", kotlin_version)) | compile(kotlinModule("stdlib-jre8", kotlin_version))
|} |}
|""".trimMargin("|")) |""".trimMargin("|")
)
importProject() importProject()
@@ -339,17 +364,20 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
| compile(kotlinModule("reflect", kotlin_version)) | compile(kotlinModule("reflect", kotlin_version))
|} |}
|""".trimMargin("|"), |""".trimMargin("|"),
LoadTextUtil.loadText(buildScript).toString()) LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testAddTestLibraryGSK() { fun testAddTestLibraryGSK() {
val buildScript = createProjectSubFile("build.gradle.kts", val buildScript = createProjectSubFile(
"build.gradle.kts",
""" """
|dependencies { |dependencies {
| compile(kotlinModule("stdlib-jre8")) | compile(kotlinModule("stdlib-jre8"))
|} |}
|""".trimMargin("|")) |""".trimMargin("|")
)
importProject() importProject()
@@ -381,18 +409,21 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
| testCompile(kotlinModule("test", "1.1.2")) | testCompile(kotlinModule("test", "1.1.2"))
|} |}
|""".trimMargin("|"), |""".trimMargin("|"),
LoadTextUtil.loadText(buildScript).toString()) LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testAddLibraryGSK() { fun testAddLibraryGSK() {
val buildScript = createProjectSubFile("build.gradle.kts", val buildScript = createProjectSubFile(
"build.gradle.kts",
""" """
|dependencies { |dependencies {
| testCompile("junit:junit:4.12") | testCompile("junit:junit:4.12")
| compile(kotlinModule("stdlib-jre8")) | compile(kotlinModule("stdlib-jre8"))
|} |}
|""".trimMargin("|")) |""".trimMargin("|")
)
importProject() importProject()
@@ -401,7 +432,7 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
KotlinWithGradleConfigurator.addKotlinLibraryToModule( KotlinWithGradleConfigurator.addKotlinLibraryToModule(
myTestFixture.module, myTestFixture.module,
DependencyScope.COMPILE, DependencyScope.COMPILE,
object: ExternalLibraryDescriptor("org.jetbrains.kotlin", "kotlin-reflect", "1.0.0", "1.0.0") { object : ExternalLibraryDescriptor("org.jetbrains.kotlin", "kotlin-reflect", "1.0.0", "1.0.0") {
override fun getLibraryClassesRoots() = emptyList<String>() override fun getLibraryClassesRoots() = emptyList<String>()
}) })
} }
@@ -417,12 +448,14 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
| compile(kotlinModule("reflect", "1.0.0")) | compile(kotlinModule("reflect", "1.0.0"))
|} |}
|""".trimMargin("|"), |""".trimMargin("|"),
LoadTextUtil.loadText(buildScript).toString()) LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testAddCoroutinesSupport() { fun testAddCoroutinesSupport() {
val buildScript = createProjectSubFile("build.gradle", """ val buildScript = createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -438,7 +471,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib-1.1.0"
} }
""".trimIndent()) """.trimIndent()
)
importProject() importProject()
@@ -450,7 +484,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
FileDocumentManager.getInstance().saveAllDocuments() FileDocumentManager.getInstance().saveAllDocuments()
} }
assertEquals(""" assertEquals(
"""
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -472,7 +507,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
} }
} }
""".trimIndent(), """.trimIndent(),
LoadTextUtil.loadText(buildScript).toString()) LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
@@ -495,12 +531,14 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
|kotlin { |kotlin {
| experimental.coroutines = Coroutines.ENABLE | experimental.coroutines = Coroutines.ENABLE
|}""".trimMargin("|"), |}""".trimMargin("|"),
LoadTextUtil.loadText(buildScript).toString()) LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testChangeCoroutinesSupport() { fun testChangeCoroutinesSupport() {
val buildScript = createProjectSubFile("build.gradle", """ val buildScript = createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -521,7 +559,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
coroutines "error" coroutines "error"
} }
} }
""".trimIndent()) """.trimIndent()
)
importProject() importProject()
@@ -533,7 +572,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
FileDocumentManager.getInstance().saveAllDocuments() FileDocumentManager.getInstance().saveAllDocuments()
} }
assertEquals(""" assertEquals(
"""
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -554,18 +594,21 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
coroutines "enable" coroutines "enable"
} }
} }
""".trimIndent(), LoadTextUtil.loadText(buildScript).toString()) """.trimIndent(), LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testChangeCoroutinesSupportGSK() { fun testChangeCoroutinesSupportGSK() {
val buildScript = createProjectSubFile("build.gradle.kts", val buildScript = createProjectSubFile(
"build.gradle.kts",
"""import org.jetbrains.kotlin.gradle.dsl.Coroutines """import org.jetbrains.kotlin.gradle.dsl.Coroutines
| |
|kotlin { |kotlin {
| experimental.coroutines = Coroutines.DISABLE | experimental.coroutines = Coroutines.DISABLE
|} |}
|""".trimMargin("|")) |""".trimMargin("|")
)
importProject() importProject()
@@ -584,12 +627,14 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
| experimental.coroutines = Coroutines.ENABLE | experimental.coroutines = Coroutines.ENABLE
|} |}
|""".trimMargin("|"), |""".trimMargin("|"),
LoadTextUtil.loadText(buildScript).toString()) LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testAddLanguageVersion() { fun testAddLanguageVersion() {
val buildScript = createProjectSubFile("build.gradle", """ val buildScript = createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -605,7 +650,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib-1.1.0"
} }
""".trimIndent()) """.trimIndent()
)
importProject() importProject()
@@ -617,7 +663,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
FileDocumentManager.getInstance().saveAllDocuments() FileDocumentManager.getInstance().saveAllDocuments()
} }
assertEquals(""" assertEquals(
"""
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -638,7 +685,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
languageVersion = "1.1" languageVersion = "1.1"
} }
} }
""".trimIndent(), LoadTextUtil.loadText(buildScript).toString()) """.trimIndent(), LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
@@ -662,12 +710,14 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
|compileKotlin.kotlinOptions { |compileKotlin.kotlinOptions {
| languageVersion = "1.1" | languageVersion = "1.1"
|}""".trimMargin("|"), |}""".trimMargin("|"),
LoadTextUtil.loadText(buildScript).toString()) LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testChangeLanguageVersion() { fun testChangeLanguageVersion() {
val buildScript = createProjectSubFile("build.gradle", """ val buildScript = createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -688,7 +738,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
languageVersion = "1.0" languageVersion = "1.0"
} }
} }
""".trimIndent()) """.trimIndent()
)
importProject() importProject()
@@ -700,7 +751,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
FileDocumentManager.getInstance().saveAllDocuments() FileDocumentManager.getInstance().saveAllDocuments()
} }
assertEquals(""" assertEquals(
"""
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -721,17 +773,20 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
languageVersion = "1.1" languageVersion = "1.1"
} }
} }
""".trimIndent(), LoadTextUtil.loadText(buildScript).toString()) """.trimIndent(), LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testChangeLanguageVersionGSK() { fun testChangeLanguageVersionGSK() {
val buildScript = createProjectSubFile("build.gradle.kts", val buildScript = createProjectSubFile(
"build.gradle.kts",
"""val compileKotlin: KotlinCompile by tasks """val compileKotlin: KotlinCompile by tasks
|compileKotlin.kotlinOptions { |compileKotlin.kotlinOptions {
| languageVersion = "1.0" | languageVersion = "1.0"
|} |}
|""".trimMargin("|")) |""".trimMargin("|")
)
importProject() importProject()
@@ -749,12 +804,14 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
| languageVersion = "1.1" | languageVersion = "1.1"
|} |}
|""".trimMargin("|"), |""".trimMargin("|"),
LoadTextUtil.loadText(buildScript).toString()) LoadTextUtil.loadText(buildScript).toString()
)
} }
@Test @Test
fun testAddLibrary() { fun testAddLibrary() {
val buildScript = createProjectSubFile("build.gradle", """ val buildScript = createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -770,7 +827,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib-1.1.0"
} }
""".trimIndent()) """.trimIndent()
)
importProject() importProject()
@@ -779,7 +837,7 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
KotlinWithGradleConfigurator.addKotlinLibraryToModule( KotlinWithGradleConfigurator.addKotlinLibraryToModule(
myTestFixture.module, myTestFixture.module,
DependencyScope.COMPILE, DependencyScope.COMPILE,
object: ExternalLibraryDescriptor("org.jetbrains.kotlin", "kotlin-reflect", "1.0.0", "1.0.0") { object : ExternalLibraryDescriptor("org.jetbrains.kotlin", "kotlin-reflect", "1.0.0", "1.0.0") {
override fun getLibraryClassesRoots() = emptyList<String>() override fun getLibraryClassesRoots() = emptyList<String>()
}) })
} }
@@ -787,7 +845,8 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
FileDocumentManager.getInstance().saveAllDocuments() FileDocumentManager.getInstance().saveAllDocuments()
} }
assertEquals(""" assertEquals(
"""
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
@@ -804,6 +863,7 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
compile "org.jetbrains.kotlin:kotlin-stdlib-1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib-1.1.0"
compile "org.jetbrains.kotlin:kotlin-reflect:1.0.0" compile "org.jetbrains.kotlin:kotlin-reflect:1.0.0"
} }
""".trimIndent(), LoadTextUtil.loadText(buildScript).toString()) """.trimIndent(), LoadTextUtil.loadText(buildScript).toString()
)
} }
} }
@@ -25,8 +25,6 @@ import com.intellij.openapi.roots.LibraryOrderEntry
import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.impl.libraries.LibraryEx import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.PathUtil
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
@@ -43,7 +41,6 @@ import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import java.io.File
internal fun GradleImportingTestCase.facetSettings(moduleName: String) = KotlinFacet.get(getModule(moduleName))!!.configuration.settings internal fun GradleImportingTestCase.facetSettings(moduleName: String) = KotlinFacet.get(getModule(moduleName))!!.configuration.settings
@@ -56,7 +53,8 @@ internal val GradleImportingTestCase.testFacetSettings: KotlinFacetSettings
class GradleFacetImportTest : GradleImportingTestCase() { class GradleFacetImportTest : GradleImportingTestCase() {
@Test @Test
fun testJvmImport() { fun testJvmImport() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -86,28 +84,33 @@ class GradleFacetImportTest : GradleImportingTestCase() {
kotlinOptions.apiVersion = "1.0" kotlinOptions.apiVersion = "1.0"
kotlinOptions.freeCompilerArgs = ["-Xdump-declarations-to", "tmpTest"] kotlinOptions.freeCompilerArgs = ["-Xdump-declarations-to", "tmpTest"]
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("-Xdump-declarations-to=tmp -Xsingle-module", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-Xdump-declarations-to=tmp -Xsingle-module",
compilerSettings!!.additionalArguments
)
} }
with (testFacetSettings) { with(testFacetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("-Xdump-declarations-to=tmpTest", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-Xdump-declarations-to=tmpTest",
compilerSettings!!.additionalArguments
)
} }
assertAllModulesConfigured() assertAllModulesConfigured()
@@ -115,7 +118,8 @@ class GradleFacetImportTest : GradleImportingTestCase() {
@Test @Test
fun testJvmImportWithPlugin() { fun testJvmImportWithPlugin() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -147,7 +151,8 @@ compileKotlin {
compileTestKotlin { compileTestKotlin {
kotlinOptions.jvmTarget = "1.8" kotlinOptions.jvmTarget = "1.8"
} }
""") """
)
importProject() importProject()
assertAllModulesConfigured() assertAllModulesConfigured()
@@ -155,7 +160,8 @@ compileTestKotlin {
@Test @Test
fun testJvmImport_1_1_2() { fun testJvmImport_1_1_2() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -193,30 +199,36 @@ compileTestKotlin {
kotlinOptions.apiVersion = "1.0" kotlinOptions.apiVersion = "1.0"
kotlinOptions.freeCompilerArgs = ["-Xdump-declarations-to", "tmpTest"] kotlinOptions.freeCompilerArgs = ["-Xdump-declarations-to", "tmpTest"]
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("-Xdump-declarations-to=tmp -Xsingle-module", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-Xdump-declarations-to=tmp -Xsingle-module",
compilerSettings!!.additionalArguments
)
} }
with (testFacetSettings) { with(testFacetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("-Xdump-declarations-to=tmpTest", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-Xdump-declarations-to=tmpTest",
compilerSettings!!.additionalArguments
)
} }
} }
@Test @Test
fun testJvmImportWithCustomSourceSets() { fun testJvmImportWithCustomSourceSets() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -262,24 +274,29 @@ compileTestKotlin {
kotlinOptions.apiVersion = "1.0" kotlinOptions.apiVersion = "1.0"
kotlinOptions.freeCompilerArgs = ["-Xdump-declarations-to", "tmpTest"] kotlinOptions.freeCompilerArgs = ["-Xdump-declarations-to", "tmpTest"]
} }
""") """
)
importProject() importProject()
with (facetSettings("project_myMain")) { with(facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("-Xdump-declarations-to=tmp -Xsingle-module", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-Xdump-declarations-to=tmp -Xsingle-module",
compilerSettings!!.additionalArguments
)
} }
with (facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("-Xdump-declarations-to=tmpTest", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-Xdump-declarations-to=tmpTest",
compilerSettings!!.additionalArguments
)
} }
assertAllModulesConfigured() assertAllModulesConfigured()
@@ -287,7 +304,8 @@ compileTestKotlin {
@Test @Test
fun testJvmImportWithCustomSourceSets_1_1_2() { fun testJvmImportWithCustomSourceSets_1_1_2() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -336,30 +354,36 @@ compileTestKotlin {
kotlinOptions.apiVersion = "1.0" kotlinOptions.apiVersion = "1.0"
kotlinOptions.freeCompilerArgs = ["-Xdump-declarations-to", "tmpTest"] kotlinOptions.freeCompilerArgs = ["-Xdump-declarations-to", "tmpTest"]
} }
""") """
)
importProject() importProject()
with (facetSettings("project_myMain")) { with(facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], targetPlatformKind)
Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.7", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("-Xdump-declarations-to=tmp -Xsingle-module", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-Xdump-declarations-to=tmp -Xsingle-module",
compilerSettings!!.additionalArguments
)
} }
with (facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind)
Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget) Assert.assertEquals("1.6", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("-Xdump-declarations-to=tmpTest", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-Xdump-declarations-to=tmpTest",
compilerSettings!!.additionalArguments
)
} }
} }
@Test @Test
fun testCoroutineImportByOptions() { fun testCoroutineImportByOptions() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -387,10 +411,11 @@ compileTestKotlin {
coroutines 'enable' coroutines 'enable'
} }
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
} }
} }
@@ -398,7 +423,8 @@ compileTestKotlin {
@Test @Test
fun testCoroutineImportByProperties() { fun testCoroutineImportByProperties() {
createProjectSubFile("gradle.properties", "kotlin.coroutines=enable") createProjectSubFile("gradle.properties", "kotlin.coroutines=enable")
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -420,17 +446,19 @@ compileTestKotlin {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
} }
} }
@Test @Test
fun testJsImport() { fun testJsImport() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -466,10 +494,11 @@ compileTestKotlin {
kotlinOptions.apiVersion = "1.0" kotlinOptions.apiVersion = "1.0"
kotlinOptions.freeCompilerArgs = ["-module-kind", "umd", "-main", "callTest"] kotlinOptions.freeCompilerArgs = ["-module-kind", "umd", "-main", "callTest"]
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
@@ -479,11 +508,13 @@ compileTestKotlin {
Assert.assertEquals(true, sourceMap) Assert.assertEquals(true, sourceMap)
Assert.assertEquals("plain", moduleKind) Assert.assertEquals("plain", moduleKind)
} }
Assert.assertEquals("-main callMain", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-main callMain",
compilerSettings!!.additionalArguments
)
} }
with (testFacetSettings) { with(testFacetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
@@ -493,8 +524,10 @@ compileTestKotlin {
Assert.assertEquals(false, sourceMap) Assert.assertEquals(false, sourceMap)
Assert.assertEquals("umd", moduleKind) Assert.assertEquals("umd", moduleKind)
} }
Assert.assertEquals("-main callTest", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-main callTest",
compilerSettings!!.additionalArguments
)
} }
val rootManager = ModuleRootManager.getInstance(getModule("project_main")) val rootManager = ModuleRootManager.getInstance(getModule("project_main"))
@@ -510,7 +543,8 @@ compileTestKotlin {
@Test @Test
fun testJsImportTransitive() { fun testJsImportTransitive() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -536,10 +570,11 @@ compileTestKotlin {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-test-js:1.1.0" compile "org.jetbrains.kotlin:kotlin-test-js:1.1.0"
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
@@ -557,7 +592,8 @@ compileTestKotlin {
@Test @Test
fun testJsImportWithCustomSourceSets() { fun testJsImportWithCustomSourceSets() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -602,10 +638,11 @@ compileTestKotlin {
kotlinOptions.apiVersion = "1.0" kotlinOptions.apiVersion = "1.0"
kotlinOptions.freeCompilerArgs = ["-module-kind", "umd", "-main", "callTest"] kotlinOptions.freeCompilerArgs = ["-module-kind", "umd", "-main", "callTest"]
} }
""") """
)
importProject() importProject()
with (facetSettings("project_myMain")) { with(facetSettings("project_myMain")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
@@ -613,11 +650,13 @@ compileTestKotlin {
Assert.assertEquals(true, sourceMap) Assert.assertEquals(true, sourceMap)
Assert.assertEquals("plain", moduleKind) Assert.assertEquals("plain", moduleKind)
} }
Assert.assertEquals("-main callMain", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-main callMain",
compilerSettings!!.additionalArguments
)
} }
with (facetSettings("project_myTest")) { with(facetSettings("project_myTest")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
@@ -625,8 +664,10 @@ compileTestKotlin {
Assert.assertEquals(false, sourceMap) Assert.assertEquals(false, sourceMap)
Assert.assertEquals("umd", moduleKind) Assert.assertEquals("umd", moduleKind)
} }
Assert.assertEquals("-main callTest", Assert.assertEquals(
compilerSettings!!.additionalArguments) "-main callTest",
compilerSettings!!.additionalArguments
)
} }
assertAllModulesConfigured() assertAllModulesConfigured()
@@ -634,7 +675,8 @@ compileTestKotlin {
@Test @Test
fun testDetectOldJsStdlib() { fun testDetectOldJsStdlib() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -656,17 +698,19 @@ compileTestKotlin {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-js-library:1.0.6" compile "org.jetbrains.kotlin:kotlin-js-library:1.0.6"
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
} }
} }
@Test @Test
fun testJvmImportByPlatformPlugin() { fun testJvmImportByPlatformPlugin() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -684,10 +728,11 @@ compileTestKotlin {
} }
apply plugin: 'kotlin-platform-jvm' apply plugin: 'kotlin-platform-jvm'
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind)
@@ -696,7 +741,8 @@ compileTestKotlin {
@Test @Test
fun testJsImportByPlatformPlugin() { fun testJsImportByPlatformPlugin() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -720,10 +766,11 @@ compileTestKotlin {
compile "org.jetbrains.kotlin:kotlin-stdlib-common:1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib-common:1.1.0"
compile "org.jetbrains.kotlin:kotlin-stdlib-js:1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib-js:1.1.0"
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
@@ -737,7 +784,8 @@ compileTestKotlin {
@Test @Test
fun testCommonImportByPlatformPlugin() { fun testCommonImportByPlatformPlugin() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -764,10 +812,11 @@ compileTestKotlin {
compile "org.jetbrains.kotlin:kotlin-stdlib-common:1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib-common:1.1.0"
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind)
@@ -780,7 +829,8 @@ compileTestKotlin {
@Test @Test
fun testCommonImportByPlatformPlugin_SingleModule() { fun testCommonImportByPlatformPlugin_SingleModule() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -806,10 +856,11 @@ compileTestKotlin {
compile "org.jetbrains.kotlin:kotlin-stdlib-common:1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib-common:1.1.0"
} }
""") """
)
importProjectUsingSingeModulePerGradleProject() importProjectUsingSingeModulePerGradleProject()
with (facetSettings("project")) { with(facetSettings("project")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind)
@@ -822,7 +873,8 @@ compileTestKotlin {
@Test @Test
fun testJvmImportByKotlinPlugin() { fun testJvmImportByKotlinPlugin() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -840,10 +892,11 @@ compileTestKotlin {
} }
apply plugin: 'kotlin' apply plugin: 'kotlin'
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind) Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind)
@@ -852,7 +905,8 @@ compileTestKotlin {
@Test @Test
fun testJsImportByKotlin2JsPlugin() { fun testJsImportByKotlin2JsPlugin() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -870,10 +924,11 @@ compileTestKotlin {
} }
apply plugin: 'kotlin2js' apply plugin: 'kotlin2js'
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
@@ -882,7 +937,8 @@ compileTestKotlin {
@Test @Test
fun testArgumentEscaping() { fun testArgumentEscaping() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -904,10 +960,11 @@ compileTestKotlin {
compileKotlin { compileKotlin {
kotlinOptions.freeCompilerArgs = ["-module", "module with spaces"] kotlinOptions.freeCompilerArgs = ["-module", "module with spaces"]
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals( Assert.assertEquals(
listOf("-Xbuild-file=module with spaces"), listOf("-Xbuild-file=module with spaces"),
compilerSettings!!.additionalArgumentsAsList compilerSettings!!.additionalArgumentsAsList
@@ -917,7 +974,8 @@ compileTestKotlin {
@Test @Test
fun testNoPluginsInAdditionalArgs() { fun testNoPluginsInAdditionalArgs() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -934,21 +992,24 @@ compileTestKotlin {
apply plugin: 'kotlin' apply plugin: 'kotlin'
apply plugin: "kotlin-spring" apply plugin: "kotlin-spring"
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals( Assert.assertEquals(
"-version", "-version",
compilerSettings!!.additionalArguments compilerSettings!!.additionalArguments
) )
Assert.assertEquals( Assert.assertEquals(
listOf("plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.stereotype.Component", listOf(
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.stereotype.Component",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.transaction.annotation.Transactional", "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.transaction.annotation.Transactional",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.scheduling.annotation.Async", "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.scheduling.annotation.Async",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.cache.annotation.Cacheable", "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.cache.annotation.Cacheable",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.boot.test.context.SpringBootTest", "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.boot.test.context.SpringBootTest",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.validation.annotation.Validated"), "plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.validation.annotation.Validated"
),
compilerArguments!!.pluginOptions!!.toList() compilerArguments!!.pluginOptions!!.toList()
) )
} }
@@ -956,7 +1017,8 @@ compileTestKotlin {
@Test @Test
fun testNoArgInvokeInitializers() { fun testNoArgInvokeInitializers() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -978,17 +1040,20 @@ compileTestKotlin {
invokeInitializers = true invokeInitializers = true
annotation("NoArg") annotation("NoArg")
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals( Assert.assertEquals(
"-version", "-version",
compilerSettings!!.additionalArguments compilerSettings!!.additionalArguments
) )
Assert.assertEquals( Assert.assertEquals(
listOf("plugin:org.jetbrains.kotlin.noarg:annotation=NoArg", listOf(
"plugin:org.jetbrains.kotlin.noarg:invokeInitializers=true"), "plugin:org.jetbrains.kotlin.noarg:annotation=NoArg",
"plugin:org.jetbrains.kotlin.noarg:invokeInitializers=true"
),
compilerArguments!!.pluginOptions!!.toList() compilerArguments!!.pluginOptions!!.toList()
) )
} }
@@ -996,7 +1061,8 @@ compileTestKotlin {
@Test @Test
fun testAndroidGradleJsDetection() { fun testAndroidGradleJsDetection() {
createProjectSubFile("android-module/build.gradle", """ createProjectSubFile(
"android-module/build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1042,14 +1108,18 @@ compileTestKotlin {
} }
} }
} }
""") """
createProjectSubFile("android-module/src/main/AndroidManifest.xml", """ )
createProjectSubFile(
"android-module/src/main/AndroidManifest.xml", """
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="my.test.project" > package="my.test.project" >
</manifest> </manifest>
""") """
createProjectSubFile("js-module/build.gradle", """ )
createProjectSubFile(
"js-module/build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1071,8 +1141,10 @@ compileTestKotlin {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib-js:1.1.0"
} }
""") """
createProjectSubFile("build.gradle", """ )
createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1103,18 +1175,23 @@ compileTestKotlin {
jcenter() jcenter()
} }
} }
""") """
createProjectSubFile("settings.gradle", """ )
createProjectSubFile(
"settings.gradle", """
rootProject.name = "android-js-test" rootProject.name = "android-js-test"
include ':android-module' include ':android-module'
include ':js-module' include ':js-module'
""") """
createProjectSubFile("local.properties", """ )
createProjectSubFile(
"local.properties", """
sdk.dir=/${KotlinTestUtils.getAndroidSdkSystemIndependentPath()} sdk.dir=/${KotlinTestUtils.getAndroidSdkSystemIndependentPath()}
""") """
)
importProject() importProject()
with (facetSettings("js-module")) { with(facetSettings("js-module")) {
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind) Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
} }
@@ -1126,7 +1203,8 @@ compileTestKotlin {
@Test @Test
fun testKotlinAndroidPluginDetection() { fun testKotlinAndroidPluginDetection() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1177,16 +1255,21 @@ compileTestKotlin {
} }
} }
} }
""") """
createProjectSubFile("local.properties", """ )
createProjectSubFile(
"local.properties", """
sdk.dir=/${KotlinTestUtils.getAndroidSdkSystemIndependentPath()} sdk.dir=/${KotlinTestUtils.getAndroidSdkSystemIndependentPath()}
""") """
createProjectSubFile("src/main/AndroidManifest.xml", """ )
createProjectSubFile(
"src/main/AndroidManifest.xml", """
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="my.test.project" > package="my.test.project" >
</manifest> </manifest>
""") """
)
importProject() importProject()
Assert.assertNotNull(KotlinFacet.get(getModule("project"))) Assert.assertNotNull(KotlinFacet.get(getModule("project")))
@@ -1194,7 +1277,8 @@ compileTestKotlin {
@Test @Test
fun testNoFacetInModuleWithoutKotlinPlugin() { fun testNoFacetInModuleWithoutKotlinPlugin() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'gr01' group 'gr01'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1218,12 +1302,16 @@ compileTestKotlin {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1" compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1"
} }
""") """
createProjectSubFile("settings.gradle", """ )
createProjectSubFile(
"settings.gradle", """
rootProject.name = 'gr01' rootProject.name = 'gr01'
include 'm1' include 'm1'
""") """
createProjectSubFile("m1/build.gradle", """ )
createProjectSubFile(
"m1/build.gradle", """
group 'gr01' group 'gr01'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1243,7 +1331,8 @@ compileTestKotlin {
dependencies { dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11' testCompile group: 'junit', name: 'junit', version: '4.11'
} }
""") """
)
importProject() importProject()
Assert.assertNotNull(KotlinFacet.get(getModule("gr01_main"))) Assert.assertNotNull(KotlinFacet.get(getModule("gr01_main")))
@@ -1254,7 +1343,8 @@ compileTestKotlin {
@Test @Test
fun testClasspathWithDependenciesImport() { fun testClasspathWithDependenciesImport() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1281,17 +1371,19 @@ compileTestKotlin {
compileKotlin { compileKotlin {
kotlinOptions.freeCompilerArgs += ["-cp", "tmp.jar"] kotlinOptions.freeCompilerArgs += ["-cp", "tmp.jar"]
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("tmp.jar", (compilerArguments as K2JVMCompilerArguments).classpath) Assert.assertEquals("tmp.jar", (compilerArguments as K2JVMCompilerArguments).classpath)
} }
} }
@Test @Test
fun testDependenciesClasspathImport() { fun testDependenciesClasspathImport() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1314,10 +1406,11 @@ compileTestKotlin {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
compile "org.apache.logging.log4j:log4j-core:2.7" compile "org.apache.logging.log4j:log4j-core:2.7"
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals(null, (compilerArguments as K2JVMCompilerArguments).classpath) Assert.assertEquals(null, (compilerArguments as K2JVMCompilerArguments).classpath)
} }
} }
@@ -1332,7 +1425,8 @@ compileTestKotlin {
}.execute() }.execute()
try { try {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1359,15 +1453,15 @@ compileTestKotlin {
compileKotlin { compileKotlin {
kotlinOptions.jdkHome = "my/path/to/jdk" kotlinOptions.jdkHome = "my/path/to/jdk"
} }
""") """
)
importProject() importProject()
val moduleSDK = ModuleRootManager.getInstance(getModule("project_main")).sdk!! val moduleSDK = ModuleRootManager.getInstance(getModule("project_main")).sdk!!
Assert.assertTrue(moduleSDK.sdkType is JavaSdk) Assert.assertTrue(moduleSDK.sdkType is JavaSdk)
Assert.assertEquals("myJDK", moduleSDK.name) Assert.assertEquals("myJDK", moduleSDK.name)
Assert.assertEquals("my/path/to/jdk", moduleSDK.homePath) Assert.assertEquals("my/path/to/jdk", moduleSDK.homePath)
} } finally {
finally {
object : WriteAction<Unit>() { object : WriteAction<Unit>() {
override fun run(result: Result<Unit>) { override fun run(result: Result<Unit>) {
val jdkTable = ProjectJdkTable.getInstance() val jdkTable = ProjectJdkTable.getInstance()
@@ -1638,7 +1732,8 @@ compileTestKotlin {
@Test @Test
fun testAPIVersionExceedingLanguageVersion() { fun testAPIVersionExceedingLanguageVersion() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -1662,10 +1757,11 @@ compileTestKotlin {
kotlinOptions.languageVersion = "1.1" kotlinOptions.languageVersion = "1.1"
kotlinOptions.apiVersion = "1.2" kotlinOptions.apiVersion = "1.2"
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
} }
@@ -1680,7 +1776,8 @@ compileTestKotlin {
apiVersion = "1.0" apiVersion = "1.0"
} }
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -1699,10 +1796,11 @@ compileTestKotlin {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0" compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString) Assert.assertEquals("1.1", apiLevel!!.versionString)
} }
@@ -1712,7 +1810,8 @@ compileTestKotlin {
@Test @Test
fun testCommonArgumentsImport() { fun testCommonArgumentsImport() {
createProjectSubFile("build.gradle", """ createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -1760,10 +1859,11 @@ compileTestKotlin {
} }
} }
""") """
)
importProject() importProject()
with (facetSettings) { with(facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
@@ -1773,7 +1873,7 @@ compileTestKotlin {
Assert.assertEquals("my/destination", (compilerArguments as K2MetadataCompilerArguments).destination) Assert.assertEquals("my/destination", (compilerArguments as K2MetadataCompilerArguments).destination)
} }
with (facetSettings("project_test")) { with(facetSettings("project_test")) {
Assert.assertEquals("1.1", languageLevel!!.versionString) Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.0", apiLevel!!.versionString) Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion) Assert.assertFalse(compilerArguments!!.autoAdvanceLanguageVersion)
@@ -166,7 +166,7 @@ public abstract class GradleImportingTestCase extends ExternalSystemImportingTes
public void onProjectsLinked(@NotNull Collection settings) { public void onProjectsLinked(@NotNull Collection settings) {
Object item = ContainerUtil.getFirstItem(settings); Object item = ContainerUtil.getFirstItem(settings);
if (item instanceof GradleProjectSettings) { if (item instanceof GradleProjectSettings) {
((GradleProjectSettings)item).setGradleJvm(GRADLE_JDK_NAME); ((GradleProjectSettings) item).setGradleJvm(GRADLE_JDK_NAME);
} }
} }
}); });
@@ -20,9 +20,9 @@ import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.ProblemDescriptorBase import com.intellij.codeInspection.ProblemDescriptorBase
import com.intellij.openapi.util.Ref import com.intellij.openapi.util.Ref
import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.idea.inspections.gradle.DeprecatedGradleDependencyInspection
import org.jetbrains.kotlin.idea.inspections.gradle.DifferentKotlinGradleVersionInspection import org.jetbrains.kotlin.idea.inspections.gradle.DifferentKotlinGradleVersionInspection
import org.jetbrains.kotlin.idea.inspections.gradle.DifferentStdlibGradleVersionInspection import org.jetbrains.kotlin.idea.inspections.gradle.DifferentStdlibGradleVersionInspection
import org.jetbrains.kotlin.idea.inspections.gradle.DeprecatedGradleDependencyInspection
import org.jetbrains.kotlin.idea.inspections.runInspection import org.jetbrains.kotlin.idea.inspections.runInspection
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
@@ -30,7 +30,8 @@ import org.junit.Test
class GradleInspectionTest : GradleImportingTestCase() { class GradleInspectionTest : GradleImportingTestCase() {
@Test @Test
fun testDifferentStdlibGradleVersion() { fun testDifferentStdlibGradleVersion() {
val localFile = createProjectSubFile("build.gradle", """ val localFile = createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -49,7 +50,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.0.3" compile "org.jetbrains.kotlin:kotlin-stdlib:1.0.3"
} }
""") """
)
importProject() importProject()
val tool = DifferentStdlibGradleVersionInspection() val tool = DifferentStdlibGradleVersionInspection()
@@ -61,7 +63,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
@Test @Test
fun testDifferentStdlibJre7GradleVersion() { fun testDifferentStdlibJre7GradleVersion() {
val localFile = createProjectSubFile("build.gradle", """ val localFile = createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -83,7 +86,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.0-beta-22" compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.0-beta-22"
} }
""") """
)
importProject() importProject()
val tool = DifferentStdlibGradleVersionInspection() val tool = DifferentStdlibGradleVersionInspection()
@@ -95,7 +99,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
@Test @Test
fun testDifferentStdlibJdk7GradleVersion() { fun testDifferentStdlibJdk7GradleVersion() {
val localFile = createProjectSubFile("build.gradle", """ val localFile = createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -117,7 +122,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.1.0-beta-22" compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.1.0-beta-22"
} }
""") """
)
importProject() importProject()
val tool = DifferentStdlibGradleVersionInspection() val tool = DifferentStdlibGradleVersionInspection()
@@ -130,10 +136,13 @@ class GradleInspectionTest : GradleImportingTestCase() {
@Test @Test
fun testDifferentStdlibGradleVersionWithVariables() { fun testDifferentStdlibGradleVersionWithVariables() {
createProjectSubFile("gradle.properties", """ createProjectSubFile(
"gradle.properties", """
|kotlin=1.0.1 |kotlin=1.0.1
|lib_version=1.0.3""".trimMargin()) |lib_version=1.0.3""".trimMargin()
val localFile = createProjectSubFile("build.gradle", """ )
val localFile = createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -152,7 +161,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
dependencies { dependencies {
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: lib_version compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: lib_version
} }
""") """
)
importProject() importProject()
val tool = DifferentStdlibGradleVersionInspection() val tool = DifferentStdlibGradleVersionInspection()
@@ -165,7 +175,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
@Test @Test
fun testDifferentKotlinGradleVersion() { fun testDifferentKotlinGradleVersion() {
createProjectSubFile("gradle.properties", """test=1.0.1""") createProjectSubFile("gradle.properties", """test=1.0.1""")
val localFile = createProjectSubFile("build.gradle", """ val localFile = createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -180,7 +191,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
} }
apply plugin: 'kotlin' apply plugin: 'kotlin'
""") """
)
importProject() importProject()
val tool = DifferentKotlinGradleVersionInspection() val tool = DifferentKotlinGradleVersionInspection()
@@ -188,12 +200,16 @@ class GradleInspectionTest : GradleImportingTestCase() {
val problems = getInspectionResult(tool, localFile) val problems = getInspectionResult(tool, localFile)
Assert.assertTrue(problems.size == 1) Assert.assertTrue(problems.size == 1)
Assert.assertEquals("Kotlin version that is used for building with Gradle (1.0.1) differs from the one bundled into the IDE plugin (\$PLUGIN_VERSION)", problems.single()) Assert.assertEquals(
"Kotlin version that is used for building with Gradle (1.0.1) differs from the one bundled into the IDE plugin (\$PLUGIN_VERSION)",
problems.single()
)
} }
@Test @Test
fun testJreInOldVersion() { fun testJreInOldVersion() {
val localFile = createProjectSubFile("build.gradle", """ val localFile = createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -212,7 +228,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.60" compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.60"
} }
""") """
)
importProject() importProject()
val tool = DeprecatedGradleDependencyInspection() val tool = DeprecatedGradleDependencyInspection()
@@ -223,7 +240,8 @@ class GradleInspectionTest : GradleImportingTestCase() {
@Test @Test
fun testJreIsDeprecated() { fun testJreIsDeprecated() {
val localFile = createProjectSubFile("build.gradle", """ val localFile = createProjectSubFile(
"build.gradle", """
group 'Again' group 'Again'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
@@ -242,14 +260,18 @@ class GradleInspectionTest : GradleImportingTestCase() {
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.0" compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.0"
} }
""") """
)
importProject() importProject()
val tool = DeprecatedGradleDependencyInspection() val tool = DeprecatedGradleDependencyInspection()
val problems = getInspectionResult(tool, localFile) val problems = getInspectionResult(tool, localFile)
Assert.assertTrue(problems.size == 1) Assert.assertTrue(problems.size == 1)
Assert.assertEquals("kotlin-stdlib-jre7 is deprecated since 1.2.0 and should be replaced with kotlin-stdlib-jdk7", problems.single()) Assert.assertEquals(
"kotlin-stdlib-jre7 is deprecated since 1.2.0 and should be replaced with kotlin-stdlib-jdk7",
problems.single()
)
} }
fun getInspectionResult(tool: LocalInspectionTool, file: VirtualFile): List<String> { fun getInspectionResult(tool: LocalInspectionTool, file: VirtualFile): List<String> {
@@ -140,16 +140,23 @@ class GradleMultiplatformRunTest : GradleImportingTestCase() {
val producer = RunConfigurationProducer.getInstance(KotlinRunConfigurationProducer::class.java) val producer = RunConfigurationProducer.getInstance(KotlinRunConfigurationProducer::class.java)
val configuration = producer.createConfigurationFromContext(configurationContext)!! val configuration = producer.createConfigurationFromContext(configurationContext)!!
val executionEnvironment = ExecutionEnvironmentBuilder.create(myProject, val executionEnvironment = ExecutionEnvironmentBuilder.create(
myProject,
DefaultRunExecutor.getRunExecutorInstance(), DefaultRunExecutor.getRunExecutorInstance(),
configuration.configuration) configuration.configuration
)
.build() .build()
val compileStepBeforeRun = CompileStepBeforeRun(myProject) val compileStepBeforeRun = CompileStepBeforeRun(myProject)
compileStepBeforeRun.executeTask(dataContext, configuration.configuration, executionEnvironment, compileStepBeforeRun.executeTask(
CompileStepBeforeRun.MakeBeforeRunTask()) dataContext, configuration.configuration, executionEnvironment,
CompileStepBeforeRun.MakeBeforeRunTask()
)
val state = configuration.configuration.getState(DefaultRunExecutor.getRunExecutorInstance(), executionEnvironment) as JavaCommandLineState val state = configuration.configuration.getState(
DefaultRunExecutor.getRunExecutorInstance(),
executionEnvironment
) as JavaCommandLineState
state.javaParameters state.javaParameters
} }
@@ -46,23 +46,28 @@ class GradleUpdateConfigurationQuickFixTest : GradleImportingTestCase() {
myTestFixture = null myTestFixture = null
} }
@Test fun testUpdateLanguageVersion() { @Test
fun testUpdateLanguageVersion() {
doTest("Set module language version to 1.1") doTest("Set module language version to 1.1")
} }
@Test fun testUpdateApiVersion() { @Test
fun testUpdateApiVersion() {
doTest("Set module API version to 1.1") doTest("Set module API version to 1.1")
} }
@Test fun testUpdateLanguageAndApiVersion() { @Test
fun testUpdateLanguageAndApiVersion() {
doTest("Set module language version to 1.1") doTest("Set module language version to 1.1")
} }
@Test fun testEnableCoroutines() { @Test
fun testEnableCoroutines() {
doTest("Enable coroutine support in the current module") doTest("Enable coroutine support in the current module")
} }
@Test fun testAddKotlinReflect() { @Test
fun testAddKotlinReflect() {
doTest("Add kotlin-reflect.jar to the classpath") doTest("Add kotlin-reflect.jar to the classpath")
} }
@@ -26,7 +26,8 @@ import org.jetbrains.kotlin.test.KotlinTestUtils.isAllFilesPresentTest
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
import java.io.File import java.io.File
abstract class AbstractGradleConfigureProjectByChangingFileTest : AbstractConfigureProjectByChangingFileTest<KotlinWithGradleConfigurator>() { abstract class AbstractGradleConfigureProjectByChangingFileTest :
AbstractConfigureProjectByChangingFileTest<KotlinWithGradleConfigurator>() {
fun doTestGradle(path: String) { fun doTestGradle(path: String) {
val (before, after) = beforeAfterFiles() val (before, after) = beforeAfterFiles()
doTest(before, after, if ("js" in path) KotlinJsGradleModuleConfigurator() else KotlinGradleModuleConfigurator()) doTest(before, after, if ("js" in path) KotlinJsGradleModuleConfigurator() else KotlinGradleModuleConfigurator())
@@ -53,7 +54,13 @@ abstract class AbstractGradleConfigureProjectByChangingFileTest : AbstractConfig
} }
} }
override fun runConfigurator(module: Module, file: PsiFile, configurator: KotlinWithGradleConfigurator, version: String, collector: NotificationMessageCollector) { override fun runConfigurator(
module: Module,
file: PsiFile,
configurator: KotlinWithGradleConfigurator,
version: String,
collector: NotificationMessageCollector
) {
if (file !is GroovyFile && file !is KtFile) { if (file !is GroovyFile && file !is KtFile) {
fail("file $file is not a GroovyFile or KtFile") fail("file $file is not a GroovyFile or KtFile")
return return