Add getTargetPlatform method in ProjectConfigurator
#KT-6605 Fixed
This commit is contained in:
@@ -86,7 +86,7 @@
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</group>
|
||||
|
||||
<action id="ConfigureKotlinInProject" class="org.jetbrains.kotlin.idea.actions.ConfigureKotlinInProjectAction"
|
||||
<action id="ConfigureKotlinInProject" class="org.jetbrains.kotlin.idea.actions.ConfigureKotlinJavaInProjectAction"
|
||||
text="Configure Kotlin in Project">
|
||||
<add-to-group group-id="KotlinToolsGroup"/>
|
||||
</action>
|
||||
|
||||
@@ -1,66 +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.actions;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils;
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinJsModuleConfigurator;
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ConfigureKotlinInProjectAction extends AnAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ConfigureKotlinInProjectUtils.isProjectConfigured(project)) {
|
||||
Messages.showInfoMessage("All modules with kotlin files are configured", "Configure Project Info");
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<KotlinProjectConfigurator> configurators =
|
||||
Collections2.filter(ConfigureKotlinInProjectUtils.getAbleToRunConfigurators(project), new Predicate<KotlinProjectConfigurator>() {
|
||||
@Override
|
||||
public boolean apply(KotlinProjectConfigurator input) {
|
||||
return !input.getName().equals(KotlinJsModuleConfigurator.NAME);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (configurators.size() == 1) {
|
||||
configurators.iterator().next().configure(project);
|
||||
}
|
||||
else if (configurators.isEmpty()) {
|
||||
Messages.showErrorDialog("There aren't configurators available", "Configure Kotlin in Project");
|
||||
}
|
||||
else {
|
||||
Messages.showErrorDialog("More than one configurator are available", "Configure Kotlin in Project");
|
||||
ConfigureKotlinInProjectUtils.showConfigureKotlinNotificationIfNeeded(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.actions
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator
|
||||
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatform
|
||||
|
||||
public abstract class ConfigureKotlinInProjectAction : AnAction() {
|
||||
|
||||
abstract fun getAbleToRunConfigurators(project: Project): Collection<KotlinProjectConfigurator>
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val project = CommonDataKeys.PROJECT.getData(e.getDataContext())
|
||||
if (project == null) return
|
||||
|
||||
if (ConfigureKotlinInProjectUtils.isProjectConfigured(project)) {
|
||||
Messages.showInfoMessage("All modules with kotlin files are configured", e.getPresentation().getText())
|
||||
return
|
||||
}
|
||||
|
||||
val configurators = getAbleToRunConfigurators(project)
|
||||
|
||||
when {
|
||||
configurators.size() == 1 -> configurators.first().configure(project)
|
||||
configurators.isEmpty() -> Messages.showErrorDialog("There aren't configurators available", e.getPresentation().getText())
|
||||
else -> {
|
||||
Messages.showErrorDialog("More than one configurator is available", e.getPresentation().getText())
|
||||
ConfigureKotlinInProjectUtils.showConfigureKotlinNotificationIfNeeded(project)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfigureKotlinJsInProjectAction: ConfigureKotlinInProjectAction() {
|
||||
override fun getAbleToRunConfigurators(project: Project) = ConfigureKotlinInProjectUtils.getAbleToRunConfigurators(project).filter {
|
||||
it.getTargetPlatform() == TargetPlatform.JS
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfigureKotlinJavaInProjectAction: ConfigureKotlinInProjectAction() {
|
||||
override fun getAbleToRunConfigurators(project: Project) = ConfigureKotlinInProjectUtils.getAbleToRunConfigurators(project).filter {
|
||||
it.getTargetPlatform() == TargetPlatform.JVM
|
||||
}
|
||||
}
|
||||
@@ -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.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils;
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinJsModuleConfigurator;
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator;
|
||||
|
||||
public class ConfigureKotlinJsInProjectAction extends AnAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
KotlinProjectConfigurator configurator = ConfigureKotlinInProjectUtils.getConfiguratorByName(KotlinJsModuleConfigurator.NAME);
|
||||
|
||||
assert configurator != null : "JsModuleConfigurator should be non-null";
|
||||
|
||||
if (ConfigureKotlinInProjectUtils.getNonConfiguredModules(project, configurator).isEmpty()) {
|
||||
Messages.showInfoMessage("All modules are configured", "Configure Project Info");
|
||||
return;
|
||||
}
|
||||
configurator.configure(project);
|
||||
}
|
||||
}
|
||||
+7
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.configuration;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.JetPluginUtil;
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
|
||||
@@ -33,6 +34,12 @@ public class KotlinAndroidGradleModuleConfigurator extends KotlinWithGradleConfi
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TargetPlatform getTargetPlatform() {
|
||||
return TargetPlatform.JVM;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.configuration;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.JetPluginUtil;
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
|
||||
@@ -33,6 +34,12 @@ public class KotlinGradleModuleConfigurator extends KotlinWithGradleConfigurator
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TargetPlatform getTargetPlatform() {
|
||||
return TargetPlatform.JVM;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin;
|
||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
||||
|
||||
public class KotlinJavaMavenConfigurator extends KotlinMavenConfigurator {
|
||||
private static final String NAME = "maven";
|
||||
@@ -41,4 +42,10 @@ public class KotlinJavaMavenConfigurator extends KotlinMavenConfigurator {
|
||||
createExecution(virtualFile, kotlinPlugin, module, false);
|
||||
createExecution(virtualFile, kotlinPlugin, module, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TargetPlatform getTargetPlatform() {
|
||||
return TargetPlatform.JVM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription;
|
||||
import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider;
|
||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
||||
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryCoreUtil;
|
||||
import org.jetbrains.kotlin.utils.PathUtil;
|
||||
|
||||
@@ -90,6 +91,12 @@ public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TargetPlatform getTargetPlatform() {
|
||||
return TargetPlatform.JVM;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public File getExistedJarFile() {
|
||||
|
||||
+7
@@ -21,6 +21,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin;
|
||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
||||
|
||||
public class KotlinJavascriptMavenConfigurator extends KotlinMavenConfigurator {
|
||||
private static final String NAME = "js maven";
|
||||
@@ -54,4 +55,10 @@ public class KotlinJavascriptMavenConfigurator extends KotlinMavenConfigurator {
|
||||
protected String getGoal(boolean isTest) {
|
||||
return JS_GOAL;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TargetPlatform getTargetPlatform() {
|
||||
return TargetPlatform.JS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.module.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryStdDescription;
|
||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
||||
import org.jetbrains.kotlin.js.JavaScript;
|
||||
import org.jetbrains.kotlin.utils.PathUtil;
|
||||
|
||||
@@ -34,6 +35,12 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TargetPlatform getTargetPlatform() {
|
||||
return TargetPlatform.JS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
||||
|
||||
public interface KotlinProjectConfigurator {
|
||||
ExtensionPointName<KotlinProjectConfigurator> EP_NAME = ExtensionPointName.create("org.jetbrains.kotlin.projectConfigurator");
|
||||
@@ -33,4 +34,7 @@ public interface KotlinProjectConfigurator {
|
||||
@NotNull String getPresentableText();
|
||||
|
||||
@NotNull String getName();
|
||||
|
||||
@NotNull
|
||||
TargetPlatform getTargetPlatform();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user