use of com.intellij.openapi.externalSystem.model.project.ProjectData 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.project.ProjectData 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.project.ProjectData in project android by JetBrains.
the class IdeaGradleSync method sync.
@Override
public void sync(@NotNull Project project, @NotNull GradleSyncInvoker.Request request, @Nullable GradleSyncListener listener) {
// Prevent IDEA from syncing with Gradle. We want to have full control of syncing.
project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, true);
if (SYNC_WITH_CACHED_MODEL_ONLY || request.isUseCachedGradleModels()) {
GradleProjectSyncData syncData = GradleProjectSyncData.getInstance((project));
if (syncData != null && syncData.canUseCachedProjectData()) {
DataNodeCaches dataNodeCaches = DataNodeCaches.getInstance(project);
DataNode<ProjectData> cache = dataNodeCaches.getCachedProjectData();
if (cache != null && !dataNodeCaches.isCacheMissingModels(cache)) {
PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
// @formatter:off
setupRequest.setUsingCachedGradleModels(true).setGenerateSourcesAfterSync(false).setLastSyncTimestamp(syncData.getLastGradleSyncTimestamp());
// @formatter:on
boolean newProject = request.isNewProject();
ProjectSetUpTask setUpTask = new ProjectSetUpTask(project, setupRequest, listener, newProject, !newProject, true);
setUpTask.onSuccess(cache);
return;
}
}
}
PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
// @formatter:off
setupRequest.setGenerateSourcesAfterSync(request.isGenerateSourcesOnSuccess()).setCleanProjectAfterSync(request.isCleanProject());
// @formatter:on
String externalProjectPath = getBaseDirPath(project).getPath();
ProjectSetUpTask setUpTask = new ProjectSetUpTask(project, setupRequest, listener, request.isNewProject(), false, false);
ProgressExecutionMode executionMode = request.getProgressExecutionMode();
refreshProject(project, GRADLE_SYSTEM_ID, externalProjectPath, setUpTask, false, /* resolve dependencies */
executionMode, true);
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData in project android by JetBrains.
the class GradleSyncIntegrationTest method testWithCacheMissingModules.
// Verifies that if syncing using cached model, and if the cached model is missing data, we fall back to a full Gradle sync.
// See: https://code.google.com/p/android/issues/detail?id=160899
public void testWithCacheMissingModules() throws Exception {
Project project = getProject();
myOriginalDataNodeCaches = DataNodeCaches.getInstance(project);
loadSimpleApplication();
// Simulate data node cache is missing modules.
//noinspection unchecked
DataNode<ProjectData> cache = mock(DataNode.class);
DataNodeCaches dataNodeCaches = IdeComponents.replaceServiceWithMock(project, DataNodeCaches.class);
when(dataNodeCaches.getCachedProjectData()).thenReturn(cache);
when(dataNodeCaches.isCacheMissingModels(cache)).thenReturn(true);
GradleSyncInvoker.Request request = new GradleSyncInvoker.Request();
// @formatter:off
request.setGenerateSourcesOnSuccess(false).setUseCachedGradleModels(true);
// @formatter:on
// Sync again, and a full sync should occur, since the cache is missing modules.
// 'waitForGradleProjectSyncToFinish' will never finish and test will time out and fail if the IDE never gets notified that the sync
// finished.
requestSyncAndWait(request);
}
use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.
the class ExternalProjectDataSelectorDialog method doOKAction.
@Override
protected void doOKAction() {
loadingPanel.setLoadingText("Please wait...");
loadingPanel.startLoading();
final DataNode<ProjectData> projectStructure = myProjectInfo.getExternalProjectStructure();
if (projectStructure != null) {
final boolean[] isModified = { false };
ExternalSystemApiUtil.visit(projectStructure, node -> {
final DataNode modifiedDataNode = node.getUserData(MODIFIED_NODE_KEY);
if (modifiedDataNode != null) {
if (node.isIgnored() != modifiedDataNode.isIgnored()) {
node.setIgnored(modifiedDataNode.isIgnored());
isModified[0] = true;
}
node.removeUserData(MODIFIED_NODE_KEY);
node.removeUserData(CONNECTED_UI_NODE_KEY);
}
});
if (isModified[0]) {
DataNode<?> notIgnoredNode = ContainerUtil.find(projectStructure.getChildren(), node -> !node.isIgnored());
projectStructure.setIgnored(notIgnoredNode == null);
// execute when current dialog is closed
ExternalSystemUtil.invokeLater(myProject, ModalityState.NON_MODAL, () -> {
final ProjectData projectData = projectStructure.getData();
String title = ExternalSystemBundle.message("progress.refresh.text", projectData.getExternalName(), projectData.getOwner().getReadableName());
new Task.Backgroundable(myProject, title, true, PerformInBackgroundOption.DEAF) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
ServiceManager.getService(ProjectDataManager.class).importData(projectStructure, myProject, false);
}
}.queue();
});
}
}
super.doOKAction();
}
Aggregations