use of com.intellij.openapi.externalSystem.autoimport.ProjectNotificationAware in project azure-tools-for-java by Microsoft.
the class AddDependencyAction method onActionPerformed.
@Override
public boolean onActionPerformed(@NotNull AnActionEvent event, @Nullable Operation operation) {
final Module module = event.getData(LangDataKeys.MODULE);
final Project project = module.getProject();
final MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
final MavenProject mavenProject = projectsManager.findProject(module);
if (mavenProject == null) {
PluginUtil.showErrorNotificationProject(project, "Error", String.format("Project '%s' is not a maven project.", project.getName()));
return true;
}
final AzureString title = AzureOperationBundle.title("springcloud.update_dependency", project.getName());
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, true, () -> {
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
progressIndicator.setText("Syncing maven project " + project.getName());
final SettableFuture<Boolean> isDirty = SettableFuture.create();
AzureTaskManager.getInstance().runAndWait(() -> {
ProjectNotificationAware notificationAware = ProjectNotificationAware.getInstance(project);
isDirty.set(notificationAware.isNotificationVisible());
if (notificationAware.isNotificationVisible()) {
ExternalSystemProjectTracker projectTracker = ExternalSystemProjectTracker.getInstance(project);
projectTracker.scheduleProjectRefresh();
}
});
try {
if (isDirty.get().booleanValue()) {
projectsManager.forceUpdateProjects(Collections.singletonList(mavenProject)).get();
}
} catch (InterruptedException | ExecutionException e) {
PluginUtil.showErrorNotification("Error", "Failed to update project due to error: " + e.getMessage());
return;
}
try {
progressIndicator.setText("Check existing dependencies");
final String evaluateEffectivePom = MavenUtils.evaluateEffectivePom(project, mavenProject);
ProgressManager.checkCanceled();
if (StringUtils.isEmpty(evaluateEffectivePom)) {
PluginUtil.showErrorNotificationProject(project, "Error", "Failed to evaluate effective pom.");
return;
}
final String springBootVer = getMavenLibraryVersion(mavenProject, SPRING_BOOT_GROUP_ID, "spring-boot-autoconfigure");
if (StringUtils.isEmpty(springBootVer)) {
throw new AzureExecutionException(String.format("Module %s is not a spring-boot application.", module.getName()));
}
progressIndicator.setText("Get latest versions ...");
SpringCloudDependencyManager dependencyManager = new SpringCloudDependencyManager(evaluateEffectivePom);
Map<String, DependencyArtifact> versionMaps = dependencyManager.getDependencyVersions();
Map<String, DependencyArtifact> managerDependencyVersionsMaps = dependencyManager.getDependencyManagementVersions();
// given the spring-cloud-commons is greater or equal to 2.2.5.RELEASE, we should not add spring-cloud-starter-azure-spring-cloud-client
// because the code is already merged into spring repo: https://github.com/spring-cloud/spring-cloud-commons/pull/803
boolean noAzureSpringCloudClientDependency = shouldNotAddAzureSpringCloudClientDependency(versionMaps) || shouldNotAddAzureSpringCloudClientDependency(managerDependencyVersionsMaps);
ProgressManager.checkCanceled();
final List<DependencyArtifact> versionChanges = calculateVersionChanges(springBootVer, noAzureSpringCloudClientDependency, versionMaps);
if (versionChanges.isEmpty()) {
PluginUtil.showInfoNotificationProject(project, "Your project is update-to-date.", "No updates are needed.");
return;
}
progressIndicator.setText("Applying versions ...");
final File pomFile = new File(mavenProject.getFile().getCanonicalPath());
ProgressManager.checkCanceled();
if (applyVersionChanges(dependencyManager, pomFile, springBootVer, managerDependencyVersionsMaps, versionChanges)) {
noticeUserVersionChanges(project, pomFile, versionChanges);
} else {
PluginUtil.showInfoNotificationProject(project, "Your project is update-to-date.", "No updates are needed.");
}
} catch (DocumentException | IOException | AzureExecutionException | MavenProcessCanceledException e) {
PluginUtil.showErrorNotification("Error", "Failed to update Azure Spring Cloud dependencies due to error: " + e.getMessage());
}
}));
return false;
}
Aggregations