SetUpJSModuleAction puts library jar under "lib" directory. Set up kotlin runtime notification suggests setting up JS module as well as JVM.
This commit is contained in:
@@ -27,6 +27,7 @@ import com.intellij.openapi.roots.ModuleRootManager;
|
|||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.plugin.k2jsrun.K2JSRunnerUtils;
|
import org.jetbrains.jet.plugin.k2jsrun.K2JSRunnerUtils;
|
||||||
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
||||||
import org.jetbrains.jet.utils.PathUtil;
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
@@ -42,7 +43,13 @@ import static org.jetbrains.jet.plugin.k2jsrun.K2JSRunnerUtils.copyFileToDir;
|
|||||||
public final class SetUpJsModuleAction extends AnAction {
|
public final class SetUpJsModuleAction extends AnAction {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(AnActionEvent event) {
|
public void actionPerformed(AnActionEvent event) {
|
||||||
Project project = event.getProject();
|
if (event == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
doSetUpModule(event.getProject());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void doSetUpModule(@Nullable Project project) {
|
||||||
if (project == null) {
|
if (project == null) {
|
||||||
notifyFailure("Internal error: Project not found.");
|
notifyFailure("Internal error: Project not found.");
|
||||||
return;
|
return;
|
||||||
@@ -74,12 +81,12 @@ public final class SetUpJsModuleAction extends AnAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void refreshRootDir(@NotNull Project project) {
|
private static void refreshRootDir(@NotNull Project project) {
|
||||||
getContentRoot(project).refresh(true, false);
|
getContentRoot(project).refresh(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createIndicationFile(@NotNull File file) {
|
private static void createIndicationFile(@NotNull File file) {
|
||||||
try {
|
try {
|
||||||
FileUtil.writeToFile(file, PathUtil.JS_LIB_JAR_NAME);
|
FileUtil.writeToFile(file, "lib/" + PathUtil.JS_LIB_JAR_NAME);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
notifyFailure("Failed to write file " + file.getName());
|
notifyFailure("Failed to write file " + file.getName());
|
||||||
@@ -88,7 +95,7 @@ public final class SetUpJsModuleAction extends AnAction {
|
|||||||
|
|
||||||
private static boolean copyJsLib(@NotNull File jsLibPath, @NotNull File rootDir) {
|
private static boolean copyJsLib(@NotNull File jsLibPath, @NotNull File rootDir) {
|
||||||
try {
|
try {
|
||||||
copyFileToDir(jsLibPath, rootDir);
|
copyFileToDir(jsLibPath, new File(rootDir, "lib"));
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
notifyFailure("Failed to copy file: " + e.getMessage());
|
notifyFailure("Failed to copy file: " + e.getMessage());
|
||||||
|
|||||||
+42
-23
@@ -50,14 +50,14 @@ import com.intellij.ui.EditorNotificationPanel;
|
|||||||
import com.intellij.ui.EditorNotifications;
|
import com.intellij.ui.EditorNotifications;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
import org.jetbrains.jet.plugin.actions.SetUpJsModuleAction;
|
||||||
import org.jetbrains.jet.utils.PathUtil;
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.jetbrains.jet.plugin.project.JsModuleDetector.*;
|
import static org.jetbrains.jet.plugin.project.JsModuleDetector.isJsProject;
|
||||||
|
|
||||||
public class ConfigureKotlinLibraryNotificationProvider implements EditorNotifications.Provider<EditorNotificationPanel> {
|
public class ConfigureKotlinLibraryNotificationProvider implements EditorNotifications.Provider<EditorNotificationPanel> {
|
||||||
private static final Key<EditorNotificationPanel> KEY = Key.create("configure.kotlin.library");
|
private static final Key<EditorNotificationPanel> KEY = Key.create("configure.kotlin.library");
|
||||||
@@ -155,36 +155,55 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific
|
|||||||
private EditorNotificationPanel createNotificationPanel(final Module module) {
|
private EditorNotificationPanel createNotificationPanel(final Module module) {
|
||||||
final EditorNotificationPanel answer = new EditorNotificationPanel();
|
final EditorNotificationPanel answer = new EditorNotificationPanel();
|
||||||
|
|
||||||
answer.setText("Kotlin runtime library is not configured for module '" + module.getName() + "'");
|
answer.setText("Kotlin is not configured for module '" + module.getName() + "'");
|
||||||
answer.createActionLabel("Setup Kotlin Runtime", new Runnable() {
|
answer.createActionLabel("Set Up module '" + module.getName() + "' as JVM Kotlin module", new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
setUpKotlinRuntime(module);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
answer.createActionLabel("Set Up module '" + module.getName() + "' as JavaScript Kotlin module", new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Library library = findOrCreateRuntimeLibrary(module);
|
setUpJSModule(module);
|
||||||
if (library != null) {
|
|
||||||
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
|
||||||
if (model.findLibraryOrderEntry(library) == null) {
|
|
||||||
model.addLibraryEntry(library);
|
|
||||||
model.commit();
|
|
||||||
}
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
EditorNotifications.getInstance(myProject).updateAllNotifications();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUpJSModule(@NotNull Module module) {
|
||||||
|
SetUpJsModuleAction.doSetUpModule(module.getProject());
|
||||||
|
updateNotifications();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpKotlinRuntime(@NotNull final Module module) {
|
||||||
|
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Library library = findOrCreateRuntimeLibrary(module);
|
||||||
|
if (library != null) {
|
||||||
|
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||||
|
if (model.findLibraryOrderEntry(library) == null) {
|
||||||
|
model.addLibraryEntry(library);
|
||||||
|
model.commit();
|
||||||
|
}
|
||||||
|
updateNotifications();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateNotifications() {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
EditorNotifications.getInstance(myProject).updateAllNotifications();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isMavenModule(@NotNull Module module) {
|
private static boolean isMavenModule(@NotNull Module module) {
|
||||||
for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
|
for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
|
||||||
if (root.findChild("pom.xml") != null) return true;
|
if (root.findChild("pom.xml") != null) return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user