Search in sources :

Example 1 with FlexUnitRunConfiguration

use of com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration in project intellij-plugins by JetBrains.

the class FlexTestUtils method checkFlexUnitRunConfig.

public static void checkFlexUnitRunConfig(final RunManager runManager, final Module module, final String configName, final String packageName, final String className, final String methodName) {
    final List<RunnerAndConfigurationSettings> settings = runManager.getConfigurationSettingsList(FlexUnitRunConfigurationType.getInstance());
    RunnerAndConfigurationSettings settingsToCheck = null;
    for (RunnerAndConfigurationSettings setting : settings) {
        if (configName.equals(setting.getName())) {
            settingsToCheck = setting;
            break;
        }
    }
    Assert.assertNotNull("Run configuration not found: " + configName, settingsToCheck);
    final FlexUnitRunnerParameters params = ((FlexUnitRunConfiguration) settingsToCheck.getConfiguration()).getRunnerParameters();
    Assert.assertEquals(packageName, params.getPackageName());
    Assert.assertEquals(className, params.getClassName());
    Assert.assertEquals(methodName, params.getMethodName());
    Assert.assertEquals(FlexBuildConfigurationManager.getInstance(module).getActiveConfiguration().getName(), params.getBCName());
}
Also used : FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings)

Example 2 with FlexUnitRunConfiguration

use of com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration in project intellij-plugins by JetBrains.

the class FlexRunConfigRefactoringListener method updatePackage.

private static void updatePackage(final RunConfigurationBase runConfiguration, final String newPackage) {
    if (runConfiguration instanceof FlexUnitRunConfiguration) {
        final FlexUnitRunnerParameters params = ((FlexUnitRunConfiguration) runConfiguration).getRunnerParameters();
        if (params.getScope() == FlexUnitRunnerParameters.Scope.Package) {
            params.setPackageName(newPackage);
        } else {
            final String oldFqn = params.getClassName();
            params.setClassName(StringUtil.getQualifiedName(newPackage, StringUtil.getShortName(oldFqn)));
        }
    } else {
        final FlashRunnerParameters params = ((FlashRunConfiguration) runConfiguration).getRunnerParameters();
        final String oldFqn = params.getOverriddenMainClass();
        params.setOverriddenMainClass(StringUtil.getQualifiedName(newPackage, StringUtil.getShortName(oldFqn)));
    }
}
Also used : FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration)

Example 3 with FlexUnitRunConfiguration

use of com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration in project intellij-plugins by JetBrains.

the class FlexBaseRunner method doExecute.

@Override
@Nullable
protected RunContentDescriptor doExecute(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    final RunProfile runProfile = env.getRunProfile();
    final boolean isDebug = this instanceof FlexDebugRunner;
    try {
        if (runProfile instanceof RunProfileWithCompileBeforeLaunchOption) {
            checkMakeBeforeRunEnabled(env.getProject(), runProfile);
        }
        if (runProfile instanceof RemoteFlashRunConfiguration) {
            final RemoteFlashRunnerParameters params = ((RemoteFlashRunConfiguration) runProfile).getRunnerParameters();
            final Pair<Module, FlexBuildConfiguration> moduleAndBC = params.checkAndGetModuleAndBC(env.getProject());
            if (params.getDebugTransport() == FlashRunnerParameters.AirMobileDebugTransport.USB) {
                final Sdk sdk = moduleAndBC.second.getSdk();
                assert sdk != null;
                if (params.getRemoteDebugTarget() == RemoteDebugTarget.AndroidDevice) {
                    if (!AirPackageUtil.startAdbServer(env.getProject(), sdk) || !AirPackageUtil.scanAndroidDevices(env.getProject(), sdk, params) || !AirPackageUtil.androidForwardTcpPort(env.getProject(), sdk, params.getDeviceInfo(), params.getUsbDebugPort())) {
                        return null;
                    }
                } else if (params.getRemoteDebugTarget() == RemoteDebugTarget.iOSDevice) {
                    final String adtVersion = AirPackageUtil.getAdtVersion(env.getProject(), sdk);
                    if (!AirPackageUtil.checkAdtVersionForPackaging(env.getProject(), adtVersion, "3.4", sdk.getName(), FlexBundle.message("air.ios.debug.via.usb.requires.3.4"))) {
                        return null;
                    }
                    if (!AirPackageUtil.scanIosDevices(env.getProject(), sdk, params)) {
                        return null;
                    }
                    final DeviceInfo device = params.getDeviceInfo();
                    final int deviceHandle = device == null ? -1 : device.IOS_HANDLE;
                    if (deviceHandle < 0) {
                        return null;
                    }
                    if (!AirPackageUtil.iosForwardTcpPort(env.getProject(), sdk, params.getUsbDebugPort(), deviceHandle)) {
                        return null;
                    }
                }
            }
            return launchDebugProcess(moduleAndBC.first, moduleAndBC.second, params, env);
        }
        if (runProfile instanceof FlexUnitRunConfiguration) {
            final FlexUnitRunnerParameters params = ((FlexUnitRunConfiguration) runProfile).getRunnerParameters();
            final Pair<Module, FlexBuildConfiguration> moduleAndConfig = params.checkAndGetModuleAndBC(env.getProject());
            final Module module = moduleAndConfig.first;
            final FlexBuildConfiguration bc = moduleAndConfig.second;
            if (bc.getTargetPlatform() == TargetPlatform.Web) {
                FlashPlayerTrustUtil.updateTrustedStatus(module, bc, isDebug, params.isTrusted());
                return launchWebFlexUnit(env.getProject(), env.getContentToReuse(), env, params, bc.getActualOutputFilePath());
            } else {
                return launchAirFlexUnit(env.getProject(), state, env.getContentToReuse(), env, params);
            }
        }
        if (runProfile instanceof FlashRunConfiguration) {
            final FlashRunnerParameters params = ((FlashRunConfiguration) runProfile).getRunnerParameters();
            params.setDeviceInfo(null);
            final Pair<Module, FlexBuildConfiguration> moduleAndConfig = params.checkAndGetModuleAndBC(env.getProject());
            final Module module = moduleAndConfig.first;
            final FlexBuildConfiguration bc = moduleAndConfig.second;
            if (bc.isSkipCompile()) {
                showBCCompilationSkippedWarning(module, bc);
            }
            if (isDebug && SystemInfo.isMac && bc.getTargetPlatform() == TargetPlatform.Web) {
                checkDebuggerFromSdk4(env.getProject(), runProfile, params, bc);
            }
            if (bc.getTargetPlatform() == TargetPlatform.Web && !params.isLaunchUrl()) {
                FlashPlayerTrustUtil.updateTrustedStatus(module, bc, isDebug, params.isRunTrusted());
            }
            return launchFlexConfig(module, bc, params, state, env.getContentToReuse(), env);
        }
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e.getMessage());
    }
    return null;
}
Also used : FlexDebugRunner(com.intellij.lang.javascript.flex.debug.FlexDebugRunner) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) DeviceInfo(com.intellij.lang.javascript.flex.actions.airpackage.DeviceInfo) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with FlexUnitRunConfiguration

use of com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration in project intellij-plugins by JetBrains.

the class FlexTestUtils method createFlexUnitRunConfig.

public static void createFlexUnitRunConfig(final RunManager runManager, final String configName, final Module module, final FlexUnitRunnerParameters.Scope scope, final String packageName, final String className, final String methodName, boolean generatedName) {
    final RunnerAndConfigurationSettings settings = runManager.createRunConfiguration(configName, FlexUnitRunConfigurationType.getFactory());
    runManager.addConfiguration(settings, false);
    final FlexUnitRunnerParameters params = ((FlexUnitRunConfiguration) settings.getConfiguration()).getRunnerParameters();
    params.setModuleName(module.getName());
    params.setBCName(FlexBuildConfigurationManager.getInstance(module).getActiveConfiguration().getName());
    params.setScope(scope);
    params.setPackageName(packageName);
    params.setClassName(className);
    params.setMethodName(methodName);
    if (generatedName) {
        ((FlexUnitRunConfiguration) settings.getConfiguration()).setGeneratedName();
    }
}
Also used : FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings)

Example 5 with FlexUnitRunConfiguration

use of com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration in project intellij-plugins by JetBrains.

the class FlexUnitExecutionTest method doTest.

private AbstractTestProxy doTest(boolean debugNotRun, FlexUnitRunnerParameters.Scope testScope, String testClassOrPackage, @Nullable String testMethod, @Nullable String projectRoot, @Nullable FlexUnitRunnerParameters.OutputLogLevel outputLogLevel, String... files) throws Exception {
    configureByFiles(projectRoot, files);
    final Ref<IXMLElement> expected = new Ref<>();
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> {
        try {
            Collection<IXMLElement> collection = JSTestUtils.extractXml(myEditor.getDocument(), "testResults");
            assertEquals("Invalid expected structure", 1, collection.size());
            expected.set(collection.iterator().next());
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }));
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> FlexTestUtils.modifyBuildConfiguration(myModule, configuration -> configuration.setTargetPlatform(myTargetPlatform))));
    final RunnerAndConfigurationSettings runnerAndConfigurationSettings = RunManager.getInstance(myProject).createRunConfiguration("test", FlexUnitRunConfigurationType.getFactory());
    final FlexUnitRunConfiguration flexUnitRunConfig = (FlexUnitRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
    final FlexUnitRunnerParameters params = flexUnitRunConfig.getRunnerParameters();
    params.setModuleName(myModule.getName());
    params.setBCName(FlexBuildConfigurationManager.getInstance(myModule).getBuildConfigurations()[0].getName());
    params.setOutputLogLevel(outputLogLevel);
    params.setScope(testScope);
    switch(testScope) {
        case Class:
            params.setClassName(testClassOrPackage);
            break;
        case Method:
            params.setClassName(testClassOrPackage);
            params.setMethodName(testMethod);
            break;
        case Package:
            params.setPackageName(testClassOrPackage);
            break;
        default:
            fail("Unknown scope: " + testScope);
    }
    flexUnitRunConfig.checkConfiguration();
    final ProgramRunner runner = new FlexUnitTestRunner();
    final Executor executor = debugNotRun ? DefaultDebugExecutor.getDebugExecutorInstance() : DefaultRunExecutor.getRunExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, runnerAndConfigurationSettings, getProject());
    final Semaphore compilation = new Semaphore();
    compilation.down();
    final Semaphore execution = new Semaphore();
    execution.down();
    final Semaphore startup = new Semaphore();
    final ProcessListener listener = new ProcessListener() {

        @Override
        public void startNotified(ProcessEvent event) {
            startup.up();
        }

        @Override
        public void processTerminated(ProcessEvent event) {
            execution.up();
        }

        @Override
        public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
        }

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            System.out.println("FlexUnit: " + event.getText());
        }
    };
    final Ref<ExecutionConsole> executionConsole = new Ref<>();
    ApplicationManager.getApplication().invokeLater(() -> {
        try {
            runner.execute(env, new ProgramRunner.Callback() {

                @Override
                public void processStarted(RunContentDescriptor descriptor) {
                    compilation.up();
                    startup.down();
                    descriptor.getProcessHandler().addProcessListener(listener);
                    executionConsole.set(descriptor.getExecutionConsole());
                }
            });
        } catch (Throwable t) {
            t.printStackTrace();
            fail(t.getMessage());
            compilation.up();
            startup.up();
            execution.up();
        }
    });
    if (!compilation.waitFor(COMPILATION_TIMEOUT * 1000)) {
        fail("Compilation did not succeed in " + COMPILATION_TIMEOUT + " seconds. There was an error or it took too long\n" + FlexCompilerHandler.getInstance(myProject).getLastCompilationMessages());
    }
    if (!startup.waitFor(STARTUP_TIMEOUT * 1000)) {
        fail("Process was not started in " + STARTUP_TIMEOUT + " seconds");
    }
    if (!execution.waitFor(EXECUTION_TIMEOUT * 1000)) {
        fail("Execution did not finish in " + EXECUTION_TIMEOUT + " seconds");
    }
    // give tests tree some time to stabilize
    Thread.sleep(200);
    final AbstractTestProxy testRoot = ((SMTRunnerConsoleView) executionConsole.get()).getResultsViewer().getRoot();
    checkResults(expected.get(), testRoot);
    if (outputLogLevel == null) {
        checkOutput(testRoot, outputLogLevel);
    }
    return testRoot;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) TargetPlatform(com.intellij.flex.model.bc.TargetPlatform) ServerSocket(java.net.ServerSocket) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) FlexCompilerHandler(com.intellij.lang.javascript.flex.build.FlexCompilerHandler) Semaphore(com.intellij.util.concurrency.Semaphore) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Map(java.util.Map) TestStateInfo(com.intellij.execution.testframework.sm.runner.states.TestStateInfo) FlexUnitRunConfigurationType(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfigurationType) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Collection(java.util.Collection) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable) Printable(com.intellij.execution.testframework.Printable) ProcessListener(com.intellij.execution.process.ProcessListener) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ProcessEvent(com.intellij.execution.process.ProcessEvent) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) Ref(com.intellij.openapi.util.Ref) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) CodeInsightTestCase(com.intellij.codeInsight.CodeInsightTestCase) WriteAction(com.intellij.openapi.application.WriteAction) JSTestOption(com.intellij.lang.javascript.JSTestOption) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) FlexUnitLibs(com.intellij.flex.util.FlexUnitLibs) HashMap(java.util.HashMap) CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension) IXMLElement(net.n3.nanoxml.IXMLElement) SocketTimeoutException(java.net.SocketTimeoutException) RunManager(com.intellij.execution.RunManager) ModuleType(com.intellij.openapi.module.ModuleType) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) ThrowableRunnable(com.intellij.util.ThrowableRunnable) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ProgramRunner(com.intellij.execution.runners.ProgramRunner) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) Key(com.intellij.openapi.util.Key) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) IOException(java.io.IOException) Executor(com.intellij.execution.Executor) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) JSTestUtils(com.intellij.lang.javascript.JSTestUtils) Printer(com.intellij.execution.testframework.Printer) FlexCompilerProjectConfiguration(com.intellij.lang.javascript.flex.build.FlexCompilerProjectConfiguration) Assert(org.junit.Assert) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Semaphore(com.intellij.util.concurrency.Semaphore) IXMLElement(net.n3.nanoxml.IXMLElement) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) Ref(com.intellij.openapi.util.Ref) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Key(com.intellij.openapi.util.Key)

Aggregations

FlexUnitRunConfiguration (com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration)8 FlexUnitRunnerParameters (com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters)6 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)3 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)3 Module (com.intellij.openapi.module.Module)3 BCBasedRunnerParameters (com.intellij.lang.javascript.flex.run.BCBasedRunnerParameters)2 FlashRunConfiguration (com.intellij.lang.javascript.flex.run.FlashRunConfiguration)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 Pair (com.intellij.openapi.util.Pair)2 Ref (com.intellij.openapi.util.Ref)2 Map (java.util.Map)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 CodeInsightTestCase (com.intellij.codeInsight.CodeInsightTestCase)1 Executor (com.intellij.execution.Executor)1 RunManager (com.intellij.execution.RunManager)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1