diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java index 014e05a7a4e..3fd75fd0ec0 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java @@ -42,11 +42,12 @@ public class JSLibraryDescription extends CustomLibraryDescription { public static final String LIBRARY_NAME = "KotlinJavaScript"; private static final String JAVA_SCRIPT_LIBRARY_CREATION = "JavaScript Library Creation"; + private static final Set libraryKinds = Sets.newHashSet(KOTLIN_JAVASCRIPT_KIND); @NotNull @Override public Set getSuitableLibraryKinds() { - return Sets.newHashSet(KOTLIN_JAVASCRIPT_KIND); + return libraryKinds; } @Nullable @@ -55,53 +56,51 @@ public class JSLibraryDescription extends CustomLibraryDescription { CreateJavaScriptLibraryDialog dialog = new CreateJavaScriptLibraryDialog(null, "Create Kotlin JavaScript Library", contextDirectory); dialog.show(); - if (dialog.isOK()) { - KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin(); + if (!dialog.isOK()) return null; - File libraryFile = paths.getJsLibJarPath(); - if (!libraryFile.exists()) { - Messages.showErrorDialog(String.format("JavaScript standard library was not found in %s", paths.getLibPath()), - JAVA_SCRIPT_LIBRARY_CREATION); + KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin(); + + File libraryFile = paths.getJsLibJarPath(); + if (!libraryFile.exists()) { + Messages.showErrorDialog(String.format("JavaScript standard library was not found in %s", paths.getLibPath()), + JAVA_SCRIPT_LIBRARY_CREATION); + return null; + } + + Map copyToPaths = new HashMap(); + if (dialog.isCopyLibraryFiles()) { + String copyIntoPath = dialog.getCopyLibraryIntoPath(); + assert copyIntoPath != null; + + copyToPaths.put(libraryFile, copyIntoPath); + } + + if (dialog.isCopyJS()) { + String copyIntoPath = dialog.getCopyJsIntoPath(); + assert copyIntoPath != null; + + copyToPaths.put(paths.getJsLibJsPath(), copyIntoPath); + } + + if (!copyToPaths.isEmpty()) { + Map copiedFiles = + FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths); + if (copiedFiles == null) { return null; } - Map copyToPaths = new HashMap(); if (dialog.isCopyLibraryFiles()) { - String copyIntoPath = dialog.getCopyLibraryIntoPath(); - assert copyIntoPath != null; - - copyToPaths.put(libraryFile, copyIntoPath); + libraryFile = copiedFiles.get(libraryFile); } - - if (dialog.isCopyJS()) { - String copyIntoPath = dialog.getCopyJsIntoPath(); - assert copyIntoPath != null; - - copyToPaths.put(paths.getJsLibJsPath(), copyIntoPath); - } - - if (!copyToPaths.isEmpty()) { - Map copiedFiles = - FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths); - if (copiedFiles == null) { - return null; - } - - if (dialog.isCopyLibraryFiles()) { - libraryFile = copiedFiles.get(libraryFile); - } - } - - final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile); - return new NewLibraryConfiguration(LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) { - @Override - public void addRoots(@NotNull LibraryEditor editor) { - editor.addRoot(libraryFileUrl, OrderRootType.CLASSES); - editor.addRoot(libraryFileUrl, OrderRootType.SOURCES); - } - }; } - return null; + final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile); + return new NewLibraryConfiguration(LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) { + @Override + public void addRoots(@NotNull LibraryEditor editor) { + editor.addRoot(libraryFileUrl, OrderRootType.CLASSES); + editor.addRoot(libraryFileUrl, OrderRootType.SOURCES); + } + }; } } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java index dcacc91a0a1..6617f8b45ff 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java @@ -28,7 +28,6 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.plugin.JetPluginUtil; import org.jetbrains.jet.plugin.framework.ui.CreateJavaLibraryDialog; import org.jetbrains.jet.plugin.framework.ui.FileUIUtils; import org.jetbrains.jet.utils.KotlinPaths; @@ -43,11 +42,12 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription { public static final String LIBRARY_NAME = "KotlinJavaRuntime"; private static final String JAVA_RUNTIME_LIBRARY_CREATION = "Java Runtime Library Creation"; + private static final Set libraryKinds = Sets.newHashSet(KOTLIN_JAVA_RUNTIME_KIND); @NotNull @Override public Set getSuitableLibraryKinds() { - return Sets.newHashSet(KOTLIN_JAVA_RUNTIME_KIND); + return libraryKinds; } @Nullable @@ -56,36 +56,34 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription { CreateJavaLibraryDialog dialog = new CreateJavaLibraryDialog(null, "Create Kotlin Java Runtime Library", contextDirectory); dialog.show(); - if (dialog.isOK()) { - KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin(); + if (!dialog.isOK()) return null; - File libraryFile = paths.getRuntimePath(); - if (!libraryFile.exists()) { - Messages.showErrorDialog( - parentComponent, - String.format("Java Runtime library was not found in '%s'." , paths.getLibPath()), - JAVA_RUNTIME_LIBRARY_CREATION); - return null; - } + KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin(); - String copyIntoPath = dialog.getCopyIntoPath(); - if (copyIntoPath != null) { - libraryFile = FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_RUNTIME_LIBRARY_CREATION, copyIntoPath, libraryFile); - if (libraryFile == null) { - return null; - } - } - - final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile); - return new NewLibraryConfiguration(LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) { - @Override - public void addRoots(@NotNull LibraryEditor editor) { - editor.addRoot(libraryFileUrl, OrderRootType.CLASSES); - editor.addRoot(libraryFileUrl + "src", OrderRootType.SOURCES); - } - }; + File libraryFile = paths.getRuntimePath(); + if (!libraryFile.exists()) { + Messages.showErrorDialog( + parentComponent, + String.format("Java Runtime library was not found in '%s'." , paths.getLibPath()), + JAVA_RUNTIME_LIBRARY_CREATION); + return null; } - return null; + String copyIntoPath = dialog.getCopyIntoPath(); + if (copyIntoPath != null) { + libraryFile = FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_RUNTIME_LIBRARY_CREATION, copyIntoPath, libraryFile); + if (libraryFile == null) { + return null; + } + } + + final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile); + return new NewLibraryConfiguration(LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) { + @Override + public void addRoots(@NotNull LibraryEditor editor) { + editor.addRoot(libraryFileUrl, OrderRootType.CLASSES); + editor.addRoot(libraryFileUrl + "src", OrderRootType.SOURCES); + } + }; } } \ No newline at end of file