Search in sources :

Example 1 with MOERunConfiguration

use of org.moe.idea.runconfig.configuration.MOERunConfiguration in project moe-ide-integration by multi-os-engine.

the class ModuleObserver method checkRunConfiguration.

private void checkRunConfiguration(@NotNull Project project, @NotNull Module module) {
    LOG.debug("Check run configuration for the module " + module.getName() + " in the project " + project.getName());
    // Find run config for the module
    final RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);
    for (RunConfiguration runConfig : runManager.getConfigurationsList(MOERunConfigurationType.getInstance())) {
        final MOERunConfiguration moeRunConfig = (MOERunConfiguration) runConfig;
        // Set module in the config
        moeRunConfig.moduleName(moeRunConfig.moduleName());
        if (module.getName().equals(moeRunConfig.module().getName())) {
            return;
        }
        ;
    }
    // Create MOE run config
    RunnerAndConfigurationSettings settings = null;
    try {
        LOG.debug("Create run configuration " + module.getName());
        settings = MOERunConfiguration.createRunConfiguration(project, module);
        runManager.addConfiguration(settings, false);
        runManager.setSelectedConfiguration(settings);
    } catch (Exception ee) {
        LOG.error("Unable to create run configuration", ee);
    }
}
Also used : MOERunConfiguration(org.moe.idea.runconfig.configuration.MOERunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) MOERunConfiguration(org.moe.idea.runconfig.configuration.MOERunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl)

Example 2 with MOERunConfiguration

use of org.moe.idea.runconfig.configuration.MOERunConfiguration 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 3 with MOERunConfiguration

use of org.moe.idea.runconfig.configuration.MOERunConfiguration 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

MOERunConfiguration (org.moe.idea.runconfig.configuration.MOERunConfiguration)3 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)2 MOEToolWindow (org.moe.idea.ui.MOEToolWindow)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 NotNull (org.jetbrains.annotations.NotNull)1 MOEMavenBuildTask (org.moe.idea.maven.MOEMavenBuildTask)1 DeviceChooserDialog (org.moe.idea.ui.DeviceChooserDialog)1