use of com.intellij.openapi.externalSystem.model.DataNode 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.DataNode in project intellij-community by JetBrains.
the class GradleProjectImportBuilder method createFinalImportCallback.
@Override
protected ExternalProjectRefreshCallback createFinalImportCallback(@NotNull final Project project, @NotNull ExternalProjectSettings projectSettings) {
return new ExternalProjectRefreshCallback() {
@Override
public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
if (externalProject == null)
return;
Runnable selectDataTask = () -> {
ExternalProjectDataSelectorDialog dialog = new ExternalProjectDataSelectorDialog(project, new InternalExternalProjectInfo(GradleConstants.SYSTEM_ID, projectSettings.getExternalProjectPath(), externalProject));
if (dialog.hasMultipleDataToSelect()) {
dialog.showAndGet();
} else {
Disposer.dispose(dialog.getDisposable());
}
};
Runnable importTask = () -> ServiceManager.getService(ProjectDataManager.class).importData(externalProject, project, false);
if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
ApplicationManager.getApplication().invokeLater(() -> {
selectDataTask.run();
ApplicationManager.getApplication().executeOnPooledThread(importTask);
});
} else {
importTask.run();
}
}
@Override
public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
}
};
}
use of com.intellij.openapi.externalSystem.model.DataNode 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.DataNode in project intellij-community by JetBrains.
the class BaseGradleProjectResolverExtension method buildDependency.
@NotNull
private static ModuleDependencyData buildDependency(@NotNull ProjectResolverContext resolverContext, @NotNull DataNode<ModuleData> ownerModule, @NotNull IdeaModuleDependency dependency, @NotNull DataNode<ProjectData> ideProject) throws IllegalStateException {
IdeaModule module = dependency.getDependencyModule();
if (module == null) {
if (resolverContext.getSettings() != null) {
String moduleName = dependency.getTargetModuleName();
GradleExecutionWorkspace executionWorkspace = resolverContext.getSettings().getExecutionWorkspace();
ModuleData moduleData = executionWorkspace.findModuleDataByName(moduleName);
if (moduleData != null) {
return new ModuleDependencyData(ownerModule.getData(), moduleData);
} else {
for (IdeaProject project : resolverContext.getModels().getIncludedBuilds()) {
moduleData = executionWorkspace.findModuleDataByName(project.getName() + ':' + moduleName);
if (moduleData != null) {
return new ModuleDependencyData(ownerModule.getData(), moduleData);
}
}
}
return new ModuleDependencyData(ownerModule.getData(), new ModuleData("", GradleConstants.SYSTEM_ID, StdModuleTypes.JAVA.getId(), moduleName, "", ""));
}
throw new IllegalStateException(String.format("Can't parse gradle module dependency '%s'. Reason: referenced module is null", dependency));
}
String moduleName = module.getName();
if (moduleName == null) {
throw new IllegalStateException(String.format("Can't parse gradle module dependency '%s'. Reason: referenced module name is undefined (module: '%s') ", dependency, module));
}
Set<String> registeredModuleNames = ContainerUtilRt.newHashSet();
Collection<DataNode<ModuleData>> modulesDataNode = ExternalSystemApiUtil.getChildren(ideProject, ProjectKeys.MODULE);
for (DataNode<ModuleData> moduleDataNode : modulesDataNode) {
String name = moduleDataNode.getData().getExternalName();
registeredModuleNames.add(name);
if (name.equals(moduleName)) {
return new ModuleDependencyData(ownerModule.getData(), moduleDataNode.getData());
}
}
throw new IllegalStateException(String.format("Can't parse gradle module dependency '%s'. Reason: no module with such name (%s) is found. Registered modules: %s", dependency, moduleName, registeredModuleNames));
}
use of com.intellij.openapi.externalSystem.model.DataNode 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();
}
}
Aggregations