Don't show "Configure Kotlin" if module is configured, project is not

Report CAN_BE_CONFIGURED from Gradle configurator only if we didn't
find any file containing valid configuration (normally the top-level
project file in an Android project doesn't have any Kotlin
configuration, so we report CAN_BE_CONFIGURED even though the module
file contains valid configuration)
This commit is contained in:
Dmitry Jemerov
2017-03-10 16:38:14 +01:00
parent b48b3b3237
commit 0f21595e4b
2 changed files with 70 additions and 7 deletions
@@ -62,13 +62,10 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
return ConfigureKotlinStatus.CONFIGURED
}
val moduleGradleFile = getBuildGradleFile(module.project, getModuleFilePath(module))
if (moduleGradleFile != null && !isFileConfigured(moduleGradleFile)) {
return ConfigureKotlinStatus.CAN_BE_CONFIGURED
}
val projectGradleFile = getBuildGradleFile(module.project, getTopLevelProjectFilePath(module.project))
if (projectGradleFile != null && !isFileConfigured(projectGradleFile)) {
val buildFiles = listOf(getBuildGradleFile(module.project, getModuleFilePath(module)),
getBuildGradleFile(module.project, getTopLevelProjectFilePath(module.project)))
.filterNotNull()
if (buildFiles.none(this::isFileConfigured)) {
return ConfigureKotlinStatus.CAN_BE_CONFIGURED
}
@@ -0,0 +1,66 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.codeInsight.gradle
import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.module.ModuleManager
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinStatus
import org.jetbrains.kotlin.idea.configuration.KotlinGradleModuleConfigurator
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator
import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait
import org.jetbrains.kotlin.test.testFramework.runWriteAction
import org.junit.Test
class GradleConfiguratorTest : GradleImportingTestCase() {
@Test
fun testProjectWithModule() {
createProjectSubFile("settings.gradle", "include ':app'")
createProjectSubFile("app/build.gradle", """
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0"
}
}
apply plugin: 'kotlin'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-0.0" // intentionally invalid version
}
""".trimIndent())
importProject()
runInEdtAndWait {
runWriteAction {
// Create not configured build.gradle for project
myProject.baseDir.createChildData(null, "build.gradle")
val module = ModuleManager.getInstance(myProject).findModuleByName("app")!!
val configurator = Extensions.findExtension(KotlinProjectConfigurator.EP_NAME,
KotlinGradleModuleConfigurator::class.java)
// We have a Kotlin runtime in build.gradle but not in the classpath, so it doesn't make sense
// to suggest configuring it
assertEquals(ConfigureKotlinStatus.BROKEN, configurator.getStatus(module))
}
}
}
}