Search in sources :

Example 26 with ExternalProjectSettings

use of com.intellij.openapi.externalSystem.settings.ExternalProjectSettings 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)

Aggregations

ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)26 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)13 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)7 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)5 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)4 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)4 File (java.io.File)4 Collection (java.util.Collection)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)3 DataNode (com.intellij.openapi.externalSystem.model.DataNode)2 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)2 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)2 ExternalConfigPathAware (com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware)2 ExternalSystemProcessingManager (com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager)2 ProjectDataManager (com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager)2 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 ModulesConfigurator (com.intellij.openapi.roots.ui.configuration.ModulesConfigurator)2