com.intellij.openapi.externalSystem.service.project.ProjectDataManager Java Examples

The following examples show how to use com.intellij.openapi.externalSystem.service.project.ProjectDataManager. 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: GradleModuleBuilderPostProcessor.java    From intellij-spring-assistant with MIT License 6 votes vote down vote up
@Override
public boolean postProcess(Module module) {
  // TODO: Find a way to use GradleModuleBuilder instead of GradleProjectImportBuilder when adding a child module to the parent
  Project project = module.getProject();
  VirtualFile gradleFile = findFileUnderRootInModule(module, "build.gradle");
  if (gradleFile == null) { // not a gradle project
    return true;
  } else {
    ProjectDataManager projectDataManager = getService(ProjectDataManager.class);
    GradleProjectImportBuilder importBuilder = new GradleProjectImportBuilder(projectDataManager);
    GradleProjectImportProvider importProvider = new GradleProjectImportProvider(importBuilder);
    AddModuleWizard addModuleWizard =
        new AddModuleWizard(project, gradleFile.getPath(), importProvider);
    if (addModuleWizard.getStepCount() > 0 && !addModuleWizard
        .showAndGet()) { // user has cancelled import project prompt
      return true;
    } else { // user chose to import via the gradle import prompt
      importBuilder.commit(project, null, null);
      return false;
    }
  }
}
 
Example #2
Source File: ExternalSystemImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
protected void ignoreData(BooleanFunction<DataNode<?>> booleanFunction, final boolean ignored) {
  final ExternalProjectInfo externalProjectInfo = ProjectDataManagerImpl.getInstance().getExternalProjectData(
    myProject, getExternalSystemId(), getCurrentExternalProjectSettings().getExternalProjectPath());
  assertNotNull(externalProjectInfo);

  final DataNode<ProjectData> projectDataNode = externalProjectInfo.getExternalProjectStructure();
  assertNotNull(projectDataNode);

  final Collection<DataNode<?>> nodes = ExternalSystemApiUtil.findAllRecursively(projectDataNode, booleanFunction);
  for (DataNode<?> node : nodes) {
    ExternalSystemApiUtil.visit(node, dataNode -> dataNode.setIgnored(ignored));
  }
  ServiceManager.getService(ProjectDataManager.class).importData(projectDataNode, myProject, true);
}
 
Example #3
Source File: AndroidUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@SuppressWarnings("DuplicatedCode")
private static Map<ProjectData, MultiMap<String, String>> getTasksMap(Project project) {
  Map<ProjectData, MultiMap<String, String>> tasks = new LinkedHashMap<>();
  for (GradleProjectSettings setting : GradleSettings.getInstance(project).getLinkedProjectsSettings()) {
    final ExternalProjectInfo projectData =
      ProjectDataManager.getInstance().getExternalProjectData(project, GradleConstants.SYSTEM_ID, setting.getExternalProjectPath());
    if (projectData == null || projectData.getExternalProjectStructure() == null) continue;

    MultiMap<String, String> projectTasks = MultiMap.createOrderedSet();
    for (DataNode<ModuleData> moduleDataNode : getChildren(projectData.getExternalProjectStructure(), ProjectKeys.MODULE)) {
      String gradlePath;
      String moduleId = moduleDataNode.getData().getId();
      if (moduleId.charAt(0) != ':') {
        int colonIndex = moduleId.indexOf(':');
        gradlePath = colonIndex > 0 ? moduleId.substring(colonIndex) : ":";
      }
      else {
        gradlePath = moduleId;
      }
      for (DataNode<TaskData> node : getChildren(moduleDataNode, ProjectKeys.TASK)) {
        TaskData taskData = node.getData();
        String taskName = taskData.getName();
        if (isNotEmpty(taskName)) {
          String taskPathPrefix = ":".equals(gradlePath) || taskName.startsWith(gradlePath) ? "" : (gradlePath + ':');
          projectTasks.putValue(taskPathPrefix, taskName);
        }
      }
    }
    tasks.put(projectData.getExternalProjectStructure().getData(), projectTasks);
  }
  return tasks;
}
 
Example #4
Source File: AndroidUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@SuppressWarnings("DuplicatedCode")
private static Map<ProjectData, MultiMap<String, String>> getTasksMap(Project project) {
  Map<ProjectData, MultiMap<String, String>> tasks = new LinkedHashMap<>();
  for (GradleProjectSettings setting : GradleSettings.getInstance(project).getLinkedProjectsSettings()) {
    final ExternalProjectInfo projectData =
      ProjectDataManager.getInstance().getExternalProjectData(project, GradleConstants.SYSTEM_ID, setting.getExternalProjectPath());
    if (projectData == null || projectData.getExternalProjectStructure() == null) continue;

    MultiMap<String, String> projectTasks = MultiMap.createOrderedSet();
    for (DataNode<ModuleData> moduleDataNode : getChildren(projectData.getExternalProjectStructure(), ProjectKeys.MODULE)) {
      String gradlePath;
      String moduleId = moduleDataNode.getData().getId();
      if (moduleId.charAt(0) != ':') {
        int colonIndex = moduleId.indexOf(':');
        gradlePath = colonIndex > 0 ? moduleId.substring(colonIndex) : ":";
      }
      else {
        gradlePath = moduleId;
      }
      for (DataNode<TaskData> node : getChildren(moduleDataNode, ProjectKeys.TASK)) {
        TaskData taskData = node.getData();
        String taskName = taskData.getName();
        if (isNotEmpty(taskName)) {
          String taskPathPrefix = ":".equals(gradlePath) || taskName.startsWith(gradlePath) ? "" : (gradlePath + ':');
          projectTasks.putValue(taskPathPrefix, taskName);
        }
      }
    }
    tasks.put(projectData.getExternalProjectStructure().getData(), projectTasks);
  }
  return tasks;
}
 
Example #5
Source File: ExternalSystemImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
private void doImportProject() {
  AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId());
  final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
  projectSettings.setExternalProjectPath(getProjectPath());
  //noinspection unchecked
  Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
  projects.remove(projectSettings);
  projects.add(projectSettings);
  //noinspection unchecked
  systemSettings.setLinkedProjectsSettings(projects);

  final Ref<Couple<String>> error = Ref.create();
  ImportSpec importSpec = createImportSpec();
  if (importSpec.getCallback() == null) {
    importSpec = new ImportSpecBuilder(importSpec).callback(new ExternalProjectRefreshCallback() {
      @Override
      public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
        if (externalProject == null) {
          System.err.println("Got null External project after import");
          return;
        }
        ServiceManager.getService(ProjectDataManager.class).importData(externalProject, myProject, true);
        System.out.println("External project was successfully imported");
      }

      @Override
      public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
        error.set(Couple.of(errorMessage, errorDetails));
      }
    }).build();
  }

  ExternalSystemProgressNotificationManager notificationManager =
    ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
  ExternalSystemTaskNotificationListenerAdapter listener = new ExternalSystemTaskNotificationListenerAdapter() {
    @Override
    public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) {
      if (StringUtil.isEmptyOrSpaces(text)) return;
      (stdOut ? System.out : System.err).print(text);
    }
  };
  notificationManager.addNotificationListener(listener);
  try {
    ExternalSystemUtil.refreshProjects(importSpec);
  }
  finally {
    notificationManager.removeNotificationListener(listener);
  }

  if (!error.isNull()) {
    String failureMsg = "Import failed: " + error.get().first;
    if (StringUtil.isNotEmpty(error.get().second)) {
      failureMsg += "\nError details: \n" + error.get().second;
    }
    fail(failureMsg);
  }
}
 
Example #6
Source File: GradleMonitor.java    From spring-javaformat with Apache License 2.0 4 votes vote down vote up
private void check() {
	ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
	boolean hasFormatPlugin = hasFormatPlugin(
			projectDataManager.getExternalProjectsData(getProject(), GradleConstants.SYSTEM_ID));
	getTrigger().updateState(hasFormatPlugin ? State.ACTIVE : State.NOT_ACTIVE);
}
 
Example #7
Source File: TalendModuleBuilder.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public Module createModule(final ModifiableModuleModel moduleModel) throws InvalidDataException, IOException,
        ModuleWithNameAlreadyExists, ConfigurationException, JDOMException {
    final Module module = super.createModule(moduleModel);
    getApplication().invokeLater(() -> {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final ProjectDownloader downloader = new ProjectDownloader(this, request);
            try {
                downloader.download(ProgressManager.getInstance().getProgressIndicator());
            } catch (IOException e) {
                getApplication()
                        .invokeLater(() -> MessagesEx
                                .showErrorDialog(e.getMessage(), getMessage("download.project.file.error")));
            }
        }, getMessage("download.project.file"), true, null);

        final Project moduleProject = module.getProject();
        switch (jsonProject.get("buildType").getAsString()) {
        case "Maven":
            final VirtualFile pomFile = findFileUnderRootInModule(module, "pom.xml");
            if (pomFile != null) {
                final MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(moduleProject);
                mavenProjectsManager.addManagedFiles(singletonList(pomFile));
            }
            break;
        case "Gradle":
            final VirtualFile gradleFile = findFileUnderRootInModule(module, "build.gradle");
            if (gradleFile != null) {
                final ProjectDataManager projectDataManager = getService(ProjectDataManager.class);
                // todo: move to JavaGradleProjectImportBuilder
                final GradleProjectImportBuilder importBuilder = new GradleProjectImportBuilder(projectDataManager);
                final GradleProjectImportProvider importProvider = new GradleProjectImportProvider(importBuilder);
                final AddModuleWizard addModuleWizard =
                        new AddModuleWizard(moduleProject, gradleFile.getPath(), importProvider);
                if (addModuleWizard.getStepCount() == 0 && addModuleWizard.showAndGet()) {
                    // user chose to import via the gradle import prompt
                    importBuilder.commit(moduleProject, null, null);
                }
            }
            break;
        default:
            break;
        }

    }, ModalityState.current());
    return module;
}
 
Example #8
Source File: PantsProjectImportBuilder.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
public PantsProjectImportBuilder() {
  super(ProjectDataManager.getInstance(), ImportFromPantsControl::new, PantsConstants.SYSTEM_ID);
}