Introduce project descriptor for testing js configuration

This commit is contained in:
Nikolay Krasko
2013-04-02 19:51:29 +04:00
parent 84627700a2
commit a13d61e618
4 changed files with 121 additions and 24 deletions
@@ -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();
}
@@ -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<File, String> copyToPaths = new HashMap<File, String>();
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<File,File> copiedFiles =
FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths);
assert parentComponent != null : "Copying should be performed only when executed in GUI";
Map<File,File> copiedFiles = FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths);
if (copiedFiles == null) {
return null;
}
if (dialog.isCopyLibraryFiles()) {
if (copyLibraryIntoPath != null) {
libraryFile = copiedFiles.get(libraryFile);
}
}
@@ -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());
@@ -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);
}
}