reuse for KotlinJS library common Library dialogs
remove unnecessary code for kotlin js library support JS backend: simplify check isConfigured for kotlin js module
This commit is contained in:
@@ -39,9 +39,6 @@ public interface KotlinPaths {
|
|||||||
@NotNull
|
@NotNull
|
||||||
File getAndroidSdkAnnotationsPath();
|
File getAndroidSdkAnnotationsPath();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
File getJsLibJsPath();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
File getJsLibJarPath();
|
File getJsLibJarPath();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,12 +64,6 @@ public class KotlinPathsFromHomeDir implements KotlinPaths {
|
|||||||
return getLibraryFile(PathUtil.ANDROID_SDK_ANNOTATIONS_JAR);
|
return getLibraryFile(PathUtil.ANDROID_SDK_ANNOTATIONS_JAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public File getJsLibJsPath() {
|
|
||||||
return getLibraryFile(PathUtil.JS_LIB_JS_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public File getJsLibJarPath() {
|
public File getJsLibJarPath() {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class PathUtil {
|
|||||||
public static final String JPS_KOTLIN_HOME_PROPERTY = "jps.kotlin.home";
|
public static final String JPS_KOTLIN_HOME_PROPERTY = "jps.kotlin.home";
|
||||||
|
|
||||||
public static final String JS_LIB_JAR_NAME = "kotlin-jslib.jar";
|
public static final String JS_LIB_JAR_NAME = "kotlin-jslib.jar";
|
||||||
public static final String JS_LIB_JS_NAME = "kotlin.js";
|
public static final String JS_LIB_SRC_JAR_NAME = "kotlin-jslib-sources.jar";
|
||||||
public static final String JDK_ANNOTATIONS_JAR = "kotlin-jdk-annotations.jar";
|
public static final String JDK_ANNOTATIONS_JAR = "kotlin-jdk-annotations.jar";
|
||||||
public static final String ANDROID_SDK_ANNOTATIONS_JAR = "kotlin-android-sdk-annotations.jar";
|
public static final String ANDROID_SDK_ANNOTATIONS_JAR = "kotlin-android-sdk-annotations.jar";
|
||||||
public static final String KOTLIN_JAVA_RUNTIME_JAR = "kotlin-runtime.jar";
|
public static final String KOTLIN_JAVA_RUNTIME_JAR = "kotlin-runtime.jar";
|
||||||
|
|||||||
@@ -20,12 +20,9 @@ import com.intellij.openapi.application.ApplicationManager;
|
|||||||
import com.intellij.openapi.module.Module;
|
import com.intellij.openapi.module.Module;
|
||||||
import com.intellij.openapi.module.ModuleManager;
|
import com.intellij.openapi.module.ModuleManager;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.OrderRootType;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.plugin.framework.JSLibraryStdDescription;
|
import org.jetbrains.jet.plugin.framework.JSLibraryStdDescription;
|
||||||
import org.jetbrains.jet.plugin.framework.ui.CreateJavaScriptLibraryDialogWithModules;
|
import org.jetbrains.jet.plugin.framework.ui.CreateLibraryDialogWithModules;
|
||||||
import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
|
|
||||||
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
||||||
import org.jetbrains.jet.utils.PathUtil;
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
import org.jetbrains.k2js.JavaScript;
|
import org.jetbrains.k2js.JavaScript;
|
||||||
@@ -51,11 +48,7 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConfigured(@NotNull Module module) {
|
public boolean isConfigured(@NotNull Module module) {
|
||||||
if (ProjectStructureUtil.isJsKotlinModule(module)) {
|
return ProjectStructureUtil.isJsKotlinModule(module);
|
||||||
String pathFromLibrary = getPathFromLibrary(module.getProject(), OrderRootType.CLASSES);
|
|
||||||
return pathFromLibrary != null && getFileInDir(getJarName(), pathFromLibrary).exists();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -72,8 +65,8 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected String getSourcesJarName() {
|
public String getSourcesJarName() {
|
||||||
return PathUtil.JS_LIB_JAR_NAME;
|
return PathUtil.JS_LIB_SRC_JAR_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -89,17 +82,14 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected File getExistedSourcesJarFile() {
|
public File getExistedSourcesJarFile() {
|
||||||
return getExistedJarFile();
|
return getExistedJarFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(@NotNull Project project) {
|
public void configure(@NotNull Project project) {
|
||||||
String defaultPathToJar = getDefaultPathToJarFile(project);
|
String defaultPathToJar = getDefaultPathToJarFile(project);
|
||||||
String defaultPathToJsFile = getDefaultPathToJsFile(project);
|
|
||||||
|
|
||||||
boolean showPathToJarPanel = needToChooseJarPath(project);
|
boolean showPathToJarPanel = needToChooseJarPath(project);
|
||||||
boolean showPathToJsFilePanel = needToChooseJsFilePath(project);
|
|
||||||
|
|
||||||
List<Module> nonConfiguredModules =
|
List<Module> nonConfiguredModules =
|
||||||
!ApplicationManager.getApplication().isUnitTestMode() ?
|
!ApplicationManager.getApplication().isUnitTestMode() ?
|
||||||
@@ -108,13 +98,12 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
|||||||
|
|
||||||
List<Module> modulesToConfigure = nonConfiguredModules;
|
List<Module> modulesToConfigure = nonConfiguredModules;
|
||||||
String copyLibraryIntoPath = null;
|
String copyLibraryIntoPath = null;
|
||||||
String jsFilesIntoPath = null;
|
|
||||||
|
|
||||||
if (nonConfiguredModules.size() > 1 || showPathToJarPanel || showPathToJsFilePanel) {
|
if (nonConfiguredModules.size() > 1 || showPathToJarPanel) {
|
||||||
CreateJavaScriptLibraryDialogWithModules dialog =
|
CreateLibraryDialogWithModules dialog = new CreateLibraryDialogWithModules(
|
||||||
new CreateJavaScriptLibraryDialogWithModules(project, nonConfiguredModules,
|
project, nonConfiguredModules, defaultPathToJar, showPathToJarPanel,
|
||||||
defaultPathToJar, defaultPathToJsFile,
|
JSLibraryStdDescription.DIALOG_TITLE,
|
||||||
showPathToJarPanel, showPathToJsFilePanel);
|
JSLibraryStdDescription.DIALOG_CAPTION);
|
||||||
|
|
||||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||||
dialog.show();
|
dialog.show();
|
||||||
@@ -122,46 +111,12 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
modulesToConfigure = dialog.getModulesToConfigure();
|
modulesToConfigure = dialog.getModulesToConfigure();
|
||||||
copyLibraryIntoPath = dialog.getCopyLibraryIntoPath();
|
copyLibraryIntoPath = dialog.getCopyIntoPath();
|
||||||
jsFilesIntoPath = dialog.getCopyJsIntoPath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Module module : modulesToConfigure) {
|
for (Module module : modulesToConfigure) {
|
||||||
configureModuleWithLibrary(module, defaultPathToJar, copyLibraryIntoPath);
|
configureModuleWithLibrary(module, defaultPathToJar, copyLibraryIntoPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
configureModuleWithJsFile(defaultPathToJsFile, jsFilesIntoPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isJsFilePresent(@NotNull String dir) {
|
|
||||||
return new File(dir + "/" + PathUtil.JS_LIB_JAR_NAME).exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public File getJsFile() {
|
|
||||||
return assertFileExists(PathUtil.getKotlinPathsForIdeaPlugin().getJsLibJsPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean needToChooseJsFilePath(@NotNull Project project) {
|
|
||||||
String defaultPath = FileUIUtils.createRelativePath(project, project.getBaseDir(), "script");
|
|
||||||
return !isJsFilePresent(defaultPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
protected String getDefaultPathToJsFile(@NotNull Project project) {
|
|
||||||
return FileUIUtils.createRelativePath(project, project.getBaseDir(), "script");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void configureModuleWithJsFile(
|
|
||||||
@NotNull String defaultPath,
|
|
||||||
@Nullable String pathToJsFromDialog
|
|
||||||
) {
|
|
||||||
boolean isJsFilePresent = isJsFilePresent(defaultPath);
|
|
||||||
if (isJsFilePresent) return;
|
|
||||||
|
|
||||||
if (pathToJsFromDialog != null) {
|
|
||||||
copyFileToDir(getJsFile(), pathToJsFromDialog);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KotlinJsModuleConfigurator() {
|
KotlinJsModuleConfigurator() {
|
||||||
|
|||||||
@@ -48,18 +48,18 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
protected abstract String getLibraryName();
|
protected abstract String getLibraryName();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected abstract String getJarName();
|
public abstract String getJarName();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected abstract String getSourcesJarName();
|
public abstract String getSourcesJarName();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected abstract String getMessageForOverrideDialog();
|
protected abstract String getMessageForOverrideDialog();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected abstract File getExistedJarFile();
|
public abstract File getExistedJarFile();
|
||||||
|
|
||||||
protected abstract File getExistedSourcesJarFile();
|
public abstract File getExistedSourcesJarFile();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(@NotNull Module module) {
|
public boolean isApplicable(@NotNull Module module) {
|
||||||
|
|||||||
+98
@@ -17,32 +17,67 @@
|
|||||||
package org.jetbrains.jet.plugin.framework;
|
package org.jetbrains.jet.plugin.framework;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.intellij.framework.library.LibraryVersionProperties;
|
||||||
import com.intellij.openapi.module.Module;
|
import com.intellij.openapi.module.Module;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||||
import com.intellij.openapi.roots.OrderRootType;
|
import com.intellij.openapi.roots.OrderRootType;
|
||||||
import com.intellij.openapi.roots.libraries.Library;
|
import com.intellij.openapi.roots.libraries.Library;
|
||||||
import com.intellij.openapi.roots.libraries.LibraryKind;
|
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.libraries.CustomLibraryDescription;
|
||||||
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
|
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
|
||||||
|
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import com.intellij.openapi.vfs.VfsUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import kotlin.Function1;
|
import kotlin.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.plugin.configuration.ConfigureKotlinInProjectUtils;
|
||||||
|
import org.jetbrains.jet.plugin.configuration.KotlinJavaModuleConfigurator;
|
||||||
import org.jetbrains.jet.plugin.configuration.KotlinWithLibraryConfigurator;
|
import org.jetbrains.jet.plugin.configuration.KotlinWithLibraryConfigurator;
|
||||||
|
import org.jetbrains.jet.plugin.framework.ui.CreateLibraryDialog;
|
||||||
|
import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
|
||||||
import org.jetbrains.jet.plugin.util.projectStructure.ProjectStructurePackage;
|
import org.jetbrains.jet.plugin.util.projectStructure.ProjectStructurePackage;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.plugin.configuration.KotlinWithLibraryConfigurator.getFileInDir;
|
||||||
|
|
||||||
public abstract class CustomLibraryDescriptorWithDefferConfig extends CustomLibraryDescription {
|
public abstract class CustomLibraryDescriptorWithDefferConfig extends CustomLibraryDescription {
|
||||||
|
|
||||||
|
private static final String DEFAULT_LIB_DIR_NAME = "lib";
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public abstract LibraryKind getLibraryKind();
|
public abstract LibraryKind getLibraryKind();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract DeferredCopyFileRequests getCopyFileRequests();
|
public abstract DeferredCopyFileRequests getCopyFileRequests();
|
||||||
|
|
||||||
|
protected final boolean useRelativePaths;
|
||||||
|
|
||||||
|
protected DeferredCopyFileRequests deferredCopyFileRequests;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected abstract String getLibraryName();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected abstract String getDialogTitle();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected abstract String getDialogCaption();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param project null when project doesn't exist yet (called from project wizard)
|
||||||
|
*/
|
||||||
|
public CustomLibraryDescriptorWithDefferConfig(@Nullable Project project) {
|
||||||
|
useRelativePaths = project == null;
|
||||||
|
}
|
||||||
|
|
||||||
public void finishLibConfiguration(@NotNull Module module, @NotNull ModifiableRootModel rootModel) {
|
public void finishLibConfiguration(@NotNull Module module, @NotNull ModifiableRootModel rootModel) {
|
||||||
DeferredCopyFileRequests deferredCopyFileRequests = getCopyFileRequests();
|
DeferredCopyFileRequests deferredCopyFileRequests = getCopyFileRequests();
|
||||||
if (deferredCopyFileRequests == null) return;
|
if (deferredCopyFileRequests == null) return;
|
||||||
@@ -112,4 +147,67 @@ public abstract class CustomLibraryDescriptorWithDefferConfig extends CustomLibr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
||||||
|
KotlinWithLibraryConfigurator configurator =
|
||||||
|
(KotlinWithLibraryConfigurator) ConfigureKotlinInProjectUtils.getConfiguratorByName(KotlinJavaModuleConfigurator.NAME);
|
||||||
|
assert configurator != null : "Configurator with name " + KotlinJavaModuleConfigurator.NAME + " should exists";
|
||||||
|
|
||||||
|
deferredCopyFileRequests = new DeferredCopyFileRequests(configurator);
|
||||||
|
|
||||||
|
String defaultPathToJarFile = useRelativePaths ? DEFAULT_LIB_DIR_NAME
|
||||||
|
: FileUIUtils.createRelativePath(null, contextDirectory, DEFAULT_LIB_DIR_NAME);
|
||||||
|
|
||||||
|
File bundledLibJarFile = configurator.getExistedJarFile();
|
||||||
|
File bundledLibSourcesJarFile = configurator.getExistedSourcesJarFile();
|
||||||
|
|
||||||
|
File libraryFile;
|
||||||
|
File librarySrcFile;
|
||||||
|
|
||||||
|
File stdJarInDefaultPath = getFileInDir(configurator.getJarName(), defaultPathToJarFile);
|
||||||
|
if (!useRelativePaths && stdJarInDefaultPath.exists()) {
|
||||||
|
libraryFile = stdJarInDefaultPath;
|
||||||
|
|
||||||
|
File sourcesJar = getFileInDir(configurator.getSourcesJarName(), defaultPathToJarFile);
|
||||||
|
if (sourcesJar.exists()) {
|
||||||
|
librarySrcFile = sourcesJar;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
deferredCopyFileRequests.addCopyWithReplaceRequest(bundledLibSourcesJarFile, libraryFile.getParent());
|
||||||
|
librarySrcFile = bundledLibSourcesJarFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
CreateLibraryDialog dialog =new CreateLibraryDialog(defaultPathToJarFile, getDialogTitle(), getDialogCaption());
|
||||||
|
dialog.show();
|
||||||
|
|
||||||
|
if (!dialog.isOK()) return null;
|
||||||
|
|
||||||
|
String copyIntoPath = dialog.getCopyIntoPath();
|
||||||
|
if (copyIntoPath != null) {
|
||||||
|
deferredCopyFileRequests.addCopyWithReplaceRequest(bundledLibJarFile, copyIntoPath);
|
||||||
|
deferredCopyFileRequests.addCopyWithReplaceRequest(bundledLibSourcesJarFile, copyIntoPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
libraryFile = bundledLibJarFile;
|
||||||
|
librarySrcFile = bundledLibSourcesJarFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
return createConfiguration(libraryFile, librarySrcFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected NewLibraryConfiguration createConfiguration(@NotNull File libraryFile, @NotNull File librarySrcFile) {
|
||||||
|
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
|
||||||
|
final String libraryFileSrcUrl = VfsUtil.getUrlForLibraryRoot(librarySrcFile);
|
||||||
|
|
||||||
|
return new NewLibraryConfiguration(getLibraryName(), null, new LibraryVersionProperties()) {
|
||||||
|
@Override
|
||||||
|
public void addRoots(@NotNull LibraryEditor editor) {
|
||||||
|
editor.addRoot(libraryFileUrl, OrderRootType.CLASSES);
|
||||||
|
editor.addRoot(libraryFileSrcUrl, OrderRootType.SOURCES);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,45 +17,51 @@
|
|||||||
package org.jetbrains.jet.plugin.framework;
|
package org.jetbrains.jet.plugin.framework;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.framework.library.LibraryVersionProperties;
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.OrderRootType;
|
|
||||||
import com.intellij.openapi.roots.libraries.LibraryKind;
|
import com.intellij.openapi.roots.libraries.LibraryKind;
|
||||||
import com.intellij.openapi.roots.libraries.NewLibraryConfiguration;
|
import com.intellij.openapi.roots.libraries.NewLibraryConfiguration;
|
||||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
|
||||||
import com.intellij.openapi.vfs.VfsUtil;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.TestOnly;
|
import org.jetbrains.annotations.TestOnly;
|
||||||
import org.jetbrains.jet.plugin.configuration.KotlinJsModuleConfigurator;
|
import org.jetbrains.jet.plugin.configuration.KotlinJsModuleConfigurator;
|
||||||
import org.jetbrains.jet.plugin.framework.ui.CreateJavaScriptLibraryDialog;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.jet.plugin.configuration.ConfigureKotlinInProjectUtils.getConfiguratorByName;
|
import static org.jetbrains.jet.plugin.configuration.ConfigureKotlinInProjectUtils.getConfiguratorByName;
|
||||||
import static org.jetbrains.jet.plugin.configuration.KotlinJsModuleConfigurator.NAME;
|
import static org.jetbrains.jet.plugin.configuration.KotlinJsModuleConfigurator.NAME;
|
||||||
import static org.jetbrains.jet.plugin.configuration.KotlinJsModuleConfigurator.isJsFilePresent;
|
|
||||||
import static org.jetbrains.jet.plugin.configuration.KotlinWithLibraryConfigurator.getFileInDir;
|
|
||||||
import static org.jetbrains.jet.plugin.framework.ui.FileUIUtils.createRelativePath;
|
|
||||||
|
|
||||||
public class JSLibraryStdDescription extends CustomLibraryDescriptorWithDefferConfig {
|
public class JSLibraryStdDescription extends CustomLibraryDescriptorWithDefferConfig {
|
||||||
public static final LibraryKind KOTLIN_JAVASCRIPT_KIND = LibraryKind.create("kotlin-js-stdlib");
|
public static final LibraryKind KOTLIN_JAVASCRIPT_KIND = LibraryKind.create("kotlin-js-stdlib");
|
||||||
public static final String LIBRARY_NAME = "KotlinJavaScript";
|
public static final String LIBRARY_NAME = "KotlinJavaScript";
|
||||||
|
|
||||||
public static final String JAVA_SCRIPT_LIBRARY_CREATION = "JavaScript Library Creation";
|
public static final String JAVA_SCRIPT_LIBRARY_CREATION = "JavaScript Library Creation";
|
||||||
|
public static final String DIALOG_TITLE = "Create Kotlin JavaScript Library";
|
||||||
|
public static final String DIALOG_CAPTION = "Kotlin JavaScript Library";
|
||||||
public static final Set<LibraryKind> SUITABLE_LIBRARY_KINDS = Sets.newHashSet(KOTLIN_JAVASCRIPT_KIND);
|
public static final Set<LibraryKind> SUITABLE_LIBRARY_KINDS = Sets.newHashSet(KOTLIN_JAVASCRIPT_KIND);
|
||||||
|
|
||||||
private static final String DEFAULT_LIB_DIR_NAME = "lib";
|
/**
|
||||||
private static final String DEFAULT_SCRIPT_DIR_NAME = "script";
|
* @param project null when project doesn't exist yet (called from project wizard)
|
||||||
|
*/
|
||||||
private final boolean useRelativePaths;
|
|
||||||
private DeferredCopyFileRequests deferredCopyFileRequests;
|
|
||||||
|
|
||||||
public JSLibraryStdDescription(@Nullable Project project) {
|
public JSLibraryStdDescription(@Nullable Project project) {
|
||||||
useRelativePaths = project == null;
|
super(project);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getLibraryName() {
|
||||||
|
return LIBRARY_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getDialogTitle() {
|
||||||
|
return DIALOG_TITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getDialogCaption() {
|
||||||
|
return DIALOG_CAPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -76,68 +82,11 @@ public class JSLibraryStdDescription extends CustomLibraryDescriptorWithDefferCo
|
|||||||
return deferredCopyFileRequests;
|
return deferredCopyFileRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
|
||||||
KotlinJsModuleConfigurator jsConfigurator = (KotlinJsModuleConfigurator) getConfiguratorByName(NAME);
|
|
||||||
assert jsConfigurator != null : "Cannot find configurator with name " + NAME;
|
|
||||||
|
|
||||||
deferredCopyFileRequests = new DeferredCopyFileRequests(jsConfigurator);
|
|
||||||
|
|
||||||
String defaultPathToJsFileDir =
|
|
||||||
useRelativePaths ? DEFAULT_SCRIPT_DIR_NAME : createRelativePath(null, contextDirectory, DEFAULT_SCRIPT_DIR_NAME);
|
|
||||||
String defaultPathToJarFileDir =
|
|
||||||
useRelativePaths ? DEFAULT_LIB_DIR_NAME : createRelativePath(null, contextDirectory, DEFAULT_LIB_DIR_NAME);
|
|
||||||
|
|
||||||
boolean jsFilePresent = !useRelativePaths && isJsFilePresent(defaultPathToJsFileDir);
|
|
||||||
boolean jarFilePresent = !useRelativePaths && getFileInDir(jsConfigurator.getJarName(), defaultPathToJarFileDir).exists();
|
|
||||||
|
|
||||||
if (jarFilePresent && jsFilePresent) {
|
|
||||||
return createConfiguration(getFileInDir(jsConfigurator.getJarName(), defaultPathToJarFileDir));
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateJavaScriptLibraryDialog dialog =
|
|
||||||
new CreateJavaScriptLibraryDialog(defaultPathToJarFileDir, defaultPathToJsFileDir, !jarFilePresent, !jsFilePresent);
|
|
||||||
dialog.show();
|
|
||||||
|
|
||||||
if (!dialog.isOK()) return null;
|
|
||||||
|
|
||||||
String copyJsFileIntoPath = dialog.getCopyJsIntoPath();
|
|
||||||
if (!jsFilePresent && copyJsFileIntoPath != null) {
|
|
||||||
deferredCopyFileRequests.addCopyRequest(jsConfigurator.getJsFile(), copyJsFileIntoPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jarFilePresent) {
|
|
||||||
return createConfiguration(getFileInDir(jsConfigurator.getJarName(), defaultPathToJarFileDir));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
String copyIntoPath = dialog.getCopyLibraryIntoPath();
|
|
||||||
File existedJarFile = jsConfigurator.getExistedJarFile();
|
|
||||||
|
|
||||||
if (copyIntoPath != null) {
|
|
||||||
deferredCopyFileRequests.addCopyWithReplaceRequest(existedJarFile, copyIntoPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return createConfiguration(existedJarFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestOnly
|
@TestOnly
|
||||||
public NewLibraryConfiguration createNewLibraryForTests() {
|
public NewLibraryConfiguration createNewLibraryForTests() {
|
||||||
KotlinJsModuleConfigurator configurator = (KotlinJsModuleConfigurator) getConfiguratorByName(NAME);
|
KotlinJsModuleConfigurator configurator = (KotlinJsModuleConfigurator) getConfiguratorByName(NAME);
|
||||||
assert configurator != null : "Cannot find configurator with name " + NAME;
|
assert configurator != null : "Cannot find configurator with name " + NAME;
|
||||||
|
|
||||||
return createConfiguration(configurator.getExistedJarFile());
|
return createConfiguration(configurator.getExistedJarFile(), configurator.getExistedJarFile());
|
||||||
}
|
|
||||||
|
|
||||||
private NewLibraryConfiguration createConfiguration(@NotNull File libraryFile) {
|
|
||||||
final String libraryRoot = VfsUtil.getUrlForLibraryRoot(libraryFile);
|
|
||||||
return new NewLibraryConfiguration(LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) {
|
|
||||||
@Override
|
|
||||||
public void addRoots(@NotNull LibraryEditor editor) {
|
|
||||||
editor.addRoot(libraryRoot, OrderRootType.CLASSES);
|
|
||||||
editor.addRoot(libraryRoot, OrderRootType.SOURCES);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,27 +17,13 @@
|
|||||||
package org.jetbrains.jet.plugin.framework;
|
package org.jetbrains.jet.plugin.framework;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.framework.library.LibraryVersionProperties;
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.OrderRootType;
|
|
||||||
import com.intellij.openapi.roots.libraries.LibraryKind;
|
import com.intellij.openapi.roots.libraries.LibraryKind;
|
||||||
import com.intellij.openapi.roots.libraries.NewLibraryConfiguration;
|
|
||||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
|
||||||
import com.intellij.openapi.vfs.VfsUtil;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.plugin.configuration.ConfigureKotlinInProjectUtils;
|
|
||||||
import org.jetbrains.jet.plugin.configuration.KotlinJavaModuleConfigurator;
|
|
||||||
import org.jetbrains.jet.plugin.framework.ui.CreateLibraryDialog;
|
|
||||||
import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.jet.plugin.configuration.KotlinWithLibraryConfigurator.getFileInDir;
|
|
||||||
|
|
||||||
public class JavaRuntimeLibraryDescription extends CustomLibraryDescriptorWithDefferConfig {
|
public class JavaRuntimeLibraryDescription extends CustomLibraryDescriptorWithDefferConfig {
|
||||||
public static final LibraryKind KOTLIN_JAVA_RUNTIME_KIND = LibraryKind.create("kotlin-java-runtime");
|
public static final LibraryKind KOTLIN_JAVA_RUNTIME_KIND = LibraryKind.create("kotlin-java-runtime");
|
||||||
public static final String LIBRARY_NAME = "KotlinJavaRuntime";
|
public static final String LIBRARY_NAME = "KotlinJavaRuntime";
|
||||||
@@ -47,17 +33,29 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescriptorWithDe
|
|||||||
public static final String DIALOG_CAPTION = "Kotlin Java Runtime Library";
|
public static final String DIALOG_CAPTION = "Kotlin Java Runtime Library";
|
||||||
public static final Set<LibraryKind> SUITABLE_LIBRARY_KINDS = Sets.newHashSet(KOTLIN_JAVA_RUNTIME_KIND);
|
public static final Set<LibraryKind> SUITABLE_LIBRARY_KINDS = Sets.newHashSet(KOTLIN_JAVA_RUNTIME_KIND);
|
||||||
|
|
||||||
private static final String DEFAULT_LIB_DIR_NAME = "lib";
|
|
||||||
|
|
||||||
private final boolean useRelativePaths;
|
|
||||||
|
|
||||||
private DeferredCopyFileRequests deferredCopyFileRequests = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param project null when project doesn't exist yet (called from project wizard)
|
* @param project null when project doesn't exist yet (called from project wizard)
|
||||||
*/
|
*/
|
||||||
public JavaRuntimeLibraryDescription(@Nullable Project project) {
|
public JavaRuntimeLibraryDescription(@Nullable Project project) {
|
||||||
useRelativePaths = project == null;
|
super(project);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getLibraryName() {
|
||||||
|
return LIBRARY_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getDialogTitle() {
|
||||||
|
return DIALOG_TITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getDialogCaption() {
|
||||||
|
return DIALOG_CAPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -77,63 +75,4 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescriptorWithDe
|
|||||||
public DeferredCopyFileRequests getCopyFileRequests() {
|
public DeferredCopyFileRequests getCopyFileRequests() {
|
||||||
return deferredCopyFileRequests;
|
return deferredCopyFileRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
|
||||||
KotlinJavaModuleConfigurator jvmConfigurator =
|
|
||||||
(KotlinJavaModuleConfigurator) ConfigureKotlinInProjectUtils.getConfiguratorByName(KotlinJavaModuleConfigurator.NAME);
|
|
||||||
assert jvmConfigurator != null : "Configurator with name " + KotlinJavaModuleConfigurator.NAME + " should exists";
|
|
||||||
|
|
||||||
deferredCopyFileRequests = new DeferredCopyFileRequests(jvmConfigurator);
|
|
||||||
|
|
||||||
String defaultPathToJarFile = useRelativePaths ? DEFAULT_LIB_DIR_NAME
|
|
||||||
: FileUIUtils.createRelativePath(null, contextDirectory, DEFAULT_LIB_DIR_NAME);
|
|
||||||
|
|
||||||
File bundledLibJarFile = jvmConfigurator.getExistedJarFile();
|
|
||||||
File bundledLibSourcesJarFile = jvmConfigurator.getExistedSourcesJarFile();
|
|
||||||
|
|
||||||
File libraryFile;
|
|
||||||
File librarySrcFile;
|
|
||||||
|
|
||||||
File stdJarInDefaultPath = getFileInDir(jvmConfigurator.getJarName(), defaultPathToJarFile);
|
|
||||||
if (!useRelativePaths && stdJarInDefaultPath.exists()) {
|
|
||||||
libraryFile = stdJarInDefaultPath;
|
|
||||||
|
|
||||||
File sourcesJar = getFileInDir(jvmConfigurator.getSourcesJarName(), defaultPathToJarFile);
|
|
||||||
if (sourcesJar.exists()) {
|
|
||||||
librarySrcFile = sourcesJar;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
deferredCopyFileRequests.addCopyWithReplaceRequest(bundledLibSourcesJarFile, libraryFile.getParent());
|
|
||||||
librarySrcFile = bundledLibSourcesJarFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
CreateLibraryDialog dialog =new CreateLibraryDialog(defaultPathToJarFile, DIALOG_TITLE, DIALOG_CAPTION);
|
|
||||||
dialog.show();
|
|
||||||
|
|
||||||
if (!dialog.isOK()) return null;
|
|
||||||
|
|
||||||
String copyIntoPath = dialog.getCopyIntoPath();
|
|
||||||
if (copyIntoPath != null) {
|
|
||||||
deferredCopyFileRequests.addCopyWithReplaceRequest(bundledLibJarFile, copyIntoPath);
|
|
||||||
deferredCopyFileRequests.addCopyWithReplaceRequest(bundledLibSourcesJarFile, copyIntoPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
libraryFile = bundledLibJarFile;
|
|
||||||
librarySrcFile = bundledLibSourcesJarFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
|
|
||||||
final String libraryFileSrcUrl = VfsUtil.getUrlForLibraryRoot(librarySrcFile);
|
|
||||||
|
|
||||||
return new NewLibraryConfiguration(LIBRARY_NAME, null, new LibraryVersionProperties()) {
|
|
||||||
@Override
|
|
||||||
public void addRoots(@NotNull LibraryEditor editor) {
|
|
||||||
editor.addRoot(libraryFileUrl, OrderRootType.CLASSES);
|
|
||||||
editor.addRoot(libraryFileSrcUrl, OrderRootType.SOURCES);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.plugin.framework.JSLibraryCreateOptions;
|
|
||||||
|
|
||||||
public class CreateJavaScriptLibraryDialog extends CreateJavaScriptLibraryDialogBase implements JSLibraryCreateOptions {
|
|
||||||
|
|
||||||
public CreateJavaScriptLibraryDialog(
|
|
||||||
@NotNull String defaultPathToJar,
|
|
||||||
@NotNull String defaultPathToJsFile,
|
|
||||||
boolean showPathToJarPanel,
|
|
||||||
boolean showPathToJsFilePanel
|
|
||||||
) {
|
|
||||||
super(null, defaultPathToJar, defaultPathToJsFile, showPathToJarPanel, showPathToJsFilePanel);
|
|
||||||
updateComponents();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
<?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.CreateJavaScriptLibraryDialogBase">
|
|
||||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="6" 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="48" y="54" width="436" height="297"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<vspacer id="bb37c">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" 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="982e8" class="javax.swing.JLabel" binding="compilerTextLabel">
|
|
||||||
<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="Using compiler bundled into plugin"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<grid id="beed7" binding="chooseModulesPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<grid id="486ab" binding="copyLibraryPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
|
||||||
<constraints>
|
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<grid id="11e35" binding="copyJsFilesPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
|
||||||
<constraints>
|
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children/>
|
|
||||||
</grid>
|
|
||||||
<component id="89994" class="com.intellij.ui.SeparatorWithText" binding="modulesSeparator">
|
|
||||||
<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/>
|
|
||||||
</component>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
<buttonGroups>
|
|
||||||
<group name="sourceGroup">
|
|
||||||
<member id="730af"/>
|
|
||||||
<member id="c709f"/>
|
|
||||||
</group>
|
|
||||||
</buttonGroups>
|
|
||||||
</form>
|
|
||||||
-114
@@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.project.Project;
|
|
||||||
import com.intellij.openapi.ui.DialogWrapper;
|
|
||||||
import com.intellij.ui.SeparatorWithText;
|
|
||||||
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.*;
|
|
||||||
|
|
||||||
public abstract class CreateJavaScriptLibraryDialogBase extends DialogWrapper implements JSLibraryCreateOptions {
|
|
||||||
protected final CopyIntoPanel copyJsFilesPanel;
|
|
||||||
protected final CopyIntoPanel copyLibraryFilePanel;
|
|
||||||
|
|
||||||
protected JPanel contentPane;
|
|
||||||
|
|
||||||
protected JLabel compilerTextLabel;
|
|
||||||
protected JPanel chooseModulesPlace;
|
|
||||||
|
|
||||||
private SeparatorWithText modulesSeparator;
|
|
||||||
|
|
||||||
protected JPanel copyJsFilesPlace;
|
|
||||||
protected JPanel copyLibraryPlace;
|
|
||||||
|
|
||||||
public CreateJavaScriptLibraryDialogBase(
|
|
||||||
@Nullable Project project,
|
|
||||||
@NotNull String defaultPathToJar,
|
|
||||||
@NotNull String defaultPathToJsFile,
|
|
||||||
boolean showPathToJarPanel,
|
|
||||||
boolean showPathToJsFilePanel
|
|
||||||
) {
|
|
||||||
super(project);
|
|
||||||
|
|
||||||
setTitle("Create Kotlin JavaScript Library");
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
compilerTextLabel.setText(compilerTextLabel.getText() + " - " + JetPluginUtil.getPluginVersion());
|
|
||||||
|
|
||||||
modulesSeparator.setCaption("Kotlin JavaScript Library");
|
|
||||||
|
|
||||||
ValidityListener validityListener = new ValidityListener() {
|
|
||||||
@Override
|
|
||||||
public void validityChanged(boolean isValid) {
|
|
||||||
updateComponents();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
copyJsFilesPanel = new CopyIntoPanel(project, defaultPathToJsFile, "Copy &runtime files to:");
|
|
||||||
copyJsFilesPanel.addValidityListener(validityListener);
|
|
||||||
copyJsFilesPanel.setLabelWidth(110);
|
|
||||||
copyJsFilesPlace.add(copyJsFilesPanel.getContentPane(), BorderLayout.CENTER);
|
|
||||||
|
|
||||||
copyLibraryFilePanel = new CopyIntoPanel(project, defaultPathToJar, "Copy &headers to:");
|
|
||||||
copyLibraryFilePanel.addValidityListener(validityListener);
|
|
||||||
copyLibraryFilePanel.setLabelWidth(110);
|
|
||||||
copyLibraryPlace.add(copyLibraryFilePanel.getContentPane(), BorderLayout.CENTER);
|
|
||||||
|
|
||||||
if (!showPathToJarPanel) {
|
|
||||||
copyLibraryPlace.setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!showPathToJsFilePanel) {
|
|
||||||
copyJsFilesPlace.setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!showPathToJarPanel && !showPathToJsFilePanel) {
|
|
||||||
modulesSeparator.setVisible(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public String getCopyJsIntoPath() {
|
|
||||||
if (!copyJsFilesPlace.isVisible()) return null;
|
|
||||||
return copyJsFilesPanel.getPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public String getCopyLibraryIntoPath() {
|
|
||||||
if (!copyLibraryPlace.isVisible()) return null;
|
|
||||||
return copyLibraryFilePanel.getPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateComponents() {
|
|
||||||
setOKActionEnabled(!copyJsFilesPanel.hasErrors() && !copyLibraryFilePanel.hasErrors());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
protected JComponent createCenterPanel() {
|
|
||||||
return contentPane;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-50
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.module.Module;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.plugin.framework.JSLibraryCreateOptions;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CreateJavaScriptLibraryDialogWithModules extends CreateJavaScriptLibraryDialogBase implements JSLibraryCreateOptions {
|
|
||||||
|
|
||||||
private final ChooseModulePanel chooseModulePanel;
|
|
||||||
|
|
||||||
public CreateJavaScriptLibraryDialogWithModules(
|
|
||||||
@NotNull Project project,
|
|
||||||
@NotNull List<Module> modules,
|
|
||||||
@NotNull String defaultPathToJar,
|
|
||||||
@NotNull String defaultPathToJsFile,
|
|
||||||
boolean showPathToJarPanel,
|
|
||||||
boolean showPathToJsFilePanel
|
|
||||||
) {
|
|
||||||
super(project, defaultPathToJar, defaultPathToJsFile, showPathToJarPanel, showPathToJsFilePanel);
|
|
||||||
|
|
||||||
chooseModulePanel = new ChooseModulePanel(project, modules);
|
|
||||||
chooseModulesPlace.add(chooseModulePanel.getContentPane(), BorderLayout.CENTER);
|
|
||||||
|
|
||||||
updateComponents();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Module> getModulesToConfigure() {
|
|
||||||
return chooseModulePanel.getModulesToConfigure();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -51,12 +51,6 @@ public class ConfigureKotlinTest extends PlatformTestCase {
|
|||||||
protected String getDefaultPathToJarFile(@NotNull Project project) {
|
protected String getDefaultPathToJarFile(@NotNull Project project) {
|
||||||
return getPathRelativeToTemp("default_js_lib");
|
return getPathRelativeToTemp("default_js_lib");
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected String getDefaultPathToJsFile(@NotNull Project project) {
|
|
||||||
return getPathRelativeToTemp("default_script");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -180,7 +174,7 @@ public class ConfigureKotlinTest extends PlatformTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doTestConfigureModulesWithNonDefaultSetup(KotlinWithLibraryConfigurator configurator) {
|
private void doTestConfigureModulesWithNonDefaultSetup(KotlinWithLibraryConfigurator configurator) {
|
||||||
assertNoFilesInDefaultPaths(true);
|
assertNoFilesInDefaultPaths();
|
||||||
|
|
||||||
Module[] modules = getModules();
|
Module[] modules = getModules();
|
||||||
for (Module module : modules) {
|
for (Module module : modules) {
|
||||||
@@ -189,7 +183,7 @@ public class ConfigureKotlinTest extends PlatformTestCase {
|
|||||||
|
|
||||||
configurator.configure(myProject);
|
configurator.configure(myProject);
|
||||||
|
|
||||||
assertNoFilesInDefaultPaths(false);
|
assertNoFilesInDefaultPaths();
|
||||||
|
|
||||||
for (Module module : modules) {
|
for (Module module : modules) {
|
||||||
assertProperlyConfigured(module, configurator);
|
assertProperlyConfigured(module, configurator);
|
||||||
@@ -310,13 +304,9 @@ public class ConfigureKotlinTest extends PlatformTestCase {
|
|||||||
protected void setUpModule() {
|
protected void setUpModule() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNoFilesInDefaultPaths(boolean checkJsFiles) {
|
private void assertNoFilesInDefaultPaths() {
|
||||||
assertDoesntExist(new File(JAVA_CONFIGURATOR.getDefaultPathToJarFile(getProject())));
|
assertDoesntExist(new File(JAVA_CONFIGURATOR.getDefaultPathToJarFile(getProject())));
|
||||||
assertDoesntExist(new File(JS_CONFIGURATOR.getDefaultPathToJarFile(getProject())));
|
assertDoesntExist(new File(JS_CONFIGURATOR.getDefaultPathToJarFile(getProject())));
|
||||||
|
|
||||||
if (checkJsFiles) {
|
|
||||||
assertDoesntExist(new File(JS_CONFIGURATOR.getDefaultPathToJsFile(getProject())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertNotConfigured(Module module, KotlinWithLibraryConfigurator configurator) {
|
private static void assertNotConfigured(Module module, KotlinWithLibraryConfigurator configurator) {
|
||||||
|
|||||||
Reference in New Issue
Block a user