diff --git a/annotations/com/intellij/platform/annotations.xml b/annotations/com/intellij/platform/annotations.xml new file mode 100644 index 00000000000..4d50b6072ed --- /dev/null +++ b/annotations/com/intellij/platform/annotations.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/idea/resources/org/jetbrains/jet/plugin/icons/kotlin24.png b/idea/resources/org/jetbrains/jet/plugin/icons/kotlin24.png new file mode 100644 index 00000000000..57733d2a379 Binary files /dev/null and b/idea/resources/org/jetbrains/jet/plugin/icons/kotlin24.png differ diff --git a/idea/resources/org/jetbrains/jet/plugin/icons/kotlin24@2x.png b/idea/resources/org/jetbrains/jet/plugin/icons/kotlin24@2x.png new file mode 100644 index 00000000000..0ff2c7eee0e Binary files /dev/null and b/idea/resources/org/jetbrains/jet/plugin/icons/kotlin24@2x.png differ diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index c73148b46bf..1b7b4d3732b 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -305,6 +305,8 @@ + + diff --git a/idea/src/org/jetbrains/jet/plugin/JetIcons.java b/idea/src/org/jetbrains/jet/plugin/JetIcons.java index 2ab18c3b3f8..b04ee650346 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetIcons.java +++ b/idea/src/org/jetbrains/jet/plugin/JetIcons.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 JetBrains s.r.o. + * Copyright 2010-2014 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. @@ -23,6 +23,7 @@ import javax.swing.*; public interface JetIcons { Icon SMALL_LOGO = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin.png"); + Icon KOTLIN_LOGO_24 = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin24.png"); Icon SMALL_LOGO_13 = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin13.png"); diff --git a/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleBuilder.kt b/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleBuilder.kt new file mode 100644 index 00000000000..2e0a4ce1c3a --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleBuilder.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2010-2014 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.jet.plugin.framework + +import com.intellij.ide.util.projectWizard.JavaModuleBuilder +import com.intellij.ide.util.projectWizard.ModuleWizardStep +import com.intellij.ide.util.projectWizard.SettingsStep +import com.intellij.openapi.module.ModifiableModuleModel +import com.intellij.openapi.module.Module +import com.intellij.openapi.module.ModuleWithNameAlreadyExists +import com.intellij.openapi.options.ConfigurationException +import com.intellij.openapi.util.InvalidDataException +import org.jdom.JDOMException +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.plugin.JetIcons +import org.jetbrains.jet.plugin.project.TargetPlatform +import javax.swing.* +import java.io.IOException +import com.intellij.openapi.roots.ui.configuration.ModulesProvider +import com.intellij.ide.util.projectWizard.WizardContext + +public class KotlinModuleBuilder( + val targetPlatform: TargetPlatform, val builderName: String, val builderDescription: String) : JavaModuleBuilder() { + override fun getBuilderId() = "kotlin.module.builder" + override fun getName() = builderName + override fun getPresentableName() = builderName + override fun getDescription() = builderDescription + override fun getBigIcon() = JetIcons.KOTLIN_LOGO_24 + override fun getNodeIcon() = JetIcons.SMALL_LOGO + override fun getGroupName() = KotlinTemplatesFactory.KOTLIN_GROUP_NAME + override fun createWizardSteps(wizardContext: WizardContext, modulesProvider: ModulesProvider) = ModuleWizardStep.EMPTY_ARRAY + + override fun modifySettingsStep(settingsStep: SettingsStep): ModuleWizardStep { + return KotlinModuleSettingStep(targetPlatform, this, settingsStep) + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleSettingStep.java b/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleSettingStep.java new file mode 100644 index 00000000000..b71ed99c6c1 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/KotlinModuleSettingStep.java @@ -0,0 +1,140 @@ +/* + * Copyright 2010-2014 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.jet.plugin.framework; + +import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings; +import com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel; +import com.intellij.framework.library.FrameworkLibraryVersionFilter; +import com.intellij.ide.util.projectWizard.ModuleBuilder; +import com.intellij.ide.util.projectWizard.ModuleWizardStep; +import com.intellij.ide.util.projectWizard.SettingsStep; +import com.intellij.openapi.module.JavaModuleType; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; +import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; +import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.io.FileUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.plugin.project.TargetPlatform; + +import javax.swing.*; +import java.util.ArrayList; + +public class KotlinModuleSettingStep extends ModuleWizardStep { + private final TargetPlatform targetPlatform; + + @Nullable + private final ModuleWizardStep myJavaStep; + + private final CustomLibraryDescription customLibraryDescription; + private final LibrariesContainer librariesContainer; + + private LibraryOptionsPanel libraryOptionsPanel; + private LibraryCompositionSettings libraryCompositionSettings; + + private final String basePath; + + public KotlinModuleSettingStep(TargetPlatform targetPlatform, ModuleBuilder moduleBuilder, @NotNull SettingsStep settingsStep) { + this.targetPlatform = targetPlatform; + + myJavaStep = JavaModuleType.getModuleType().modifySettingsStep(settingsStep, moduleBuilder); + + basePath = moduleBuilder.getContentEntryPath(); + librariesContainer = LibrariesContainerFactory.createContainer(settingsStep.getContext().getProject()); + + customLibraryDescription = getCustomLibraryDescription(settingsStep.getContext().getProject()); + + moduleBuilder.addModuleConfigurationUpdater(createModuleConfigurationUpdater()); + + settingsStep.addSettingsField(getLibraryLabelText(), getLibraryPanel().getSimplePanel()); + } + + protected ModuleBuilder.ModuleConfigurationUpdater createModuleConfigurationUpdater() { + return new ModuleBuilder.ModuleConfigurationUpdater() { + @Override + public void update(@NotNull Module module, @NotNull ModifiableRootModel rootModel) { + if (libraryCompositionSettings != null) { + libraryCompositionSettings.addLibraries(rootModel, new ArrayList(), librariesContainer); + + if (customLibraryDescription instanceof CustomLibraryDescriptorWithDefferConfig) { + ((CustomLibraryDescriptorWithDefferConfig) customLibraryDescription).finishLibConfiguration(module, rootModel); + } + } + } + }; + } + + @Override + public void disposeUIResources() { + if (libraryOptionsPanel != null) { + Disposer.dispose(libraryOptionsPanel); + } + } + + @Override + public JComponent getComponent() { + return getLibraryPanel().getMainPanel(); + } + + @NotNull + protected String getLibraryLabelText() { + if (targetPlatform == TargetPlatform.JVM) return "\u001BKotlin runtime:"; + if (targetPlatform == TargetPlatform.JS) return "\u001BKotlin JS library:"; + throw new IllegalStateException("Only JS and JVM target are supported"); + } + + @NotNull + protected CustomLibraryDescription getCustomLibraryDescription(@Nullable Project project) { + if (targetPlatform == TargetPlatform.JVM) return new JavaRuntimeLibraryDescription(project); + if (targetPlatform == TargetPlatform.JS) return new JSLibraryStdDescription(project); + throw new IllegalStateException("Only JS and JVM target are supported"); + } + + @Override + public void updateDataModel() { + libraryCompositionSettings = getLibraryPanel().apply(); + if (myJavaStep != null) { + myJavaStep.updateDataModel(); + } + } + + @Override + public boolean validate() throws ConfigurationException { + return super.validate() && (myJavaStep == null || myJavaStep.validate()); + } + + protected LibraryOptionsPanel getLibraryPanel() { + if (libraryOptionsPanel == null) { + String baseDirPath = basePath != null ? FileUtil.toSystemIndependentName(basePath) : ""; + + libraryOptionsPanel = new LibraryOptionsPanel( + customLibraryDescription, + baseDirPath, + FrameworkLibraryVersionFilter.ALL, + librariesContainer, + false); + } + + return libraryOptionsPanel; + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/framework/KotlinTemplatesFactory.kt b/idea/src/org/jetbrains/jet/plugin/framework/KotlinTemplatesFactory.kt new file mode 100644 index 00000000000..3bdcbfa73a4 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/KotlinTemplatesFactory.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2014 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.jet.plugin.framework + +import com.intellij.ide.util.projectWizard.WizardContext +import com.intellij.platform.ProjectTemplate +import com.intellij.platform.ProjectTemplatesFactory +import com.intellij.platform.templates.BuilderBasedTemplate +import org.jetbrains.jet.plugin.JetIcons +import org.jetbrains.jet.plugin.project.TargetPlatform +import javax.swing.* + +public class KotlinTemplatesFactory : ProjectTemplatesFactory() { + class object { + public val KOTLIN_GROUP_NAME: String = "Kotlin" + } + + override fun getGroups() = array(KOTLIN_GROUP_NAME) + override fun getGroupIcon(group: String) = JetIcons.KOTLIN_LOGO_24 + + override fun createTemplates(group: String, context: WizardContext?) = + array( + BuilderBasedTemplate(KotlinModuleBuilder(TargetPlatform.JVM, "Kotlin - JVM", "Kotlin module for JVM target")), + BuilderBasedTemplate(KotlinModuleBuilder(TargetPlatform.JS, "Kotlin - JavaScript", "Kotlin module for JavaScript target")) + ) +}