Search in sources :

Example 11 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class CompilerConfigGenerator method getCustomLinkReportPath.

@Nullable
private static String getCustomLinkReportPath(final Module module, final FlexBuildConfiguration rlmBC) {
    final FlexBuildConfiguration appBC = FlexBuildConfigurationManager.getInstance(module).findConfigurationByName(rlmBC.getName());
    if (appBC != null) {
        final List<String> linkReports = FlexCommonUtils.getOptionValues(appBC.getCompilerOptions().getAdditionalOptions(), "link-report");
        if (!linkReports.isEmpty()) {
            final String path = linkReports.get(0);
            if (new File(path).isFile())
                return path;
            final String absPath = FlexUtils.getFlexCompilerWorkDirPath(module.getProject(), null) + "/" + path;
            if (new File(absPath).isFile())
                return absPath;
        } else {
            final String configFilePath = appBC.getCompilerOptions().getAdditionalConfigFilePath();
            if (!configFilePath.isEmpty()) {
                final VirtualFile configFile = LocalFileSystem.getInstance().findFileByPath(configFilePath);
                if (configFile != null) {
                    try {
                        String path = FlexUtils.findXMLElement(configFile.getInputStream(), "<flex-config><link-report>");
                        if (path != null) {
                            path = path.trim();
                            if (new File(path).isFile())
                                return path;
                            // I have no idea why Flex compiler treats path relative to source root for "link-report" option
                            for (VirtualFile srcRoot : ModuleRootManager.getInstance(module).getSourceRoots()) {
                                final String absPath = srcRoot.getPath() + "/" + path;
                                if (new File(absPath).isFile())
                                    return absPath;
                            }
                        }
                    } catch (IOException ignore) {
                    /*ignore*/
                    }
                }
            }
        }
    }
    return null;
}
Also used : FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) IOException(java.io.IOException) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class JSConditionalCompilationDefinitionsProviderImpl method processConditionalCompilationDefinitions.

private void processConditionalCompilationDefinitions(final Module module, final Processor<Pair<String, String>> processor) {
    final FlexBuildConfigurationManager manager = FlexBuildConfigurationManager.getInstance(module);
    final FlexBuildConfiguration bc = manager.getActiveConfiguration();
    final ModuleOrProjectCompilerOptions moduleLevelOptions = manager.getModuleLevelCompilerOptions();
    final ModuleOrProjectCompilerOptions projectLevelOptions = FlexProjectLevelCompilerOptionsHolder.getInstance(module.getProject()).getProjectLevelCompilerOptions();
    if (!FlexUtils.processCompilerOption(module, bc, "compiler.define", processor))
        return;
    if (!processDefinitionsFromCompilerOptions(projectLevelOptions.getAdditionalOptions(), processor))
        return;
    if (!processDefinitionsFromCompilerOptions(moduleLevelOptions.getAdditionalOptions(), processor))
        return;
    if (!processDefinitionsFromCompilerOptions(bc.getCompilerOptions().getAdditionalOptions(), processor))
        return;
    for (Pair<String, String> nameAndValue : getDefinitionsFromConfigFile(bc.getCompilerOptions().getAdditionalConfigFilePath())) {
        if (!processor.process(nameAndValue))
            return;
    }
}
Also used : ModuleOrProjectCompilerOptions(com.intellij.lang.javascript.flex.projectStructure.model.ModuleOrProjectCompilerOptions) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)

Example 13 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class FlexBuildTargetScopeProvider method appendBCDependencies.

private static void appendBCDependencies(final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCs, final Module module, final FlexBuildConfiguration bc) throws ConfigurationException {
    for (final DependencyEntry entry : bc.getDependencies().getEntries()) {
        if (entry instanceof BuildConfigurationEntry) {
            final BuildConfigurationEntry bcEntry = (BuildConfigurationEntry) entry;
            final Module dependencyModule = bcEntry.findModule();
            final FlexBuildConfiguration dependencyBC = dependencyModule == null ? null : bcEntry.findBuildConfiguration();
            if (dependencyModule == null || dependencyBC == null) {
                throw new ConfigurationException(FlexBundle.message("bc.dependency.does.not.exist", bcEntry.getBcName(), bcEntry.getModuleName(), bc.getName(), module.getName()));
            }
            final Pair<Module, FlexBuildConfiguration> dependencyModuleAndBC = Pair.create(dependencyModule, dependencyBC);
            if (!dependencyBC.isSkipCompile()) {
                if (modulesAndBCs.add(dependencyModuleAndBC)) {
                    appendBCDependencies(modulesAndBCs, dependencyModule, dependencyBC);
                }
            }
        }
    }
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) Module(com.intellij.openapi.module.Module)

Example 14 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class FlexUnitPrecompileTask method execute.

public boolean execute(CompileContext context) {
    final RunConfiguration runConfiguration = CompileStepBeforeRun.getRunConfiguration(context.getCompileScope());
    if (!(runConfiguration instanceof FlexUnitRunConfiguration)) {
        return true;
    }
    final Ref<Boolean> isDumb = new Ref<>(false);
    final RuntimeConfigurationException validationError = ApplicationManager.getApplication().runReadAction((NullableComputable<RuntimeConfigurationException>) () -> {
        if (DumbService.getInstance(myProject).isDumb()) {
            isDumb.set(true);
            return null;
        }
        try {
            runConfiguration.checkConfiguration();
            return null;
        } catch (RuntimeConfigurationException e) {
            return e;
        }
    });
    if (isDumb.get()) {
        context.addMessage(CompilerMessageCategory.ERROR, FlexBundle.message("dumb.mode.flex.unit.warning"), null, -1, -1);
        return false;
    }
    if (validationError != null) {
        context.addMessage(CompilerMessageCategory.ERROR, FlexBundle.message("configuration.not.valid", validationError.getMessage()), null, -1, -1);
        return false;
    }
    int flexUnitPort = ServerConnectionBase.getFreePort(FLEX_UNIT_PORT_START, PORTS_ATTEMPT_NUMBER);
    if (flexUnitPort == -1) {
        context.addMessage(CompilerMessageCategory.ERROR, FlexBundle.message("no.free.port"), null, -1, -1);
        return false;
    }
    final int socketPolicyPort;
    if (SystemInfo.isWindows && ServerConnectionBase.tryPort(SwfPolicyFileConnection.DEFAULT_PORT)) {
        socketPolicyPort = SwfPolicyFileConnection.DEFAULT_PORT;
    } else {
        socketPolicyPort = ServerConnectionBase.getFreePort(SWC_POLICY_PORT_START, PORTS_ATTEMPT_NUMBER);
    }
    if (socketPolicyPort == -1) {
        context.addMessage(CompilerMessageCategory.ERROR, FlexBundle.message("no.free.port"), null, -1, -1);
        return false;
    }
    final FlexUnitRunnerParameters params = ((FlexUnitRunConfiguration) runConfiguration).getRunnerParameters();
    params.setPort(flexUnitPort);
    params.setSocketPolicyPort(socketPolicyPort);
    final Ref<Module> moduleRef = new Ref<>();
    final Ref<FlexBuildConfiguration> bcRef = new Ref<>();
    final Ref<FlexUnitSupport> supportRef = new Ref<>();
    ApplicationManager.getApplication().runReadAction(() -> {
        if (DumbService.getInstance(myProject).isDumb())
            return;
        try {
            final Pair<Module, FlexBuildConfiguration> moduleAndBC = params.checkAndGetModuleAndBC(myProject);
            moduleRef.set(moduleAndBC.first);
            bcRef.set(moduleAndBC.second);
            supportRef.set(FlexUnitSupport.getSupport(moduleAndBC.second, moduleAndBC.first));
        } catch (RuntimeConfigurationError e) {
            // already checked above, can't happen
            throw new RuntimeException(e);
        }
    });
    final Module module = moduleRef.get();
    final FlexBuildConfiguration bc = bcRef.get();
    final FlexUnitSupport support = supportRef.get();
    if (bc == null || support == null) {
        context.addMessage(CompilerMessageCategory.ERROR, FlexBundle.message("dumb.mode.flex.unit.warning"), null, -1, -1);
        return false;
    }
    final GlobalSearchScope moduleScope = GlobalSearchScope.moduleScope(module);
    StringBuilder imports = new StringBuilder();
    StringBuilder code = new StringBuilder();
    final boolean flexUnit4;
    switch(params.getScope()) {
        case Class:
            {
                final Ref<Boolean> isFlexUnit1Suite = new Ref<>();
                final Ref<Boolean> isSuite = new Ref<>();
                Set<String> customRunners = ApplicationManager.getApplication().runReadAction((NullableComputable<Set<String>>) () -> {
                    if (DumbService.getInstance(myProject).isDumb())
                        return null;
                    Set<String> result = new THashSet<>();
                    final JSClass clazz = (JSClass) ActionScriptClassResolver.findClassByQNameStatic(params.getClassName(), moduleScope);
                    collectCustomRunners(result, clazz, support, null);
                    isFlexUnit1Suite.set(support.isFlexUnit1SuiteSubclass(clazz));
                    isSuite.set(support.isSuite(clazz));
                    return result;
                });
                if (customRunners == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, FlexBundle.message("dumb.mode.flex.unit.warning"), null, -1, -1);
                    return false;
                }
                // FlexUnit4 can't run FlexUnit1 TestSuite subclasses, fallback to FlexUnit1 runner
                flexUnit4 = support.flexUnit4Present && !isFlexUnit1Suite.get();
                generateImportCode(imports, params.getClassName(), customRunners);
                generateTestClassCode(code, params.getClassName(), customRunners, isSuite.get());
            }
            break;
        case Method:
            {
                Set<String> customRunners = ApplicationManager.getApplication().runReadAction((NullableComputable<Set<String>>) () -> {
                    if (DumbService.getInstance(myProject).isDumb())
                        return null;
                    Set<String> result = new THashSet<>();
                    final JSClass clazz = (JSClass) ActionScriptClassResolver.findClassByQNameStatic(params.getClassName(), moduleScope);
                    collectCustomRunners(result, clazz, support, null);
                    return result;
                });
                if (customRunners == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, FlexBundle.message("dumb.mode.flex.unit.warning"), null, -1, -1);
                    return false;
                }
                flexUnit4 = support.flexUnit4Present;
                generateImportCode(imports, params.getClassName(), customRunners);
                generateTestMethodCode(code, params.getClassName(), params.getMethodName(), customRunners);
            }
            break;
        case Package:
            {
                final Collection<Pair<String, Set<String>>> classes = ApplicationManager.getApplication().runReadAction((NullableComputable<Collection<Pair<String, Set<String>>>>) () -> {
                    if (DumbService.getInstance(myProject).isDumb())
                        return null;
                    final Collection<Pair<String, Set<String>>> result = new ArrayList<>();
                    JSPackageIndex.processElementsInScopeRecursive(params.getPackageName(), new JSPackageIndex.PackageQualifiedElementsProcessor() {

                        public boolean process(String qualifiedName, JSPackageIndexInfo.Kind kind, boolean isPublic) {
                            if (kind == JSPackageIndexInfo.Kind.CLASS) {
                                PsiElement clazz = ActionScriptClassResolver.findClassByQNameStatic(qualifiedName, moduleScope);
                                if (clazz instanceof JSClass && support.isTestClass((JSClass) clazz, false)) {
                                    Set<String> customRunners = new THashSet<>();
                                    collectCustomRunners(customRunners, (JSClass) clazz, support, null);
                                    result.add(Pair.create(((JSClass) clazz).getQualifiedName(), customRunners));
                                }
                            }
                            return true;
                        }
                    }, moduleScope, myProject);
                    return result;
                });
                if (classes == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, FlexBundle.message("dumb.mode.flex.unit.warning"), null, -1, -1);
                    return false;
                }
                if (classes.isEmpty()) {
                    String message = MessageFormat.format("No tests found in package ''{0}''", params.getPackageName());
                    context.addMessage(CompilerMessageCategory.WARNING, message, null, -1, -1);
                    return false;
                }
                flexUnit4 = support.flexUnit4Present;
                for (Pair<String, Set<String>> classAndRunner : classes) {
                    generateImportCode(imports, classAndRunner.first, classAndRunner.second);
                    generateTestClassCode(code, classAndRunner.first, classAndRunner.second, false);
                }
            }
            break;
        default:
            flexUnit4 = false;
            assert false : "Unknown scope: " + params.getScope();
    }
    if (!flexUnit4 && bc.isPureAs()) {
        context.addMessage(CompilerMessageCategory.ERROR, FlexBundle.message("cant.execute.flexunit1.for.pure.as.bc"), null, -1, -1);
    }
    String launcherText;
    try {
        launcherText = getLauncherTemplate(bc);
    } catch (IOException e) {
        context.addMessage(CompilerMessageCategory.ERROR, e.getMessage(), null, -1, -1);
        return false;
    }
    final boolean desktop = bc.getTargetPlatform() == TargetPlatform.Desktop;
    if (desktop) {
        generateImportCode(imports, "flash.desktop.NativeApplication");
    }
    launcherText = replace(launcherText, "/*imports*/", imports.toString());
    launcherText = replace(launcherText, "/*test_runner*/", flexUnit4 ? FlexCommonUtils.FLEXUNIT_4_TEST_RUNNER : FlexCommonUtils.FLEXUNIT_1_TEST_RUNNER);
    launcherText = replace(launcherText, "/*code*/", code.toString());
    launcherText = replace(launcherText, "/*port*/", String.valueOf(flexUnitPort));
    launcherText = replace(launcherText, "/*socketPolicyPort*/", String.valueOf(socketPolicyPort));
    launcherText = replace(launcherText, "/*module*/", module.getName());
    if (!bc.isPureAs()) {
        final FlexUnitRunnerParameters.OutputLogLevel logLevel = params.getOutputLogLevel();
        launcherText = replace(launcherText, "/*isLogEnabled*/", logLevel != null ? "1" : "0");
        launcherText = replace(launcherText, "/*logLevel*/", logLevel != null ? logLevel.getFlexConstant() : FlexUnitRunnerParameters.OutputLogLevel.All.getFlexConstant());
    }
    final File tmpDir = new File(getPathToFlexUnitTempDirectory(myProject));
    boolean ok = true;
    if (tmpDir.isFile())
        ok &= FileUtil.delete(tmpDir);
    if (!tmpDir.isDirectory())
        ok &= tmpDir.mkdirs();
    if (!ok) {
        final String message = UIBundle.message("create.new.folder.could.not.create.folder.error.message", FileUtil.toSystemDependentName(tmpDir.getPath()));
        context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
        return false;
    }
    final String fileName = FlexCommonUtils.FLEX_UNIT_LAUNCHER + FlexCommonUtils.getFlexUnitLauncherExtension(bc.getNature());
    final File launcherFile = new File(tmpDir, fileName);
    FileUtil.delete(launcherFile);
    try {
        FileUtil.writeToFile(launcherFile, launcherText);
    } catch (IOException e) {
        context.addMessage(CompilerMessageCategory.ERROR, e.getMessage(), null, -1, -1);
        return false;
    }
    context.putUserData(FILES_TO_DELETE, Collections.singletonList(launcherFile.getPath()));
    return true;
}
Also used : ComponentSet(com.intellij.flex.model.bc.ComponentSet) THashSet(gnu.trove.THashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RuntimeConfigurationException(com.intellij.execution.configurations.RuntimeConfigurationException) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSPackageIndex(com.intellij.lang.javascript.index.JSPackageIndex) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) PsiElement(com.intellij.psi.PsiElement) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) Collection(java.util.Collection) JSPackageIndexInfo(com.intellij.lang.javascript.index.JSPackageIndexInfo) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) File(java.io.File)

Example 15 with FlexBuildConfiguration

use of com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration in project intellij-plugins by JetBrains.

the class FlexUnitRunConfiguration method getState.

@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
    final FlexBuildConfiguration bc;
    try {
        bc = myRunnerParameters.checkAndGetModuleAndBC(getProject()).second;
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e.getMessage());
    }
    final BuildConfigurationNature nature = bc.getNature();
    if (nature.isDesktopPlatform() || nature.isMobilePlatform()) {
        return new FlashRunConfiguration.AirRunState(getProject(), env, myRunnerParameters) {

            @NotNull
            @Override
            public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
                final ProcessHandler processHandler = startProcess();
                final ExecutionConsole console = FlexBaseRunner.createFlexUnitRunnerConsole(getProject(), env, processHandler);
                return new DefaultExecutionResult(console, processHandler);
            }
        };
    }
    return EmptyRunProfileState.INSTANCE;
}
Also used : BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) ProgramRunner(com.intellij.execution.runners.ProgramRunner) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)52 Module (com.intellij.openapi.module.Module)30 Sdk (com.intellij.openapi.projectRoots.Sdk)9 Pair (com.intellij.openapi.util.Pair)7 ArrayList (java.util.ArrayList)7 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)6 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)5 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)5 FlexBuildConfigurationManager (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager)5 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)4 Project (com.intellij.openapi.project.Project)4 FlexModuleType (com.intellij.lang.javascript.flex.FlexModuleType)3 FlexUnitRunConfiguration (com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration)3 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)3 FlashRunConfiguration (com.intellij.lang.javascript.flex.run.FlashRunConfiguration)3 FlashRunnerParameters (com.intellij.lang.javascript.flex.run.FlashRunnerParameters)3 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 ProjectStructureConfigurable (com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable)3 CheckedTreeNode (com.intellij.ui.CheckedTreeNode)3 Place (com.intellij.ui.navigation.Place)3