diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index a21f6452d3a..8dc5eb66406 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -580,8 +580,6 @@ - - diff --git a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSBrowserProgramRunner.java b/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSBrowserProgramRunner.java deleted file mode 100644 index d4a63baecea..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSBrowserProgramRunner.java +++ /dev/null @@ -1,64 +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.k2jsrun; - -import com.intellij.execution.ExecutionException; -import com.intellij.execution.configurations.RunProfile; -import com.intellij.execution.configurations.RunProfileState; -import com.intellij.execution.runners.ExecutionEnvironment; -import com.intellij.execution.runners.GenericProgramRunner; -import com.intellij.execution.ui.RunContentDescriptor; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.jetbrains.kotlin.idea.k2jsrun.K2JSRunnerUtils.copyJSFileFromOutputToDestination; -import static org.jetbrains.kotlin.idea.k2jsrun.K2JSRunnerUtils.openBrowser; - -public final class K2JSBrowserProgramRunner extends GenericProgramRunner { - @Nullable - @Override - protected RunContentDescriptor doExecute( - Project project, - RunProfileState state, - RunContentDescriptor contentToReuse, - ExecutionEnvironment env - ) throws ExecutionException { - if (project == null) { - return null; - } - try { - copyJSFileFromOutputToDestination(project, K2JSRunnerUtils.getSettings(env)); - openBrowser(K2JSRunnerUtils.getSettings(env)); - } - catch (Throwable e) { - throw new ExecutionException(e); - } - return null; - } - - @NotNull - @Override - public String getRunnerId() { - return "K2JSBrowserRunner"; - } - - @Override - public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) { - return (profile instanceof K2JSRunConfiguration); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSConfigurationSettings.java b/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSConfigurationSettings.java deleted file mode 100644 index ae94f711224..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSConfigurationSettings.java +++ /dev/null @@ -1,80 +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.k2jsrun; - -import com.intellij.ide.browsers.BrowserFamily; -import com.intellij.ide.browsers.WebBrowserManager; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; - -public final class K2JSConfigurationSettings { - - @NotNull - private String pageToOpenFilePath = ""; - - @NotNull - private String generatedFilePath; - - private boolean shouldOpenInBrowserAfterTranslation = false; - - @NotNull - private BrowserFamily browserFamily = WebBrowserManager.getInstance().getActiveBrowsers().get(0).getFamily(); - - public K2JSConfigurationSettings(@NotNull Project project) { - String basePath = project.getBasePath(); - generatedFilePath = basePath != null ? basePath : ""; - } - - public K2JSConfigurationSettings() { - generatedFilePath = ""; - } - - @NotNull - public BrowserFamily getBrowserFamily() { - return browserFamily; - } - - public void setBrowserFamily(@NotNull BrowserFamily browserFamily) { - this.browserFamily = browserFamily; - } - - @NotNull - public String getPageToOpenFilePath() { - return pageToOpenFilePath; - } - - public void setPageToOpenFilePath(@NotNull String pageToOpenFilePath) { - this.pageToOpenFilePath = pageToOpenFilePath; - } - - @NotNull - public String getGeneratedFilePath() { - return generatedFilePath; - } - - public void setGeneratedFilePath(@NotNull String generatedFilePath) { - this.generatedFilePath = generatedFilePath; - } - - public boolean isShouldOpenInBrowserAfterTranslation() { - return shouldOpenInBrowserAfterTranslation; - } - - public void setShouldOpenInBrowserAfterTranslation(boolean shouldOpenInBrowserAfterTranslation) { - this.shouldOpenInBrowserAfterTranslation = shouldOpenInBrowserAfterTranslation; - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfiguration.java b/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfiguration.java deleted file mode 100644 index e436841b0fe..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfiguration.java +++ /dev/null @@ -1,109 +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.k2jsrun; - -import com.intellij.execution.DefaultExecutionResult; -import com.intellij.execution.ExecutionException; -import com.intellij.execution.ExecutionResult; -import com.intellij.execution.Executor; -import com.intellij.execution.configurations.*; -import com.intellij.execution.runners.ExecutionEnvironment; -import com.intellij.execution.runners.ProgramRunner; -import com.intellij.execution.runners.RunConfigurationWithSuppressedDefaultRunAction; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.options.SettingsEditor; -import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.WriteExternalException; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.util.xmlb.XmlSerializer; -import org.jdom.Element; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.Collection; - -@SuppressWarnings("deprecation") -public final class K2JSRunConfiguration extends ModuleBasedConfiguration - implements RunConfigurationWithSuppressedDefaultRunAction { - - @NotNull - private K2JSConfigurationSettings settings = new K2JSConfigurationSettings(getProject()); - - public K2JSRunConfiguration(String name, RunConfigurationModule runConfigurationModule, ConfigurationFactory factory) { - super(name, runConfigurationModule, factory); - runConfigurationModule.init(); - } - - - @Override - public Collection getValidModules() { - return Arrays.asList(ModuleManager.getInstance(getProject()).getModules()); - } - - @Override - public GlobalSearchScope getSearchScope() { - return SearchScopeProvider.createSearchScope(getModules()); - } - - @Override - protected ModuleBasedConfiguration createInstance() { - return new K2JSRunConfiguration(getName(), getConfigurationModule(), getFactory()); - } - - @Override - public SettingsEditor getConfigurationEditor() { - return new K2JSRunConfigurationEditor(getProject()); - } - - - @Override - public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) - throws ExecutionException { - return new MyProfileState(); - } - - private static final class MyProfileState implements RunProfileState { - @Override - public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException { - return new DefaultExecutionResult(); - } - } - - @NotNull - public K2JSConfigurationSettings settings() { - return settings; - } - - @Override - public void readExternal(Element element) throws InvalidDataException { - super.readExternal(element); - Element settingsElement = element.getChild(K2JSConfigurationSettings.class.getSimpleName()); - if (settingsElement != null) { - K2JSConfigurationSettings deserializedSettings = XmlSerializer.deserialize(settingsElement, K2JSConfigurationSettings.class); - if (deserializedSettings != null) { - settings = deserializedSettings; - } - } - } - - @Override - public void writeExternal(Element element) throws WriteExternalException { - super.writeExternal(element); - element.addContent(XmlSerializer.serialize(settings())); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfigurationEditor.form b/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfigurationEditor.form deleted file mode 100644 index b1146ccd666..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfigurationEditor.form +++ /dev/null @@ -1,99 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfigurationEditor.java b/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfigurationEditor.java deleted file mode 100644 index c90172344c5..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfigurationEditor.java +++ /dev/null @@ -1,167 +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.k2jsrun; - - import com.intellij.ide.browsers.BrowserFamily; -import com.intellij.ide.browsers.WebBrowser; -import com.intellij.ide.browsers.WebBrowserManager; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; -import com.intellij.openapi.fileTypes.StdFileTypes; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.SettingsEditor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.ui.JBColor; -import com.intellij.ui.ListCellRendererWrapper; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.io.File; - -import static com.intellij.openapi.util.io.FileUtil.toSystemIndependentName; - -public final class K2JSRunConfigurationEditor extends SettingsEditor { - - private JPanel mainPanel; - private TextFieldWithBrowseButton htmlChooseFile; - private JComboBox browserComboBox; - private JCheckBox openInBrowserCheckBox; - private TextFieldWithBrowseButton generatedChooseFile; - private JLabel chooseBrowserLabel; - private JLabel htmlFileLabel; - @NotNull - private final Project project; - - public K2JSRunConfigurationEditor(@NotNull Project project) { - this.project = project; - } - - @Override - protected void resetEditorFrom(@NotNull K2JSRunConfiguration configuration) { - htmlChooseFile.setText(toSystemIndependentName(configuration.settings().getPageToOpenFilePath())); - browserComboBox.setSelectedItem(configuration.settings().getBrowserFamily()); - generatedChooseFile.setText(toSystemIndependentName(configuration.settings().getGeneratedFilePath())); - openInBrowserCheckBox.setSelected(configuration.settings().isShouldOpenInBrowserAfterTranslation()); - } - - @Override - protected void applyEditorTo(@NotNull K2JSRunConfiguration configuration) throws ConfigurationException { - K2JSConfigurationSettings settings = configuration.settings(); - settings.setPageToOpenFilePath(toSystemIndependentName(htmlChooseFile.getText())); - Object item = browserComboBox.getSelectedItem(); - if (item instanceof BrowserFamily) { - settings.setBrowserFamily((BrowserFamily) item); - } - settings.setGeneratedFilePath(toSystemIndependentName(generatedChooseFile.getText())); - settings.setShouldOpenInBrowserAfterTranslation(openInBrowserCheckBox.isSelected()); - } - - @NotNull - @Override - protected JComponent createEditor() { - setUpShowInBrowserCheckBox(); - setUpChooseHtmlToShow(); - setUpBrowserCombobox(); - setUpChooseGenerateFilePath(); - return mainPanel; - } - - private void setUpChooseGenerateFilePath() { - FileChooserDescriptor fileChooserDescriptor = - FileChooserDescriptorFactory.getDirectoryChooserDescriptor("directory where generated files will be stored"); - fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots()); - generatedChooseFile.addBrowseFolderListener(null, null, project, fileChooserDescriptor); - final JTextField textField = generatedChooseFile.getTextField(); - textField.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void insertUpdate(@NotNull DocumentEvent e) { - onChange(); - } - - @Override - public void removeUpdate(@NotNull DocumentEvent e) { - onChange(); - } - - @Override - public void changedUpdate(@NotNull DocumentEvent e) { - onChange(); - } - - private void onChange() { - File file = new File(generatedChooseFile.getText()); - if (!file.isDirectory()) { - textField.setForeground(JBColor.red); - } else { - textField.setForeground(JBColor.foreground()); - } - } - }); - } - - private void setUpShowInBrowserCheckBox() { - openInBrowserCheckBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(@NotNull ItemEvent e) { - boolean selected = openInBrowserCheckBox.isSelected(); - htmlChooseFile.setEnabled(selected); - browserComboBox.setEnabled(selected); - htmlFileLabel.setEnabled(selected); - chooseBrowserLabel.setEnabled(selected); - } - }); - } - - private void setUpChooseHtmlToShow() { - FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(StdFileTypes.HTML); - fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots()); - htmlChooseFile.addBrowseFolderListener("Choose file to show after translation is finished", null, project, fileChooserDescriptor); - } - - private void setUpBrowserCombobox() { - for (WebBrowser browser : WebBrowserManager.getInstance().getActiveBrowsers()) { - browserComboBox.addItem(browser.getFamily()); - } - browserComboBox.setRenderer(new ListCellRendererWrapper() { - @Override - public void customize(JList list, BrowserFamily family, int index, boolean selected, boolean hasFocus) { - if (family != null) { - setText(family.getName()); - setIcon(family.getIcon()); - } - } - }); - if (browserComboBox.getItemCount() < 2) { - browserComboBox.setVisible(false); - browserComboBox.setVisible(false); - } - else { - browserComboBox.setSelectedItem(0); - } - } - - @Override - protected void disposeEditor() { - // do nothing - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfigurationType.java b/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfigurationType.java deleted file mode 100644 index 51b9902c11e..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunConfigurationType.java +++ /dev/null @@ -1,43 +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.k2jsrun; - -import com.intellij.execution.configurations.*; -import com.intellij.openapi.project.Project; -import org.jetbrains.kotlin.idea.KotlinIcons; - -public final class K2JSRunConfigurationType extends ConfigurationTypeBase { - public static K2JSRunConfigurationType getInstance() { - return ConfigurationTypeUtil.findConfigurationType(K2JSRunConfigurationType.class); - } - - public K2JSRunConfigurationType() { - super("K2JSConfigurationType", "Kotlin (JavaScript)", "Kotlin to JavaScript configuration", KotlinIcons.SMALL_LOGO_13); - addFactory(new K2JSConfigurationFactory()); - } - - private class K2JSConfigurationFactory extends ConfigurationFactory { - protected K2JSConfigurationFactory() { - super(K2JSRunConfigurationType.this); - } - - @Override - public RunConfiguration createTemplateConfiguration(Project project) { - return new K2JSRunConfiguration("Kotlin to JavaScript", new RunConfigurationModule(project), this); - } - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunnerUtils.java b/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunnerUtils.java deleted file mode 100644 index c3fea0a32fd..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/k2jsrun/K2JSRunnerUtils.java +++ /dev/null @@ -1,117 +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.k2jsrun; - -import com.intellij.execution.configurations.RunProfile; -import com.intellij.execution.runners.ExecutionEnvironment; -import com.intellij.ide.browsers.BrowserLauncher; -import com.intellij.ide.browsers.WebBrowser; -import com.intellij.ide.browsers.WebBrowserManager; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.CompilerModuleExtension; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.js.JavaScript; - -import java.io.File; -import java.io.IOException; - -public final class K2JSRunnerUtils { - - private K2JSRunnerUtils() { - } - - @NotNull - public static String constructPathToGeneratedFile(@NotNull Project project, @NotNull String outputDirPath) { - return outputDirPath + "/" + project.getName() + JavaScript.DOT_EXTENSION; - } - - public static void copyJSFileFromOutputToDestination(@NotNull Project project, - @NotNull K2JSConfigurationSettings configurationSettings) { - VirtualFile outputDir = getOutputDir(project); - if (outputDir == null) { - throw new RuntimeException("Cannot find output dir for project " + project.getName()); - } - String pathToGeneratedJsFile = constructPathToGeneratedFile(project, outputDir.getPath()); - try { - copyFileToDir(new File(pathToGeneratedJsFile), new File(configurationSettings.getGeneratedFilePath())); - } - catch (IOException e) { - throw new RuntimeException("Output JavaScript file was not generated or missing.", e); - } - } - - //todo[Alefas]: replacement of com.intellij.openapi.compiler.CompilerPaths.getModuleOutputDirectory() - @Nullable - private static VirtualFile getModuleOutputDirectory(@NotNull Module module) { - CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module); - - if (compilerModuleExtension == null) { - return null; - } - - VirtualFile outPath = compilerModuleExtension.getCompilerOutputPath(); - - if (outPath == null || !outPath.isValid()) return null; - return outPath; - } - - @Nullable - private static VirtualFile getOutputDir(@NotNull Project project) { - Module module = getJsModule(project); - return getModuleOutputDirectory(module); - } - - @NotNull - public static Module getJsModule(@NotNull Project project) { - //TODO Should not be there, we should know what module we are in - Module[] modules = ModuleManager.getInstance(project).getModules(); - if (modules.length != 1) { - throw new UnsupportedOperationException("Kotlin to JavaScript translator temporarily does not support multiple modules."); - } - return modules[0]; - } - - public static void openBrowser(@NotNull K2JSConfigurationSettings configurationSettings) { - if (!configurationSettings.isShouldOpenInBrowserAfterTranslation()) { - return; - } - String filePath = configurationSettings.getPageToOpenFilePath(); - String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, filePath); - - WebBrowser browser = WebBrowserManager.getInstance().findBrowserById(configurationSettings.getBrowserFamily().getName()); - BrowserLauncher.getInstance().browse(url, browser); - } - - @NotNull - public static K2JSConfigurationSettings getSettings(@NotNull ExecutionEnvironment env) { - RunProfile profile = env.getRunProfile(); - assert profile instanceof K2JSRunConfiguration; - return ((K2JSRunConfiguration) profile).settings(); - } - - //TODO: this method does not really belong here, but dunno where it should be - public static void copyFileToDir(@NotNull File file, @NotNull File dir) throws IOException { - FileUtil.copy(file, new File(dir, file.getName())); - } -}