Search in sources :

Example 6 with ExternalProjectRefreshCallback

use of com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback in project intellij-community by JetBrains.

the class ExternalSystemUtil method linkExternalProject.

/**
   * 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(@NotNull final ProjectSystemId externalSystemId, @NotNull final ExternalProjectSettings projectSettings, @NotNull final Project project, @Nullable final Consumer<Boolean> executionResultCallback, boolean isPreviewMode, @NotNull 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.newHashSet(systemSettings.getLinkedProjectsSettings());
            projects.add(projectSettings);
            systemSettings.setLinkedProjectsSettings(projects);
            ensureToolWindowInitialized(project, externalSystemId);
            ServiceManager.getService(ProjectDataManager.class).importData(externalProject, project, true);
            if (executionResultCallback != null) {
                executionResultCallback.consume(true);
            }
        }

        @Override
        public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
            if (executionResultCallback != null) {
                executionResultCallback.consume(false);
            }
        }
    };
    refreshProject(project, externalSystemId, projectSettings.getExternalProjectPath(), callback, isPreviewMode, progressExecutionMode);
}
Also used : ProjectDataManager(com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)

Example 7 with ExternalProjectRefreshCallback

use of com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback in project intellij-community by JetBrains.

the class AbstractExternalProjectImportBuilder method ensureProjectIsDefined.

/**
   * Asks current builder to ensure that target external project is defined.
   *
   * @param wizardContext             current wizard context
   * @throws ConfigurationException   if external project is not defined and can't be constructed
   */
@SuppressWarnings("unchecked")
public void ensureProjectIsDefined(@NotNull WizardContext wizardContext) throws ConfigurationException {
    final String externalSystemName = myExternalSystemId.getReadableName();
    File projectFile = getProjectFile();
    if (projectFile == null) {
        throw new ConfigurationException(ExternalSystemBundle.message("error.project.undefined"));
    }
    projectFile = getExternalProjectConfigToUse(projectFile);
    final Ref<ConfigurationException> error = new Ref<>();
    final ExternalProjectRefreshCallback callback = new ExternalProjectRefreshCallback() {

        @Override
        public void onSuccess(@Nullable DataNode<ProjectData> externalProject) {
            myExternalProjectNode = externalProject;
        }

        @Override
        public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
            if (!StringUtil.isEmpty(errorDetails)) {
                LOG.warn(errorDetails);
            }
            error.set(new ConfigurationException(ExternalSystemBundle.message("error.resolve.with.log_link", errorMessage, PathManager.getLogPath()), ExternalSystemBundle.message("error.resolve.generic")));
        }
    };
    final Project project = getProject(wizardContext);
    final File finalProjectFile = projectFile;
    final String externalProjectPath = FileUtil.toCanonicalPath(finalProjectFile.getAbsolutePath());
    final Ref<ConfigurationException> exRef = new Ref<>();
    executeAndRestoreDefaultProjectSettings(project, () -> {
        try {
            ExternalSystemUtil.refreshProject(project, myExternalSystemId, externalProjectPath, callback, true, ProgressExecutionMode.MODAL_SYNC);
        } catch (IllegalArgumentException e) {
            exRef.set(new ConfigurationException(e.getMessage(), ExternalSystemBundle.message("error.cannot.parse.project", externalSystemName)));
        }
    });
    ConfigurationException ex = exRef.get();
    if (ex != null) {
        throw ex;
    }
    if (myExternalProjectNode == null) {
        ConfigurationException exception = error.get();
        if (exception != null) {
            throw exception;
        }
    } else {
        applyProjectSettings(wizardContext);
    }
}
Also used : Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ConfigurationException(com.intellij.openapi.options.ConfigurationException) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with ExternalProjectRefreshCallback

use of com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback in project kotlin by JetBrains.

the class ExternalSystemImportingTestCase method doImportProject.

private void doImportProject() {
    AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId());
    ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
    projectSettings.setExternalProjectPath(getProjectPath());
    @SuppressWarnings("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();
    ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(myProject, getExternalSystemId()).use(ProgressExecutionMode.MODAL_SYNC).callback(new ExternalProjectRefreshCallback() {

        @Override
        public void onSuccess(@Nullable 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));
        }
    }).forceWhenUptodate());
    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);
    }
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) Couple(com.intellij.openapi.util.Couple) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Example 9 with ExternalProjectRefreshCallback

use of com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback in project liferay-ide by liferay.

the class LiferayGradleProjectImportBuilder method createFinalImportCallback.

@Override
protected ExternalProjectRefreshCallback createFinalImportCallback(@NotNull Project project, @NotNull ExternalProjectSettings projectSettings) {
    return new ExternalProjectRefreshCallback() {

        @Override
        public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
        }

        @Override
        public void onSuccess(@Nullable DataNode<ProjectData> externalProject) {
            if (externalProject == null) {
                return;
            }
            Runnable selectDataTask = () -> {
                ExternalProjectDataSelectorDialog dialog = new ExternalProjectDataSelectorDialog(project, new InternalExternalProjectInfo(GradleConstants.SYSTEM_ID, projectSettings.getExternalProjectPath(), externalProject));
                if (dialog.hasMultipleDataToSelect()) {
                    dialog.showAndGet();
                } else {
                    Disposer.dispose(dialog.getDisposable());
                }
            };
            ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
            Runnable importTask = () -> projectDataManager.importData(externalProject, project, false);
            GradleSettings gradleProjectSettings = GradleSettings.getInstance(project);
            boolean showSelectiveImportDialog = gradleProjectSettings.showSelectiveImportDialogOnInitialImport();
            Application application = ApplicationManager.getApplication();
            if (showSelectiveImportDialog && !application.isHeadlessEnvironment()) {
                application.invokeLater(() -> {
                    selectDataTask.run();
                    application.executeOnPooledThread(importTask);
                });
            } else {
                importTask.run();
            }
        }
    };
}
Also used : ProjectDataManager(com.intellij.openapi.externalSystem.service.project.ProjectDataManager) GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ExternalProjectDataSelectorDialog(com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo) NotNull(org.jetbrains.annotations.NotNull) Application(com.intellij.openapi.application.Application) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)9 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)5 NotNull (org.jetbrains.annotations.NotNull)5 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)4 Nullable (org.jetbrains.annotations.Nullable)4 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)3 DataNode (com.intellij.openapi.externalSystem.model.DataNode)3 ProjectDataManager (com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager)3 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)3 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)2 ExternalProjectDataSelectorDialog (com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog)2 Project (com.intellij.openapi.project.Project)2 Couple (com.intellij.openapi.util.Couple)2 File (java.io.File)2 Application (com.intellij.openapi.application.Application)1 ImportCanceledException (com.intellij.openapi.externalSystem.service.ImportCanceledException)1 ProgressExecutionMode (com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode)1 ExternalSystemProcessingManager (com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager)1 ExternalSystemResolveProjectTask (com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask)1 ProjectDataManager (com.intellij.openapi.externalSystem.service.project.ProjectDataManager)1