use of org.jetbrains.idea.maven.project.MavenProjectsManager in project google-cloud-intellij by GoogleCloudPlatform.
the class MavenTestUtils method resolveDependenciesAndImport.
private void resolveDependenciesAndImport(Project project) {
MavenProjectsManager myProjectsManager = MavenProjectsManager.getInstance(project);
myProjectsManager.waitForResolvingCompletion();
myProjectsManager.performScheduledImportInTests();
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project google-cloud-intellij by GoogleCloudPlatform.
the class DefaultAppEngineProjectService method isMavenModule.
@Override
public boolean isMavenModule(@NotNull Module module) {
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
MavenProject mavenProject = projectsManager.findProject(module);
return mavenProject != null && projectsManager.isMavenizedModule(module);
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project azure-tools-for-java by Microsoft.
the class FunctionsModuleBuilder method setupRootModel.
@Override
public void setupRootModel(@NotNull final ModifiableRootModel rootModel) {
final VirtualFile root = createAndGetContentEntry();
rootModel.addContentEntry(root);
// todo this should be moved to generic ModuleBuilder
if (myJdk != null) {
rootModel.setSdk(myJdk);
} else {
rootModel.inheritSdk();
}
final Project project = rootModel.getProject();
runWhenInitialized(rootModel.getProject(), () -> {
final Operation operation = TelemetryManager.createOperation(TelemetryConstants.FUNCTION, TelemetryConstants.CREATE_FUNCTION_PROJECT);
try {
operation.start();
final String tool = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_TOOL_KEY);
final String groupId = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_GROUPID_KEY);
final String artifactId = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_ARTIFACTID_KEY);
final String version = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_VERSION_KEY);
final String packageName = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_PACKAGE_NAME_KEY);
final String[] triggers = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_TRIGGERS_KEY);
operation.trackProperty("tool", tool);
operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, StringUtils.join(triggers, ","));
File tempProjectFolder = null;
try {
tempProjectFolder = AzureFunctionsUtils.createFunctionProjectToTempFolder(groupId, artifactId, version, tool);
if (tempProjectFolder != null) {
if (tempProjectFolder.exists() && tempProjectFolder.isDirectory()) {
final File moduleFile = new File(getContentEntryPath());
final File srcFolder = Paths.get(tempProjectFolder.getAbsolutePath(), "src/main/java").toFile();
for (final String trigger : triggers) {
// class name like HttpTriggerFunction
final String className = trigger + "Function";
final String fileContent = AzureFunctionsUtils.generateFunctionClassByTrigger(trigger, packageName, className);
final File targetFile = Paths.get(srcFolder.getAbsolutePath(), String.format("%s/%s.java", packageName.replace('.', '/'), className)).toFile();
targetFile.getParentFile().mkdirs();
FileUtils.write(targetFile, fileContent, "utf-8");
}
FileUtils.copyDirectory(tempProjectFolder, moduleFile);
final VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
RefreshQueue.getInstance().refresh(true, true, null, new VirtualFile[] { vf });
final VirtualFile pomFile = vf.findChild("pom.xml");
if (pomFile != null) {
final MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project);
mavenProjectsManager.addManagedFiles(Collections.singletonList(pomFile));
}
}
}
} catch (final Exception e) {
PluginUtil.displayErrorDialogAndLog("Error", "Cannot create Azure Function Project in Java.", e);
EventUtil.logError(operation, ErrorType.systemError, e, null, null);
} finally {
if (tempProjectFolder != null && tempProjectFolder.isDirectory()) {
try {
FileUtils.deleteDirectory(tempProjectFolder);
} catch (final IOException e) {
// ignore
}
}
}
} finally {
operation.complete();
}
});
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project azure-tools-for-java by Microsoft.
the class AddDependencyAction method isEditingMavenPomXml.
protected static boolean isEditingMavenPomXml(Module module, AnActionEvent event) {
Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor == null) {
return false;
}
PsiFile psiFile = event.getData(CommonDataKeys.PSI_FILE);
boolean isMaven = module != null && MavenUtils.isMavenProject(module.getProject());
if (!isMaven) {
return false;
}
final MavenProjectsManager manager = MavenProjectsManager.getInstance(module.getProject());
final MavenProject mavenProject = manager.findProject(module);
return editor.getEditorKind() == EditorKind.MAIN_EDITOR && psiFile != null && mavenProject != null && psiFile.getVirtualFile().equals(mavenProject.getFile());
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager 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