use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.
the class ContentRootDataService method importData.
@Override
public void importData(@NotNull Collection<DataNode<ContentRootData>> toImport, @Nullable ProjectData projectData, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
if (toImport.isEmpty()) {
return;
}
boolean isNewlyImportedProject = project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) == Boolean.TRUE;
boolean forceDirectoriesCreation = false;
DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(toImport.iterator().next(), ProjectKeys.PROJECT);
if (projectDataNode != null) {
forceDirectoriesCreation = projectDataNode.getUserData(CREATE_EMPTY_DIRECTORIES) == Boolean.TRUE;
}
Set<Module> modulesToExpand = ContainerUtil.newTroveSet();
MultiMap<DataNode<ModuleData>, DataNode<ContentRootData>> byModule = ExternalSystemApiUtil.groupBy(toImport, ModuleData.class);
for (Map.Entry<DataNode<ModuleData>, Collection<DataNode<ContentRootData>>> entry : byModule.entrySet()) {
Module module = entry.getKey().getUserData(AbstractModuleDataService.MODULE_KEY);
module = module != null ? module : modelsProvider.findIdeModule(entry.getKey().getData());
if (module == null) {
LOG.warn(String.format("Can't import content roots. Reason: target module (%s) is not found at the ide. Content roots: %s", entry.getKey(), entry.getValue()));
continue;
}
importData(modelsProvider, entry.getValue(), module, forceDirectoriesCreation);
if (forceDirectoriesCreation || (isNewlyImportedProject && projectData != null && projectData.getLinkedExternalProjectPath().equals(ExternalSystemApiUtil.getExternalProjectPath(module)))) {
modulesToExpand.add(module);
}
}
if (!modulesToExpand.isEmpty()) {
for (Module module : modulesToExpand) {
String productionModuleName = modelsProvider.getProductionModuleName(module);
if (productionModuleName == null || !modulesToExpand.contains(modelsProvider.findIdeModule(productionModuleName))) {
VirtualFile[] roots = modelsProvider.getModifiableRootModel(module).getContentRoots();
if (roots.length > 0) {
VirtualFile virtualFile = roots[0];
ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, () -> {
final ProjectView projectView = ProjectView.getInstance(project);
projectView.changeViewCB(ProjectViewPane.ID, null).doWhenProcessed(() -> projectView.selectCB(null, virtualFile, false));
});
}
}
}
}
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.
the class OpenTasksActivationManagerAction method isEnabled.
@Override
protected boolean isEnabled(AnActionEvent e) {
if (!super.isEnabled(e))
return false;
final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
if (selectedNodes == null || selectedNodes.size() != 1)
return false;
final Object externalData = selectedNodes.get(0).getData();
ProjectSystemId projectSystemId = getSystemId(e);
e.getPresentation().setText(ExternalSystemBundle.message("external.system.task.activation.title"));
e.getPresentation().setDescription(ExternalSystemBundle.message("external.system.task.activation.description", projectSystemId.getReadableName()));
final boolean isProjectNode = externalData instanceof ProjectData || externalData instanceof ModuleData;
return isProjectNode && StringUtil.isNotEmpty(((ExternalConfigPathAware) externalData).getLinkedExternalProjectPath());
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.
the class CachedModuleDataFinder method findModuleData.
@Nullable
public DataNode<ModuleData> findModuleData(@NotNull Module module) {
final String rootProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module);
if (rootProjectPath == null)
return null;
final String projectId = ExternalSystemApiUtil.getExternalProjectId(module);
if (projectId == null)
return null;
final String externalProjectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (externalProjectPath == null || StringUtil.endsWith(externalProjectPath, "buildSrc"))
return null;
ExternalProjectInfo projectData = ProjectDataManager.getInstance().getExternalProjectData(module.getProject(), GradleConstants.SYSTEM_ID, rootProjectPath);
if (projectData == null)
return null;
DataNode<ProjectData> projectStructure = projectData.getExternalProjectStructure();
if (projectStructure == null)
return null;
return findModuleData(projectStructure, externalProjectPath);
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.
the class GradleProjectImportBuilder method applyExtraSettings.
@Override
protected void applyExtraSettings(@NotNull WizardContext context) {
DataNode<ProjectData> node = getExternalProjectNode();
if (node == null) {
return;
}
DataNode<JavaProjectData> javaProjectNode = ExternalSystemApiUtil.find(node, JavaProjectData.KEY);
if (javaProjectNode != null) {
JavaProjectData data = javaProjectNode.getData();
context.setCompilerOutputDirectory(data.getCompileOutputPath());
JavaSdkVersion version = data.getJdkVersion();
Sdk jdk = findJdk(version);
if (jdk != null) {
context.setProjectJdk(jdk);
}
}
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData in project android by JetBrains.
the class Projects method doSelectiveImport.
/**
* Reuse external system 'selective import' feature for importing of the project sub-set.
* And do not ignore projectNode children data, e.g. project libraries
*/
private static void doSelectiveImport(@NotNull Collection<DataNode<ModuleData>> enabledModules, @NotNull Project project) {
ProjectDataManager dataManager = ServiceManager.getService(ProjectDataManager.class);
DataNode<ProjectData> projectNode = enabledModules.isEmpty() ? null : findParent(enabledModules.iterator().next(), PROJECT);
// do not ignore projectNode child data, e.g. project libraries
if (projectNode != null) {
final Collection<DataNode<ModuleData>> allModules = findAll(projectNode, ProjectKeys.MODULE);
if (enabledModules.size() != allModules.size()) {
final Set<DataNode<ModuleData>> moduleToIgnore = ContainerUtil.newIdentityTroveSet(allModules);
moduleToIgnore.removeAll(enabledModules);
for (DataNode<ModuleData> moduleNode : moduleToIgnore) {
visit(moduleNode, node -> node.setIgnored(true));
}
}
dataManager.importData(projectNode, project, true);
} else {
dataManager.importData(enabledModules, project, true);
}
}
Aggregations