Java Code Examples for com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil#getSettings()

The following examples show how to use com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil#getSettings() . 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: AbstractExternalModuleImportProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void executeAndRestoreDefaultProjectSettings(@Nonnull Project project, @Nonnull Runnable task) {
  if (!project.isDefault()) {
    task.run();
    return;
  }

  AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
  Object systemStateToRestore = null;
  if (systemSettings instanceof PersistentStateComponent) {
    systemStateToRestore = ((PersistentStateComponent)systemSettings).getState();
  }
  systemSettings.copyFrom(myControl.getSystemSettings());
  Collection projectSettingsToRestore = systemSettings.getLinkedProjectsSettings();
  systemSettings.setLinkedProjectsSettings(Collections.singleton(getCurrentExternalProjectSettings()));
  try {
    task.run();
  }
  finally {
    if (systemStateToRestore != null) {
      ((PersistentStateComponent)systemSettings).loadState(systemStateToRestore);
    }
    else {
      systemSettings.setLinkedProjectsSettings(projectSettingsToRestore);
    }
  }
}
 
Example 2
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 3
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);
  }
}