Search in sources :

Example 6 with PhoneGapCommandLine

use of com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine in project intellij-plugins by JetBrains.

the class PhoneGapAddPlatformBeforeRun method executeTask.

@Override
public boolean executeTask(DataContext context, final RunConfiguration configuration, ExecutionEnvironment env, PhoneGapAddPlatformTask task) {
    final PhoneGapRunConfiguration phoneGapRunConfiguration = (PhoneGapRunConfiguration) configuration;
    final PhoneGapCommandLine line = phoneGapRunConfiguration.getCommandLine();
    if (!line.needAddPlatform()) {
        return true;
    }
    final Project project = configuration.getProject();
    final Semaphore targetDone = new Semaphore();
    final Ref<Boolean> result = new Ref<>(true);
    final List<Exception> exceptions = new ArrayList<>();
    ApplicationManager.getApplication().invokeAndWait(() -> {
        //Save all opened documents
        FileDocumentManager.getInstance().saveAllDocuments();
        targetDone.down();
        new Task.Backgroundable(project, PhoneGapBundle.message("phonegap.before.task.init.title"), true) {

            public boolean shouldStartInBackground() {
                return true;
            }

            public void run(@NotNull final ProgressIndicator indicator) {
                try {
                    String platform = phoneGapRunConfiguration.getPlatform();
                    assert platform != null;
                    ProcessOutput output = line.platformAdd(platform);
                    if (output.getExitCode() != 0) {
                        ExecutionHelper.showOutput(project, output, PhoneGapBundle.message("phonegap.before.task.init.title"), null, true);
                        result.set(false);
                    }
                } catch (final Exception e) {
                    exceptions.add(e);
                    result.set(false);
                } finally {
                    targetDone.up();
                }
            }
        }.queue();
    }, ModalityState.NON_MODAL);
    if (!targetDone.waitFor(TimeUnit.MINUTES.toMillis(2))) {
        ExecutionHelper.showErrors(project, ContainerUtil.createMaybeSingletonList(new RuntimeException("Timeout")), PhoneGapBundle.message("phonegap.before.task.init.error"), null);
    } else if (!exceptions.isEmpty()) {
        ExecutionHelper.showErrors(project, exceptions, PhoneGapBundle.message("phonegap.before.task.init.error"), null);
    }
    return result.get();
}
Also used : PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine) Task(com.intellij.openapi.progress.Task) BeforeRunTask(com.intellij.execution.BeforeRunTask) ArrayList(java.util.ArrayList) Semaphore(com.intellij.util.concurrency.Semaphore) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessOutput(com.intellij.execution.process.ProcessOutput)

Example 7 with PhoneGapCommandLine

use of com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine in project intellij-plugins by JetBrains.

the class PhoneGapRunProfileState method startProcess.

@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
    PhoneGapCommandLine line = phoneGapRunConfiguration.getCommandLine();
    String command = phoneGapRunConfiguration.getCommand();
    assert command != null;
    String platform = phoneGapRunConfiguration.getPlatform();
    assert platform != null;
    return line.runCommand(command, platform, phoneGapRunConfiguration.hasTarget() ? phoneGapRunConfiguration.getTarget() : null, phoneGapRunConfiguration.getExtraArgs());
}
Also used : PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PhoneGapCommandLine (com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine)7 ProcessOutput (com.intellij.execution.process.ProcessOutput)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Ref (com.intellij.openapi.util.Ref)2 File (java.io.File)2 PhoneGapSettings (com.github.masahirosuzuka.PhoneGapIntelliJPlugin.settings.PhoneGapSettings)1 BeforeRunTask (com.intellij.execution.BeforeRunTask)1 ExecutionException (com.intellij.execution.ExecutionException)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1