void () { AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId()); final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings(); projectSettings.setExternalProjectPath(getProjectPath()); //noinspection unchecked Set<ExternalProjectSettings> projects = new HashSet<>(systemSettings.getLinkedProjectsSettings()); projects.remove(projectSettings); projects.add(projectSettings); //noinspection unchecked systemSettings.setLinkedProjectsSettings(projects); final Ref<Couple<String>> error = Ref.create(); ImportSpec importSpec = createImportSpec(); ExternalProjectRefreshCallback callback = importSpec.getCallback(); if (callback == null || callback instanceof ImportSpecBuilder.DefaultProjectRefreshCallback) { 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; } try { ProjectDataManager.getInstance().importData(externalProject, myProject); } catch (Throwable ex) { ex.printStackTrace(System.err); error.set(Couple.of("Exception occurred in `ProjectDataManager.importData` (see output for the details)", null)); } 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 = ExternalSystemProgressNotificationManager.getInstance(); ExternalSystemTaskNotificationListenerAdapter listener = new ExternalSystemTaskNotificationListenerAdapter() { @Override public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) { printOutput(text, stdOut); } }; notificationManager.addNotificationListener(listener); try { ExternalSystemUtil.refreshProjects(importSpec); } finally { notificationManager.removeNotificationListener(listener); } if (!error.isNull()) { handleImportFailure(error.get().first, error.get().second); } }