Search in sources :

Example 1 with MessageSocketManager

use of com.intellij.flex.uiDesigner.io.MessageSocketManager in project intellij-plugins by JetBrains.

the class DesignerApplicationLauncher method doRun.

@Override
protected boolean doRun(@NotNull final ProgressIndicator indicator) throws IOException, java.util.concurrent.ExecutionException, InterruptedException, TimeoutException {
    indicator.setText(FlashUIDesignerBundle.message("copying.app.files"));
    copyAppFiles();
    indicator.setText(FlashUIDesignerBundle.message("finding.suitable.air.runtime"));
    List<AdlRunConfiguration> adlRunConfigurations = getSuitableAdlRunConfigurations();
    if (adlRunConfigurations.isEmpty()) {
        notifyNoSuitableSdkToLaunch();
        return false;
    }
    indicator.checkCanceled();
    DesignerApplicationManager.getInstance().setApplication(new DesignerApplication());
    runInitializeLibrariesAndModuleThread();
    if (debug && !runAndWaitDebugger()) {
        return false;
    }
    indicator.checkCanceled();
    MessageSocketManager messageSocketManager = new MessageSocketManager(this, DesignerApplicationManager.APP_DIR);
    Disposer.register(DesignerApplicationManager.getApplication(), messageSocketManager);
    final List<String> arguments = new ArrayList<>();
    arguments.add(Integer.toString(messageSocketManager.listen()));
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        arguments.add("-p");
        arguments.add(DebugPathManager.resolveTestArtifactPath("test-1.0-SNAPSHOT.swf"));
    }
    AdlProcessHandler adlProcessHandler = null;
    final Ref<Boolean> found = new Ref<>(true);
    for (AdlRunConfiguration adlRunConfiguration : adlRunConfigurations) {
        found.set(true);
        adlRunConfiguration.arguments = arguments;
        try {
            final String appClassifierVersion;
            if (StringUtil.compareVersionNumbers(adlRunConfiguration.getRuntimeVersion(), "3.0") < 0 || !(SystemInfo.isMac || SystemInfo.isWindows)) {
                appClassifierVersion = "2.6";
            } else {
                appClassifierVersion = "3.0";
            }
            adlProcessHandler = runAdl(adlRunConfiguration, DesignerApplicationManager.APP_DIR.getPath() + File.separatorChar + "descriptor-air" + appClassifierVersion + ".xml", exitCode -> {
                found.set(false);
                if (!indicator.isCanceled()) {
                    LOG.info(describeAdlExit(exitCode));
                    semaphore.up();
                }
            });
        } catch (ExecutionException e) {
            adlProcessHandler = null;
            LOG.error(e);
            continue;
        }
        semaphore.down();
        try {
            if (!semaphore.waitForUnsafe(60 * 1000)) {
                found.set(false);
                LOG.warn("Client not opened in 60 seconds");
                if (checkStartupError()) {
                    return false;
                }
            }
        } catch (InterruptedException e) {
            if (indicator.isCanceled()) {
                return false;
            }
            LOG.warn(e);
            continue;
        }
        indicator.checkCanceled();
        if (found.get()) {
            break;
        }
    }
    if (!found.get()) {
        if (!checkStartupError()) {
            notifyNoSuitableSdkToLaunch();
        }
        return false;
    }
    ProjectComponentReferenceCounter projectComponentReferenceCounter = initializeTask.get(DebugPathManager.IS_DEV ? 999 : 60, TimeUnit.SECONDS);
    indicator.checkCanceled();
    final DesignerApplication application = DesignerApplicationManager.getApplication();
    LOG.assertTrue(adlProcessHandler != null && application != null);
    application.setProcessHandler(adlProcessHandler);
    DesignerApplicationManager.getInstance().attachProjectAndModuleListeners(application);
    return postTask.run(module, projectComponentReferenceCounter, indicator, problemsHolder);
}
Also used : ExecutionException(com.intellij.execution.ExecutionException) URL(java.net.URL) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IOUtil(com.intellij.flex.uiDesigner.io.IOUtil) Semaphore(com.intellij.util.concurrency.Semaphore) InitException(com.intellij.flex.uiDesigner.libraries.InitException) Disposer(com.intellij.openapi.util.Disposer) FileUtil(com.intellij.openapi.util.io.FileUtil) FlexSdkUtils(com.intellij.lang.javascript.flex.sdk.FlexSdkUtils) Module(com.intellij.openapi.module.Module) OutputStream(java.io.OutputStream) DumbService(com.intellij.openapi.project.DumbService) ProjectJdksEditor(com.intellij.openapi.projectRoots.ui.ProjectJdksEditor) StringUtil(com.intellij.openapi.util.text.StringUtil) MessageSocketManager(com.intellij.flex.uiDesigner.io.MessageSocketManager) WindowManager(com.intellij.openapi.wm.WindowManager) IOException(java.io.IOException) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Sdk(com.intellij.openapi.projectRoots.Sdk) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) LibraryManager(com.intellij.flex.uiDesigner.libraries.LibraryManager) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) AdlUtil(com.intellij.flex.uiDesigner.AdlUtil) Ref(com.intellij.openapi.util.Ref) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) ArrayList(java.util.ArrayList) MessageSocketManager(com.intellij.flex.uiDesigner.io.MessageSocketManager) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Ref(com.intellij.openapi.util.Ref) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)1 AdlUtil (com.intellij.flex.uiDesigner.AdlUtil)1 IOUtil (com.intellij.flex.uiDesigner.io.IOUtil)1 MessageSocketManager (com.intellij.flex.uiDesigner.io.MessageSocketManager)1 StringRegistry (com.intellij.flex.uiDesigner.io.StringRegistry)1 InitException (com.intellij.flex.uiDesigner.libraries.InitException)1 LibraryManager (com.intellij.flex.uiDesigner.libraries.LibraryManager)1 ProjectComponentReferenceCounter (com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter)1 FlexSdkUtils (com.intellij.lang.javascript.flex.sdk.FlexSdkUtils)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Module (com.intellij.openapi.module.Module)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 DumbService (com.intellij.openapi.project.DumbService)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 ProjectJdksEditor (com.intellij.openapi.projectRoots.ui.ProjectJdksEditor)1 Disposer (com.intellij.openapi.util.Disposer)1 Pair (com.intellij.openapi.util.Pair)1 Ref (com.intellij.openapi.util.Ref)1 SystemInfo (com.intellij.openapi.util.SystemInfo)1 FileUtil (com.intellij.openapi.util.io.FileUtil)1