use of com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode in project android by JetBrains.
the class IdeaGradleSync method sync.
@Override
public void sync(@NotNull Project project, @NotNull GradleSyncInvoker.Request request, @Nullable GradleSyncListener listener) {
// Prevent IDEA from syncing with Gradle. We want to have full control of syncing.
project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, true);
if (SYNC_WITH_CACHED_MODEL_ONLY || request.isUseCachedGradleModels()) {
GradleProjectSyncData syncData = GradleProjectSyncData.getInstance((project));
if (syncData != null && syncData.canUseCachedProjectData()) {
DataNodeCaches dataNodeCaches = DataNodeCaches.getInstance(project);
DataNode<ProjectData> cache = dataNodeCaches.getCachedProjectData();
if (cache != null && !dataNodeCaches.isCacheMissingModels(cache)) {
PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
// @formatter:off
setupRequest.setUsingCachedGradleModels(true).setGenerateSourcesAfterSync(false).setLastSyncTimestamp(syncData.getLastGradleSyncTimestamp());
// @formatter:on
boolean newProject = request.isNewProject();
ProjectSetUpTask setUpTask = new ProjectSetUpTask(project, setupRequest, listener, newProject, !newProject, true);
setUpTask.onSuccess(cache);
return;
}
}
}
PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
// @formatter:off
setupRequest.setGenerateSourcesAfterSync(request.isGenerateSourcesOnSuccess()).setCleanProjectAfterSync(request.isCleanProject());
// @formatter:on
String externalProjectPath = getBaseDirPath(project).getPath();
ProjectSetUpTask setUpTask = new ProjectSetUpTask(project, setupRequest, listener, request.isNewProject(), false, false);
ProgressExecutionMode executionMode = request.getProgressExecutionMode();
refreshProject(project, GRADLE_SYSTEM_ID, externalProjectPath, setUpTask, false, /* resolve dependencies */
executionMode, true);
}
use of com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode in project intellij-community by JetBrains.
the class ExternalSystemUtil method refreshProject.
public static void refreshProject(@NotNull final String externalProjectPath, @NotNull final ImportSpec importSpec) {
Project project = importSpec.getProject();
ProjectSystemId externalSystemId = importSpec.getExternalSystemId();
ExternalProjectRefreshCallback callback = importSpec.getCallback();
boolean isPreviewMode = importSpec.isPreviewMode();
ProgressExecutionMode progressExecutionMode = importSpec.getProgressExecutionMode();
boolean reportRefreshError = importSpec.isReportRefreshError();
String arguments = importSpec.getArguments();
String vmOptions = importSpec.getVmOptions();
File projectFile = new File(externalProjectPath);
final String projectName;
if (projectFile.isFile()) {
projectName = projectFile.getParentFile().getName();
} else {
projectName = projectFile.getName();
}
final TaskUnderProgress refreshProjectStructureTask = new TaskUnderProgress() {
private final ExternalSystemResolveProjectTask myTask = new ExternalSystemResolveProjectTask(externalSystemId, project, externalProjectPath, vmOptions, arguments, isPreviewMode);
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "IOResourceOpenedButNotSafelyClosed" })
@Override
public void execute(@NotNull ProgressIndicator indicator) {
if (project.isDisposed())
return;
if (indicator instanceof ProgressIndicatorEx) {
((ProgressIndicatorEx) indicator).addStateDelegate(new AbstractProgressIndicatorExBase() {
@Override
public void cancel() {
super.cancel();
ApplicationManager.getApplication().executeOnPooledThread((Runnable) () -> myTask.cancel(ExternalSystemTaskNotificationListener.EP_NAME.getExtensions()));
}
});
}
ExternalSystemProcessingManager processingManager = ServiceManager.getService(ExternalSystemProcessingManager.class);
if (processingManager.findTask(ExternalSystemTaskType.RESOLVE_PROJECT, externalSystemId, externalProjectPath) != null) {
if (callback != null) {
callback.onFailure(ExternalSystemBundle.message("error.resolve.already.running", externalProjectPath), null);
}
return;
}
if (!(callback instanceof MyMultiExternalProjectRefreshCallback)) {
ExternalSystemNotificationManager.getInstance(project).clearNotifications(null, NotificationSource.PROJECT_SYNC, externalSystemId);
}
final ExternalSystemTaskActivator externalSystemTaskActivator = ExternalProjectsManager.getInstance(project).getTaskActivator();
if (!isPreviewMode && !externalSystemTaskActivator.runTasks(externalProjectPath, ExternalSystemTaskActivator.Phase.BEFORE_SYNC)) {
return;
}
myTask.execute(indicator, ExternalSystemTaskNotificationListener.EP_NAME.getExtensions());
if (project.isDisposed())
return;
final Throwable error = myTask.getError();
if (error == null) {
if (callback != null) {
DataNode<ProjectData> externalProject = myTask.getExternalProject();
if (externalProject != null && importSpec.shouldCreateDirectoriesForEmptyContentRoots()) {
externalProject.putUserData(ContentRootDataService.CREATE_EMPTY_DIRECTORIES, Boolean.TRUE);
}
callback.onSuccess(externalProject);
}
if (!isPreviewMode) {
externalSystemTaskActivator.runTasks(externalProjectPath, ExternalSystemTaskActivator.Phase.AFTER_SYNC);
}
return;
}
if (error instanceof ImportCanceledException) {
// stop refresh task
return;
}
String message = ExternalSystemApiUtil.buildErrorMessage(error);
if (StringUtil.isEmpty(message)) {
message = String.format("Can't resolve %s project at '%s'. Reason: %s", externalSystemId.getReadableName(), externalProjectPath, message);
}
if (callback != null) {
callback.onFailure(message, extractDetails(error));
}
ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
if (manager == null) {
return;
}
AbstractExternalSystemSettings<?, ?, ?> settings = manager.getSettingsProvider().fun(project);
ExternalProjectSettings projectSettings = settings.getLinkedProjectSettings(externalProjectPath);
if (projectSettings == null || !reportRefreshError) {
return;
}
ExternalSystemNotificationManager.getInstance(project).processExternalProjectRefreshError(error, projectName, externalSystemId);
}
};
final String title;
switch(progressExecutionMode) {
case NO_PROGRESS_SYNC:
case NO_PROGRESS_ASYNC:
throw new ExternalSystemException("Please, use progress for the project import!");
case MODAL_SYNC:
title = ExternalSystemBundle.message("progress.import.text", projectName, externalSystemId.getReadableName());
new Task.Modal(project, title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
refreshProjectStructureTask.execute(indicator);
}
}.queue();
break;
case IN_BACKGROUND_ASYNC:
title = ExternalSystemBundle.message("progress.refresh.text", projectName, externalSystemId.getReadableName());
new Task.Backgroundable(project, title) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
refreshProjectStructureTask.execute(indicator);
}
}.queue();
break;
case START_IN_FOREGROUND_ASYNC:
title = ExternalSystemBundle.message("progress.refresh.text", projectName, externalSystemId.getReadableName());
new Task.Backgroundable(project, title, true, PerformInBackgroundOption.DEAF) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
refreshProjectStructureTask.execute(indicator);
}
}.queue();
}
}
use of com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode in project android by JetBrains.
the class NewGradleSync method sync.
@Override
public void sync(@NotNull Project project, @NotNull GradleSyncInvoker.Request request, @Nullable GradleSyncListener listener) {
String title = String.format("Syncing project '%1$s' with Gradle", project.getName());
Task task;
ProgressExecutionMode executionMode = request.getProgressExecutionMode();
switch(executionMode) {
case MODAL_SYNC:
task = new Task.Modal(project, title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
sync(project, indicator, listener);
}
};
break;
case IN_BACKGROUND_ASYNC:
task = new Task.Backgroundable(project, title, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
sync(project, indicator, listener);
}
};
break;
default:
throw new IllegalArgumentException(executionMode + " is not a supported execution mode");
}
invokeAndWaitIfNeeded((Runnable) task::queue);
}
Aggregations