Remove using standalone compiler option

This commit is contained in:
Nikolay Krasko
2013-03-04 18:31:40 +04:00
parent f5955185ac
commit f98ae18596
7 changed files with 26 additions and 208 deletions
@@ -28,6 +28,7 @@ import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.plugin.JetPluginUtil;
import org.jetbrains.jet.plugin.framework.ui.CreateJavaScriptLibraryDialog;
import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
import org.jetbrains.jet.utils.KotlinPaths;
@@ -59,10 +60,7 @@ public class JSLibraryDescription extends CustomLibraryDescription {
dialog.show();
if (dialog.isOK()) {
String standaloneCompilerPath = dialog.getStandaloneCompilerPath();
KotlinPaths paths = standaloneCompilerPath == null ?
PathUtil.getKotlinPathsForIdeaPlugin() :
PathUtil.getKotlinStandaloneCompilerPaths(standaloneCompilerPath);
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin();
File libraryFile = paths.getJsLibJarPath();
if (!libraryFile.exists()) {
@@ -71,6 +69,8 @@ public class JSLibraryDescription extends CustomLibraryDescription {
return null;
}
String libraryName = LIBRARY_NAME;
String copyIntoPath = dialog.getCopyIntoPath();
if (copyIntoPath != null) {
List<File> copyFiles = new ArrayList<File>();
@@ -86,11 +86,12 @@ public class JSLibraryDescription extends CustomLibraryDescription {
if (dialog.isCopyLibraryFiles()) {
libraryFile = copiedFiles.get(libraryFile);
libraryName = LIBRARY_NAME + "-" + JetPluginUtil.getPluginVersion();
}
}
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
return new NewLibraryConfiguration(LIBRARY_NAME + "-" + dialog.getVersion(), getDownloadableLibraryType(), new LibraryVersionProperties()) {
return new NewLibraryConfiguration(libraryName, getDownloadableLibraryType(), new LibraryVersionProperties()) {
@Override
public void addRoots(@NotNull LibraryEditor editor) {
editor.addRoot(libraryFileUrl, OrderRootType.SOURCES);
@@ -28,6 +28,7 @@ import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.plugin.JetPluginUtil;
import org.jetbrains.jet.plugin.framework.ui.CreateJavaLibraryDialog;
import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
import org.jetbrains.jet.utils.KotlinPaths;
@@ -56,10 +57,7 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription {
dialog.show();
if (dialog.isOK()) {
String standaloneCompilerPath = dialog.getStandaloneCompilerPath();
KotlinPaths paths = standaloneCompilerPath == null ?
PathUtil.getKotlinPathsForIdeaPlugin() :
PathUtil.getKotlinStandaloneCompilerPaths(standaloneCompilerPath);
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin();
File libraryFile = paths.getRuntimePath();
if (!libraryFile.exists()) {
@@ -70,16 +68,20 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription {
return null;
}
String libraryName = LIBRARY_NAME;
String copyIntoPath = dialog.getCopyIntoPath();
if (copyIntoPath != null) {
libraryFile = FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_RUNTIME_LIBRARY_CREATION, copyIntoPath, libraryFile);
if (libraryFile == null) {
return null;
}
libraryName = LIBRARY_NAME + "-" + JetPluginUtil.getPluginVersion();
}
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
return new NewLibraryConfiguration(LIBRARY_NAME + "-" + dialog.getVersion(), getDownloadableLibraryType(), new LibraryVersionProperties()) {
return new NewLibraryConfiguration(libraryName, getDownloadableLibraryType(), new LibraryVersionProperties()) {
@Override
public void addRoots(@NotNull LibraryEditor editor) {
editor.addRoot(libraryFileUrl, OrderRootType.CLASSES);
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.jet.plugin.framework.ui.ChooseCompilerSourcePanel">
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="416" height="156"/>
@@ -8,33 +8,17 @@
<properties/>
<border type="none"/>
<children>
<component id="e6e7d" class="javax.swing.JRadioButton" binding="useBundledKotlinRadioButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="Use compiler &amp;bundled in plugin"/>
</properties>
</component>
<vspacer id="150a1">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="7c565" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="kotlinStandalonePathField">
<component id="920d" class="javax.swing.JLabel" binding="bundledPluginVersion">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="3" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="4b0f" class="javax.swing.JRadioButton" binding="useStandaloneKotlinRadioButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="false"/>
<text value="Use standalone Kotlin compiler &amp;installation"/>
<text value="Using compiler bundled into plugin"/>
</properties>
</component>
</children>
@@ -16,150 +16,19 @@
package org.jetbrains.jet.plugin.framework.ui;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.DocumentAdapter;
import com.intellij.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.plugin.JetPluginUtil;
import org.jetbrains.jet.utils.KotlinPaths;
import org.jetbrains.jet.utils.PathUtil;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
public class ChooseCompilerSourcePanel {
private JRadioButton useBundledKotlinRadioButton;
private JRadioButton useStandaloneKotlinRadioButton;
private TextFieldWithBrowseButton kotlinStandalonePathField;
private JPanel contentPane;
private JLabel bundledPluginVersion;
private final EventDispatcher<ValidityListener> validityDispatcher = EventDispatcher.create(ValidityListener.class);
private boolean hasErrorsState = false;
private String version = null;
private final String initialStandaloneLabelText;
public ChooseCompilerSourcePanel(@Nullable Project project) {
useBundledKotlinRadioButton.setText(useBundledKotlinRadioButton.getText() + " - " + JetPluginUtil.getPluginVersion());
initialStandaloneLabelText = useStandaloneKotlinRadioButton.getText();
kotlinStandalonePathField.setEditable(false);
kotlinStandalonePathField.addBrowseFolderListener(
"Kotlin Compiler", "Choose folder with Kotlin compiler installation", project,
new FileChooserDescriptor(false, true, false, false, false, false) {
@Override
public boolean isFileSelectable(VirtualFile file) {
if (!super.isFileSelectable(file)) {
return false;
}
return PathUtil.KOTLIN_HOME_DIRECTORY_FINDER.fun(com.intellij.util.PathUtil.getLocalPath(file)) != null;
}
});
kotlinStandalonePathField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(final DocumentEvent e) {
updateStandaloneVersion();
updateComponents();
}
});
useStandaloneKotlinRadioButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
updateComponents();
}
});
useBundledKotlinRadioButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
updateComponents();
}
});
updateStandaloneVersion();
updateComponents();
}
public void addValidityListener(ValidityListener listener) {
validityDispatcher.addListener(listener);
}
public boolean hasErrors() {
return hasErrorsState;
}
@Nullable
public String getStandaloneCompilerPath() {
if (useStandaloneKotlinRadioButton.isSelected()) {
return kotlinStandalonePathField.getText().trim();
}
return null;
}
@NotNull
public String getVersion() {
if (useBundledKotlinRadioButton.isSelected()) {
return JetPluginUtil.getPluginVersion();
}
else {
assert version != null: "It shouldn't be possible to finish dialog with invalid version";
return version;
}
public ChooseCompilerSourcePanel() {
bundledPluginVersion.setText(bundledPluginVersion.getText() + " - " + JetPluginUtil.getPluginVersion());
}
public JPanel getContentPane() {
return contentPane;
}
private void updateComponents() {
boolean isError = false;
kotlinStandalonePathField.setEnabled(useStandaloneKotlinRadioButton.isSelected());
useStandaloneKotlinRadioButton.setForeground(Color.BLACK);
useStandaloneKotlinRadioButton.setText(initialStandaloneLabelText);
if (useStandaloneKotlinRadioButton.isSelected()) {
if (version != null) {
useStandaloneKotlinRadioButton.setText(initialStandaloneLabelText + " - " + version);
}
else {
useStandaloneKotlinRadioButton.setForeground(Color.RED);
useStandaloneKotlinRadioButton.setText(initialStandaloneLabelText + " - " + "Invalid Version");
isError = true;
}
}
if (hasErrorsState != isError) {
hasErrorsState = isError;
validityDispatcher.getMulticaster().validityChanged(isError);
}
}
private void updateStandaloneVersion() {
if (useStandaloneKotlinRadioButton.isSelected()) {
KotlinPaths paths = PathUtil.getKotlinStandaloneCompilerPaths(kotlinStandalonePathField.getTextField().getText().trim());
try {
version = FileUtilRt.loadFile(paths.getBuildVersionFile());
return;
}
catch (IOException e) {
// Do nothing. Version will be set to null.
}
}
version = null;
}
}
@@ -26,7 +26,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Copy library &amp;files into project"/>
<text value="Make local copy of library (could be stored in VCS) "/>
</properties>
</component>
<grid id="e47d8" binding="copyIntoPanelPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
@@ -28,7 +28,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CreateJavaLibraryDialog extends DialogWrapper {
private final ChooseCompilerSourcePanel compilerSourcePanel;
private final CopyIntoPanel copyIntoPanel;
private JPanel contentPane;
@@ -43,13 +42,7 @@ public class CreateJavaLibraryDialog extends DialogWrapper {
init();
compilerSourcePanel = new ChooseCompilerSourcePanel(project);
compilerSourcePanel.addValidityListener(new ValidityListener() {
@Override
public void validityChanged(boolean isValid) {
updateComponents();
}
});
ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel();
compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER, 0);
copyIntoPanel = new CopyIntoPanel(project, contextDirectory);
@@ -61,8 +54,6 @@ public class CreateJavaLibraryDialog extends DialogWrapper {
});
copyIntoPanelPlace.add(copyIntoPanel.getContentPane(), BorderLayout.CENTER);
contentPane.setMinimumSize(new Dimension(380, 180));
copyLibraryCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
@@ -73,24 +64,14 @@ public class CreateJavaLibraryDialog extends DialogWrapper {
updateComponents();
}
@Nullable
public String getStandaloneCompilerPath() {
return compilerSourcePanel.getStandaloneCompilerPath();
}
@Nullable
public String getCopyIntoPath() {
return copyIntoPanel.getPath();
}
@NotNull
public String getVersion() {
return compilerSourcePanel.getVersion();
}
private void updateComponents() {
copyIntoPanel.setEnabled(copyLibraryCheckbox.isSelected());
setOKActionEnabled(!(compilerSourcePanel.hasErrors() || copyIntoPanel.hasErrors()));
setOKActionEnabled(!copyIntoPanel.hasErrors());
}
@Nullable
@@ -12,7 +12,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CreateJavaScriptLibraryDialog extends DialogWrapper {
private final ChooseCompilerSourcePanel compilerSourcePanel;
private final CopyIntoPanel copyIntoPanel;
private JPanel contentPane;
@@ -28,13 +27,7 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper {
init();
compilerSourcePanel = new ChooseCompilerSourcePanel(project);
compilerSourcePanel.addValidityListener(new ValidityListener() {
@Override
public void validityChanged(boolean isValid) {
updateComponents();
}
});
ChooseCompilerSourcePanel compilerSourcePanel = new ChooseCompilerSourcePanel();
compilerSourcePanelPlace.add(compilerSourcePanel.getContentPane(), BorderLayout.CENTER);
copyIntoPanel = new CopyIntoPanel(project, contextDirectory);
@@ -46,8 +39,6 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper {
});
copyIntoPanelPlace.add(copyIntoPanel.getContentPane(), BorderLayout.CENTER);
contentPane.setMinimumSize(new Dimension(380, 180));
ActionListener updateComponentsListener = new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
@@ -61,11 +52,6 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper {
updateComponents();
}
@Nullable
public String getStandaloneCompilerPath() {
return compilerSourcePanel.getStandaloneCompilerPath();
}
@Nullable
public String getCopyIntoPath() {
return copyIntoPanel.getPath();
@@ -79,16 +65,11 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper {
return ECMAScript3JavaScriptRuntimeCheckBox.isSelected();
}
@NotNull
public String getVersion() {
return compilerSourcePanel.getVersion();
}
private void updateComponents() {
copyIntoPanel.setEnabled(copyLibraryCheckbox.isSelected() ||
ECMAScript3JavaScriptRuntimeCheckBox.isSelected());
setOKActionEnabled(!(compilerSourcePanel.hasErrors() || copyIntoPanel.hasErrors()));
setOKActionEnabled(!copyIntoPanel.hasErrors());
}
@Nullable