Search in sources :

Example 6 with FlexProjectConfigurationEditor

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

the class FlashBuilderImporter method commit.

public List<Module> commit(final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider, final ModifiableArtifactModel artifactModel) {
    //FlexModuleBuilder.setupResourceFilePatterns(project);
    final boolean needToCommit = model == null;
    final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel();
    final List<String> paths = getList();
    final boolean isArchive = paths.size() == 1 && FlashBuilderProjectFinder.hasArchiveExtension(paths.get(0));
    final List<String> dotProjectPaths = getDotProjectPaths(project);
    final List<FlashBuilderProject> flashBuilderProjects = FlashBuilderProjectLoadUtil.loadProjects(dotProjectPaths, isArchive);
    final Map<FlashBuilderProject, ModifiableRootModel> flashBuilderProjectToModifiableModelMap = new THashMap<>();
    final Map<Module, ModifiableRootModel> moduleToModifiableModelMap = new THashMap<>();
    final Set<String> moduleNames = new THashSet<>(flashBuilderProjects.size());
    final FlexProjectConfigurationEditor currentFlexEditor = FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor();
    assert needToCommit == (currentFlexEditor == null);
    for (FlashBuilderProject flashBuilderProject : flashBuilderProjects) {
        final String moduleName = makeUnique(flashBuilderProject.getName(), moduleNames);
        moduleNames.add(moduleName);
        final String moduleFilePath = flashBuilderProject.getProjectRootPath() + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
        if (LocalFileSystem.getInstance().findFileByPath(moduleFilePath) != null) {
            ApplicationManager.getApplication().runWriteAction(() -> ModuleBuilder.deleteModuleFile(moduleFilePath));
        }
        final Module module = moduleModel.newModule(moduleFilePath, FlexModuleType.getInstance().getId());
        final ModifiableRootModel rootModel = currentFlexEditor != null ? currentFlexEditor.getModifiableRootModel(module) : ModuleRootManager.getInstance(module).getModifiableModel();
        flashBuilderProjectToModifiableModelMap.put(flashBuilderProject, rootModel);
        moduleToModifiableModelMap.put(module, rootModel);
    }
    final FlexProjectConfigurationEditor flexConfigEditor = currentFlexEditor != null ? currentFlexEditor : FlexProjectConfigurationEditor.createEditor(project, moduleToModifiableModelMap, null, null);
    final FlashBuilderSdkFinder sdkFinder = new FlashBuilderSdkFinder(project, getParameters().myInitiallySelectedPath, flashBuilderProjects);
    final FlashBuilderModuleImporter flashBuilderModuleImporter = new FlashBuilderModuleImporter(project, flexConfigEditor, flashBuilderProjects, sdkFinder);
    for (final FlashBuilderProject flashBuilderProject : flashBuilderProjects) {
        flashBuilderModuleImporter.setupModule(flashBuilderProjectToModifiableModelMap.get(flashBuilderProject), flashBuilderProject);
    }
    if (needToCommit) {
        try {
            flexConfigEditor.commit();
        } catch (ConfigurationException e) {
            Logger.getInstance(FlashBuilderImporter.class).error(e);
        }
        ApplicationManager.getApplication().runWriteAction(() -> {
            ModifiableModelCommitter.multiCommit(moduleToModifiableModelMap.values(), moduleModel);
        });
    }
    return new ArrayList<>(moduleToModifiableModelMap.keySet());
}
Also used : THashSet(gnu.trove.THashSet) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) THashMap(gnu.trove.THashMap) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Module(com.intellij.openapi.module.Module)

Example 7 with FlexProjectConfigurationEditor

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

the class BuildConfigurationProjectStructureElement method checkIfBCOutputUsedAs3rdPartyLib.

private void checkIfBCOutputUsedAs3rdPartyLib(final ProjectStructureProblemsHolder problemsHolder, final FlexBCConfigurator configurator, final DependencyEntry entry, final VirtualFile[] classesRoots) {
    for (VirtualFile libFile : classesRoots) {
        final VirtualFile realFile = FlexCompilerHandler.getRealFile(libFile);
        if (realFile != null && !realFile.isDirectory() && "swc".equalsIgnoreCase(realFile.getExtension())) {
            final List<ModifiableFlexBuildConfiguration> bcs = configurator.getBCsByOutputPath(realFile.getPath());
            if (bcs != null && !bcs.isEmpty()) {
                final ModifiableFlexBuildConfiguration otherLibBC = bcs.get(0);
                final FlexProjectConfigurationEditor editor = configurator.getConfigEditor();
                assert editor != null;
                final Module otherLibModule = editor.getModule(otherLibBC);
                final String message = FlexBundle.message("own.lib.used.as.3rd.party", realFile.getName(), otherLibBC.getName(), otherLibModule.getName());
                final Object location = entry instanceof ModuleLibraryEntry ? DependenciesConfigurable.Location.TableEntry.forModuleLibrary(((ModuleLibraryEntry) entry).getLibraryId()) : DependenciesConfigurable.Location.TableEntry.forSharedLibrary(((SharedLibraryEntry) entry).getLibraryLevel(), ((SharedLibraryEntry) entry).getLibraryName());
                final PlaceInProjectStructure placeInPS = new PlaceInBuildConfiguration(this, DependenciesConfigurable.TAB_NAME, location);
                final String quickFixName = FlexBundle.message("instead.setup.dependency.on.bc", otherLibBC.getName(), otherLibModule.getName());
                final ConfigurationErrorQuickFix quickFix = new ConfigurationErrorQuickFix(quickFixName) {

                    public void performFix() {
                        final FlexBCConfigurable configurable = configurator.getBCConfigurable(myBc);
                        final DependenciesConfigurable dependenciesConfigurable = configurable.getDependenciesConfigurable();
                        final FlexBCConfigurable otherLibConfigurable = configurator.getBCConfigurable(otherLibBC);
                        final LinkageType linkageType = entry.getDependencyType().getLinkageType();
                        dependenciesConfigurable.addBCDependency(otherLibConfigurable, linkageType);
                        if (entry instanceof ModuleLibraryEntry) {
                            dependenciesConfigurable.removeDependency(((ModuleLibraryEntry) entry).getLibraryId());
                        } else {
                            dependenciesConfigurable.removeDependency(((SharedLibraryEntry) entry).getLibraryLevel(), ((SharedLibraryEntry) entry).getLibraryName());
                        }
                        final Place place = configurator.getPlaceFor(myModule, myBc.getName());
                        place.putPath(CompositeConfigurable.TAB_NAME, DependenciesConfigurable.TAB_NAME);
                        place.putPath(FlexBCConfigurable.LOCATION_ON_TAB, DependenciesConfigurable.Location.TableEntry.forBc(otherLibConfigurable));
                        ProjectStructureConfigurable.getInstance(myModule.getProject()).navigateTo(place, true);
                    }
                };
                final String errorId = entry instanceof ModuleLibraryEntry ? ((ModuleLibraryEntry) entry).getLibraryId() : ((SharedLibraryEntry) entry).getLibraryName();
                problemsHolder.registerProblem(message, null, ProjectStructureProblemType.warning(errorId), placeInPS, quickFix);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) Module(com.intellij.openapi.module.Module) Place(com.intellij.ui.navigation.Place) LinkageType(com.intellij.flex.model.bc.LinkageType)

Example 8 with FlexProjectConfigurationEditor

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

the class FlexSdkStep method selectSdkUsedByOtherModules.

private static void selectSdkUsedByOtherModules(@Nullable final Project project, final FlexSdkComboBoxWithBrowseButton combo) {
    if (project == null) {
        return;
    }
    final FlexProjectConfigurationEditor currentEditor = FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor();
    if (currentEditor != null) {
        final Module[] modules = ModuleStructureConfigurable.getInstance(project).getModules();
        for (Module module : modules) {
            if (ModuleType.get(module) != FlexModuleType.getInstance()) {
                continue;
            }
            for (ModifiableFlexBuildConfiguration c : currentEditor.getConfigurations(module)) {
                SdkEntry sdkEntry = c.getDependencies().getSdkEntry();
                Sdk sdk;
                if (sdkEntry != null && (sdk = FlexSdkUtils.findFlexOrFlexmojosSdk(sdkEntry.getName())) != null && sdk.getSdkType() == FlexSdkType2.getInstance()) {
                    combo.setSelectedSdkRaw(sdk.getName());
                    return;
                }
            }
        }
    } else {
        for (final Module module : ModuleManager.getInstance(project).getModules()) {
            if (ModuleType.get(module) == FlexModuleType.getInstance()) {
                for (FlexBuildConfiguration bc : FlexBuildConfigurationManager.getInstance(module).getBuildConfigurations()) {
                    Sdk sdk = bc.getSdk();
                    if (sdk != null) {
                        combo.setSelectedSdkRaw(sdk.getName());
                        return;
                    }
                }
            }
        }
    }
}
Also used : FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration) SdkEntry(com.intellij.lang.javascript.flex.projectStructure.model.SdkEntry)

Example 9 with FlexProjectConfigurationEditor

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

the class FlexModuleBuilder method setupRootModel.

public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException {
    final ContentEntry contentEntry = doAddContentEntry(modifiableRootModel);
    if (contentEntry == null)
        return;
    final VirtualFile sourceRoot = createSourceRoot(contentEntry);
    final Module module = modifiableRootModel.getModule();
    final FlexProjectConfigurationEditor currentFlexEditor = FlexBuildConfigurationsExtension.getInstance().getConfigurator().getConfigEditor();
    final boolean needToCommitFlexEditor = currentFlexEditor == null;
    final FlexProjectConfigurationEditor flexConfigEditor;
    flexConfigEditor = currentFlexEditor != null ? currentFlexEditor : FlexProjectConfigurationEditor.createEditor(module.getProject(), Collections.singletonMap(module, modifiableRootModel), null, null);
    final ModifiableFlexBuildConfiguration[] configurations = flexConfigEditor.getConfigurations(module);
    assert configurations.length == 1;
    final ModifiableFlexBuildConfiguration bc = configurations[0];
    setupBC(modifiableRootModel, bc);
    if (bc.getOutputType() == OutputType.Application) {
        createRunConfiguration(module, bc);
    }
    if (sourceRoot != null && myCreateSampleApp && myFlexSdk != null) {
        try {
            final boolean flex4 = !FlexSdkUtils.isAirSdkWithoutFlex(myFlexSdk) && StringUtil.compareVersionNumbers(myFlexSdk.getVersionString(), "4") >= 0;
            FlexUtils.createSampleApp(module.getProject(), sourceRoot, mySampleAppName, myTargetPlatform, flex4);
        } catch (IOException ex) {
            throw new ConfigurationException(ex.getMessage());
        }
    }
    if (myCreateHtmlWrapperTemplate && myFlexSdk != null) {
        final String path = VfsUtilCore.urlToPath(contentEntry.getUrl()) + "/" + CreateHtmlWrapperTemplateDialog.HTML_TEMPLATE_FOLDER_NAME;
        if (CreateHtmlWrapperTemplateDialog.createHtmlWrapperTemplate(module.getProject(), myFlexSdk, path, myEnableHistory, myCheckPlayerVersion, myExpressInstall)) {
            bc.setUseHtmlWrapper(true);
            bc.setWrapperTemplatePath(path);
        }
    }
    if (needToCommitFlexEditor) {
        flexConfigEditor.commit();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ContentEntry(com.intellij.openapi.roots.ContentEntry) IOException(java.io.IOException) Module(com.intellij.openapi.module.Module) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)

Example 10 with FlexProjectConfigurationEditor

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

the class AddAsSwcLibDialog method doOKAction.

@Override
protected void doOKAction() {
    final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCs = myBCTree.getSelectedBCs();
    final Map<Module, ModifiableRootModel> moduleToModifiableModelMap = new THashMap<>();
    for (Pair<Module, FlexBuildConfiguration> moduleAndBC : modulesAndBCs) {
        moduleToModifiableModelMap.put(moduleAndBC.first, ModuleRootManager.getInstance(moduleAndBC.first).getModifiableModel());
    }
    final LibraryTable.ModifiableModel projectLibsModel = ProjectLibraryTable.getInstance(myProject).getModifiableModel();
    final LibraryTable.ModifiableModel globalLibsModel = ApplicationLibraryTable.getApplicationTable().getModifiableModel();
    final FlexProjectConfigurationEditor flexConfigEditor = FlexProjectConfigurationEditor.createEditor(myProject, moduleToModifiableModelMap, projectLibsModel, globalLibsModel);
    addLib(flexConfigEditor, modulesAndBCs, myRoots);
    try {
        flexConfigEditor.commit();
    } catch (ConfigurationException e) {
        Logger.getInstance(AddAsSwcLibDialog.class).error(e);
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        globalLibsModel.commit();
        projectLibsModel.commit();
        for (ModifiableRootModel modifiableRootModel : moduleToModifiableModelMap.values()) {
            modifiableRootModel.commit();
        }
    });
    if (myOpenProjectStructureCheckBox.isSelected()) {
        final Pair<Module, FlexBuildConfiguration> moduleAndBc = modulesAndBCs.iterator().next();
        openProjectStructure(moduleAndBc.first, moduleAndBc.second);
    }
    super.doOKAction();
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) 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) THashMap(gnu.trove.THashMap) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Module(com.intellij.openapi.module.Module) Pair(com.intellij.openapi.util.Pair)

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