use of com.intellij.openapi.externalSystem.importing.ImportSpecBuilder in project intellij-community by JetBrains.
the class ExternalSystemUtil method refreshProjects.
/**
* Asks to refresh all external projects of the target external system linked to the given ide project based on provided spec
*
* @param spec import specification
*/
public static void refreshProjects(@NotNull final ImportSpec spec) {
ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(spec.getExternalSystemId());
if (manager == null) {
return;
}
AbstractExternalSystemSettings<?, ?, ?> settings = manager.getSettingsProvider().fun(spec.getProject());
final Collection<? extends ExternalProjectSettings> projectsSettings = settings.getLinkedProjectsSettings();
if (projectsSettings.isEmpty()) {
return;
}
final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
final ExternalProjectRefreshCallback callback;
if (spec.getCallback() == null) {
callback = new MyMultiExternalProjectRefreshCallback(spec.getProject(), projectDataManager, spec.getExternalSystemId());
} else {
callback = spec.getCallback();
}
Set<String> toRefresh = ContainerUtilRt.newHashSet();
for (ExternalProjectSettings setting : projectsSettings) {
// don't refresh project when auto-import is disabled if such behavior needed (e.g. on project opening when auto-import is disabled)
if (!setting.isUseAutoImport() && spec.whenAutoImportEnabled())
continue;
toRefresh.add(setting.getExternalProjectPath());
}
if (!toRefresh.isEmpty()) {
ExternalSystemNotificationManager.getInstance(spec.getProject()).clearNotifications(null, NotificationSource.PROJECT_SYNC, spec.getExternalSystemId());
for (String path : toRefresh) {
refreshProject(path, new ImportSpecBuilder(spec).callback(callback).build());
}
}
}
use of com.intellij.openapi.externalSystem.importing.ImportSpecBuilder in project intellij-community by JetBrains.
the class ExternalSystemUtil method refreshProject.
/**
* <p>
* Refresh target gradle project.
*
* @param project target intellij project to use
* @param externalProjectPath path of the target external project
* @param callback callback to be notified on refresh result
* @param isPreviewMode flag that identifies whether libraries should be resolved during the refresh
* @param reportRefreshError prevent to show annoying error notification, e.g. if auto-import mode used
*/
public static void refreshProject(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId, @NotNull final String externalProjectPath, @NotNull final ExternalProjectRefreshCallback callback, final boolean isPreviewMode, @NotNull final ProgressExecutionMode progressExecutionMode, final boolean reportRefreshError) {
ImportSpecBuilder builder = new ImportSpecBuilder(project, externalSystemId).callback(callback).use(progressExecutionMode);
if (isPreviewMode)
builder.usePreviewMode();
if (!reportRefreshError)
builder.dontReportRefreshErrors();
refreshProject(externalProjectPath, builder.build());
}
use of com.intellij.openapi.externalSystem.importing.ImportSpecBuilder in project intellij-community by JetBrains.
the class ExternalSystemImportingTestCase method doImportProject.
private void doImportProject() {
AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId());
final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
projectSettings.setExternalProjectPath(getProjectPath());
Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
projects.remove(projectSettings);
projects.add(projectSettings);
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 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));
}
}).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);
}
}
use of com.intellij.openapi.externalSystem.importing.ImportSpecBuilder in project intellij-community by JetBrains.
the class ExternalSystemStartupActivity method runActivity.
@Override
public void runActivity(@NotNull final Project project) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
Runnable task = () -> {
for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
if (manager instanceof StartupActivity) {
((StartupActivity) manager).runActivity(project);
}
}
if (project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) != Boolean.TRUE) {
for (ExternalSystemManager manager : ExternalSystemManager.EP_NAME.getExtensions()) {
final boolean isNewProject = project.getUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT) == Boolean.TRUE;
if (isNewProject) {
ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(project, manager.getSystemId()).createDirectoriesForEmptyContentRoots());
}
}
}
ExternalToolWindowManager.handle(project);
ExternalSystemVcsRegistrar.handle(project);
ProjectRenameAware.beAware(project);
};
ExternalProjectsManager.getInstance(project).init();
DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(task, project));
}
use of com.intellij.openapi.externalSystem.importing.ImportSpecBuilder in project intellij-community by JetBrains.
the class GradleRefreshProjectDependenciesAction method perform.
@Override
public void perform(@NotNull final Project project, @NotNull ProjectSystemId projectSystemId, @NotNull AbstractExternalEntityData externalEntityData, @NotNull AnActionEvent e) {
final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
final ExternalSystemNode<?> externalSystemNode = ContainerUtil.getFirstItem(selectedNodes);
assert externalSystemNode != null;
final ExternalConfigPathAware externalConfigPathAware = externalSystemNode.getData() instanceof ExternalConfigPathAware ? (ExternalConfigPathAware) externalSystemNode.getData() : null;
assert externalConfigPathAware != null;
// We save all documents because there is a possible case that there is an external system config file changed inside the ide.
FileDocumentManager.getInstance().saveAllDocuments();
final ExternalProjectSettings linkedProjectSettings = ExternalSystemApiUtil.getSettings(project, projectSystemId).getLinkedProjectSettings(externalConfigPathAware.getLinkedExternalProjectPath());
final String externalProjectPath = linkedProjectSettings == null ? externalConfigPathAware.getLinkedExternalProjectPath() : linkedProjectSettings.getExternalProjectPath();
ExternalSystemUtil.refreshProject(externalProjectPath, new ImportSpecBuilder(project, projectSystemId).useDefaultCallback().use(ProgressExecutionMode.IN_BACKGROUND_ASYNC).withArguments("--refresh-dependencies").build());
}
Aggregations