Search in sources :

Example 1 with MOEToolWindow

use of org.moe.idea.ui.MOEToolWindow in project moe-ide-integration by multi-os-engine.

the class MOERunConfigurationEditor method testRemoteConnection.

private void testRemoteConnection() {
    String moduleName = (String) moduleCombo.getSelectedItem();
    if (moduleName == null || moduleName.isEmpty()) {
        showMessage("Please select module.");
        return;
    }
    Module module = ModuleManager.getInstance(myProject).findModuleByName(moduleName);
    if (module == null) {
        showMessage("Not found module: " + moduleName);
        return;
    }
    Properties properties = RemoteSettings.getProperties(hostTextField.getText(), portTextField.getText(), userTextField.getText(), knownhostsTextField.getText(), identityTextField.getText(), keychainNameTextField.getText(), keychainPassTextField.getText(), keychainLocktimeoutTextField.getText(), gradleRepositoriesTextField.getText());
    try {
        RemoteSettings.validate(properties);
    } catch (ConfigurationValidationException e) {
        showMessage(e.getErrorMessage());
        return;
    }
    File f = new File(ModuleUtils.getModulePath(module));
    final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
    toolWindow.show();
    final StringBuffer runError = new StringBuffer();
    String errorMessage = RemoteSettings.test(f, properties, new ExecRunnerBase.ExecRunnerListener() {

        @Override
        public void stdout(String s) {
            toolWindow.printMessage(s + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
            if (s.toLowerCase().contains("error")) {
                runError.append(s);
            }
        }

        @Override
        public void stderr(String s) {
            toolWindow.printMessage(s + "\n", ConsoleViewContentType.ERROR_OUTPUT);
            runError.append(s);
        }
    });
    String runErrorText = runError.toString();
    if (errorMessage == null && (runErrorText == null || runErrorText.isEmpty())) {
        showMessage("Test successful");
    } else {
        if (errorMessage == null) {
            errorMessage = runErrorText;
        } else {
            errorMessage += " " + runErrorText;
        }
        showMessage(errorMessage);
    }
}
Also used : ConfigurationValidationException(org.moe.common.configuration.ConfigurationValidationException) MOEToolWindow(org.moe.idea.ui.MOEToolWindow) ExecRunnerBase(org.moe.common.exec.ExecRunnerBase) Module(com.intellij.openapi.module.Module) Properties(java.util.Properties) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with MOEToolWindow

use of org.moe.idea.ui.MOEToolWindow in project moe-ide-integration by multi-os-engine.

the class MOEGradleRunner method buildProject.

private void buildProject(MOEGradleInvocationResult result) {
    final Stopwatch stopwatch = Stopwatch.createUnstarted();
    stopwatch.start();
    String errorMessage = null;
    try {
        LOG.debug("Start build process");
        final org.moe.idea.compiler.MOEGradleRunner gradleRunner = new org.moe.idea.compiler.MOEGradleRunner(runConfig);
        final boolean isDebug = runConfig.getActionType().equals("Debug");
        boolean isMaven = ModuleUtils.isMOEMavenModule(runConfig.module());
        final MOEToolWindow toolWindow = MOEToolWindow.getInstance(runConfig.getProject());
        if (!isMaven) {
            final GeneralCommandLine commandLine = gradleRunner.construct(isDebug, false);
            final OSProcessHandler handler = new OSProcessHandler(commandLine);
            handler.setShouldDestroyProcessRecursively(true);
            handler.addProcessListener(new ProcessAdapter() {

                @Override
                public void onTextAvailable(ProcessEvent event, Key outputType) {
                    if (ProcessOutputTypes.STDERR.equals(outputType)) {
                        toolWindow.error(event.getText());
                    } else if (ProcessOutputTypes.STDOUT.equals(outputType)) {
                        toolWindow.log(event.getText());
                    }
                }
            });
            handler.startNotify();
            // Start and wait
            handler.waitFor();
            int returnCode = handler.getProcess().exitValue();
            // Show on failure
            if (returnCode != 0) {
                toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
                errorMessage = "Multi-OS Engine module build failed";
            }
        } else {
            MOEMavenBuildTask mavenTask = new MOEMavenBuildTask(runConfig, "Building " + runConfig.moduleName(), true);
            boolean res = mavenTask.runTask();
            if (!res) {
                toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
                errorMessage = "Multi-OS Engine module build failed";
            }
        }
        if (errorMessage == null) {
            result.setBuildSuccessful(true);
        } else {
            result.setBuildSuccessful(false);
            result.setErrorMessage(errorMessage);
        }
    } catch (Exception e) {
        result.setBuildSuccessful(false);
        result.setErrorMessage(String.format("Error while building %s .%n", e.getMessage()));
    } finally {
        stopwatch.stop();
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Stopwatch(com.google.common.base.Stopwatch) MOEToolWindow(org.moe.idea.ui.MOEToolWindow) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) MOEMavenBuildTask(org.moe.idea.maven.MOEMavenBuildTask) Key(com.intellij.openapi.util.Key)

Example 3 with MOEToolWindow

use of org.moe.idea.ui.MOEToolWindow in project moe-ide-integration by multi-os-engine.

the class MOEGenerateActionsAndOutletsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Module module = (Module) dataContext.getData(LangDataKeys.MODULE.getName());
    if (module == null) {
        Messages.showErrorDialog("Failed to locate module", "Actions and Outlets Generation Error");
        return;
    }
    boolean isMaven = ModuleUtils.isMOEMavenModule(module);
    if (!isMaven) {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {

            @Override
            public void run() {
                ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
                if (progress == null) {
                    progress = new EmptyProgressIndicator();
                }
                progress.pushState();
                try {
                    progress.setText(ACTION_PROGRESS_LABEL);
                    runInternal();
                } catch (final Throwable t) {
                    t.printStackTrace(System.err);
                    UIUtil.invokeLaterIfNeeded(new Runnable() {

                        @Override
                        public void run() {
                            String message = t.getMessage();
                            if (message == null || message.length() == 0) {
                                message = "Unknown error";
                            }
                            Messages.showErrorDialog(message, "Actions and Outlets Generation Error");
                            final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
                            toolWindow.show();
                        }
                    });
                } finally {
                    progress.popState();
                }
            }

            private void runInternal() throws IOException, ExecutionException {
                final GeneralCommandLine commandLine = MOEGradleRunner.construct(module, "moeGenerateUIObjCInterfaces");
                final OSProcessHandler handler = new OSProcessHandler(commandLine);
                handler.setShouldDestroyProcessRecursively(true);
                // Configure output
                final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
                toolWindow.clear();
                handler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void onTextAvailable(ProcessEvent event, Key outputType) {
                        if (ProcessOutputTypes.STDERR.equals(outputType)) {
                            toolWindow.error(event.getText());
                        } else if (ProcessOutputTypes.STDOUT.equals(outputType)) {
                            toolWindow.log(event.getText());
                        }
                    }
                });
                handler.startNotify();
                // Start and wait
                handler.waitFor();
                final int exitValue = handler.getProcess().exitValue();
                if (exitValue != 0) {
                    throw new IOException(ACTION_TITLE + " finished with non-zero exit value (" + exitValue + ")");
                }
            }
        }, ACTION_TITLE, true, module.getProject());
    } else {
        CompilerTask compilerTask = new CompilerTask(module.getProject(), "", false, true, true, true);
        compilerTask.start(new Runnable() {

            @Override
            public void run() {
                MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
                task.setGoal("moe:generateUIObjCInterfaces");
                if (!task.runTask()) {
                    ModuleUtils.runInDispatchedThread(new Runnable() {

                        @Override
                        public void run() {
                            Messages.showErrorDialog("Unable run generation", "Actions and Outlets Generation Error");
                        }
                    });
                }
            }
        }, null);
        ModuleUtils.runInDispatchedThread(new Runnable() {

            @Override
            public void run() {
                MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
                task.setGoal("moe:generateUIObjCInterfaces");
                if (!task.runTask()) {
                    Messages.showErrorDialog("Unable run generation", "Actions and Outlets Generation Error");
                }
            }
        });
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) CompilerTask(com.intellij.compiler.progress.CompilerTask) IOException(java.io.IOException) MOEMavenTask(org.moe.idea.maven.MOEMavenTask) DataContext(com.intellij.openapi.actionSystem.DataContext) MOEToolWindow(org.moe.idea.ui.MOEToolWindow) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 4 with MOEToolWindow

use of org.moe.idea.ui.MOEToolWindow in project moe-ide-integration by multi-os-engine.

the class MOECompileTask method execute.

@Override
public boolean execute(CompileContext context) {
    RunConfiguration c = context.getCompileScope().getUserData(CompileStepBeforeRun.RUN_CONFIGURATION);
    if (!(c instanceof MOERunConfiguration)) {
        return true;
    }
    final MOERunConfiguration runConfig = (MOERunConfiguration) c;
    isOpenDialog = runConfig.getOpenDeploymentTargetDialog();
    canceled = false;
    runConfig.setCanceled(canceled);
    final MOEToolWindow toolWindow = MOEToolWindow.getInstance(runConfig.getProject());
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            toolWindow.clear();
            if (isOpenDialog) {
                DeviceChooserDialog dialog = new DeviceChooserDialog(runConfig.module(), runConfig);
                dialog.show();
                if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
                    canceled = true;
                    runConfig.setCanceled(canceled);
                }
                isOpenDialog = false;
            }
        }
    });
    try {
        while (isOpenDialog) {
            Thread.sleep(100);
        }
        boolean isMaven = ModuleUtils.isMOEMavenModule(runConfig.module());
        // Start progress
        ProgressIndicator progress = context.getProgressIndicator();
        context.getProgressIndicator().pushState();
        progress.setText("Building MOE application");
        if (canceled) {
            toolWindow.balloon(MessageType.INFO, "BUILD CANCELED");
            return true;
        }
        if (!isMaven) {
            final CompileThread compileThread = new CompileThread(runConfig, context);
            compileThread.start();
            context.addMessage(CompilerMessageCategory.INFORMATION, "Building " + runConfig.moduleName(), null, -1, -1);
            // Wait for completion
            while (compileThread.isAlive() && !progress.isCanceled()) {
                compileThread.join(1000);
            }
            if (compileThread.isAlive() && progress.isCanceled()) {
                compileThread.interrupt();
                compileThread.join(1000);
            }
            // Re-throw error
            if (compileThread.throwable != null) {
                throw compileThread.throwable;
            }
            // Show on failure
            if (compileThread.returnCode != 0) {
                if (!compileThread.canceled) {
                    toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
                    context.addMessage(CompilerMessageCategory.ERROR, "Multi-OS Engine module build failed", null, -1, -1, toolWindow.getNavigatable());
                } else {
                    toolWindow.balloon(MessageType.INFO, "BUILD CANCELED");
                }
                return false;
            }
        } else {
            MOEMavenBuildTask mavenTask = new MOEMavenBuildTask(runConfig, "Building " + runConfig.moduleName(), true);
            boolean result = mavenTask.runTask();
            if (!result) {
                toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
                context.addMessage(CompilerMessageCategory.ERROR, "Multi-OS Engine module build failed", null, -1, -1, toolWindow.getNavigatable());
                return false;
            }
        }
    } catch (Throwable t) {
        toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
        LOG.error("Failed to compile module", t);
        context.addMessage(CompilerMessageCategory.ERROR, "Multi-OS Engine module build failed, an internal error occurred", null, -1, -1);
        return false;
    } finally {
        context.getProgressIndicator().popState();
    }
    return true;
}
Also used : DeviceChooserDialog(org.moe.idea.ui.DeviceChooserDialog) MOERunConfiguration(org.moe.idea.runconfig.configuration.MOERunConfiguration) MOEToolWindow(org.moe.idea.ui.MOEToolWindow) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) MOERunConfiguration(org.moe.idea.runconfig.configuration.MOERunConfiguration) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) MOEMavenBuildTask(org.moe.idea.maven.MOEMavenBuildTask)

Example 5 with MOEToolWindow

use of org.moe.idea.ui.MOEToolWindow in project moe-ide-integration by multi-os-engine.

the class MOERefreshXcodeProject method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Module module = (Module) dataContext.getData(LangDataKeys.MODULE.getName());
    if (module == null) {
        Messages.showErrorDialog("Failed to locate module", "Injecting/Refreshing Xcode Settings Error");
        return;
    }
    boolean isMaven = ModuleUtils.isMOEMavenModule(module);
    if (!isMaven) {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {

            @Override
            public void run() {
                ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
                if (progress == null) {
                    progress = new EmptyProgressIndicator();
                }
                progress.pushState();
                try {
                    progress.setText(ACTION_PROGRESS_LABEL);
                    runInternal();
                } catch (final Throwable t) {
                    t.printStackTrace(System.err);
                    UIUtil.invokeLaterIfNeeded(new Runnable() {

                        @Override
                        public void run() {
                            String message = t.getMessage();
                            if (message == null || message.length() == 0) {
                                message = "Unknown error";
                            }
                            Messages.showErrorDialog(message, "Injecting/Refreshing Xcode Settings Error");
                            final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
                            toolWindow.show();
                        }
                    });
                } finally {
                    progress.popState();
                }
            }

            private void runInternal() throws IOException, ExecutionException {
                final GeneralCommandLine commandLine = MOEGradleRunner.construct(module, "moeUpdateXcodeSettings");
                final OSProcessHandler handler = new OSProcessHandler(commandLine);
                handler.setShouldDestroyProcessRecursively(true);
                // Configure output
                final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
                toolWindow.clear();
                handler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void onTextAvailable(ProcessEvent event, Key outputType) {
                        if (ProcessOutputTypes.STDERR.equals(outputType)) {
                            toolWindow.error(event.getText());
                        } else if (ProcessOutputTypes.STDOUT.equals(outputType)) {
                            toolWindow.log(event.getText());
                        }
                    }
                });
                handler.startNotify();
                // Start and wait
                handler.waitFor();
                final int exitValue = handler.getProcess().exitValue();
                if (exitValue != 0) {
                    throw new IOException(ACTION_TITLE + " finished with non-zero exit value (" + exitValue + ")");
                }
            }
        }, ACTION_TITLE, true, module.getProject());
    } else {
        CompilerTask compilerTask = new CompilerTask(module.getProject(), "", false, true, true, true);
        compilerTask.start(new Runnable() {

            @Override
            public void run() {
                MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
                task.setGoal("moe:updateXcodeSettings");
                if (!task.runTask()) {
                    ModuleUtils.runInDispatchedThread(new Runnable() {

                        @Override
                        public void run() {
                            Messages.showErrorDialog("Unable to refresh Xcode project", "Injecting/Refreshing Xcode Settings Error");
                        }
                    });
                }
            }
        }, null);
        ModuleUtils.runInDispatchedThread(new Runnable() {

            @Override
            public void run() {
                MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
                task.setGoal("moe:updateXcodeSettings");
                if (!task.runTask()) {
                    Messages.showErrorDialog("Unable to refresh Xcode project", "Injecting/Refreshing Xcode Settings Error");
                }
            }
        });
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) CompilerTask(com.intellij.compiler.progress.CompilerTask) IOException(java.io.IOException) MOEMavenTask(org.moe.idea.maven.MOEMavenTask) DataContext(com.intellij.openapi.actionSystem.DataContext) MOEToolWindow(org.moe.idea.ui.MOEToolWindow) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Aggregations

MOEToolWindow (org.moe.idea.ui.MOEToolWindow)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)4 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)3 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)3 ProcessEvent (com.intellij.execution.process.ProcessEvent)3 Module (com.intellij.openapi.module.Module)3 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)3 Key (com.intellij.openapi.util.Key)3 IOException (java.io.IOException)3 CompilerTask (com.intellij.compiler.progress.CompilerTask)2 ExecutionException (com.intellij.execution.ExecutionException)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 File (java.io.File)2 MOEMavenBuildTask (org.moe.idea.maven.MOEMavenBuildTask)2 MOEMavenTask (org.moe.idea.maven.MOEMavenTask)2 MOERunConfiguration (org.moe.idea.runconfig.configuration.MOERunConfiguration)2 Stopwatch (com.google.common.base.Stopwatch)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1