Search in sources :

Example 1 with IdeUIModifiableModelsProvider

use of com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider in project intellij-community by JetBrains.

the class AbstractExternalProjectImportBuilder method commit.

@Override
public List<Module> commit(final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider, final ModifiableArtifactModel artifactModel) {
    project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE);
    final DataNode<ProjectData> externalProjectNode = getExternalProjectNode();
    if (externalProjectNode != null) {
        beforeCommit(externalProjectNode, project);
    }
    final boolean isFromUI = model != null;
    final List<Module> modules = ContainerUtil.newSmartList();
    final IdeModifiableModelsProvider modelsProvider = isFromUI ? new IdeUIModifiableModelsProvider(project, model, (ModulesConfigurator) modulesProvider, artifactModel) {

        @NotNull
        @Override
        public Module newModule(@NotNull @NonNls String filePath, String moduleTypeId) {
            final Module module = super.newModule(filePath, moduleTypeId);
            modules.add(module);
            return module;
        }
    } : new IdeModifiableModelsProviderImpl(project) {

        @NotNull
        @Override
        public Module newModule(@NotNull @NonNls String filePath, String moduleTypeId) {
            final Module module = super.newModule(filePath, moduleTypeId);
            modules.add(module);
            return module;
        }
    };
    AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
    final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
    //noinspection unchecked
    Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
    // add current importing project settings to linked projects settings or replace if similar already exist
    projects.remove(projectSettings);
    projects.add(projectSettings);
    //noinspection unchecked
    systemSettings.copyFrom(myControl.getSystemSettings());
    //noinspection unchecked
    systemSettings.setLinkedProjectsSettings(projects);
    if (externalProjectNode != null) {
        if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
            ExternalProjectDataSelectorDialog dialog = new ExternalProjectDataSelectorDialog(project, new InternalExternalProjectInfo(myExternalSystemId, projectSettings.getExternalProjectPath(), externalProjectNode));
            if (dialog.hasMultipleDataToSelect()) {
                dialog.showAndGet();
            } else {
                Disposer.dispose(dialog.getDisposable());
            }
        }
        if (!project.isInitialized()) {
            StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings));
        } else
            finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings);
    }
    return modules;
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo) NotNull(org.jetbrains.annotations.NotNull) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) IdeUIModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ExternalProjectDataSelectorDialog(com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog) ModulesConfigurator(com.intellij.openapi.roots.ui.configuration.ModulesConfigurator) Module(com.intellij.openapi.module.Module) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 2 with IdeUIModifiableModelsProvider

use of com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider in project intellij-community by JetBrains.

the class LibraryDataService method postProcess.

/**
   * Remove orphan project libraries during postprocess phase (after execution of LibraryDependencyDataService#import)
   * in order to use LibraryDataService.isOrphanProjectLibrary method properly
   */
@Override
public void postProcess(@NotNull Collection<DataNode<LibraryData>> toImport, @Nullable ProjectData projectData, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    if (projectData == null)
        return;
    // and hence #isOrphanProjectLibrary() method will work incorrectly
    if (modelsProvider instanceof IdeUIModifiableModelsProvider)
        return;
    final List<Library> orphanIdeLibraries = ContainerUtil.newSmartList();
    final LibraryTable.ModifiableModel librariesModel = modelsProvider.getModifiableProjectLibrariesModel();
    for (Library library : librariesModel.getLibraries()) {
        if (!ExternalSystemApiUtil.isExternalSystemLibrary(library, projectData.getOwner()))
            continue;
        if (isOrphanProjectLibrary(library, modelsProvider)) {
            orphanIdeLibraries.add(library);
        }
    }
    for (Library library : orphanIdeLibraries) {
        String libraryName = library.getName();
        if (libraryName != null) {
            Library libraryToRemove = librariesModel.getLibraryByName(libraryName);
            if (libraryToRemove != null) {
                librariesModel.removeLibrary(libraryToRemove);
            }
        }
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) IdeUIModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider) Library(com.intellij.openapi.roots.libraries.Library)

Example 3 with IdeUIModifiableModelsProvider

use of com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider in project intellij-community by JetBrains.

the class MavenProjectBuilder method commit.

@Override
public List<Module> commit(Project project, ModifiableModuleModel model, ModulesProvider modulesProvider, ModifiableArtifactModel artifactModel) {
    MavenWorkspaceSettings settings = MavenWorkspaceSettingsComponent.getInstance(project).getSettings();
    settings.generalSettings = getGeneralSettings();
    settings.importingSettings = getImportingSettings();
    String settingsFile = System.getProperty("idea.maven.import.settings.file");
    if (!StringUtil.isEmptyOrSpaces(settingsFile)) {
        settings.generalSettings.setUserSettingsFile(settingsFile.trim());
    }
    MavenExplicitProfiles selectedProfiles = getSelectedProfiles();
    String enabledProfilesList = System.getProperty("idea.maven.import.enabled.profiles");
    String disabledProfilesList = System.getProperty("idea.maven.import.disabled.profiles");
    if (enabledProfilesList != null || disabledProfilesList != null) {
        selectedProfiles = selectedProfiles.clone();
        appendProfilesFromString(selectedProfiles.getEnabledProfiles(), enabledProfilesList);
        appendProfilesFromString(selectedProfiles.getDisabledProfiles(), disabledProfilesList);
    }
    MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    manager.setIgnoredState(getParameters().mySelectedProjects, false);
    manager.addManagedFilesWithProfiles(MavenUtil.collectFiles(getParameters().mySelectedProjects), selectedProfiles);
    manager.waitForReadingCompletion();
    boolean isFromUI = model != null;
    return manager.importProjects(isFromUI ? new IdeUIModifiableModelsProvider(project, model, (ModulesConfigurator) modulesProvider, artifactModel) : new IdeModifiableModelsProviderImpl(project));
}
Also used : IdeUIModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)

Aggregations

IdeUIModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider)3 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)2 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)1 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)1 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)1 ExternalProjectDataSelectorDialog (com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog)1 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)1 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)1 Module (com.intellij.openapi.module.Module)1 Library (com.intellij.openapi.roots.libraries.Library)1 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)1 ModulesConfigurator (com.intellij.openapi.roots.ui.configuration.ModulesConfigurator)1 NotNull (org.jetbrains.annotations.NotNull)1 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)1