Search in sources :

Example 11 with FlexProjectConfigurationEditor

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

the class BuildConfigurationProjectStructureElement method check.

@Override
public void check(final ProjectStructureProblemsHolder problemsHolder) {
    final FlexBCConfigurator configurator = FlexBuildConfigurationsExtension.getInstance().getConfigurator();
    final FlexProjectConfigurationEditor editor = configurator.getConfigEditor();
    assert editor != null;
    /*
    final SdkEntry sdkEntry = myBc.getDependencies().getSdkEntry();
    if (sdkEntry == null) {
      Pair<String, Object> location =
        Pair.<String, Object>create(FlexBCConfigurable.LOCATION_ON_TAB, DependenciesConfigurable.Location.SDK);

      PlaceInProjectStructure place = new PlaceInBuildConfiguration(this, DependenciesConfigurable.TAB_NAME, location);
      problemsHolder.registerProblem(FlexBundle.message("bc.problem.no.sdk"), null, ProjectStructureProblemType.error("sdk"),
                                     place, null);
    }
    else {
      if (FlexSdkUtils.findFlexOrFlexmojosSdk(sdkEntry.getName()) == null) {
        Pair<String, Object> location =
          Pair.<String, Object>create(FlexBCConfigurable.LOCATION_ON_TAB, DependenciesConfigurable.Location.SDK);

        PlaceInProjectStructure place = new PlaceInBuildConfiguration(this, DependenciesConfigurable.TAB_NAME, location);
        problemsHolder.registerProblem(FlexBundle.message("bc.problem.sdk.not.found", sdkEntry.getName()), null,
                                       ProjectStructureProblemType.error("flex-bc-sdk"), place, null);
      }
    }
    */
    checkDependencies(problemsHolder, editor);
    checkSameOutputPaths(problemsHolder, configurator, editor);
    checkIfBCOutputUsedAs3rdPartyLib(problemsHolder, configurator, editor);
    ValidateFlashConfigurationsPrecompileTask.checkConfiguration(myModule, myBc, true, problem -> {
        if (!(problem instanceof FlashProjectStructureProblem.FlexUnitOutputFolderProblem)) {
            PlaceInProjectStructure place = new PlaceInBuildConfiguration(this, problem.tabName, problem.locationOnTab);
            final ProjectStructureProblemType problemType = problem.severity == ProjectStructureProblemType.Severity.ERROR ? ProjectStructureProblemType.error(problem.errorId) : ProjectStructureProblemType.warning(problem.errorId);
            problemsHolder.registerProblem(problem.errorMessage, null, problemType, place, null);
        }
    });
}
Also used : FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)

Example 12 with FlexProjectConfigurationEditor

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

the class BuildConfigurationProjectStructureElement method getUsagesInElement.

@Override
public List<ProjectStructureElementUsage> getUsagesInElement() {
    FlexBCConfigurator configurator = FlexBuildConfigurationsExtension.getInstance().getConfigurator();
    final FlexProjectConfigurationEditor editor = configurator.getConfigEditor();
    assert editor != null;
    final ModulesConfigurator modulesConfigurator = myContext.getModulesConfigurator();
    final List<ProjectStructureElementUsage> usages = new ArrayList<>();
    for (DependencyEntry dependencyEntry : myBc.getDependencies().getEntries()) {
        if (dependencyEntry instanceof SharedLibraryEntry) {
            String libraryName = ((SharedLibraryEntry) dependencyEntry).getLibraryName();
            String libraryLevel = ((SharedLibraryEntry) dependencyEntry).getLibraryLevel();
            final Library library = myContext.getLibrary(libraryName, libraryLevel);
            if (library != null) {
                usages.add(new UsageInBcDependencies(this, new LibraryProjectStructureElement(myContext, library)) {

                    @Override
                    public void removeSourceElement() {
                        libraryReplaced(library, null);
                    }

                    @Override
                    public void replaceElement(final ProjectStructureElement newElement) {
                        libraryReplaced(library, ((LibraryProjectStructureElement) newElement).getLibrary());
                    }
                });
            }
        } else if (dependencyEntry instanceof BuildConfigurationEntry) {
            final BuildConfigurationEntry bcEntry = (BuildConfigurationEntry) dependencyEntry;
            Module module = modulesConfigurator.getModule(bcEntry.getModuleName());
            if (module != null) {
                final ModifiableFlexBuildConfiguration bc = ContainerUtil.find(editor.getConfigurations(module), configuration -> bcEntry.getBcName().equals(configuration.getName()));
                if (bc != null) {
                    usages.add(new UsageInBcDependencies(this, new BuildConfigurationProjectStructureElement(bc, module, myContext)) {

                        @Override
                        public void removeSourceElement() {
                        // ignore as editor already listens to BC removal
                        }

                        @Override
                        public void replaceElement(final ProjectStructureElement newElement) {
                            throw new UnsupportedOperationException();
                        }
                    });
                }
            }
            bcEntry.findBuildConfiguration();
        }
    }
    Sdk sdk = myBc.getSdk();
    if (sdk != null) {
        usages.add(new UsageInBcDependencies(this, new SdkProjectStructureElement(myContext, sdk)) {

            @Override
            public void removeSourceElement() {
                myBc.getDependencies().setSdkEntry(null);
            }

            @Override
            public void replaceElement(final ProjectStructureElement newElement) {
                throw new UnsupportedOperationException();
            }
        });
    }
    return usages;
}
Also used : FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) Library(com.intellij.openapi.roots.libraries.Library) FlexCompilerHandler(com.intellij.lang.javascript.flex.build.FlexCompilerHandler) StructureConfigurableContext(com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext) com.intellij.openapi.roots.ui.configuration.projectRoot.daemon(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) FlexCommonBundle(com.intellij.flex.FlexCommonBundle) FlexBuildConfigurationsExtension(com.intellij.lang.javascript.flex.projectStructure.FlexBuildConfigurationsExtension) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) OrderRootType(com.intellij.openapi.roots.OrderRootType) FlexBundle(com.intellij.lang.javascript.flex.FlexBundle) ValidateFlashConfigurationsPrecompileTask(com.intellij.lang.javascript.flex.build.ValidateFlashConfigurationsPrecompileTask) com.intellij.lang.javascript.flex.projectStructure.model(com.intellij.lang.javascript.flex.projectStructure.model) Sdk(com.intellij.openapi.projectRoots.Sdk) ModulesConfigurator(com.intellij.openapi.roots.ui.configuration.ModulesConfigurator) LinkageType(com.intellij.flex.model.bc.LinkageType) FlexProjectRootsUtil(com.intellij.lang.javascript.flex.projectStructure.options.FlexProjectRootsUtil) FlashProjectStructureProblem(com.intellij.lang.javascript.flex.build.FlashProjectStructureProblem) Nullable(org.jetbrains.annotations.Nullable) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Place(com.intellij.ui.navigation.Place) List(java.util.List) ProjectStructureConfigurable(com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) Condition(com.intellij.openapi.util.Condition) ArrayList(java.util.ArrayList) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ModulesConfigurator(com.intellij.openapi.roots.ui.configuration.ModulesConfigurator) Library(com.intellij.openapi.roots.libraries.Library) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 13 with FlexProjectConfigurationEditor

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

the class FlexTestUtils method createConfigEditor.

public static FlexProjectConfigurationEditor createConfigEditor(final Module... modules) {
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final Map<Module, ModifiableRootModel> models = new FactoryMap<Module, ModifiableRootModel>() {

        @Override
        protected ModifiableRootModel create(final Module module) {
            final ModifiableRootModel result = ModuleRootManager.getInstance(module).getModifiableModel();
            Disposer.register(module, new Disposable() {

                @Override
                public void dispose() {
                    if (!result.isDisposed()) {
                        result.dispose();
                    }
                }
            });
            return result;
        }
    };
    return new FlexProjectConfigurationEditor(modules[0].getProject(), new FlexProjectConfigurationEditor.ProjectModifiableModelProvider() {

        @Override
        public Module[] getModules() {
            return modules;
        }

        @Override
        public ModifiableRootModel getModuleModifiableModel(Module module) {
            return models.get(module);
        }

        @Override
        public void addListener(FlexBCConfigurator.Listener listener, Disposable parentDisposable) {
        // ignore
        }

        @Override
        public void commitModifiableModels() throws ConfigurationException {
            ApplicationManager.getApplication().runWriteAction(() -> {
                for (ModifiableRootModel model : models.values()) {
                    if (model.isChanged()) {
                        model.commit();
                    }
                }
            });
        }

        public Library findSourceLibraryForLiveName(final String name, final String level) {
            return findSourceLibrary(name, level);
        }

        public Library findSourceLibrary(final String name, final String level) {
            return getLibrariesTable(level).getLibraryByName(name);
        }

        private LibraryTable getLibrariesTable(final String level) {
            if (LibraryTablesRegistrar.APPLICATION_LEVEL.equals(level)) {
                return ApplicationLibraryTable.getApplicationTable();
            } else {
                assert LibraryTablesRegistrar.PROJECT_LEVEL.equals(level);
                return ProjectLibraryTable.getInstance(modules[0].getProject());
            }
        }
    });
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) Disposable(com.intellij.openapi.Disposable) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) ApplicationLibraryTable(com.intellij.openapi.roots.impl.libraries.ApplicationLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module)

Example 14 with FlexProjectConfigurationEditor

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

the class ActionScriptCompletionTest method testTwoSdks.

public void testTwoSdks() throws Exception {
    final Sdk sdk45 = FlexTestUtils.createSdk(FlexTestUtils.getPathToCompleteFlexSdk("4.5"), null, true);
    final Sdk sdk46 = FlexTestUtils.createSdk(FlexTestUtils.getPathToCompleteFlexSdk("4.6"), null, false);
    FlexTestUtils.modifyConfigs(myProject, new Consumer<FlexProjectConfigurationEditor>() {

        public void consume(final FlexProjectConfigurationEditor editor) {
            ModifiableFlexBuildConfiguration bc1 = editor.getConfigurations(myModule)[0];
            bc1.setName("1");
            FlexTestUtils.setSdk(bc1, sdk45);
            ModifiableFlexBuildConfiguration bc2 = editor.createConfiguration(myModule);
            bc2.setName("2");
            FlexTestUtils.setSdk(bc2, sdk46);
        }
    });
    final FlexBuildConfigurationManager m = FlexBuildConfigurationManager.getInstance(myModule);
    class TestZZ implements ThrowableRunnable<Exception> {

        private final String myBcName;

        private final String myExpectedTypeText;

        TestZZ(final String bcName, final String expectedTypeText) {
            myBcName = bcName;
            myExpectedTypeText = expectedTypeText;
        }

        @Override
        public void run() throws Exception {
            m.setActiveBuildConfiguration(m.findConfigurationByName(myBcName));
            defaultTest();
            for (LookupElement item : myItems) {
                final LookupElementPresentation p = new LookupElementPresentation();
                item.renderElement(p);
                assertEquals(myExpectedTypeText, p.getTypeText());
            }
        }
    }
    new TestZZ("1", sdk45.getName()).run();
    new TestZZ("2", sdk46.getName()).run();
    new TestZZ("1", sdk45.getName()).run();
}
Also used : FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) ThrowableRunnable(com.intellij.util.ThrowableRunnable) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) Sdk(com.intellij.openapi.projectRoots.Sdk) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)

Example 15 with FlexProjectConfigurationEditor

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

the class FlexmojosImporter method process.

public void process(final IdeModifiableModelsProvider modelsProvider, final Module module, final MavenRootModelAdapter modelAdapter, final MavenProjectsTree mavenTree, final MavenProject mavenProject, final MavenProjectChanges changes, final Map<MavenProject, String> mavenProjectToModuleName, final List<MavenProjectsProcessorTask> postTasks) {
    expireNotification();
    final FlexProjectConfigurationEditor currentEditor = FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor();
    final boolean needToCommit = currentEditor == null;
    final LibraryTable.ModifiableModel projectLibrariesModel = modelsProvider.getModifiableProjectLibrariesModel();
    final Map<Module, ModifiableRootModel> moduleToModifiableModel = Collections.singletonMap(module, modelAdapter.getRootModel());
    final FlexProjectConfigurationEditor flexEditor = currentEditor != null ? currentEditor : new FlexProjectConfigurationEditor(module.getProject(), FlexProjectConfigurationEditor.createModelProvider(moduleToModifiableModel, projectLibrariesModel, null)) {

        @Nullable
        protected Module findModuleWithBC(final BuildConfigurationEntry bcEntry) {
            // don't check BC presence here because corresponding BC may appear later in next import cycle
            return modelAdapter.findModuleByName(bcEntry.getModuleName());
        }
    };
    final MavenPlugin flexmojosPlugin = getFlexmojosPlugin(mavenProject);
    final Flexmojos3Configurator configurator = StringUtil.compareVersionNumbers(flexmojosPlugin.getVersion(), "5") >= 0 ? new Flexmojos5Configurator(module, modelsProvider, flexEditor, mavenTree, mavenProjectToModuleName, mavenProject, flexmojosPlugin, getCompiledLocales(mavenProject), getRuntimeLocales(mavenProject), this) : StringUtil.compareVersionNumbers(flexmojosPlugin.getVersion(), "4") >= 0 ? new Flexmojos4Configurator(module, modelsProvider, flexEditor, mavenTree, mavenProjectToModuleName, mavenProject, flexmojosPlugin, getCompiledLocales(mavenProject), getRuntimeLocales(mavenProject), this) : new Flexmojos3Configurator(module, modelsProvider, flexEditor, mavenTree, mavenProjectToModuleName, mavenProject, flexmojosPlugin, getCompiledLocales(mavenProject), getRuntimeLocales(mavenProject), this);
    configurator.configureAndAppendTasks(postTasks);
    if (needToCommit) {
        try {
            flexEditor.commit();
        } catch (ConfigurationException e) {
            // can't happen
            MavenLog.LOG.error(e);
        }
    }
}
Also used : MavenPlugin(org.jetbrains.idea.maven.model.MavenPlugin) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) BuildConfigurationEntry(com.intellij.lang.javascript.flex.projectStructure.model.BuildConfigurationEntry) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)15 Module (com.intellij.openapi.module.Module)9 ConfigurationException (com.intellij.openapi.options.ConfigurationException)7 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)4 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 FlexBCConfigurator (com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)3 LinkageType (com.intellij.flex.model.bc.LinkageType)2 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)2 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)2 ApplicationLibraryTable (com.intellij.openapi.roots.impl.libraries.ApplicationLibraryTable)2 Library (com.intellij.openapi.roots.libraries.Library)2 Place (com.intellij.ui.navigation.Place)2 Nullable (org.jetbrains.annotations.Nullable)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementPresentation (com.intellij.codeInsight.lookup.LookupElementPresentation)1 FlexCommonBundle (com.intellij.flex.FlexCommonBundle)1