use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class GradleExecutionWorkspace method findModuleDataByName.
public ModuleData findModuleDataByName(String moduleName) {
ModuleData result = null;
Pair<DataNode<ModuleData>, IdeaModule> modulePair = myModuleMap.get(moduleName);
if (modulePair == null) {
modulePair = myModuleMap.get(":" + moduleName);
}
if (modulePair != null) {
return modulePair.first.getData();
}
for (GradleBuildParticipant buildParticipant : myBuildParticipants) {
result = buildParticipant.findModuleDataByName(moduleName);
if (result != null)
break;
}
return result;
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class GradleTestRunConfigurationProducer method getTasksToRun.
@NotNull
public static List<String> getTasksToRun(@NotNull Module module) {
for (GradleTestTasksProvider provider : GradleTestTasksProvider.EP_NAME.getExtensions()) {
final List<String> tasks = provider.getTasks(module);
if (!ContainerUtil.isEmpty(tasks)) {
return tasks;
}
}
final List<String> result;
final String externalProjectId = ExternalSystemApiUtil.getExternalProjectId(module);
if (externalProjectId == null)
return ContainerUtil.emptyList();
final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (projectPath == null)
return ContainerUtil.emptyList();
final ExternalProjectInfo externalProjectInfo = ExternalSystemUtil.getExternalProjectInfo(module.getProject(), GradleConstants.SYSTEM_ID, projectPath);
if (externalProjectInfo == null)
return ContainerUtil.emptyList();
boolean trimSourceSet = false;
if (StringUtil.endsWith(externalProjectId, ":test") || StringUtil.endsWith(externalProjectId, ":main")) {
result = TEST_SOURCE_SET_TASKS;
trimSourceSet = true;
} else {
final DataNode<ModuleData> moduleNode = GradleProjectResolverUtil.findModule(externalProjectInfo.getExternalProjectStructure(), projectPath);
if (moduleNode == null)
return ContainerUtil.emptyList();
final DataNode<TaskData> taskNode;
final String sourceSetId = StringUtil.substringAfter(externalProjectId, moduleNode.getData().getExternalName() + ':');
if (sourceSetId == null) {
taskNode = ExternalSystemApiUtil.find(moduleNode, ProjectKeys.TASK, node -> GradleCommonClassNames.GRADLE_API_TASKS_TESTING_TEST.equals(node.getData().getType()) && StringUtil.equals("test", node.getData().getName()));
} else {
trimSourceSet = true;
taskNode = ExternalSystemApiUtil.find(moduleNode, ProjectKeys.TASK, node -> GradleCommonClassNames.GRADLE_API_TASKS_TESTING_TEST.equals(node.getData().getType()) && StringUtil.startsWith(sourceSetId, node.getData().getName()));
}
if (taskNode == null)
return ContainerUtil.emptyList();
final String taskName = taskNode.getData().getName();
result = ContainerUtil.list("clean" + StringUtil.capitalize(taskName), taskName);
}
final String path;
if (!externalProjectId.startsWith(":")) {
path = ":";
} else {
final List<String> pathParts = StringUtil.split(externalProjectId, ":");
if (trimSourceSet && !pathParts.isEmpty())
pathParts.remove(pathParts.size() - 1);
final String join = StringUtil.join(pathParts, ":");
path = ":" + join + (!join.isEmpty() ? ":" : "");
}
return ContainerUtil.map(result, s -> path + s);
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project android by JetBrains.
the class ProjectSubset method findAndIncludeModuleContainingSourceFile.
/**
* Finds and includes the module that contains the given file.
* <p>
* When using the "Project Subset" feature it is possible that the user knows which file she wants to edit but not the module where
* such file is. This method tries to find the module that includes the given file in the folders that it marked as "source", either
* production or test code.
* </p>
* <p>
* The search is based on the Gradle models for both Android and Java modules. If the search finds more than one module that might contain
* the file, the IDE will display a dialog where the user can see the potential matches and choose the module to include in the project.
* </p>
*
* @param virtualFile the given file.
*/
public void findAndIncludeModuleContainingSourceFile(@NotNull VirtualFile virtualFile) {
DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(myProject).getCachedProjectData();
if (projectInfo == null) {
return;
}
Collection<DataNode<ModuleData>> moduleInfos = findAll(projectInfo, MODULE);
if (!moduleInfos.isEmpty()) {
File file = virtualToIoFile(virtualFile);
new Task.Modal(myProject, "Looking up Module", false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
List<ModuleSearchResult> results = Lists.newArrayList();
String[] storedSelection = getSelection();
Set<String> selection = storedSelection != null ? Sets.newHashSet(storedSelection) : Sets.newHashSet();
List<DataNode<ModuleData>> selectedModules = Lists.newArrayList();
int doneCount = 0;
for (DataNode<ModuleData> moduleNode : moduleInfos) {
indicator.setFraction(++doneCount / moduleInfos.size());
ModuleData module = moduleNode.getData();
String name = module.getExternalName();
boolean selected = selection.contains(name);
if (selected) {
// This module is already included in the project. We need to mark it as "selected" so when we are done searching we don't
// exclude it by accident.
selectedModules.add(moduleNode);
}
ModuleSearchResult result = containsSourceFile(moduleNode, file, selected);
if (result != null) {
// Even though the module is already included, we add it to the search results, because the module might not be the one that
// actually contains the file, and the user might need to exclude it in the case that the module that contains the file has
// the same path as the already-included module.
results.add(result);
}
}
int resultCount = results.size();
if (resultCount == 0) {
// Nothing found.
invokeLaterIfNeeded(() -> {
String text = String.format("Unable to find a module containing the file '%1$s' in a source directory.", file.getName());
AndroidGradleNotification notification = AndroidGradleNotification.getInstance(ProjectSubset.this.myProject);
notification.showBalloon(MODULE_LOOKUP_MESSAGE_TITLE, text, ERROR);
});
} else if (resultCount == 1) {
// If there is one result,just apply it.
addResultAndPopulateProject(results.get(0), projectInfo, selectedModules, file);
} else {
// We need to let user decide which modules to include.
showModuleSelectionDialog(results, projectInfo, selectedModules, file);
}
}
}.queue();
}
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project android by JetBrains.
the class ProjectSubset method showModuleSelectionDialog.
/**
* Displays the "Select Modules" dialog. This method is invoked when the search for a module containing a file returns more than one
* result. The user now needs to select the module(s) to include.
*
* @param searchResults includes the modules that might contain the given file.
* @param selection all the modules that need to be included in the project.
* @param file the file to include in the project.
*/
private void showModuleSelectionDialog(@NotNull List<ModuleSearchResult> searchResults, @NotNull DataNode<ProjectData> projectInfo, @NotNull List<DataNode<ModuleData>> selection, @NotNull File file) {
List<DataNode<ModuleData>> finalSelection = Lists.newArrayList(selection);
List<DataNode<ModuleData>> modulesToDisplayInDialog = Lists.newArrayList();
Map<String, ModuleSearchResult> resultsByModuleName = Maps.newHashMap();
for (ModuleSearchResult result : searchResults) {
DataNode<ModuleData> module = result.moduleNode;
modulesToDisplayInDialog.add(module);
if (result.selected) {
finalSelection.remove(module);
}
String moduleName = getNameOf(module);
resultsByModuleName.put(moduleName, result);
}
invokeLaterIfNeeded(() -> {
ModulesToImportDialog dialog = new ModulesToImportDialog(modulesToDisplayInDialog, myProject);
String description = String.format("The file '%1$s' may be include in one of the following modules.", file.getName());
dialog.setDescription(description);
dialog.clearSelection();
if (dialog.showAndGet()) {
Collection<DataNode<ModuleData>> selectedModules = dialog.getSelectedModules();
if (!selectedModules.isEmpty()) {
for (DataNode<ModuleData> selectedModule : selectedModules) {
String name = getNameOf(selectedModule);
ModuleSearchResult result = resultsByModuleName.get(name);
if (result != null) {
SourceFileContainerInfo containerInfo = result.containerInfo;
if (containerInfo != null) {
containerInfo.updateSelectedVariantIn(selectedModule);
}
}
}
finalSelection.addAll(selectedModules);
setSelection(finalSelection);
populate(myProject, projectInfo, finalSelection, DEFAULT_REQUEST);
}
}
});
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project android by JetBrains.
the class DataNodeCaches method indexByModuleName.
@NotNull
private static Map<String, DataNode<ModuleData>> indexByModuleName(@NotNull Collection<DataNode<ModuleData>> moduleDataNodes) {
Map<String, DataNode<ModuleData>> mapping = Maps.newHashMap();
for (DataNode<ModuleData> moduleDataNode : moduleDataNodes) {
ModuleData data = moduleDataNode.getData();
mapping.put(data.getExternalName(), moduleDataNode);
}
return mapping;
}
Aggregations