Search in sources :

Example 6 with MOEToolWindow

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

the class GeneratorRunner method run.

private void run() {
    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(progress);
            } 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";
                        }
                        String title = test ? "Test Binding Error" : "Generate Binding Error";
                        Messages.showErrorDialog(message, title);
                    }
                });
            } finally {
                progress.popState();
            }
        }

        private void runInternal(final ProgressIndicator progress) throws ProjectException, IOException {
            String s = null;
            final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
            toolWindow.clear();
            progress.setFraction(0.1);
            final StringBuilder errorBuilder = new StringBuilder();
            String modulePath = ModuleUtils.getModulePath(module);
            File moduleFile = new File(modulePath);
            progress.setFraction(0.2);
            GradleExec exec = new GradleExec(moduleFile);
            exec.getArguments().add("moeNatJGen");
            exec.getArguments().add("-Draw-binding-output");
            exec.getArguments().add("-Dmoe.binding.conf=" + coonfigurationFile.getPath());
            if (test) {
                exec.getArguments().add("-Dmoe.natjgen.testrun=true");
            }
            if (keep) {
                exec.getArguments().add("-Dmoe.keep.natjgen");
            }
            ExecRunner runner = exec.getRunner();
            runner.getBuilder().directory(moduleFile);
            runner.setListener(new ExecRunnerBase.ExecRunnerListener() {

                @Override
                public void stdout(String line) {
                    toolWindow.printNormalMessage(line + "\n");
                }

                @Override
                public void stderr(String line) {
                    toolWindow.printErrorMessage(line + "\n");
                    errorBuilder.append(line);
                    errorBuilder.append("\n");
                }
            });
            runner.run(new IKillListener() {

                @Override
                public boolean needsKill() {
                    return progress.isCanceled();
                }
            });
            progress.setFraction(0.9);
            module.getProject().getBaseDir().getFileSystem().refresh(true);
            progress.setFraction(1.0);
            final String errorMessage = errorBuilder.toString();
            if (errorMessage == null || errorMessage.isEmpty()) {
                String format = test ? "Test successful" : "Generate successful";
                toolWindow.balloon(MessageType.INFO, format);
            } else {
                String format = test ? "Test Error" : "Generate Error";
                toolWindow.balloon(MessageType.INFO, format);
                UIUtil.invokeLaterIfNeeded(new Runnable() {

                    @Override
                    public void run() {
                        String title = test ? "Test Binding Error" : "Generate Binding Error";
                        Messages.showErrorDialog(errorMessage, title);
                    }
                });
            }
        }
    }, ACTION_TITLE, true, module.getProject());
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) IOException(java.io.IOException) ProjectException(org.moe.document.pbxproj.ProjectException) MOEToolWindow(org.moe.idea.ui.MOEToolWindow) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) File(java.io.File)

Example 7 with MOEToolWindow

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

the class MOEGradleTaskProvider method executeTask.

@Override
public boolean executeTask(DataContext context, final RunConfiguration configuration, final ExecutionEnvironment env, MOEGradleTask task) {
    final AtomicBoolean success = new AtomicBoolean();
    final AtomicReference<String> errorMsgRef = new AtomicReference<String>();
    try {
        final Semaphore doneSemaphore = new Semaphore();
        doneSemaphore.down();
        final MOERunConfiguration runConfig = (MOERunConfiguration) configuration;
        isOpenDialog = runConfig.getOpenDeploymentTargetDialog();
        final MOEGradleRunner gradleRunner = new MOEGradleRunner(env.getProject(), "Building MOE application", runConfig);
        final MOEAfterGradleInvocationTask afterTask = new MOEAfterGradleInvocationTask() {

            @Override
            public void execute(@NotNull MOEGradleInvocationResult result) {
                LOG.debug("MOE application gradle build ended");
                success.set(result.isBuildSuccessful());
                errorMsgRef.set(result.getErrorMessage());
                gradleRunner.removeAfterTask(this);
                doneSemaphore.up();
            }
        };
        gradleRunner.addAfterTask(afterTask);
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                if (ApplicationManager.getApplication().isDispatchThread()) {
                    showDialog(runConfig);
                    gradleRunner.queue();
                } else {
                    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

                        @Override
                        public void run() {
                            showDialog(runConfig);
                            gradleRunner.queue();
                        }
                    });
                }
            }
        });
        doneSemaphore.waitFor();
    } catch (Exception e) {
        Log.debug("Unable execute task", e);
        return false;
    }
    ApplicationManager.getApplication().invokeLater(new Runnable() {

        @Override
        public void run() {
            String errorMessage = errorMsgRef.get();
            if (errorMessage != null) {
                MOEToolWindow toolWindow = MOEToolWindow.getInstance(env.getProject());
                toolWindow.printErrorMessage(errorMessage);
            }
        }
    });
    return success.get();
}
Also used : MOERunConfiguration(org.moe.idea.runconfig.configuration.MOERunConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(com.intellij.util.concurrency.Semaphore) NotNull(org.jetbrains.annotations.NotNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MOEToolWindow(org.moe.idea.ui.MOEToolWindow)

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