com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode Java Examples

The following examples show how to use com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode. 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 5 votes vote down vote up
private void refresh(VirtualFile file, Project project) {
  ExternalSystemUtil.refreshProject(
    file.getPath(),
    new ImportSpecBuilder(project, PantsConstants.SYSTEM_ID).usePreviewMode().use(ProgressExecutionMode.MODAL_SYNC)
  );
  ExternalSystemUtil.refreshProject(
    file.getPath(),
    new ImportSpecBuilder(project, PantsConstants.SYSTEM_ID)
  );
}
 
Example #2
Source File: ExternalProjectUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static void refresh(@NotNull Project project, ProjectSystemId id) {
  // This code needs to run on the dispatch thread, but in some cases
  // refreshAllProjects() is called on a non-dispatch thread; we use
  // invokeLater() to run in the dispatch thread.
  ApplicationManager.getApplication().invokeAndWait(
    () -> {
      ApplicationManager.getApplication().runWriteAction(() -> FileDocumentManager.getInstance().saveAllDocuments());

      final ImportSpecBuilder specBuilder = new ImportSpecBuilder(project, id);
      ProgressExecutionMode executionMode = ApplicationManager.getApplication().isUnitTestMode() ?
                                            ProgressExecutionMode.MODAL_SYNC : ProgressExecutionMode.IN_BACKGROUND_ASYNC;
      specBuilder.use(executionMode);
      ExternalSystemUtil.refreshProjects(specBuilder);
    });
}
 
Example #3
Source File: ExternalSystemImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
protected ImportSpec createImportSpec() {
  ImportSpecBuilder importSpecBuilder = new ImportSpecBuilder(myProject, getExternalSystemId())
    .use(ProgressExecutionMode.MODAL_SYNC)
    .forceWhenUptodate();
  return importSpecBuilder.build();
}
 
Example #4
Source File: ImportSpec.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ImportSpec(@Nonnull Project project, @Nonnull ProjectSystemId id) {
  myProject = project;
  myExternalSystemId = id;
  myProgressExecutionMode = ProgressExecutionMode.MODAL_SYNC;
}
 
Example #5
Source File: ImportSpec.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public ProgressExecutionMode getProgressExecutionMode() {
  return myProgressExecutionMode;
}
 
Example #6
Source File: ImportSpec.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void setProgressExecutionMode(@Nonnull ProgressExecutionMode progressExecutionMode) {
  myProgressExecutionMode = progressExecutionMode;
}
 
Example #7
Source File: ImportSpecBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ImportSpecBuilder(@Nonnull Project project, @Nonnull ProjectSystemId id) {
  myProject = project;
  myExternalSystemId = id;
  myProgressExecutionMode = ProgressExecutionMode.IN_BACKGROUND_ASYNC;
}
 
Example #8
Source File: ImportSpecBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ImportSpecBuilder use(@Nonnull ProgressExecutionMode executionMode) {
  myProgressExecutionMode = executionMode;
  return this;
}
 
Example #9
Source File: AbstractExternalModuleImportProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Asks current builder to ensure that target external project is defined.
 *
 * @param context current wizard context
 * @throws WizardStepValidationException if gradle project is not defined and can't be constructed
 */
@SuppressWarnings("unchecked")
public void ensureProjectIsDefined(@Nonnull ExternalModuleImportContext<C> context) throws WizardStepValidationException {
  final String externalSystemName = myExternalSystemId.getReadableName();
  File projectFile = getProjectFile();
  if (projectFile == null) {
    throw new WizardStepValidationException(ExternalSystemBundle.message("error.project.undefined"));
  }
  projectFile = getExternalProjectConfigToUse(projectFile);
  final Ref<WizardStepValidationException> error = new Ref<>();
  final ExternalProjectRefreshCallback callback = new ExternalProjectRefreshCallback() {
    @Override
    public void onSuccess(@Nullable DataNode<ProjectData> externalProject) {
      myExternalProjectNode = externalProject;
    }

    @Override
    public void onFailure(@Nonnull String errorMessage, @Nullable String errorDetails) {
      if (!StringUtil.isEmpty(errorDetails)) {
        LOG.warn(errorDetails);
      }
      error.set(new WizardStepValidationException(ExternalSystemBundle.message("error.resolve.with.reason", errorMessage)));
    }
  };

  final Project project = getContextOrDefaultProject(context);
  final File finalProjectFile = projectFile;
  final String externalProjectPath = FileUtil.toCanonicalPath(finalProjectFile.getAbsolutePath());
  final Ref<WizardStepValidationException> exRef = new Ref<>();
  executeAndRestoreDefaultProjectSettings(project, new Runnable() {
    @Override
    public void run() {
      try {
        ExternalSystemUtil.refreshProject(project, myExternalSystemId, externalProjectPath, callback, true, ProgressExecutionMode.MODAL_SYNC);
      }
      catch (IllegalArgumentException e) {
        exRef.set(new WizardStepValidationException(ExternalSystemBundle.message("error.cannot.parse.project", externalSystemName)));
      }
    }
  });
  WizardStepValidationException ex = exRef.get();
  if (ex != null) {
    throw ex;
  }
  if (myExternalProjectNode == null) {
    WizardStepValidationException exception = error.get();
    if (exception != null) {
      throw exception;
    }
  }
  else {
    applyProjectSettings(context);
  }
}
 
Example #10
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void runTask(@Nonnull ExternalSystemTaskExecutionSettings taskSettings,
                           @Nonnull String executorId,
                           @Nonnull Project project,
                           @Nonnull ProjectSystemId externalSystemId) {
  runTask(taskSettings, executorId, project, externalSystemId, null, ProgressExecutionMode.IN_BACKGROUND_ASYNC);
}
 
Example #11
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Tries to obtain external project info implied by the given settings and link that external project to the given ide project.
 *
 * @param externalSystemId        target external system
 * @param projectSettings         settings of the external project to link
 * @param project                 target ide project to link external project to
 * @param executionResultCallback it might take a while to resolve external project info, that's why it's possible to provide
 *                                a callback to be notified on processing result. It receives <code>true</code> if an external
 *                                project has been successfully linked to the given ide project;
 *                                <code>false</code> otherwise (note that corresponding notification with error details is expected
 *                                to be shown to the end-user then)
 * @param isPreviewMode           flag which identifies if missing external project binaries should be downloaded
 * @param progressExecutionMode   identifies how progress bar will be represented for the current processing
 */
@SuppressWarnings("UnusedDeclaration")
public static void linkExternalProject(@Nonnull final ProjectSystemId externalSystemId,
                                       @Nonnull final ExternalProjectSettings projectSettings,
                                       @Nonnull final Project project,
                                       @Nullable final Consumer<Boolean> executionResultCallback,
                                       boolean isPreviewMode,
                                       @Nonnull final ProgressExecutionMode progressExecutionMode) {
  ExternalProjectRefreshCallback callback = new ExternalProjectRefreshCallback() {
    @SuppressWarnings("unchecked")
    @Override
    public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
      if (externalProject == null) {
        if (executionResultCallback != null) {
          executionResultCallback.consume(false);
        }
        return;
      }
      AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, externalSystemId);
      Set<ExternalProjectSettings> projects = ContainerUtilRt.<ExternalProjectSettings>newHashSet(systemSettings.getLinkedProjectsSettings());
      projects.add(projectSettings);
      systemSettings.setLinkedProjectsSettings(projects);
      ensureToolWindowInitialized(project, externalSystemId);
      ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {
        @RequiredUIAccess
        @Override
        public void execute() {
          ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(new Runnable() {
            @Override
            public void run() {
              ProjectDataManager dataManager = ServiceManager.getService(ProjectDataManager.class);
              dataManager.importData(externalProject.getKey(), Collections.singleton(externalProject), project, true);
            }
          });
        }
      });
      if (executionResultCallback != null) {
        executionResultCallback.consume(true);
      }
    }

    @Override
    public void onFailure(@Nonnull String errorMessage, @Nullable String errorDetails) {
      if (executionResultCallback != null) {
        executionResultCallback.consume(false);
      }
    }
  };
  refreshProject(project, externalSystemId, projectSettings.getExternalProjectPath(), callback, isPreviewMode, progressExecutionMode);
}
 
Example #12
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 3 votes vote down vote up
/**
 * Asks to refresh all external projects of the target external system linked to the given ide project.
 * <p>
 * 'Refresh' here means 'obtain the most up-to-date version and apply it to the ide'.
 *
 * @param project          target ide project
 * @param externalSystemId target external system which projects should be refreshed
 * @param force            flag which defines if external project refresh should be performed if it's config is up-to-date
 * @deprecated use {@link  ExternalSystemUtil#refreshProjects(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)}
 */
@Deprecated
public static void refreshProjects(@Nonnull final Project project,
                                   @Nonnull final ProjectSystemId externalSystemId,
                                   boolean force,
                                   @Nonnull final ProgressExecutionMode progressExecutionMode) {
  refreshProjects(new ImportSpecBuilder(project, externalSystemId).forceWhenUptodate(force).use(progressExecutionMode));
}
 
Example #13
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 3 votes vote down vote up
/**
 * TODO[Vlad]: refactor the method to use {@link com.intellij.openapi.externalSystem.importing.ImportSpecBuilder}
 * <p>
 * Queries slave gradle process to refresh target gradle project.
 *
 * @param project             target intellij project to use
 * @param externalProjectPath path of the target gradle project's file
 * @param callback            callback to be notified on refresh result
 * @param isPreviewMode       flag that identifies whether gradle libraries should be resolved during the refresh
 * @return the most up-to-date gradle project (if any)
 */
public static void refreshProject(@Nonnull final Project project,
                                  @Nonnull final ProjectSystemId externalSystemId,
                                  @Nonnull final String externalProjectPath,
                                  @Nonnull final ExternalProjectRefreshCallback callback,
                                  final boolean isPreviewMode,
                                  @Nonnull final ProgressExecutionMode progressExecutionMode) {
  refreshProject(project, externalSystemId, externalProjectPath, callback, isPreviewMode, progressExecutionMode, true);
}
 
Example #14
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Asks to refresh all external projects of the target external system linked to the given ide project.
 * <p>
 * 'Refresh' here means 'obtain the most up-to-date version and apply it to the ide'.
 *
 * @param project          target ide project
 * @param externalSystemId target external system which projects should be refreshed
 * @param force            flag which defines if external project refresh should be performed if it's config is up-to-date
 * @deprecated use {@link  ExternalSystemUtil#refreshProjects(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)}
 */
@Deprecated
public static void refreshProjects(@Nonnull final Project project, @Nonnull final ProjectSystemId externalSystemId, boolean force) {
  refreshProjects(project, externalSystemId, force, ProgressExecutionMode.IN_BACKGROUND_ASYNC);
}