From a13d61e6185d53f7b9134e0699b92105f528398b Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 2 Apr 2013 19:51:29 +0400 Subject: [PATCH] Introduce project descriptor for testing js configuration --- .../framework/JSLibraryCreateOptions.java | 41 +++++++++++++ .../framework/JSLibraryStdDescription.java | 31 +++++----- .../ui/CreateJavaScriptLibraryDialog.java | 15 ++--- .../jet/plugin/JetStdJSProjectDescriptor.java | 58 +++++++++++++++++++ 4 files changed, 121 insertions(+), 24 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/framework/JSLibraryCreateOptions.java create mode 100644 idea/tests/org/jetbrains/jet/plugin/JetStdJSProjectDescriptor.java diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryCreateOptions.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryCreateOptions.java new file mode 100644 index 00000000000..c18e1b04f70 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryCreateOptions.java @@ -0,0 +1,41 @@ +/* + * 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 org.jetbrains.annotations.Nullable; + +public interface JSLibraryCreateOptions { + JSLibraryCreateOptions DEFAULT = new JSLibraryCreateOptions() { + @Nullable + @Override + public String getCopyJsIntoPath() { + return null; + } + + @Nullable + @Override + public String getCopyLibraryIntoPath() { + return null; + } + }; + + @Nullable + String getCopyJsIntoPath(); + + @Nullable + String getCopyLibraryIntoPath(); +} diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdDescription.java index 75a6bd946f6..7e08c849abb 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdDescription.java @@ -58,10 +58,15 @@ public class JSLibraryStdDescription extends CustomLibraryDescription { CreateJavaScriptLibraryDialog dialog = new CreateJavaScriptLibraryDialog(null, "Create Kotlin JavaScript Library", contextDirectory); dialog.show(); - if (!dialog.isOK()) return null; + if (dialog.isOK()) { + return createNewLibrary(parentComponent, PathUtil.getKotlinPathsForIdeaPlugin(), dialog); + } - KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin(); + return null; + } + @Nullable + public NewLibraryConfiguration createNewLibrary(@Nullable JComponent parentComponent, @NotNull KotlinPaths paths, @NotNull JSLibraryCreateOptions options) { File libraryFile = paths.getJsLibJarPath(); if (!libraryFile.exists()) { Messages.showErrorDialog(String.format("JavaScript standard library was not found in %s", paths.getLibPath()), @@ -70,28 +75,26 @@ public class JSLibraryStdDescription extends CustomLibraryDescription { } Map copyToPaths = new HashMap(); - if (dialog.isCopyLibraryFiles()) { - String copyIntoPath = dialog.getCopyLibraryIntoPath(); - assert copyIntoPath != null; - copyToPaths.put(libraryFile, copyIntoPath); + String copyLibraryIntoPath = options.getCopyLibraryIntoPath(); + if (copyLibraryIntoPath != null) { + copyToPaths.put(libraryFile, copyLibraryIntoPath); } - if (dialog.isCopyJS()) { - String copyIntoPath = dialog.getCopyJsIntoPath(); - assert copyIntoPath != null; - - copyToPaths.put(paths.getJsLibJsPath(), copyIntoPath); + String copyJsIntoPath = options.getCopyJsIntoPath(); + if (copyJsIntoPath != null) { + copyToPaths.put(paths.getJsLibJsPath(), copyJsIntoPath); } if (!copyToPaths.isEmpty()) { - Map copiedFiles = - FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths); + assert parentComponent != null : "Copying should be performed only when executed in GUI"; + + Map copiedFiles = FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths); if (copiedFiles == null) { return null; } - if (dialog.isCopyLibraryFiles()) { + if (copyLibraryIntoPath != null) { libraryFile = copiedFiles.get(libraryFile); } } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java index 2da80dc5666..212233cff6a 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateJavaScriptLibraryDialog.java @@ -22,13 +22,14 @@ 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.JSLibraryCreateOptions; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -public class CreateJavaScriptLibraryDialog extends DialogWrapper { +public class CreateJavaScriptLibraryDialog extends DialogWrapper implements JSLibraryCreateOptions { private final CopyIntoPanel copyJSIntoPanel; private final CopyIntoPanel copyLibraryIntoPanel; @@ -48,7 +49,7 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper { compilerTextLabel.setText(compilerTextLabel.getText() + " - " + JetPluginUtil.getPluginVersion()); - copyJSIntoPanel = new CopyIntoPanel(project, FileUIUtils.createRelativePath(project, contextDirectory, "script"), "&Script directory:"); + copyJSIntoPanel = new CopyIntoPanel(project, FileUIUtils.createRelativePath(project, contextDirectory, "script"), "Script directory:"); copyJSIntoPanel.addValidityListener(new ValidityListener() { @Override public void validityChanged(boolean isValid) { @@ -79,24 +80,18 @@ public class CreateJavaScriptLibraryDialog extends DialogWrapper { updateComponents(); } + @Override @Nullable public String getCopyJsIntoPath() { return copyJSIntoPanel.getPath(); } + @Override @Nullable public String getCopyLibraryIntoPath() { return copyLibraryIntoPanel.getPath(); } - public boolean isCopyLibraryFiles() { - return copyLibraryCheckbox.isSelected(); - } - - public boolean isCopyJS() { - return copyJSRuntimeCheckbox.isSelected(); - } - private void updateComponents() { copyLibraryIntoPanel.setEnabled(copyLibraryCheckbox.isSelected()); copyJSIntoPanel.setEnabled(copyJSRuntimeCheckbox.isSelected()); diff --git a/idea/tests/org/jetbrains/jet/plugin/JetStdJSProjectDescriptor.java b/idea/tests/org/jetbrains/jet/plugin/JetStdJSProjectDescriptor.java new file mode 100644 index 00000000000..14d505b356f --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/JetStdJSProjectDescriptor.java @@ -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; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.module.StdModuleTypes; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.roots.ContentEntry; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.libraries.NewLibraryConfiguration; +import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; +import com.intellij.testFramework.LightProjectDescriptor; +import org.jetbrains.jet.plugin.framework.JSLibraryCreateOptions; +import org.jetbrains.jet.plugin.framework.JSLibraryStdDescription; +import org.jetbrains.jet.testing.ConfigLibraryUtil; +import org.jetbrains.jet.utils.PathUtil; + +public class JetStdJSProjectDescriptor implements LightProjectDescriptor { + public static final JetStdJSProjectDescriptor INSTANCE = new JetStdJSProjectDescriptor(); + + @Override + public ModuleType getModuleType() { + return StdModuleTypes.JAVA; + } + + @Override + public Sdk getSdk() { + return null; + } + + @Override + public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { + NewLibraryConfiguration configuration = new JSLibraryStdDescription().createNewLibrary( + null, PathUtil.getKotlinPathsForDistDirectory(), JSLibraryCreateOptions.DEFAULT); + + assert configuration != null : "Configuration should exist"; + + NewLibraryEditor editor = new NewLibraryEditor(configuration.getLibraryType(), configuration.getProperties()); + configuration.addRoots(editor); + + ConfigLibraryUtil.addLibrary(editor, model); + } +} \ No newline at end of file