diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinPluginUtil.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinPluginUtil.java index ef46f20854f..1a4282052a0 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinPluginUtil.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinPluginUtil.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea; @@ -20,9 +9,7 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.openapi.extensions.PluginId; -import com.intellij.openapi.module.Module; import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.configuration.KotlinModuleTypeManager; import java.util.Arrays; @@ -40,18 +27,4 @@ public class KotlinPluginUtil { public static boolean isSnapshotVersion() { return "@snapshot@".equals(getPluginVersion()); } - - public static boolean isAndroidGradleModule(@NotNull Module module) { - return KotlinModuleTypeManager.getInstance().isAndroidGradleModule(module); - } - - public static boolean isGradleModule(@NotNull Module module) { - return KotlinModuleTypeManager.getInstance().isGradleModule(module); - } - - public static boolean isMavenModule(@NotNull Module module) { - // This constant could be acquired from MavenProjectsManager, but we don't want to depend on the Maven plugin... - // See MavenProjectsManager.isMavenizedModule() - return "true".equals(module.getOptionValue("org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule")); - } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfos.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfos.kt index 791dbf795a2..f8d908913fc 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfos.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IdeaModuleInfos.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the license/LICENSE.txt file. */ @@ -25,7 +25,8 @@ import org.jetbrains.kotlin.analyzer.ModuleInfo import org.jetbrains.kotlin.analyzer.TrackableModuleInfo import org.jetbrains.kotlin.caches.resolve.LibraryModuleInfo import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.idea.KotlinPluginUtil +import org.jetbrains.kotlin.idea.configuration.BuildSystemType +import org.jetbrains.kotlin.idea.configuration.getBuildSystemType import org.jetbrains.kotlin.idea.framework.getLibraryPlatform import org.jetbrains.kotlin.idea.project.KotlinModuleModificationTracker import org.jetbrains.kotlin.idea.project.TargetPlatformDetector @@ -97,7 +98,7 @@ private fun ideaModelDependencies(module: Module, forProduction: Boolean): List< //NOTE: lib dependencies can be processed several times during recursive traversal val result = LinkedHashSet() val dependencyEnumerator = ModuleRootManager.getInstance(module).orderEntries().compileOnly().recursively().exportedOnly() - if (forProduction && !(KotlinPluginUtil.isMavenModule(module) || KotlinPluginUtil.isGradleModule(module))) { + if (forProduction && module.getBuildSystemType() == BuildSystemType.JPS) { dependencyEnumerator.productionOnly() } dependencyEnumerator.forEach { orderEntry -> diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/BuildSystemType.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/BuildSystemType.kt new file mode 100644 index 00000000000..bcf4c068e0f --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/BuildSystemType.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.configuration + +import com.intellij.openapi.extensions.ExtensionPointName +import com.intellij.openapi.extensions.Extensions +import com.intellij.openapi.module.Module + +abstract class BuildSystemType { + object JPS : BuildSystemType() +} + +interface BuildSystemTypeDetector { + fun detectBuildSystemType(module: Module): BuildSystemType? + + companion object { + val EP_NAME = ExtensionPointName.create("org.jetbrains.kotlin.buildSystemTypeDetector") + } +} + +fun Module.getBuildSystemType(): BuildSystemType { + for (extension in Extensions.getExtensions(BuildSystemTypeDetector.EP_NAME)) { + val result = extension.detectBuildSystemType(this) + if (result != null) { + return result + } + } + return BuildSystemType.JPS +} diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/KotlinModuleTypeManager.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/KotlinModuleTypeManager.java deleted file mode 100644 index ed9b211a9e1..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/configuration/KotlinModuleTypeManager.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2010-2015 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.configuration; - -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.module.Module; -import org.jetbrains.annotations.NotNull; - -public abstract class KotlinModuleTypeManager { - public static KotlinModuleTypeManager getInstance() { - return ServiceManager.getService(KotlinModuleTypeManager.class); - } - - public abstract boolean isAndroidGradleModule(@NotNull Module module); - public abstract boolean isGradleModule(@NotNull Module module); -} diff --git a/idea/idea-android/src/org/jetbrains/kotlin/android/configure/KotlinAndroidGradleModuleConfigurator.kt b/idea/idea-android/src/org/jetbrains/kotlin/android/configure/KotlinAndroidGradleModuleConfigurator.kt index 493e7783a40..2019310b9aa 100644 --- a/idea/idea-android/src/org/jetbrains/kotlin/android/configure/KotlinAndroidGradleModuleConfigurator.kt +++ b/idea/idea-android/src/org/jetbrains/kotlin/android/configure/KotlinAndroidGradleModuleConfigurator.kt @@ -1,33 +1,21 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.android.configure import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleUtil -import com.intellij.openapi.projectRoots.JavaSdk import com.intellij.openapi.projectRoots.JavaSdkVersion import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.roots.ModuleRootManager import com.intellij.psi.PsiFile -import org.jetbrains.kotlin.idea.KotlinPluginUtil +import org.jetbrains.kotlin.idea.configuration.AndroidGradle import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator +import org.jetbrains.kotlin.idea.configuration.getBuildSystemType import org.jetbrains.kotlin.idea.util.projectStructure.version import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID_JDK7 -import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID_JRE7 import org.jetbrains.kotlin.idea.versions.hasJreSpecificRuntime import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform @@ -40,7 +28,7 @@ class KotlinAndroidGradleModuleConfigurator internal constructor() : KotlinWithG override val presentableText: String = "Android with Gradle" - public override fun isApplicable(module: Module): Boolean = KotlinPluginUtil.isAndroidGradleModule(module) + public override fun isApplicable(module: Module): Boolean = module.getBuildSystemType() == AndroidGradle override val kotlinPluginName: String = KOTLIN_ANDROID diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/GradleDetector.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/GradleDetector.kt new file mode 100644 index 00000000000..8de79f3a4af --- /dev/null +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/GradleDetector.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.configuration + +import com.intellij.facet.FacetManager +import com.intellij.openapi.module.Module +import org.jetbrains.kotlin.idea.framework.isGradleModule + +object Gradle : BuildSystemType() +object AndroidGradle : BuildSystemType() + +class GradleDetector : BuildSystemTypeDetector { + override fun detectBuildSystemType(module: Module): BuildSystemType? { + if (module.isGradleModule()) { + if (FacetManager.getInstance(module).allFacets.any { it.name == "Android" }) { + return AndroidGradle + } + return Gradle + } + return null + } +} diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.kt index ccf77965ecb..3f58cdc9863 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.kt @@ -1,17 +1,6 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.configuration @@ -90,7 +79,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator { } protected open fun isApplicable(module: Module): Boolean = - KotlinPluginUtil.isGradleModule(module) && !KotlinPluginUtil.isAndroidGradleModule(module) + module.getBuildSystemType() == Gradle protected open fun getMinimumSupportedVersion() = "1.0.0" @@ -277,7 +266,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator { } getManipulator(buildScript) - .addKotlinLibraryToModuleBuildScript(scope, libraryDescriptor, KotlinPluginUtil.isAndroidGradleModule(module)) + .addKotlinLibraryToModuleBuildScript(scope, libraryDescriptor, module.getBuildSystemType() == AndroidGradle) buildScript.virtualFile?.let { createConfigureKotlinNotificationCollector(buildScript.project) diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/KotlinGradleInspectionVisitor.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/KotlinGradleInspectionVisitor.kt index 6d8f490f9ec..76e258fa156 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/KotlinGradleInspectionVisitor.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/KotlinGradleInspectionVisitor.kt @@ -1,17 +1,6 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.inspections.gradle @@ -28,9 +17,9 @@ import com.intellij.openapi.module.ModuleUtilCore import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.util.io.FileUtilRt import com.intellij.psi.PsiFile -import org.jetbrains.kotlin.idea.KotlinPluginUtil import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator import org.jetbrains.kotlin.idea.framework.GRADLE_SYSTEM_ID +import org.jetbrains.kotlin.idea.framework.isGradleModule import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData import org.jetbrains.plugins.gradle.util.GradleConstants import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor @@ -46,7 +35,7 @@ abstract class KotlinGradleInspectionVisitor : BaseInspectionVisitor() { if (!ApplicationManager.getApplication().isUnitTestMode) { val module = fileIndex.getModuleForFile(file.virtualFile) ?: return - if (!KotlinPluginUtil.isGradleModule(module)) return + if (!module.isGradleModule()) return } if (fileIndex.isExcluded(file.virtualFile)) return diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/actions/ConfigureKotlinInProjectAction.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/actions/ConfigureKotlinInProjectAction.kt index 3678a205fdc..d7445aff4b5 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/actions/ConfigureKotlinInProjectAction.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/actions/ConfigureKotlinInProjectAction.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.actions @@ -21,7 +10,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.project.Project import com.intellij.openapi.ui.Messages import com.intellij.util.PlatformUtils -import org.jetbrains.kotlin.idea.KotlinPluginUtil import org.jetbrains.kotlin.idea.configuration.* import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.js.resolve.JsPlatform @@ -61,7 +49,7 @@ class ConfigureKotlinJsInProjectAction: ConfigureKotlinInProjectAction() { override fun update(e: AnActionEvent) { val project = e.project - if (!PlatformUtils.isIntelliJ() && (project == null || project.allModules().all(KotlinPluginUtil::isAndroidGradleModule))) { + if (!PlatformUtils.isIntelliJ() && (project == null || project.allModules().all { it.getBuildSystemType() != BuildSystemType.JPS })) { e.presentation.isEnabledAndVisible = false } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.kt index 8d3df980728..a4005570c91 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.configuration @@ -343,9 +332,7 @@ abstract class KotlinWithLibraryConfigurator internal constructor() : KotlinProj protected open fun findAndFixBrokenKotlinLibrary(module: Module, collector: NotificationMessageCollector): Library? = null protected open fun isApplicable(module: Module): Boolean { - return !KotlinPluginUtil.isAndroidGradleModule(module) && - !KotlinPluginUtil.isMavenModule(module) && - !KotlinPluginUtil.isGradleModule(module) + return module.getBuildSystemType() == BuildSystemType.JPS } override fun changeCoroutineConfiguration(module: Module, state: LanguageFeature.State) { diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/framework/JSFrameworkSupportProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/framework/JSFrameworkSupportProvider.kt index 50e1bb4ce6c..025da9bfa3c 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/framework/JSFrameworkSupportProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/framework/JSFrameworkSupportProvider.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.framework @@ -27,7 +16,8 @@ import com.intellij.openapi.roots.ModifiableModelsProvider import com.intellij.openapi.roots.ModifiableRootModel import com.intellij.openapi.roots.ui.configuration.FacetsProvider import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription -import org.jetbrains.kotlin.idea.KotlinPluginUtil +import org.jetbrains.kotlin.idea.configuration.BuildSystemType +import org.jetbrains.kotlin.idea.configuration.getBuildSystemType import javax.swing.JComponent class JSFrameworkSupportProvider : FrameworkSupportInModuleProvider() { @@ -72,8 +62,6 @@ class JSFrameworkSupportProvider : FrameworkSupportInModuleProvider() { override fun isEnabledForModuleType(moduleType: ModuleType<*>): Boolean = moduleType is JavaModuleType override fun canAddSupport(module: Module, facetsProvider: FacetsProvider): Boolean { - return super.canAddSupport(module, facetsProvider) && - !KotlinPluginUtil.isMavenModule(module) && - !KotlinPluginUtil.isGradleModule(module) + return super.canAddSupport(module, facetsProvider) && module.getBuildSystemType() == BuildSystemType.JPS } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/framework/JavaFrameworkSupportProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/framework/JavaFrameworkSupportProvider.kt index 0fbf3809a99..a7d370eb637 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/framework/JavaFrameworkSupportProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/framework/JavaFrameworkSupportProvider.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.framework @@ -27,7 +16,8 @@ import com.intellij.openapi.roots.ModifiableModelsProvider import com.intellij.openapi.roots.ModifiableRootModel import com.intellij.openapi.roots.ui.configuration.FacetsProvider import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription -import org.jetbrains.kotlin.idea.KotlinPluginUtil +import org.jetbrains.kotlin.idea.configuration.BuildSystemType +import org.jetbrains.kotlin.idea.configuration.getBuildSystemType import javax.swing.JComponent internal class JavaFrameworkSupportProvider : FrameworkSupportInModuleProvider() { @@ -72,8 +62,6 @@ internal class JavaFrameworkSupportProvider : FrameworkSupportInModuleProvider() override fun isEnabledForModuleType(moduleType: ModuleType<*>): Boolean = moduleType is JavaModuleType override fun canAddSupport(module: Module, facetsProvider: FacetsProvider): Boolean { - return super.canAddSupport(module, facetsProvider) && - !KotlinPluginUtil.isMavenModule(module) && - !KotlinPluginUtil.isGradleModule(module) + return super.canAddSupport(module, facetsProvider) && module.getBuildSystemType() == BuildSystemType.JPS } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/quickfix/ChangeCoroutineSupportFix.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/quickfix/ChangeCoroutineSupportFix.kt index a3a890ee5aa..df314b8a19a 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/quickfix/ChangeCoroutineSupportFix.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/quickfix/ChangeCoroutineSupportFix.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.quickfix @@ -26,9 +15,10 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Errors -import org.jetbrains.kotlin.idea.KotlinPluginUtil import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder +import org.jetbrains.kotlin.idea.configuration.BuildSystemType import org.jetbrains.kotlin.idea.configuration.findApplicableConfigurator +import org.jetbrains.kotlin.idea.configuration.getBuildSystemType import org.jetbrains.kotlin.idea.facet.KotlinFacet import org.jetbrains.kotlin.psi.KtFile @@ -100,7 +90,7 @@ sealed class ChangeCoroutineSupportFix( val facetSettings = KotlinFacet.get(module)?.configuration?.settings val configureInProject = (facetSettings == null || facetSettings.useProjectSettings) && - !KotlinPluginUtil.isGradleModule(module) && !KotlinPluginUtil.isMavenModule(module) + module.getBuildSystemType() == BuildSystemType.JPS val quickFixConstructor: (PsiElement, LanguageFeature.State) -> ChangeCoroutineSupportFix = if (configureInProject) ::InProject else ::InModule return newCoroutineSupports.map { quickFixConstructor(diagnostic.psiElement, it) } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/quickfix/EnableUnsupportedFeatureFix.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/quickfix/EnableUnsupportedFeatureFix.kt index 5dc5ac3c495..045f4fc67bc 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/quickfix/EnableUnsupportedFeatureFix.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/quickfix/EnableUnsupportedFeatureFix.kt @@ -1,17 +1,6 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.quickfix @@ -31,10 +20,11 @@ import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Errors -import org.jetbrains.kotlin.idea.KotlinPluginUtil import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder +import org.jetbrains.kotlin.idea.configuration.BuildSystemType import org.jetbrains.kotlin.idea.configuration.findApplicableConfigurator +import org.jetbrains.kotlin.idea.configuration.getBuildSystemType import org.jetbrains.kotlin.idea.facet.KotlinFacet import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion import org.jetbrains.kotlin.idea.util.projectStructure.allModules @@ -118,7 +108,7 @@ sealed class EnableUnsupportedFeatureFix( } val module = ModuleUtilCore.findModuleForPsiElement(diagnostic.psiElement) ?: return null - if (!KotlinPluginUtil.isGradleModule(module) && !KotlinPluginUtil.isMavenModule(module)) { + if (module.getBuildSystemType() == BuildSystemType.JPS) { val facetSettings = KotlinFacet.get(module)?.configuration?.settings if (facetSettings == null || facetSettings.useProjectSettings) return InProject(diagnostic.psiElement, feature, apiVersionOnly) } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/KotlinJVMRuntimeLibraryUtil.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/KotlinJVMRuntimeLibraryUtil.kt index 19417e30de8..02d295780b4 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/KotlinJVMRuntimeLibraryUtil.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/KotlinJVMRuntimeLibraryUtil.kt @@ -1,17 +1,6 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.versions @@ -24,11 +13,7 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vfs.JarFileSystem import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile -import org.jetbrains.kotlin.idea.KotlinPluginUtil -import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator -import org.jetbrains.kotlin.idea.configuration.KotlinJsModuleConfigurator -import org.jetbrains.kotlin.idea.configuration.createConfigureKotlinNotificationCollector -import org.jetbrains.kotlin.idea.configuration.getConfiguratorByName +import org.jetbrains.kotlin.idea.configuration.* import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.idea.util.projectStructure.allModules @@ -36,17 +21,13 @@ import java.io.File import java.io.IOException fun updateLibraries(project: Project, libraries: Collection) { - if (project.allModules().any { module -> KotlinPluginUtil.isMavenModule(module) }) { - Messages.showMessageDialog(project, "Automatic library version update for Maven projects is currently unsupported. Please update your pom.xml manually.", - "Update Kotlin Runtime Library", - Messages.getErrorIcon()) - return - } - - if (project.allModules().any { module -> KotlinPluginUtil.isGradleModule(module) }) { - Messages.showMessageDialog(project, "Automatic library version update for Gradle projects is currently unsupported. Please update your build.gradle manually.", - "Update Kotlin Runtime Library", - Messages.getErrorIcon()) + if (project.allModules().any { module -> module.getBuildSystemType() != BuildSystemType.JPS }) { + Messages.showMessageDialog( + project, + "Automatic library version update for Maven and Gradle projects is currently unsupported. " + + "Please update your build scripts manually.", + "Update Kotlin Runtime Library", + Messages.getErrorIcon()) return } diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/MavenDetector.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/MavenDetector.kt new file mode 100644 index 00000000000..1ef429edf4b --- /dev/null +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/MavenDetector.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.maven + +import com.intellij.openapi.module.Module +import org.jetbrains.idea.maven.project.MavenProjectsManager +import org.jetbrains.kotlin.idea.configuration.BuildSystemType +import org.jetbrains.kotlin.idea.configuration.BuildSystemTypeDetector + +object Maven : BuildSystemType() + +class MavenDetector : BuildSystemTypeDetector { + override fun detectBuildSystemType(module: Module): BuildSystemType? { + return if (MavenProjectsManager.getInstance(module.project).isMavenizedModule(module)) + Maven + else + null + } +} diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinMavenConfigurator.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinMavenConfigurator.kt index 03171f1a75a..133b84cb9cc 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinMavenConfigurator.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/configuration/KotlinMavenConfigurator.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.maven.configuration @@ -43,7 +32,6 @@ import org.jetbrains.idea.maven.utils.MavenArtifactScope import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.CoroutineSupport import org.jetbrains.kotlin.config.LanguageFeature -import org.jetbrains.kotlin.idea.KotlinPluginUtil import org.jetbrains.kotlin.idea.configuration.* import org.jetbrains.kotlin.idea.facet.getRuntimeLibraryVersion import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion @@ -60,7 +48,7 @@ abstract class KotlinMavenConfigurator override fun getStatus(moduleSourceRootGroup: ModuleSourceRootGroup): ConfigureKotlinStatus { val module = moduleSourceRootGroup.baseModule - if (!KotlinPluginUtil.isMavenModule(module)) + if (module.getBuildSystemType() != Maven) return ConfigureKotlinStatus.NON_APPLICABLE val psi = runReadAction { findModulePomFile(module) } diff --git a/idea/src/META-INF/extensions/ide.xml b/idea/src/META-INF/extensions/ide.xml index 2356a301693..115be5ad864 100644 --- a/idea/src/META-INF/extensions/ide.xml +++ b/idea/src/META-INF/extensions/ide.xml @@ -26,6 +26,8 @@ interface="org.jetbrains.kotlin.idea.actions.NewKotlinFileHook"/> + diff --git a/idea/src/META-INF/gradle.xml b/idea/src/META-INF/gradle.xml index 32788553813..d130dd02dec 100644 --- a/idea/src/META-INF/gradle.xml +++ b/idea/src/META-INF/gradle.xml @@ -78,5 +78,6 @@ + diff --git a/idea/src/META-INF/maven.xml b/idea/src/META-INF/maven.xml index 06d0408aff5..c691675b64b 100644 --- a/idea/src/META-INF/maven.xml +++ b/idea/src/META-INF/maven.xml @@ -5,6 +5,7 @@ + diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index ba2cba2422b..95944843f96 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -211,9 +211,6 @@ - - diff --git a/idea/src/org/jetbrains/kotlin/idea/KotlinModuleTypeManagerImpl.java b/idea/src/org/jetbrains/kotlin/idea/KotlinModuleTypeManagerImpl.java deleted file mode 100644 index 8462b3f0a32..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/KotlinModuleTypeManagerImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2010-2015 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; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetManager; -import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; -import com.intellij.openapi.module.Module; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.configuration.KotlinModuleTypeManager; -import org.jetbrains.kotlin.idea.framework.KotlinLibraryUtilKt; - -public class KotlinModuleTypeManagerImpl extends KotlinModuleTypeManager { - @Override - public boolean isAndroidGradleModule(@NotNull Module module) { - return hasAndroidFacet(module) && isGradleModule(module); - } - - private static boolean hasAndroidFacet(@NotNull Module module) { - for (Facet facet : FacetManager.getInstance(module).getAllFacets()) { - if (facet.getName().equals("Android")) { - return true; - } - } - return false; - } - - @Override - public boolean isGradleModule(@NotNull Module module) { - return ExternalSystemApiUtil.isExternalSystemAwareModule(KotlinLibraryUtilKt.getGRADLE_SYSTEM_ID(), module); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/framework/KotlinLibraryUtil.kt b/idea/src/org/jetbrains/kotlin/idea/framework/KotlinLibraryUtil.kt index 5478afa44cb..3678c108e74 100644 --- a/idea/src/org/jetbrains/kotlin/idea/framework/KotlinLibraryUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/framework/KotlinLibraryUtil.kt @@ -1,23 +1,13 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.framework import com.intellij.openapi.externalSystem.model.ProjectSystemId import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil +import com.intellij.openapi.module.Module import com.intellij.openapi.roots.libraries.Library private val MAVEN_SYSTEM_ID = ProjectSystemId("MAVEN") @@ -29,3 +19,6 @@ fun isExternalLibrary(library: Library): Boolean { ExternalSystemApiUtil.isExternalSystemLibrary(library, MAVEN_SYSTEM_ID) } + +fun Module.isGradleModule() = + ExternalSystemApiUtil.isExternalSystemAwareModule(GRADLE_SYSTEM_ID, this) diff --git a/ultimate/src/org/jetbrains/kotlin/idea/nodejs/nodeJsUtil.kt b/ultimate/src/org/jetbrains/kotlin/idea/nodejs/nodeJsUtil.kt index 33caaa89fa5..77c8e23e5f7 100644 --- a/ultimate/src/org/jetbrains/kotlin/idea/nodejs/nodeJsUtil.kt +++ b/ultimate/src/org/jetbrains/kotlin/idea/nodejs/nodeJsUtil.kt @@ -1,17 +1,6 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.nodejs @@ -24,7 +13,7 @@ import com.intellij.openapi.roots.CompilerModuleExtension import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.util.io.FileUtil import com.intellij.util.PathUtil -import org.jetbrains.kotlin.idea.KotlinPluginUtil +import org.jetbrains.kotlin.idea.framework.isGradleModule import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.plugins.gradle.model.ExternalProject import org.jetbrains.plugins.gradle.service.project.data.ExternalProjectDataCache @@ -57,7 +46,7 @@ private fun ExternalProject.findProjectById(id: String): ExternalProject? { } private fun getNodeJsClasspath(module: Module): List { - if (KotlinPluginUtil.isGradleModule(module)) { + if (module.isGradleModule()) { val gradleProjectPath = ExternalSystemModulePropertyManager.getInstance(module).getRootProjectPath() val projectCache = ExternalProjectDataCache.getInstance(module.project) val rootProject = projectCache.getRootExternalProject(GradleConstants.SYSTEM_ID, File(gradleProjectPath)) ?: return listOf()