Framework initial commit
This commit is contained in:
committed by
Nikolay Krasko
parent
bb53985c00
commit
9f640e7f13
@@ -214,6 +214,9 @@
|
||||
<codeInsight.implementMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler"/>
|
||||
<codeInsight.overrideMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.OverrideMethodsHandler"/>
|
||||
|
||||
<framework.type implementation="org.jetbrains.jet.plugin.framework.JetJavaFrameworkType"/>
|
||||
<framework.type implementation="org.jetbrains.jet.plugin.framework.JavaScriptFrameworkType"/>
|
||||
|
||||
<java.elementFinder implementation="org.jetbrains.jet.asJava.JavaElementFinder"/>
|
||||
<java.shortNamesCache implementation="org.jetbrains.jet.plugin.caches.JetShortNamesCache"/>
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ import javax.swing.*;
|
||||
public interface JetIcons {
|
||||
Icon SMALL_LOGO = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin.png");
|
||||
|
||||
Icon SMALL_LOGO_13 = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin_13.png");
|
||||
|
||||
Icon CLASS = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/class_kotlin.png");
|
||||
Icon ENUM = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/enum_kotlin.png");
|
||||
Icon FILE = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin_file.png");
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.framework.FrameworkTypeEx;
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetIcons;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JavaScriptFrameworkType extends FrameworkTypeEx {
|
||||
public JavaScriptFrameworkType() {
|
||||
super("kotlin-js-framework-id");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkSupportInModuleProvider createProvider() {
|
||||
return new JetJavaScriptFrameworkSupportProvider();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
return "Kotlin (JavaScript)";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return JetIcons.SMALL_LOGO_13;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.openapi.module.Module;
|
||||
|
||||
public class JetFrameworkConfigurator {
|
||||
private JetFrameworkConfigurator() {}
|
||||
|
||||
public static boolean configureAsJavaModule(Module module) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean configureAsJavaScriptModule(Module module) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.framework.FrameworkTypeEx;
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable;
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel;
|
||||
import com.intellij.openapi.module.JavaModuleType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.roots.ModifiableModelsProvider;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.framework.ui.FrameworkSourcePanel;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JetJavaFrameworkSupportProvider extends FrameworkSupportInModuleProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkTypeEx getFrameworkType() {
|
||||
return FrameworkTypeEx.EP_NAME.findExtension(JetJavaFrameworkType.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkSupportInModuleConfigurable createConfigurable(@NotNull FrameworkSupportModel model) {
|
||||
return new FrameworkSupportInModuleConfigurable() {
|
||||
public FrameworkSourcePanel panel = null;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CustomLibraryDescription createLibraryDescription() {
|
||||
return new JetJavaRuntimeLibraryDescription(panel);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
return getConfigurationPanel().getPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyLibraryAdded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFrameworkSelectionChanged(boolean selected) {
|
||||
getConfigurationPanel().onFrameworkSelectionChanged(selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSupport(
|
||||
@NotNull Module module,
|
||||
@NotNull ModifiableRootModel rootModel,
|
||||
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
|
||||
}
|
||||
|
||||
private FrameworkSourcePanel getConfigurationPanel() {
|
||||
if (panel == null) {
|
||||
panel = new FrameworkSourcePanel();
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledForModuleType(@NotNull ModuleType moduleType) {
|
||||
return moduleType instanceof JavaModuleType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.framework.FrameworkTypeEx;
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetIcons;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JetJavaFrameworkType extends FrameworkTypeEx {
|
||||
public JetJavaFrameworkType() {
|
||||
super("kotlin-java-framework-id");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkSupportInModuleProvider createProvider() {
|
||||
return new JetJavaFrameworkSupportProvider();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
return "Kotlin (Java)";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return JetIcons.SMALL_LOGO_13;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.google.common.collect.Sets;
|
||||
import com.intellij.framework.library.LibraryVersionProperties;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.LibraryKind;
|
||||
import com.intellij.openapi.roots.libraries.NewLibraryConfiguration;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.framework.ui.FrameworkSourcePanel;
|
||||
import org.jetbrains.jet.plugin.versions.KotlinRuntimeLibraryUtil;
|
||||
|
||||
import javax.management.openmbean.InvalidOpenTypeException;
|
||||
import javax.swing.*;
|
||||
import java.util.Set;
|
||||
|
||||
public class JetJavaRuntimeLibraryDescription extends CustomLibraryDescription {
|
||||
public static final LibraryKind KOTLIN_KIND = LibraryKind.create("kotlin-java-runtime");
|
||||
private final FrameworkSourcePanel frameworkSourcePanel;
|
||||
|
||||
public JetJavaRuntimeLibraryDescription(FrameworkSourcePanel frameworkSourcePanel) {
|
||||
this.frameworkSourcePanel = frameworkSourcePanel;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends LibraryKind> getSuitableLibraryKinds() {
|
||||
return Sets.newHashSet(KOTLIN_KIND);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
||||
if (frameworkSourcePanel.isConfigureFromBundled()) {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false);
|
||||
|
||||
descriptor.setTitle("Select Folder");
|
||||
descriptor.setDescription("Select folder where bundled Kotlin java runtime library should be copied");
|
||||
|
||||
final VirtualFile[] files = FileChooser.chooseFiles(descriptor, parentComponent, null, contextDirectory);
|
||||
if (files.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
assert files.length == 1: "Only one folder is expected";
|
||||
|
||||
final VirtualFile directory = files[0];
|
||||
assert directory.isDirectory();
|
||||
|
||||
return new NewLibraryConfiguration(KotlinRuntimeLibraryUtil.LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) {
|
||||
@Override
|
||||
public void addRoots(@NotNull LibraryEditor editor) {
|
||||
editor.addRoot(directory.getUrl() + "/" + KotlinRuntimeLibraryUtil.KOTLIN_RUNTIME_JAR, OrderRootType.CLASSES);
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw new InvalidOpenTypeException("Isn't supported yet");
|
||||
}
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.framework.FrameworkTypeEx;
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable;
|
||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel;
|
||||
import com.intellij.openapi.module.JavaModuleType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.roots.ModifiableModelsProvider;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.framework.ui.FrameworkSourcePanel;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JetJavaScriptFrameworkSupportProvider extends FrameworkSupportInModuleProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkTypeEx getFrameworkType() {
|
||||
return FrameworkTypeEx.EP_NAME.findExtension(JavaScriptFrameworkType.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FrameworkSupportInModuleConfigurable createConfigurable(@NotNull FrameworkSupportModel model) {
|
||||
return new FrameworkSupportInModuleConfigurable() {
|
||||
private FrameworkSourcePanel sourcePanel = null;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CustomLibraryDescription createLibraryDescription() {
|
||||
return new JetJavaScriptLibraryDescription(getConfigurationPanel());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
return getConfigurationPanel().getPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFrameworkSelectionChanged(boolean selected) {
|
||||
getConfigurationPanel().onFrameworkSelectionChanged(selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlyLibraryAdded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSupport(
|
||||
@NotNull Module module,
|
||||
@NotNull ModifiableRootModel rootModel,
|
||||
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
|
||||
}
|
||||
|
||||
private FrameworkSourcePanel getConfigurationPanel() {
|
||||
if (sourcePanel == null) {
|
||||
sourcePanel = new FrameworkSourcePanel();
|
||||
}
|
||||
return sourcePanel;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledForModuleType(@NotNull ModuleType moduleType) {
|
||||
return moduleType instanceof JavaModuleType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.google.common.collect.Sets;
|
||||
import com.intellij.framework.library.LibraryVersionProperties;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.LibraryKind;
|
||||
import com.intellij.openapi.roots.libraries.NewLibraryConfiguration;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.framework.ui.FrameworkSourcePanel;
|
||||
import org.jetbrains.jet.plugin.versions.KotlinRuntimeLibraryUtil;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
public class JetJavaScriptLibraryDescription extends CustomLibraryDescription {
|
||||
public static final LibraryKind KOTLIN_JAVASCRIPT_KIND = LibraryKind.create("kotlin-js-stdlib");
|
||||
|
||||
private final FrameworkSourcePanel configurationPanel;
|
||||
|
||||
public JetJavaScriptLibraryDescription(FrameworkSourcePanel configurationPanel) {
|
||||
this.configurationPanel = configurationPanel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends LibraryKind> getSuitableLibraryKinds() {
|
||||
return Sets.newHashSet(KOTLIN_JAVASCRIPT_KIND);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
||||
if (configurationPanel.isConfigureFromBundled()) {
|
||||
// Select folder where to copy bundled library
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false);
|
||||
descriptor.setTitle("Select Folder");
|
||||
descriptor.setDescription("Select folder where bundled runtime should be placed");
|
||||
|
||||
final VirtualFile[] files = FileChooser.chooseFiles(descriptor, parentComponent, null, contextDirectory);
|
||||
if (files.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
assert files.length == 1: "Only one folder is expected";
|
||||
|
||||
final VirtualFile directory = files[0];
|
||||
assert directory.isDirectory();
|
||||
|
||||
File runtimePath = PathUtil.getKotlinPathsForIdeaPlugin().getRuntimePath();
|
||||
if (!runtimePath.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File targetJar = new File(com.intellij.util.PathUtil.getLocalPath(directory), KotlinRuntimeLibraryUtil.KOTLIN_RUNTIME_JAR);
|
||||
try {
|
||||
FileUtil.copy(runtimePath, targetJar);
|
||||
VirtualFile jarVfs = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetJar);
|
||||
if (jarVfs != null) {
|
||||
jarVfs.refresh(false, false);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return new NewLibraryConfiguration(KotlinRuntimeLibraryUtil.LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) {
|
||||
@Override
|
||||
public void addRoots(@NotNull LibraryEditor editor) {
|
||||
editor.addRoot(directory.getUrl() + "/" + KotlinRuntimeLibraryUtil.KOTLIN_RUNTIME_JAR, OrderRootType.CLASSES);
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Feature isn't ready yet");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.ui;
|
||||
|
||||
import com.intellij.ide.util.projectWizard.ProjectWizardUtil;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
||||
import com.intellij.openapi.fileChooser.FileTextField;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
class ChoosePathDialog extends DialogWrapper {
|
||||
private final Project myProject;
|
||||
private final String defaultPath;
|
||||
private TextFieldWithBrowseButton myPathField;
|
||||
|
||||
public ChoosePathDialog(
|
||||
Project project,
|
||||
String title,
|
||||
String defaultPath) {
|
||||
super(project);
|
||||
myProject = project;
|
||||
this.defaultPath = defaultPath;
|
||||
|
||||
setTitle(title);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
|
||||
FileTextField field = FileChooserFactory.getInstance().createFileTextField(descriptor, myDisposable);
|
||||
field.getField().setColumns(25);
|
||||
|
||||
myPathField = new TextFieldWithBrowseButton(field.getField());
|
||||
myPathField.addBrowseFolderListener("Choose Destination Folder", "Choose folder", myProject, descriptor);
|
||||
myPathField.setText(defaultPath);
|
||||
|
||||
return myPathField;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
if (ProjectWizardUtil.createDirectoryIfNotExists("Destination folder", getPath(), false)) {
|
||||
super.doOKAction();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPath() {
|
||||
return myPathField.getText().trim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.ui;
|
||||
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CopyFileUtil {
|
||||
private CopyFileUtil() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File copyWithOverwriteDialog(@NotNull String destinationFolder, @NotNull File file) throws IOException {
|
||||
File folder = new File(destinationFolder);
|
||||
File targetFile = new File(folder, file.getName());
|
||||
|
||||
// TODO: create folder if it is not present yet
|
||||
assert folder.exists();
|
||||
|
||||
if (!targetFile.exists()) {
|
||||
FileUtil.copy(file, targetFile);
|
||||
}
|
||||
else {
|
||||
int replaceIfExist = Messages.showYesNoDialog(
|
||||
String.format("File \"%s\" already exist in %s. Do you want to rewrite it?", targetFile.getName(),
|
||||
folder.getAbsolutePath()),
|
||||
"Replace File", Messages.getWarningIcon());
|
||||
|
||||
if (replaceIfExist == JOptionPane.YES_OPTION) {
|
||||
FileUtil.copy(file, targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile);
|
||||
|
||||
return targetFile;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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.CreateLibraryFromBundledPanel">
|
||||
<grid id="f17b8" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="4" 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="331" height="272"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="5336b">
|
||||
<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"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="17bb1" class="javax.swing.JLabel" binding="descriptionLabel">
|
||||
<constraints>
|
||||
<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>
|
||||
<text value="Description"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c8785" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="destinationFolder">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<grid id="d70d2" binding="myConfigurationPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="bf0c6" class="com.intellij.ui.components.JBLabel" binding="myMessageLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<componentStyle value="SMALL"/>
|
||||
<enabled value="true"/>
|
||||
<fontColor value="BRIGHTER"/>
|
||||
<text value="<html>Project level library <b>spring</b> will be created</html>"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="55035" class="javax.swing.JButton" binding="myConfigureButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Configure..."/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.ui;
|
||||
|
||||
import com.intellij.facet.impl.ui.libraries.EditLibraryDialog;
|
||||
import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings;
|
||||
import com.intellij.facet.impl.ui.libraries.LibraryDownloadSettings;
|
||||
import com.intellij.framework.library.DownloadableLibraryDescription;
|
||||
import com.intellij.framework.library.DownloadableLibraryType;
|
||||
import com.intellij.framework.library.FrameworkLibraryVersion;
|
||||
import com.intellij.framework.library.FrameworkLibraryVersionFilter;
|
||||
import com.intellij.ide.util.frameworkSupport.OldCustomLibraryDescription;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CreateLibraryFromBundledPanel implements Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.framework.impl.ui.libraries.CreateLibraryFromBundledPanel");
|
||||
|
||||
private JBLabel myMessageLabel;
|
||||
private JButton myConfigureButton;
|
||||
private JPanel myConfigurationPanel;
|
||||
|
||||
private TextFieldWithBrowseButton destinationFolder;
|
||||
private JPanel myRootPanel;
|
||||
private JLabel descriptionLabel;
|
||||
|
||||
private LibraryCompositionSettings mySettings;
|
||||
private final LibrariesContainer myLibrariesContainer;
|
||||
private boolean myDisposed;
|
||||
|
||||
public CreateLibraryFromBundledPanel(
|
||||
@NotNull final CustomLibraryDescription libraryDescription,
|
||||
@NotNull final String baseDirectoryPath,
|
||||
@NotNull final FrameworkLibraryVersionFilter versionFilter,
|
||||
@NotNull final LibrariesContainer librariesContainer,
|
||||
final boolean showDoNotCreateOption
|
||||
) {
|
||||
myLibrariesContainer = librariesContainer;
|
||||
showSettingsPanel(
|
||||
libraryDescription, baseDirectoryPath, versionFilter, showDoNotCreateOption,
|
||||
new ArrayList<FrameworkLibraryVersion>());
|
||||
|
||||
destinationFolder.addBrowseFolderListener("Choose Destination Folder", "Choose folder for file", getProject(),
|
||||
FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
||||
|
||||
VirtualFile baseDir = getProject().getBaseDir();
|
||||
if (baseDir != null) {
|
||||
destinationFolder.getTextField().setText(baseDir.getPath().replace('/', File.separatorChar) + File.separatorChar + "lib");
|
||||
}
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
descriptionLabel.setText(description);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static DownloadableLibraryDescription getDownloadableDescription(CustomLibraryDescription libraryDescription) {
|
||||
final DownloadableLibraryType type = libraryDescription.getDownloadableLibraryType();
|
||||
if (type != null) return type.getLibraryDescription();
|
||||
if (libraryDescription instanceof OldCustomLibraryDescription) {
|
||||
return ((OldCustomLibraryDescription) libraryDescription).getDownloadableDescription();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void showSettingsPanel(
|
||||
CustomLibraryDescription libraryDescription,
|
||||
String baseDirectoryPath,
|
||||
FrameworkLibraryVersionFilter versionFilter,
|
||||
boolean showDoNotCreateOption, final List<? extends FrameworkLibraryVersion> versions
|
||||
) {
|
||||
mySettings = new LibraryCompositionSettings(libraryDescription, baseDirectoryPath, versionFilter, versions);
|
||||
Disposer.register(this, mySettings);
|
||||
List<Library> libraries = calculateSuitableLibraries();
|
||||
|
||||
myConfigureButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
doConfigure();
|
||||
}
|
||||
});
|
||||
|
||||
updateState();
|
||||
}
|
||||
|
||||
private void doConfigure() {
|
||||
NewLibraryEditor editor = new NewLibraryEditor();
|
||||
editor.setName("Testing");
|
||||
|
||||
EditLibraryDialog dialog = new EditLibraryDialog(myConfigurationPanel, mySettings, editor);
|
||||
dialog.show();
|
||||
|
||||
updateState();
|
||||
}
|
||||
|
||||
public void changeBaseDirectoryPath(@NotNull String directoryForLibrariesPath) {
|
||||
if (mySettings != null) {
|
||||
mySettings.changeBaseDirectoryPath(directoryForLibrariesPath);
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
|
||||
public void setVersionFilter(@NotNull FrameworkLibraryVersionFilter versionFilter) {
|
||||
if (mySettings != null) {
|
||||
mySettings.setVersionFilter(versionFilter);
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
|
||||
private void doCreate() {
|
||||
//final NewLibraryConfiguration libraryConfiguration = mySettings.getLibraryDescription().createNewLibrary(myPanel, getBaseDirectory());
|
||||
//if (libraryConfiguration != null) {
|
||||
// final NewLibraryEditor libraryEditor = new NewLibraryEditor(libraryConfiguration.getLibraryType(), libraryConfiguration.getProperties());
|
||||
// libraryEditor.setName(myLibrariesContainer.suggestUniqueLibraryName(libraryConfiguration.getDefaultLibraryName()));
|
||||
// libraryConfiguration.addRoots(libraryEditor);
|
||||
//}
|
||||
}
|
||||
|
||||
private List<Library> calculateSuitableLibraries() {
|
||||
final CustomLibraryDescription description = mySettings.getLibraryDescription();
|
||||
List<Library> suitableLibraries = new ArrayList<Library>();
|
||||
for (Library library : myLibrariesContainer.getAllLibraries()) {
|
||||
if (description instanceof OldCustomLibraryDescription &&
|
||||
((OldCustomLibraryDescription) description).isSuitableLibrary(library, myLibrariesContainer)
|
||||
||
|
||||
LibraryPresentationManager.getInstance()
|
||||
.isLibraryOfKind(library, myLibrariesContainer, description.getSuitableLibraryKinds())) {
|
||||
suitableLibraries.add(library);
|
||||
}
|
||||
}
|
||||
return suitableLibraries;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VirtualFile getBaseDirectory() {
|
||||
String path = mySettings.getBaseDirectoryPath();
|
||||
VirtualFile dir = LocalFileSystem.getInstance().findFileByPath(path);
|
||||
if (dir == null) {
|
||||
path = path.substring(0, path.lastIndexOf('/'));
|
||||
dir = LocalFileSystem.getInstance().findFileByPath(path);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
myMessageLabel.setIcon(null);
|
||||
myConfigureButton.setVisible(true);
|
||||
final LibraryDownloadSettings settings = mySettings.getDownloadSettings();
|
||||
|
||||
//String message = IdeBundle.message(
|
||||
// "label.library.will.be.created.description.text",
|
||||
// mySettings.getNewLibraryLevel(),
|
||||
// libraryEditor.getName(), libraryEditor.getFiles(OrderRootType.CLASSES).length);
|
||||
//
|
||||
//((CardLayout)myConfigurationPanel.getLayout()).show(myConfigurationPanel, showConfigurePanel ? "configure" : "empty");
|
||||
//myMessageLabel.setText("<html>" + message + "</html>");
|
||||
}
|
||||
|
||||
public LibraryCompositionSettings getSettings() {
|
||||
return mySettings;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LibraryCompositionSettings apply() {
|
||||
if (mySettings == null) return null;
|
||||
|
||||
//final Choice option = myButtonEnumModel.getSelected();
|
||||
//mySettings.setDownloadLibraries(option == Choice.DOWNLOAD);
|
||||
//
|
||||
//final Object item = myExistingLibraryComboBox.getSelectedItem();
|
||||
//if (option == Choice.USE_LIBRARY && item instanceof ExistingLibraryEditor) {
|
||||
// mySettings.setSelectedExistingLibrary(((ExistingLibraryEditor)item).getLibrary());
|
||||
//}
|
||||
//else {
|
||||
// mySettings.setSelectedExistingLibrary(null);
|
||||
//}
|
||||
//
|
||||
//if (option == Choice.USE_LIBRARY && item instanceof NewLibraryEditor) {
|
||||
// mySettings.setNewLibraryEditor((NewLibraryEditor)item);
|
||||
//}
|
||||
//else {
|
||||
// mySettings.setNewLibraryEditor(null);
|
||||
//}
|
||||
return mySettings;
|
||||
}
|
||||
|
||||
public JComponent getMainPanel() {
|
||||
return myRootPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
myDisposed = true;
|
||||
}
|
||||
|
||||
private Project getProject() {
|
||||
Project project = myLibrariesContainer.getProject();
|
||||
if (project == null) {
|
||||
project = ProjectManager.getInstance().getDefaultProject();
|
||||
}
|
||||
return project;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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.FrameworkSourcePanel">
|
||||
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" 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="333" height="150"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="fcfb7">
|
||||
<constraints>
|
||||
<grid row="2" 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="5bc21" class="javax.swing.JRadioButton" binding="configureFromStandaloneKotlinRadioButton" 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>
|
||||
<enabled value="false"/>
|
||||
<text value="Configure from &standalone Kotlin compiler installation"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a4e73" class="javax.swing.JRadioButton" binding="configureFromFilesBundledRadioButton" default-binding="true">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="true"/>
|
||||
<text value="Configure from files &bundled in Kotlin plugin "/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<buttonGroups>
|
||||
<group name="configureSourceGroup">
|
||||
<member id="5bc21"/>
|
||||
<member id="a4e73"/>
|
||||
</group>
|
||||
</buttonGroups>
|
||||
</form>
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameworkSourcePanel {
|
||||
private JRadioButton configureFromStandaloneKotlinRadioButton;
|
||||
private JRadioButton configureFromFilesBundledRadioButton;
|
||||
private JPanel contentPanel;
|
||||
|
||||
public JPanel getPanel() {
|
||||
return contentPanel;
|
||||
}
|
||||
|
||||
public boolean isConfigureFromBundled() {
|
||||
return configureFromFilesBundledRadioButton.isSelected();
|
||||
}
|
||||
|
||||
public void onFrameworkSelectionChanged(boolean selected) {
|
||||
// Don't enable for now
|
||||
configureFromStandaloneKotlinRadioButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
@@ -20,15 +20,13 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
@@ -66,33 +64,25 @@ public final class JsModuleSetUp {
|
||||
if (!copyJsLibFiles(rootDir)) return;
|
||||
|
||||
setUpK2JSModuleComponent(module);
|
||||
setUpLibraryAsSourceLibrary(module, rootDir);
|
||||
createJSLibrary(module, LibrariesContainer.LibraryLevel.MODULE, rootDir);
|
||||
|
||||
// FacetUtil.addFacet(module, JetFacetType.getInstance());
|
||||
|
||||
restartHighlightingInTheWholeProject(module);
|
||||
|
||||
refreshRootDir(module, continuation);
|
||||
}
|
||||
|
||||
private static void setUpLibraryAsSourceLibrary(final Module module, @NotNull File rootDir) {
|
||||
public static Library createJSLibrary(Module module, LibrariesContainer.LibraryLevel level, @NotNull File rootDir) {
|
||||
File libJarFile = new File(rootDir, "lib/" + PathUtil.JS_LIB_JAR_NAME);
|
||||
final VirtualFile libFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libJarFile);
|
||||
VirtualFile libFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libJarFile);
|
||||
|
||||
if (libFile != null) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
LibraryTable table = model.getModuleLibraryTable();
|
||||
Library jsLib = table.getLibraryByName(PathUtil.JS_LIB_JAR_NAME);
|
||||
if (jsLib == null) {
|
||||
VirtualFile libRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libFile);
|
||||
LibrariesContainerFactory.createContainer(model).createLibrary(PathUtil.JS_LIB_JAR_NAME,
|
||||
LibrariesContainer.LibraryLevel.MODULE, new VirtualFile[0], new VirtualFile[] { libRoot });
|
||||
model.commit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
NewLibraryEditor editor = new NewLibraryEditor();
|
||||
editor.setName(PathUtil.JS_LIB_JAR_NAME);
|
||||
editor.addRoot(libFile, OrderRootType.SOURCES);
|
||||
|
||||
LibrariesContainer container = LibrariesContainerFactory.createContainer(module);
|
||||
return container.createLibrary(editor, level);
|
||||
}
|
||||
|
||||
private static void setUpK2JSModuleComponent(@NotNull Module module) {
|
||||
|
||||
+7
-81
@@ -20,10 +20,6 @@ import com.intellij.ProjectTopics;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.compiler.CompilerManager;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
||||
import com.intellij.openapi.fileChooser.FileTextField;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -34,10 +30,6 @@ import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModuleRootAdapter;
|
||||
import com.intellij.openapi.roots.ModuleRootEvent;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.ui.popup.ListPopup;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
@@ -52,12 +44,10 @@ import com.intellij.util.messages.MessageBusConnection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.plugin.quickfix.JsModuleSetUp;
|
||||
import org.jetbrains.jet.plugin.framework.JetFrameworkConfigurator;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -135,31 +125,24 @@ public class KotlinLibrariesNotificationProvider extends EditorNotifications.Pro
|
||||
answer.createActionLabel("Set up module '" + module.getName() + "' as JVM Kotlin module", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setUpJavaModule(module);
|
||||
if (JetFrameworkConfigurator.configureAsJavaModule(module)) {
|
||||
updateNotifications();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
answer.createActionLabel("Set up module '" + module.getName() + "' as JavaScript Kotlin module", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setUpJSModule(module);
|
||||
if (JetFrameworkConfigurator.configureAsJavaScriptModule(module)) {
|
||||
updateNotifications();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
private void setUpJavaModule(Module module) {
|
||||
Library library = KotlinRuntimeLibraryUtil.findOrCreateRuntimeLibrary(myProject, new UiFindRuntimeLibraryHandler());
|
||||
if (library == null) return;
|
||||
|
||||
KotlinRuntimeLibraryUtil.setUpKotlinRuntimeLibrary(module, library, updateNotifications);
|
||||
}
|
||||
|
||||
private void setUpJSModule(@NotNull Module module) {
|
||||
JsModuleSetUp.doSetUpModule(module, updateNotifications);
|
||||
}
|
||||
|
||||
private EditorNotificationPanel createUnsupportedAbiVersionNotificationPanel(Collection<VirtualFile> badRoots) {
|
||||
EditorNotificationPanel answer = new ErrorNotificationPanel();
|
||||
|
||||
@@ -231,63 +214,6 @@ public class KotlinLibrariesNotificationProvider extends EditorNotifications.Pro
|
||||
});
|
||||
}
|
||||
|
||||
private static class ChoosePathDialog extends DialogWrapper {
|
||||
private final Project myProject;
|
||||
private TextFieldWithBrowseButton myPathField;
|
||||
|
||||
protected ChoosePathDialog(Project project) {
|
||||
super(project);
|
||||
myProject = project;
|
||||
|
||||
setTitle("Local Kotlin Runtime Path");
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
|
||||
FileTextField field = FileChooserFactory.getInstance().createFileTextField(descriptor, myDisposable);
|
||||
field.getField().setColumns(25);
|
||||
myPathField = new TextFieldWithBrowseButton(field.getField());
|
||||
myPathField.addBrowseFolderListener("Choose Destination Folder", "Choose folder for file", myProject, descriptor);
|
||||
|
||||
VirtualFile baseDir = myProject.getBaseDir();
|
||||
if (baseDir != null) {
|
||||
myPathField.setText(baseDir.getPath().replace('/', File.separatorChar) + File.separatorChar + "lib");
|
||||
}
|
||||
|
||||
return myPathField;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return myPathField.getText();
|
||||
}
|
||||
}
|
||||
|
||||
private class UiFindRuntimeLibraryHandler extends KotlinRuntimeLibraryUtil.FindRuntimeLibraryHandler {
|
||||
@Override
|
||||
public void runtimePathDoesNotExist(@NotNull File path) {
|
||||
Messages.showErrorDialog(myProject,
|
||||
"kotlin-runtime.jar is not found at " + path + ". Make sure plugin is properly installed.",
|
||||
"No Runtime Found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getRuntimeJarPath() {
|
||||
ChoosePathDialog dlg = new ChoosePathDialog(myProject);
|
||||
dlg.show();
|
||||
if (!dlg.isOK()) return null;
|
||||
String path = dlg.getPath();
|
||||
return new File(path, "kotlin-runtime.jar");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ioExceptionOnCopyingJar(@NotNull IOException e) {
|
||||
Messages.showErrorDialog(myProject, "Error copying jar: " + e.getLocalizedMessage(), "Error Copying File");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void navigateToLibraryRoot(Project project, @NotNull VirtualFile root) {
|
||||
new OpenFileDescriptor(project, root).navigate(true);
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.SdkModificator;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
|
||||
import com.intellij.openapi.roots.AnnotationOrderRootType;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.impl.elements.ManifestFileUtil;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
@@ -45,6 +45,7 @@ import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.indexing.FileBasedIndex;
|
||||
import com.intellij.util.indexing.ID;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil;
|
||||
@@ -55,7 +56,8 @@ import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
@@ -173,76 +175,64 @@ public class KotlinRuntimeLibraryUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
static void setUpKotlinRuntimeLibrary(
|
||||
@NotNull final Module module,
|
||||
@NotNull final Library library,
|
||||
@NotNull final Runnable afterSetUp
|
||||
) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
if (model.findLibraryOrderEntry(library) == null) {
|
||||
model.addLibraryEntry(library);
|
||||
model.commit();
|
||||
}
|
||||
else {
|
||||
model.dispose();
|
||||
}
|
||||
public static boolean isLibraryCanBeUsedAsJavaRuntime(@Nullable Library library) {
|
||||
if (library == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
afterSetUp.run();
|
||||
|
||||
if (!jdkAnnotationsArePresent(module)) {
|
||||
addJdkAnnotations(module);
|
||||
}
|
||||
for (VirtualFile root : library.getFiles(OrderRootType.CLASSES)) {
|
||||
if (root.getName().equals(KOTLIN_RUNTIME_JAR)) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static Library findOrCreateRuntimeLibrary(@NotNull Project project, @NotNull FindRuntimeLibraryHandler handler) {
|
||||
final LibraryTable table = ProjectLibraryTable.getInstance(project);
|
||||
final Library kotlinRuntime = table.getLibraryByName(LIBRARY_NAME);
|
||||
if (kotlinRuntime != null) {
|
||||
for (VirtualFile root : kotlinRuntime.getFiles(OrderRootType.CLASSES)) {
|
||||
if (root.getName().equals(KOTLIN_RUNTIME_JAR)) {
|
||||
return kotlinRuntime;
|
||||
}
|
||||
}
|
||||
}
|
||||
//@Nullable
|
||||
//public static Library createRuntimeLibrary(final LibraryTable table, @NotNull final String libName, FindRuntimeLibraryHandler handler) {
|
||||
// File runtimePath = PathUtil.getKotlinPathsForIdeaPlugin().getRuntimePath();
|
||||
// if (!runtimePath.exists()) {
|
||||
// handler.runtimePathDoesNotExist(runtimePath);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// final File targetJar = handler.getRuntimeJarPath();
|
||||
// if (targetJar == null) return null;
|
||||
// try {
|
||||
// FileUtil.copy(runtimePath, targetJar);
|
||||
// VirtualFile jarVfs = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetJar);
|
||||
// if (jarVfs != null) {
|
||||
// jarVfs.refresh(false, false);
|
||||
// }
|
||||
// }
|
||||
// catch (IOException e) {
|
||||
// handler.ioExceptionOnCopyingJar(e);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// return ApplicationManager.getApplication().runWriteAction(new Computable<Library>() {
|
||||
// @Override
|
||||
// public Library compute() {
|
||||
// LibraryTableBase.ModifiableModel modifiableModel = table.getModifiableModel();
|
||||
// final String name = getUniqueLibraryName(libName, modifiableModel);
|
||||
// Library library = modifiableModel.createLibrary(name);
|
||||
// final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
|
||||
// model.addRoot(VfsUtil.getUrlForLibraryRoot(targetJar), OrderRootType.CLASSES);
|
||||
// model.addRoot(VfsUtil.getUrlForLibraryRoot(targetJar) + "src", OrderRootType.SOURCES);
|
||||
// model.commit();
|
||||
// modifiableModel.commit();
|
||||
// return library;
|
||||
// }
|
||||
// });
|
||||
//}
|
||||
|
||||
File runtimePath = PathUtil.getKotlinPathsForIdeaPlugin().getRuntimePath();
|
||||
if (!runtimePath.exists()) {
|
||||
handler.runtimePathDoesNotExist(runtimePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
final File targetJar = handler.getRuntimeJarPath();
|
||||
if (targetJar == null) return null;
|
||||
try {
|
||||
FileUtil.copy(runtimePath, targetJar);
|
||||
VirtualFile jarVfs = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetJar);
|
||||
if (jarVfs != null) {
|
||||
jarVfs.refresh(false, false);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
handler.ioExceptionOnCopyingJar(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return ApplicationManager.getApplication().runWriteAction(new Computable<Library>() {
|
||||
private static String getUniqueLibraryName(final String baseName, final LibraryTable.ModifiableModel model) {
|
||||
return UniqueNameGenerator.generateUniqueName(baseName, "", "", " (", ")", new Condition<String>() {
|
||||
@Override
|
||||
public Library compute() {
|
||||
Library result = kotlinRuntime == null
|
||||
? table.createLibrary("KotlinRuntime")
|
||||
: kotlinRuntime;
|
||||
|
||||
Library.ModifiableModel model = result.getModifiableModel();
|
||||
model.addRoot(VfsUtil.getUrlForLibraryRoot(targetJar), OrderRootType.CLASSES);
|
||||
model.addRoot(VfsUtil.getUrlForLibraryRoot(targetJar) + "src", OrderRootType.SOURCES);
|
||||
model.commit();
|
||||
return result;
|
||||
public boolean value(String s) {
|
||||
return model.getLibraryByName(s) == null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -312,14 +302,14 @@ public class KotlinRuntimeLibraryUtil {
|
||||
return kotlinRuntimeJar;
|
||||
}
|
||||
|
||||
public static abstract class FindRuntimeLibraryHandler {
|
||||
@Nullable
|
||||
public abstract File getRuntimeJarPath();
|
||||
|
||||
public void runtimePathDoesNotExist(@NotNull File path) {
|
||||
}
|
||||
|
||||
public void ioExceptionOnCopyingJar(@NotNull IOException e) {
|
||||
}
|
||||
}
|
||||
//public static abstract class FindRuntimeLibraryHandler {
|
||||
// @Nullable
|
||||
// public abstract File getRuntimeJarPath();
|
||||
//
|
||||
// public void runtimePathDoesNotExist(@NotNull File path) {
|
||||
// }
|
||||
//
|
||||
// public void ioExceptionOnCopyingJar(@NotNull IOException e) {
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user