Search in sources :

Example 1 with ProjectDescriptor

use of com.intellij.ide.util.importProject.ProjectDescriptor in project intellij-community by JetBrains.

the class CreateFromSourcesMode method addSteps.

public void addSteps(WizardContext context, ModulesProvider modulesProvider, StepSequence sequence, String specific) {
    final ProjectFromSourcesBuilderImpl projectBuilder = new ProjectFromSourcesBuilderImpl(context, modulesProvider);
    myProjectBuilder = projectBuilder;
    final Icon icon = context.getStepIcon();
    if (context.isCreatingNewProject()) {
        addStep(sequence, new ProjectNameStep(context, this), specific);
    }
    addStep(sequence, new RootsDetectionStep(projectBuilder, context, sequence, icon, "reference.dialogs.new.project.fromCode.source"), specific);
    Set<String> detectorTypes = new HashSet<>();
    for (ProjectStructureDetector detector : ProjectStructureDetector.EP_NAME.getExtensions()) {
        detectorTypes.add(detector.getDetectorId());
        for (ModuleWizardStep step : detector.createWizardSteps(projectBuilder, projectBuilder.getProjectDescriptor(detector), icon)) {
            sequence.addSpecificStep(detector.getDetectorId(), step);
        }
    }
    if (FrameworkDetectionStep.isEnabled()) {
        FrameworkDetectionStep frameworkDetectionStep = new FrameworkDetectionStep(icon, projectBuilder) {

            public List<ModuleDescriptor> getModuleDescriptors() {
                final List<ModuleDescriptor> moduleDescriptors = new ArrayList<>();
                for (ProjectDescriptor descriptor : projectBuilder.getSelectedDescriptors()) {
                    moduleDescriptors.addAll(descriptor.getModules());
                }
                return moduleDescriptors;
            }
        };
        projectBuilder.addConfigurationUpdater(frameworkDetectionStep);
        sequence.addCommonFinishingStep(frameworkDetectionStep, detectorTypes);
    }
}
Also used : ArrayList(java.util.ArrayList) ProjectFromSourcesBuilderImpl(com.intellij.ide.util.projectWizard.importSources.impl.ProjectFromSourcesBuilderImpl) ModuleDescriptor(com.intellij.ide.util.importProject.ModuleDescriptor) ProjectStructureDetector(com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) ProjectNameStep(com.intellij.ide.util.newProjectWizard.ProjectNameStep) ProjectDescriptor(com.intellij.ide.util.importProject.ProjectDescriptor) FrameworkDetectionStep(com.intellij.ide.util.importProject.FrameworkDetectionStep) RootsDetectionStep(com.intellij.ide.util.importProject.RootsDetectionStep) HashSet(java.util.HashSet)

Example 2 with ProjectDescriptor

use of com.intellij.ide.util.importProject.ProjectDescriptor 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)

Aggregations

ModuleDescriptor (com.intellij.ide.util.importProject.ModuleDescriptor)2 ProjectDescriptor (com.intellij.ide.util.importProject.ProjectDescriptor)2 FrameworkDetectionStep (com.intellij.ide.util.importProject.FrameworkDetectionStep)1 LibraryDescriptor (com.intellij.ide.util.importProject.LibraryDescriptor)1 RootsDetectionStep (com.intellij.ide.util.importProject.RootsDetectionStep)1 ProjectNameStep (com.intellij.ide.util.newProjectWizard.ProjectNameStep)1 ExistingModuleLoader (com.intellij.ide.util.projectWizard.ExistingModuleLoader)1 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)1 ProjectStructureDetector (com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector)1 ProjectFromSourcesBuilderImpl (com.intellij.ide.util.projectWizard.importSources.impl.ProjectFromSourcesBuilderImpl)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Library (com.intellij.openapi.roots.libraries.Library)1 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)1 DefaultModulesProvider (com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider)1 ModulesProvider (com.intellij.openapi.roots.ui.configuration.ModulesProvider)1 InvalidDataException (com.intellij.openapi.util.InvalidDataException)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1