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;
}
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);
}
}
}
}
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));
}
Aggregations