use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.
the class DataNodeCaches method isCacheMissingModels.
public boolean isCacheMissingModels(@NotNull DataNode<ProjectData> cache) {
Collection<DataNode<ModuleData>> moduleDataNodes = findAll(cache, MODULE);
if (!moduleDataNodes.isEmpty()) {
Map<String, DataNode<ModuleData>> moduleDataNodesByName = indexByModuleName(moduleDataNodes);
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
for (Module module : moduleManager.getModules()) {
DataNode<ModuleData> moduleDataNode = moduleDataNodesByName.get(module.getName());
if (moduleDataNode == null) {
// When a Gradle facet is present, there should be a cache node for the module.
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet != null) {
return true;
}
} else if (isCacheMissingModels(moduleDataNode, module)) {
return true;
}
}
return false;
}
return true;
}
use of com.intellij.openapi.externalSystem.model.DataNode 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);
}
}
use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.
the class ProjectSubset method findAndIncludeModules.
public void findAndIncludeModules(@NotNull Collection<String> moduleGradlePaths) {
DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(myProject).getCachedProjectData();
if (projectInfo == null) {
return;
}
Collection<DataNode<ModuleData>> moduleInfos = findAll(projectInfo, MODULE);
if (!moduleInfos.isEmpty()) {
Project project = myProject;
new Task.Modal(project, "Finding Missing Modules", false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
String[] originalSelection = getSelection();
Set<String> selection = originalSelection != null ? Sets.newHashSet(originalSelection) : Sets.newHashSet();
List<DataNode<ModuleData>> selectedModules = Lists.newArrayList();
boolean found = false;
int doneCount = 0;
for (DataNode<ModuleData> moduleInfo : moduleInfos) {
indicator.setFraction(++doneCount / moduleInfos.size());
String name = getNameOf(moduleInfo);
if (selection.contains(name)) {
selectedModules.add(moduleInfo);
continue;
}
DataNode<GradleModuleModel> gradleProjectNode = find(moduleInfo, GRADLE_MODULE_MODEL);
if (gradleProjectNode != null) {
GradleModuleModel gradleModuleModel = gradleProjectNode.getData();
if (moduleGradlePaths.contains(gradleModuleModel.getGradlePath())) {
selection.add(name);
selectedModules.add(moduleInfo);
found = true;
}
}
}
if (!selectedModules.isEmpty() && found) {
setSelection(selectedModules);
populate(project, projectInfo, selectedModules, DEFAULT_REQUEST);
}
}
}.queue();
}
}
use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.
the class UniquePathModuleValidatorStrategy method fixAndReportFoundIssues.
@Override
void fixAndReportFoundIssues() {
Set<String> modulePaths = myModulesByPath.keySet();
for (String modulePath : modulePaths) {
Collection<Module> modules = myModulesByPath.get(modulePath);
int moduleCount = modules.size();
if (moduleCount <= 1) {
continue;
}
StringBuilder msg = new StringBuilder();
msg.append("The modules [");
int i = 0;
Set<String> moduleNames = Sets.newHashSet();
for (Module module : modules) {
if (i++ != 0) {
msg.append(", ");
}
String name = module.getName();
moduleNames.add(name);
msg.append("'").append(name).append("'");
}
msg.append("] point to same directory in the file system.");
String[] lines = { msg.toString(), "Each module has to have a unique path." };
SyncMessage message = new SyncMessage(PROJECT_STRUCTURE_ISSUES, ERROR, lines);
List<DataNode<ModuleData>> modulesToDisplayInDialog = Lists.newArrayList();
Project project = getProject();
if (ProjectSubset.getInstance(project).isFeatureEnabled()) {
DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(project).getCachedProjectData();
if (projectInfo != null) {
Collection<DataNode<ModuleData>> cachedModules = findAll(projectInfo, MODULE);
for (DataNode<ModuleData> moduleNode : cachedModules) {
if (moduleNames.contains(moduleNode.getData().getExternalName())) {
modulesToDisplayInDialog.add(moduleNode);
}
}
}
}
if (!modulesToDisplayInDialog.isEmpty()) {
message.add(new AddOrRemoveModulesHyperlink());
}
SyncMessages.getInstance(project).report(message);
}
}
use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.
the class ModulesToImportDialogSelectionTest method createModule.
@NotNull
private static DataNode<ModuleData> createModule(@NotNull String name) {
String path = "~/project/" + name;
ModuleData data = new ModuleData(name, GradleConstants.SYSTEM_ID, StdModuleTypes.JAVA.getId(), name, path, path);
return new DataNode<>(MODULE, data, null);
}
Aggregations