use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.
the class ExternalProjectsStructure method updateProjects.
public void updateProjects(Collection<DataNode<ProjectData>> toImport) {
List<String> orphanProjects = ContainerUtil.mapNotNull(myNodeMapping.entrySet(), entry -> entry.getValue() instanceof ProjectNode ? entry.getKey() : null);
for (DataNode<ProjectData> each : toImport) {
final ProjectData projectData = each.getData();
final String projectPath = projectData.getLinkedExternalProjectPath();
orphanProjects.remove(projectPath);
ExternalSystemNode projectNode = findNodeFor(projectPath);
if (projectNode instanceof ProjectNode) {
doMergeChildrenChanges(projectNode, each, new ProjectNode(myExternalProjectsView, each));
} else {
ExternalSystemNode node = myNodeMapping.remove(projectPath);
if (node != null) {
SimpleNode parent = node.getParent();
if (parent instanceof ExternalSystemNode) {
((ExternalSystemNode) parent).remove(projectNode);
}
}
projectNode = new ProjectNode(myExternalProjectsView, each);
myNodeMapping.put(projectPath, projectNode);
}
if (toImport.size() == 1) {
myTreeBuilder.expand(projectNode, null);
}
doUpdateProject((ProjectNode) projectNode);
}
//remove orphan projects from view
for (String orphanProjectPath : orphanProjects) {
ExternalSystemNode projectNode = myNodeMapping.remove(orphanProjectPath);
if (projectNode instanceof ProjectNode) {
SimpleNode parent = projectNode.getParent();
if (parent instanceof ExternalSystemNode) {
((ExternalSystemNode) parent).remove(projectNode);
updateUpTo(projectNode);
}
}
}
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.
the class ExternalSystemImportingTestCase method doImportProject.
private void doImportProject() {
AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId());
final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
projectSettings.setExternalProjectPath(getProjectPath());
Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
projects.remove(projectSettings);
projects.add(projectSettings);
systemSettings.setLinkedProjectsSettings(projects);
final Ref<Couple<String>> error = Ref.create();
ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(myProject, getExternalSystemId()).use(ProgressExecutionMode.MODAL_SYNC).callback(new ExternalProjectRefreshCallback() {
@Override
public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
if (externalProject == null) {
System.err.println("Got null External project after import");
return;
}
ServiceManager.getService(ProjectDataManager.class).importData(externalProject, myProject, true);
System.out.println("External project was successfully imported");
}
@Override
public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
error.set(Couple.of(errorMessage, errorDetails));
}
}).forceWhenUptodate());
if (!error.isNull()) {
String failureMsg = "Import failed: " + error.get().first;
if (StringUtil.isNotEmpty(error.get().second)) {
failureMsg += "\nError details: \n" + error.get().second;
}
fail(failureMsg);
}
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.
the class ExternalProjectsViewImpl method init.
public void init() {
Disposer.register(myProject, this);
initTree();
final ToolWindowManagerEx manager = ToolWindowManagerEx.getInstanceEx(myProject);
final ToolWindowManagerAdapter listener = new ToolWindowManagerAdapter() {
boolean wasVisible = false;
@Override
public void stateChanged() {
if (myToolWindow.isDisposed())
return;
boolean visible = myToolWindow.isVisible();
if (!visible || wasVisible) {
wasVisible = visible;
return;
}
scheduleStructureUpdate();
wasVisible = true;
}
};
manager.addToolWindowManagerListener(listener, myProject);
getShortcutsManager().addListener(new ExternalSystemShortcutsManager.Listener() {
@Override
public void shortcutsUpdated() {
scheduleTasksUpdate();
scheduleStructureRequest(() -> {
assert myStructure != null;
myStructure.updateNodes(RunConfigurationNode.class);
});
}
});
getTaskActivator().addListener(new ExternalSystemTaskActivator.Listener() {
@Override
public void tasksActivationChanged() {
scheduleTasksUpdate();
scheduleStructureRequest(() -> {
assert myStructure != null;
myStructure.updateNodes(RunConfigurationNode.class);
});
}
});
((RunManagerEx) RunManager.getInstance(myProject)).addRunManagerListener(new RunManagerListener() {
private void changed() {
scheduleStructureRequest(() -> {
assert myStructure != null;
myStructure.visitNodes(ModuleNode.class, node -> node.updateRunConfigurations());
});
}
@Override
public void runConfigurationAdded(@NotNull RunnerAndConfigurationSettings settings) {
changed();
}
@Override
public void runConfigurationRemoved(@NotNull RunnerAndConfigurationSettings settings) {
changed();
}
@Override
public void runConfigurationChanged(@NotNull RunnerAndConfigurationSettings settings) {
changed();
}
});
ExternalSystemApiUtil.subscribe(myProject, myExternalSystemId, new ExternalSystemSettingsListenerAdapter() {
@Override
public void onUseAutoImportChange(boolean currentValue, @NotNull final String linkedProjectPath) {
scheduleStructureRequest(() -> {
assert myStructure != null;
final List<ProjectNode> projectNodes = myStructure.getNodes(ProjectNode.class);
for (ProjectNode projectNode : projectNodes) {
final ProjectData projectData = projectNode.getData();
if (projectData != null && projectData.getLinkedExternalProjectPath().equals(linkedProjectPath)) {
projectNode.updateProject();
break;
}
}
});
}
});
myToolWindow.setAdditionalGearActions(createAdditionalGearActionsGroup());
scheduleStructureUpdate();
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.
the class ProjectDataManager method importData.
@SuppressWarnings("unchecked")
public void importData(@NotNull Collection<DataNode<?>> nodes, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider, boolean synchronous) {
if (project.isDisposed())
return;
MultiMap<Key<?>, DataNode<?>> grouped = ExternalSystemApiUtil.recursiveGroup(nodes);
for (Key<?> key : myServices.getValue().keySet()) {
if (!grouped.containsKey(key)) {
grouped.put(key, Collections.<DataNode<?>>emptyList());
}
}
final Collection<DataNode<?>> projects = grouped.get(ProjectKeys.PROJECT);
// only one project(can be multi-module project) expected for per single import
assert projects.size() == 1 || projects.isEmpty();
final DataNode<ProjectData> projectNode = (DataNode<ProjectData>) ContainerUtil.getFirstItem(projects);
final ProjectData projectData;
ProjectSystemId projectSystemId;
if (projectNode != null) {
projectData = projectNode.getData();
projectSystemId = projectNode.getData().getOwner();
ExternalProjectsDataStorage.getInstance(project).saveInclusionSettings(projectNode);
} else {
projectData = null;
DataNode<ModuleData> aModuleNode = (DataNode<ModuleData>) ContainerUtil.getFirstItem(grouped.get(ProjectKeys.MODULE));
projectSystemId = aModuleNode != null ? aModuleNode.getData().getOwner() : null;
}
if (projectSystemId != null) {
ExternalSystemUtil.scheduleExternalViewStructureUpdate(project, projectSystemId);
}
List<Runnable> onSuccessImportTasks = ContainerUtil.newSmartList();
try {
final Set<Map.Entry<Key<?>, Collection<DataNode<?>>>> entries = grouped.entrySet();
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null) {
indicator.setIndeterminate(false);
}
final int size = entries.size();
int count = 0;
List<Runnable> postImportTasks = ContainerUtil.newSmartList();
for (Map.Entry<Key<?>, Collection<DataNode<?>>> entry : entries) {
if (indicator != null) {
String message = ExternalSystemBundle.message("progress.update.text", projectSystemId != null ? projectSystemId.getReadableName() : "", "Refresh " + getReadableText(entry.getKey()));
indicator.setText(message);
indicator.setFraction((double) count++ / size);
}
doImportData(entry.getKey(), entry.getValue(), projectData, project, modelsProvider, postImportTasks, onSuccessImportTasks);
}
for (Runnable postImportTask : postImportTasks) {
postImportTask.run();
}
commit(modelsProvider, project, synchronous, "Imported data");
if (indicator != null) {
indicator.setIndeterminate(true);
}
} catch (Throwable t) {
dispose(modelsProvider, project, synchronous);
ExceptionUtil.rethrowAllAsUnchecked(t);
}
for (Runnable onSuccessImportTask : ContainerUtil.reverse(onSuccessImportTasks)) {
onSuccessImportTask.run();
}
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData 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;
}
Aggregations