Search in sources :

Example 6 with DefaultModulesProvider

use of com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider in project intellij-community by JetBrains.

the class NewModuleAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = getEventProject(e);
    if (project == null) {
        return;
    }
    Object dataFromContext = prepareDataFromContext(e);
    String defaultPath = null;
    final VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    if (virtualFile != null && virtualFile.isDirectory()) {
        defaultPath = virtualFile.getPath();
    }
    NewProjectWizard wizard = new NewProjectWizard(project, new DefaultModulesProvider(project), defaultPath);
    if (wizard.showAndGet()) {
        createModuleFromWizard(project, dataFromContext, wizard);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) NewProjectWizard(com.intellij.ide.projectWizard.NewProjectWizard)

Example 7 with DefaultModulesProvider

use of com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider in project intellij-community by JetBrains.

the class ProjectFromSourcesBuilderImpl method commit.

@Override
public List<Module> commit(@NotNull final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider) {
    final boolean fromProjectStructure = model != null;
    ModifiableModelsProvider modelsProvider = new IdeaModifiableModelsProvider();
    final LibraryTable.ModifiableModel projectLibraryTable = modelsProvider.getLibraryTableModifiableModel(project);
    final Map<LibraryDescriptor, Library> projectLibs = new HashMap<>();
    final List<Module> result = new ArrayList<>();
    try {
        WriteAction.run(() -> {
            // create project-level libraries
            for (ProjectDescriptor projectDescriptor : getSelectedDescriptors()) {
                for (LibraryDescriptor lib : projectDescriptor.getLibraries()) {
                    final Collection<File> files = lib.getJars();
                    final Library projectLib = projectLibraryTable.createLibrary(lib.getName());
                    final Library.ModifiableModel libraryModel = projectLib.getModifiableModel();
                    for (File file : files) {
                        libraryModel.addRoot(VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES);
                    }
                    libraryModel.commit();
                    projectLibs.put(lib, projectLib);
                }
            }
            if (!fromProjectStructure) {
                projectLibraryTable.commit();
            }
        });
    } catch (Exception e) {
        LOG.info(e);
        Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", e.getMessage()), IdeBundle.message("title.add.module"));
    }
    final Map<ModuleDescriptor, Module> descriptorToModuleMap = new HashMap<>();
    try {
        WriteAction.run(() -> {
            final ModifiableModuleModel moduleModel = fromProjectStructure ? model : ModuleManager.getInstance(project).getModifiableModel();
            for (ProjectDescriptor descriptor : getSelectedDescriptors()) {
                for (final ModuleDescriptor moduleDescriptor : descriptor.getModules()) {
                    final Module module;
                    if (moduleDescriptor.isReuseExistingElement()) {
                        final ExistingModuleLoader moduleLoader = ExistingModuleLoader.setUpLoader(FileUtil.toSystemIndependentName(moduleDescriptor.computeModuleFilePath()));
                        module = moduleLoader.createModule(moduleModel);
                    } else {
                        module = createModule(descriptor, moduleDescriptor, projectLibs, moduleModel);
                    }
                    result.add(module);
                    descriptorToModuleMap.put(moduleDescriptor, module);
                }
            }
            if (!fromProjectStructure) {
                moduleModel.commit();
            }
        });
    } catch (Exception e) {
        LOG.info(e);
        Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", e.getMessage()), IdeBundle.message("title.add.module"));
    }
    // setup dependencies between modules
    try {
        WriteAction.run(() -> {
            for (ProjectDescriptor data : getSelectedDescriptors()) {
                for (final ModuleDescriptor descriptor : data.getModules()) {
                    final Module module = descriptorToModuleMap.get(descriptor);
                    if (module == null) {
                        continue;
                    }
                    final Set<ModuleDescriptor> deps = descriptor.getDependencies();
                    if (deps.size() == 0) {
                        continue;
                    }
                    final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
                    for (ModuleDescriptor dependentDescriptor : deps) {
                        final Module dependentModule = descriptorToModuleMap.get(dependentDescriptor);
                        if (dependentModule != null) {
                            rootModel.addModuleOrderEntry(dependentModule);
                        }
                    }
                    rootModel.commit();
                }
            }
        });
    } catch (Exception e) {
        LOG.info(e);
        Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", e.getMessage()), IdeBundle.message("title.add.module"));
    }
    WriteAction.run(() -> {
        ModulesProvider updatedModulesProvider = fromProjectStructure ? modulesProvider : new DefaultModulesProvider(project);
        for (ProjectConfigurationUpdater updater : myUpdaters) {
            updater.updateProject(project, modelsProvider, updatedModulesProvider);
        }
    });
    return result;
}
Also used : ModulesProvider(com.intellij.openapi.roots.ui.configuration.ModulesProvider) DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) InvalidDataException(com.intellij.openapi.util.InvalidDataException) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ExistingModuleLoader(com.intellij.ide.util.projectWizard.ExistingModuleLoader) ModuleDescriptor(com.intellij.ide.util.importProject.ModuleDescriptor) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ProjectDescriptor(com.intellij.ide.util.importProject.ProjectDescriptor) Library(com.intellij.openapi.roots.libraries.Library) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) LibraryDescriptor(com.intellij.ide.util.importProject.LibraryDescriptor)

Example 8 with DefaultModulesProvider

use of com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider in project intellij-community by JetBrains.

the class PyContentEntriesModuleConfigurable method createEditor.

private void createEditor() {
    if (myModule == null)
        return;
    myModifiableModel = ApplicationManager.getApplication().runReadAction(new Computable<ModifiableRootModel>() {

        @Override
        public ModifiableRootModel compute() {
            return ModuleRootManager.getInstance(myModule).getModifiableModel();
        }
    });
    final ModuleConfigurationStateImpl moduleConfigurationState = new ModuleConfigurationStateImpl(myModule.getProject(), new DefaultModulesProvider(myModule.getProject())) {

        @Override
        public ModifiableRootModel getRootModel() {
            return myModifiableModel;
        }

        @Override
        public FacetsProvider getFacetsProvider() {
            return DefaultFacetsProvider.INSTANCE;
        }
    };
    myEditor = createEditor(myModule, moduleConfigurationState);
    JComponent component = ApplicationManager.getApplication().runReadAction(new Computable<JComponent>() {

        @Override
        public JComponent compute() {
            return myEditor.createComponent();
        }
    });
    myTopPanel.add(component, BorderLayout.CENTER);
}
Also used : DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) ModuleConfigurationStateImpl(com.intellij.openapi.module.impl.ModuleConfigurationStateImpl) Computable(com.intellij.openapi.util.Computable)

Example 9 with DefaultModulesProvider

use of com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider in project liferay-ide by liferay.

the class NewLiferayModuleAction method createModuleFromWizard.

@Nullable
public Module createModuleFromWizard(Project project, AbstractProjectWizard wizard) {
    ProjectBuilder builder = wizard.getProjectBuilder();
    if (builder instanceof ModuleBuilder) {
        ModuleBuilder moduleBuilder = (ModuleBuilder) builder;
        if (moduleBuilder.getName() == null) {
            moduleBuilder.setName(wizard.getProjectName());
        }
        if (moduleBuilder.getModuleFilePath() == null) {
            moduleBuilder.setModuleFilePath(wizard.getModuleFilePath());
        }
    }
    if (!builder.validate(project, project)) {
        return null;
    }
    Module module = null;
    if (builder instanceof ModuleBuilder) {
        module = ((ModuleBuilder) builder).commitModule(project, null);
    } else {
        List<Module> modules = builder.commit(project, null, new DefaultModulesProvider(project));
        if (builder.isOpenProjectSettingsAfter()) {
            ModulesConfigurator.showDialog(project, null, null);
        }
        module = modules == null || modules.isEmpty() ? null : modules.get(0);
    }
    project.save();
    return module;
}
Also used : ProjectBuilder(com.intellij.ide.util.projectWizard.ProjectBuilder) DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) ModuleBuilder(com.intellij.ide.util.projectWizard.ModuleBuilder) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with DefaultModulesProvider

use of com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider in project moe-ide-integration by multi-os-engine.

the class MOENewModuleAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = getEventProject(e);
    if (project != null) {
        Object dataFromContext = this.prepareDataFromContext(e);
        // String defaultPath = null;
        // VirtualFile virtualFile = (VirtualFile)e.getData(CommonDataKeys.VIRTUAL_FILE);
        // if(virtualFile != null && virtualFile.isDirectory()) {
        // defaultPath = virtualFile.getPath();
        // }
        // 
        // NewProjectWizard wizard = new NewProjectWizard(project, new DefaultModulesProvider(project), defaultPath);
        // TODO: temp hack for adding by force a module that will be changed with correct one.
        // TODO: didn't find alternative way to fix incorrect adding MOE module in AS 2.1 and AS 2.0
        String tempModuleDir = project.getBasePath() + File.separator + "temp";
        NewProjectWizard wizard = new NewProjectWizard(project, new DefaultModulesProvider(project), tempModuleDir);
        if (wizard.showAndGet()) {
            this.createModuleFromWizard(project, dataFromContext, wizard);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) NewProjectWizard(com.intellij.ide.projectWizard.NewProjectWizard)

Aggregations

DefaultModulesProvider (com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider)11 Module (com.intellij.openapi.module.Module)5 ModuleBuilder (com.intellij.ide.util.projectWizard.ModuleBuilder)3 ProjectBuilder (com.intellij.ide.util.projectWizard.ProjectBuilder)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Nullable (org.jetbrains.annotations.Nullable)3 NewProjectWizard (com.intellij.ide.projectWizard.NewProjectWizard)2 ModulesProvider (com.intellij.openapi.roots.ui.configuration.ModulesProvider)2 File (java.io.File)2 DetectedFrameworkDescription (com.intellij.framework.detection.DetectedFrameworkDescription)1 ConfigureDetectedFrameworksDialog (com.intellij.framework.detection.impl.ui.ConfigureDetectedFrameworksDialog)1 LibraryDescriptor (com.intellij.ide.util.importProject.LibraryDescriptor)1 ModuleDescriptor (com.intellij.ide.util.importProject.ModuleDescriptor)1 ProjectDescriptor (com.intellij.ide.util.importProject.ProjectDescriptor)1 ExistingModuleLoader (com.intellij.ide.util.projectWizard.ExistingModuleLoader)1 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)1 ModuleConfigurationStateImpl (com.intellij.openapi.module.impl.ModuleConfigurationStateImpl)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1