com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys Java Examples

The following examples show how to use com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PantsOpenProjectProvider.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private void link(@NotNull VirtualFile projectFile, @NotNull Project project, AddModuleWizard dialog) {
  if (dialog == null) return;

  ProjectBuilder builder = dialog.getBuilder(project);
  if (builder == null) return;

  try {
    ApplicationManager.getApplication().runWriteAction(() -> {
      Optional.ofNullable(dialog.getNewProjectJdk())
        .ifPresent(jdk -> NewProjectUtil.applyJdkToProject(project, jdk));

      URI output = projectDir(projectFile).resolve(".out").toUri();
      Optional.ofNullable(CompilerProjectExtension.getInstance(project))
        .ifPresent(ext -> ext.setCompilerOutputUrl(output.toString()));
    });

    builder.commit(project, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
    project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE);

    project.save();
  }
  finally {
    builder.cleanup();
  }
}
 
Example #2
Source File: AbstractToolWindowService.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void importData(@Nonnull final Collection<DataNode<T>> toImport, @Nonnull final Project project, boolean synchronous) {
  if (toImport.isEmpty()) {
    return;
  }
  ExternalSystemApiUtil.executeOnEdt(false, new Runnable() {
    @Override
    public void run() {
      ExternalSystemTasksTreeModel model = ExternalSystemUtil.getToolWindowElement(ExternalSystemTasksTreeModel.class,
                                                                                   project,
                                                                                   ExternalSystemDataKeys.ALL_TASKS_MODEL,
                                                                                   toImport.iterator().next().getData().getOwner());
      processData(toImport, project, model);
    }
  });
}
 
Example #3
Source File: AttachExternalProjectAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  ProjectSystemId externalSystemId = e.getDataContext().getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId == null) {
    return;
  }

  ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
  if (manager == null) {
    return;
  }

  Project project = e.getDataContext().getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return;
  }

  ImportModuleAction.executeImportAction(project, manager.getExternalProjectDescriptor());
}
 
Example #4
Source File: PantsOpenProjectProvider.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private Project createProject(VirtualFile file, AddModuleWizard dialog) {
  Project project = PantsUtil.findBuildRoot(file)
    .map(root -> Paths.get(root.getPath()))
    .map(root -> ProjectManagerEx.getInstanceEx().newProject(root, dialog.getProjectName(), new OpenProjectTask()))
    .orElse(null);
  if (project != null) {
    project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, true);
  }
  return project;
}
 
Example #5
Source File: AbstractExternalSystemToolWindowCondition.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean value(Project project) {
  if (project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) == Boolean.TRUE) {
    return true;
  }
  ExternalSystemManager<?,?,?,?,?> manager = ExternalSystemApiUtil.getManager(myExternalSystemId);
  if (manager == null) {
    return false;
  }
  AbstractExternalSystemSettings<?, ?,?> settings = manager.getSettingsProvider().fun(project);
  return settings != null && !settings.getLinkedProjectsSettings().isEmpty();
}
 
Example #6
Source File: ExternalSystemTasksPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (ExternalSystemDataKeys.RECENT_TASKS_LIST == dataId) {
    return myRecentTasksList;
  }
  else if (ExternalSystemDataKeys.ALL_TASKS_MODEL == dataId) {
    return myAllTasksModel;
  }
  else if (ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID == dataId) {
    return myExternalSystemId;
  }
  else if (ExternalSystemDataKeys.NOTIFICATION_GROUP == dataId) {
    return myNotificationGroup;
  }
  else if (ExternalSystemDataKeys.SELECTED_TASK == dataId) {
    return mySelectedTaskProvider == null ? null : mySelectedTaskProvider.produce();
  }
  else if (ExternalSystemDataKeys.SELECTED_PROJECT == dataId) {
    if (mySelectedTaskProvider != myAllTasksTree) {
      return null;
    }
    else {
      Object component = myAllTasksTree.getLastSelectedPathComponent();
      if (component instanceof ExternalSystemNode) {
        Object element = ((ExternalSystemNode)component).getDescriptor().getElement();
        return element instanceof ExternalProjectPojo ? element : null;
      }
    }
  }
  else if (Location.DATA_KEY == dataId) {
    Location location = buildLocation();
    return location == null ? super.getData(dataId) : location;
  }
  return null;
}
 
Example #7
Source File: AttachExternalProjectAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  ProjectSystemId externalSystemId = e.getDataContext().getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId != null) {
    String name = externalSystemId.getReadableName();
    e.getPresentation().setText(ExternalSystemBundle.message("action.attach.external.project.text", name));
    e.getPresentation().setDescription(ExternalSystemBundle.message("action.attach.external.project.description", name));
  }

  e.getPresentation().setIcon(SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add);
}
 
Example #8
Source File: RefreshAllExternalProjectsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static List<ProjectSystemId> getSystemIds(AnActionEvent e) {
  final List<ProjectSystemId> systemIds = ContainerUtil.newArrayList();

  final ProjectSystemId externalSystemId = e.getDataContext().getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId != null) {
    systemIds.add(externalSystemId);
  }
  else {
    for (ExternalSystemManager manager : ExternalSystemManager.EP_NAME.getExtensionList()) {
      systemIds.add(manager.getSystemId());
    }
  }

  return systemIds;
}
 
Example #9
Source File: OpenExternalConfigAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  ProjectSystemId externalSystemId = e.getDataContext().getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId == null) {
    e.getPresentation().setEnabled(false);
    return;
  }

  e.getPresentation().setText(ExternalSystemBundle.message("action.open.config.text", externalSystemId.getReadableName()));
  e.getPresentation().setDescription(ExternalSystemBundle.message("action.open.config.description", externalSystemId.getReadableName()));
  e.getPresentation().setIcon(ExternalSystemUiUtil.getUiAware(externalSystemId).getProjectIcon());

  VirtualFile config = getExternalConfig(e.getDataContext());
  e.getPresentation().setEnabled(config != null);
}
 
Example #10
Source File: OpenExternalConfigAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static VirtualFile getExternalConfig(@Nonnull DataContext context) {
  ProjectSystemId externalSystemId = context.getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId == null) {
    return null;
  }

  ExternalProjectPojo projectPojo = context.getData(ExternalSystemDataKeys.SELECTED_PROJECT);
  if (projectPojo == null) {
    return null;
  }

  String path = projectPojo.getPath();
  LocalFileSystem fileSystem = LocalFileSystem.getInstance();
  VirtualFile externalSystemConfigPath = fileSystem.refreshAndFindFileByPath(path);
  if (externalSystemConfigPath == null) {
    return null;
  }

  VirtualFile toOpen = externalSystemConfigPath;
  for (ExternalSystemConfigLocator locator : ExternalSystemConfigLocator.EP_NAME.getExtensionList()) {
    if (externalSystemId.equals(locator.getTargetExternalSystemId())) {
      toOpen = locator.adjust(toOpen);
      if (toOpen == null) {
        return null;
      }
    }
  }
  return toOpen.isDirectory() ? null : toOpen;
}
 
Example #11
Source File: ExternalActionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static MyInfo getProcessingInfo(@Nonnull DataContext context) {
  ExternalProjectPojo externalProject = context.getData(ExternalSystemDataKeys.SELECTED_PROJECT);
  if (externalProject == null) {
    return MyInfo.EMPTY;
  }

  ProjectSystemId externalSystemId = context.getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId == null) {
    return MyInfo.EMPTY;
  }

  Project ideProject = context.getData(CommonDataKeys.PROJECT);
  if (ideProject == null) {
    return MyInfo.EMPTY;
  }

  AbstractExternalSystemSettings<?, ?, ?> settings = ExternalSystemApiUtil.getSettings(ideProject, externalSystemId);
  ExternalProjectSettings externalProjectSettings = settings.getLinkedProjectSettings(externalProject.getPath());
  AbstractExternalSystemLocalSettings localSettings = ExternalSystemApiUtil.getLocalSettings(ideProject, externalSystemId);

  return new MyInfo(externalProjectSettings == null ? null : settings,
                    localSettings == null ? null : localSettings,
                    externalProjectSettings == null ? null : externalProject,
                    ideProject,
                    externalSystemId);
}
 
Example #12
Source File: RoboVmModuleBuilder.java    From robovm-idea with GNU General Public License v2.0 4 votes vote down vote up
private void applyBuildSystem(final Project project) {
    if (buildSystem == BuildSystem.Gradle) {
        File baseDir = VfsUtilCore.virtualToIoFile(project.getBaseDir());
        File[] files = baseDir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return FileUtil.namesEqual("build.gradle", name);
            }
        });
        if (files != null && files.length != 0) {
            project.putUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT, Boolean.TRUE);
            ProjectDataManager projectDataManager = (ProjectDataManager) ServiceManager
                    .getService(ProjectDataManager.class);
            GradleProjectImportBuilder gradleProjectImportBuilder = new GradleProjectImportBuilder(
                    projectDataManager);
            gradleProjectImportBuilder.getControl(project).getProjectSettings()
                    .setDistributionType(DistributionType.WRAPPED);
            GradleProjectImportProvider gradleProjectImportProvider = new GradleProjectImportProvider(
                    gradleProjectImportBuilder);
            AddModuleWizard wizard = new AddModuleWizard((Project) null, files[0].getPath(),
                    new ProjectImportProvider[] { gradleProjectImportProvider });
            if (wizard.getStepCount() <= 0 || wizard.showAndGet()) {
                ImportModuleAction.createFromWizard(project, wizard);

                ApplicationManager.getApplication().runWriteAction(new Runnable() {
                    @Override
                    public void run() {
                        ModifiableModuleModel modifiableModel = ModuleManager.getInstance(project).getModifiableModel();
                        for (Module module : modifiableModel.getModules()) {
                            try {
                                LanguageLevelModuleExtensionImpl langModel = (LanguageLevelModuleExtensionImpl) LanguageLevelModuleExtensionImpl.getInstance(module).getModifiableModel(true);
                                langModel.setLanguageLevel(LanguageLevel.JDK_1_8);
                                langModel.commit();
                            } catch(Throwable t) {
                                // could be a non-Java project
                                t.printStackTrace();
                            }
                        }
                        modifiableModel.commit();
                    }
                });
            }
        }
    } else {
        FileDocumentManager.getInstance().saveAllDocuments();
        MavenProjectsManager.getInstance(project).forceUpdateAllProjectsOrFindAllAvailablePomFiles();
    }
}
 
Example #13
Source File: AbstractExternalModuleImportProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
public void process(@Nonnull ExternalModuleImportContext<C> context, @Nonnull final Project project, @Nonnull ModifiableModuleModel model, @Nonnull Consumer<Module> newModuleConsumer) {
  project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE);
  final DataNode<ProjectData> externalProjectNode = getExternalProjectNode();
  if (externalProjectNode != null) {
    beforeCommit(externalProjectNode, project);
  }

  StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
    @SuppressWarnings("unchecked")
    @Override
    public void run() {
      AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
      final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
      Set<ExternalProjectSettings> projects = ContainerUtilRt.<ExternalProjectSettings>newHashSet(systemSettings.getLinkedProjectsSettings());
      // add current importing project settings to linked projects settings or replace if similar already exist
      projects.remove(projectSettings);
      projects.add(projectSettings);

      systemSettings.copyFrom(myControl.getSystemSettings());
      systemSettings.setLinkedProjectsSettings(projects);

      if (externalProjectNode != null) {
        ExternalSystemUtil.ensureToolWindowInitialized(project, myExternalSystemId);
        ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {
          @RequiredUIAccess
          @Override
          public void execute() {
            ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(new Runnable() {
              @Override
              public void run() {
                myProjectDataManager.importData(externalProjectNode.getKey(), Collections.singleton(externalProjectNode), project, true);
                myExternalProjectNode = null;
              }
            });
          }
        });

        final Runnable resolveDependenciesTask = new Runnable() {
          @Override
          public void run() {
            String progressText = ExternalSystemBundle.message("progress.resolve.libraries", myExternalSystemId.getReadableName());
            ProgressManager.getInstance().run(new Task.Backgroundable(project, progressText, false) {
              @Override
              public void run(@Nonnull final ProgressIndicator indicator) {
                if (project.isDisposed()) return;
                ExternalSystemResolveProjectTask task = new ExternalSystemResolveProjectTask(myExternalSystemId, project, projectSettings.getExternalProjectPath(), false);
                task.execute(indicator, ExternalSystemTaskNotificationListener.EP_NAME.getExtensions());
                DataNode<ProjectData> projectWithResolvedLibraries = task.getExternalProject();
                if (projectWithResolvedLibraries == null) {
                  return;
                }

                setupLibraries(projectWithResolvedLibraries, project);
              }
            });
          }
        };
        UIUtil.invokeLaterIfNeeded(resolveDependenciesTask);
      }
    }
  });
}
 
Example #14
Source File: ExternalSystemNotificationManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void showNotification(@Nonnull final ProjectSystemId externalSystemId, @Nonnull final NotificationData notificationData) {
  myUpdater.execute(new Runnable() {
    @Override
    public void run() {
      if (myProject.isDisposed()) return;

      if (!initializedExternalSystem.contains(externalSystemId)) {
        final Application app = ApplicationManager.getApplication();
        Runnable action = new Runnable() {
          @Override
          public void run() {
            app.runWriteAction(new Runnable() {
              @Override
              public void run() {
                if (myProject.isDisposed()) return;
                ExternalSystemUtil.ensureToolWindowContentInitialized(myProject, externalSystemId);
                initializedExternalSystem.add(externalSystemId);
              }
            });
          }
        };
        if (app.isDispatchThread()) {
          action.run();
        }
        else {
          app.invokeAndWait(action, ModalityState.defaultModalityState());
        }
      }

      final NotificationGroup group = ExternalSystemUtil.getToolWindowElement(
              NotificationGroup.class, myProject, ExternalSystemDataKeys.NOTIFICATION_GROUP, externalSystemId);
      if (group == null) return;

      final Notification notification = group.createNotification(
              notificationData.getTitle(), notificationData.getMessage(),
              notificationData.getNotificationCategory().getNotificationType(), notificationData.getListener());

      myNotifications.add(notification);

      if (notificationData.isBalloonNotification()) {
        applyNotification(notification);
      }
      else {
        addMessage(notification, externalSystemId, notificationData);
      }
    }
  });
}
 
Example #15
Source File: DetachExternalProjectAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  ExternalActionUtil.MyInfo info = ExternalActionUtil.getProcessingInfo(e.getDataContext());
  if (info.settings == null || info.localSettings == null || info.externalProject == null || info.ideProject == null
      || info.externalSystemId == null)
  {
    return;
  }
  
  e.getPresentation().setText(
    ExternalSystemBundle.message("action.detach.external.project.text",info.externalSystemId.getReadableName())
  );

  ExternalSystemTasksTreeModel allTasksModel = e.getDataContext().getData(ExternalSystemDataKeys.ALL_TASKS_MODEL);
  if (allTasksModel != null) {
    allTasksModel.pruneNodes(info.externalProject);
  }

  ExternalSystemRecentTasksList recentTasksList = e.getDataContext().getData(ExternalSystemDataKeys.RECENT_TASKS_LIST);
  if (recentTasksList != null) {
    recentTasksList.getModel().forgetTasksFrom(info.externalProject.getPath());
  }
  
  info.localSettings.forgetExternalProjects(Collections.singleton(info.externalProject.getPath()));
  info.settings.unlinkExternalProject(info.externalProject.getPath());

  // Process orphan modules.
  String externalSystemIdAsString = info.externalSystemId.toString();
  List<Module> orphanModules = ContainerUtilRt.newArrayList();
  for (Module module : ModuleManager.getInstance(info.ideProject).getModules()) {
    String systemId = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY);
    if (!externalSystemIdAsString.equals(systemId)) {
      continue;
    }
    String path = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.LINKED_PROJECT_PATH_KEY);
    if (info.externalProject.getPath().equals(path)) {
      orphanModules.add(module);
    }
  }

  if (!orphanModules.isEmpty()) {
    ExternalSystemUtil.ruleOrphanModules(orphanModules, info.ideProject, info.externalSystemId);
  }
}