use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class MavenIdeaPluginConfigurer method configure.
@Override
public void configure(@NotNull MavenProject mavenProject, @NotNull Project project, @Nullable Module module) {
if (module == null)
return;
Element cfg = mavenProject.getPluginConfiguration("com.googlecode", "maven-idea-plugin");
if (cfg == null)
return;
configureJdk(cfg, module);
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
String downloadSources = cfg.getChildTextTrim("downloadSources");
if (!StringUtil.isEmptyOrSpaces(downloadSources)) {
projectsManager.getImportingSettings().setDownloadSourcesAutomatically(Boolean.parseBoolean(downloadSources));
}
String downloadJavadocs = cfg.getChildTextTrim("downloadJavadocs");
if (!StringUtil.isEmptyOrSpaces(downloadJavadocs)) {
projectsManager.getImportingSettings().setDownloadDocsAutomatically(Boolean.parseBoolean(downloadJavadocs));
}
String assertNotNull = cfg.getChildTextTrim("assertNotNull");
if (!StringUtil.isEmptyOrSpaces(assertNotNull)) {
CompilerConfiguration.getInstance(project).setAddNotNullAssertions(Boolean.parseBoolean(assertNotNull));
}
String autoscrollToSource = cfg.getChildTextTrim("autoscrollToSource");
if (!StringUtil.isEmptyOrSpaces(autoscrollToSource)) {
((ProjectViewImpl) ProjectView.getInstance(project)).setAutoscrollToSource(Boolean.parseBoolean(autoscrollToSource), ProjectViewPane.ID);
}
String autoscrollFromSource = cfg.getChildTextTrim("autoscrollFromSource");
if (!StringUtil.isEmptyOrSpaces(autoscrollFromSource)) {
((ProjectViewImpl) ProjectView.getInstance(project)).setAutoscrollFromSource(Boolean.parseBoolean(autoscrollFromSource), ProjectViewPane.ID);
}
String hideEmptyPackages = cfg.getChildTextTrim("hideEmptyPackages");
if (!StringUtil.isEmptyOrSpaces(hideEmptyPackages)) {
ProjectView.getInstance(project).setHideEmptyPackages(Boolean.parseBoolean(hideEmptyPackages), ProjectViewPane.ID);
}
String optimizeImportsBeforeCommit = cfg.getChildTextTrim("optimizeImportsBeforeCommit");
if (!StringUtil.isEmptyOrSpaces(optimizeImportsBeforeCommit)) {
VcsConfiguration.getInstance(module.getProject()).OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT = Boolean.parseBoolean(optimizeImportsBeforeCommit);
}
String performCodeAnalisisBeforeCommit = cfg.getChildTextTrim("performCodeAnalisisBeforeCommit");
if (!StringUtil.isEmptyOrSpaces(performCodeAnalisisBeforeCommit)) {
VcsConfiguration.getInstance(module.getProject()).CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT = Boolean.parseBoolean(performCodeAnalisisBeforeCommit);
}
String reformatCodeBeforeCommit = cfg.getChildTextTrim("reformatCodeBeforeCommit");
if (!StringUtil.isEmptyOrSpaces(reformatCodeBeforeCommit)) {
VcsConfiguration vcsConfiguration = VcsConfiguration.getInstance(module.getProject());
boolean value = Boolean.parseBoolean(reformatCodeBeforeCommit);
vcsConfiguration.REFORMAT_BEFORE_FILE_COMMIT = value;
vcsConfiguration.REFORMAT_BEFORE_PROJECT_COMMIT = value;
}
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class SelectInMavenNavigatorTarget method getMavenProject.
private static MavenProject getMavenProject(SelectInContext context) {
VirtualFile file = context.getVirtualFile();
MavenProjectsManager manager = MavenProjectsManager.getInstance(context.getProject());
Module module = ProjectRootManager.getInstance(context.getProject()).getFileIndex().getModuleForFile(file);
return module == null ? null : manager.findProject(module);
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class MavenActionUtil method getMavenProjects.
public static List<MavenProject> getMavenProjects(DataContext context) {
Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null)
return Collections.emptyList();
VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
if (virtualFiles == null || virtualFiles.length == 0)
return Collections.emptyList();
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
if (!projectsManager.isMavenizedProject())
return Collections.emptyList();
Set<MavenProject> res = new LinkedHashSet<>();
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (VirtualFile file : virtualFiles) {
MavenProject mavenProject;
if (file.isDirectory()) {
VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
if (!file.equals(contentRoot))
return Collections.emptyList();
Module module = fileIndex.getModuleForFile(file);
if (module == null || !projectsManager.isMavenizedModule(module))
return Collections.emptyList();
mavenProject = projectsManager.findProject(module);
} else {
mavenProject = projectsManager.findProject(file);
}
if (mavenProject == null)
return Collections.emptyList();
res.add(mavenProject);
}
return new ArrayList<>(res);
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class MavenAttachSourcesProvider method getActions.
@Override
@NotNull
public Collection<AttachSourcesAction> getActions(final List<LibraryOrderEntry> orderEntries, final PsiFile psiFile) {
Collection<MavenProject> projects = getMavenProjects(psiFile);
if (projects.isEmpty())
return Collections.emptyList();
if (findArtifacts(projects, orderEntries).isEmpty())
return Collections.emptyList();
return Collections.singleton(new AttachSourcesAction() {
@Override
public String getName() {
return ProjectBundle.message("maven.action.download.sources");
}
@Override
public String getBusyText() {
return ProjectBundle.message("maven.action.download.sources.busy.text");
}
@Override
public ActionCallback perform(List<LibraryOrderEntry> orderEntries) {
// may have been changed by this time...
Collection<MavenProject> mavenProjects = getMavenProjects(psiFile);
if (mavenProjects.isEmpty()) {
return ActionCallback.REJECTED;
}
MavenProjectsManager manager = MavenProjectsManager.getInstance(psiFile.getProject());
Collection<MavenArtifact> artifacts = findArtifacts(mavenProjects, orderEntries);
if (artifacts.isEmpty())
return ActionCallback.REJECTED;
final AsyncResult<MavenArtifactDownloader.DownloadResult> result = new AsyncResult<>();
manager.scheduleArtifactsDownloading(mavenProjects, artifacts, true, false, result);
final ActionCallback resultWrapper = new ActionCallback();
result.doWhenDone(new Consumer<MavenArtifactDownloader.DownloadResult>() {
@Override
public void consume(MavenArtifactDownloader.DownloadResult downloadResult) {
if (!downloadResult.unresolvedSources.isEmpty()) {
final StringBuilder message = new StringBuilder();
message.append("<html>Sources not found for:");
int count = 0;
for (MavenId each : downloadResult.unresolvedSources) {
if (count++ > 5) {
message.append("<br>and more...");
break;
}
message.append("<br>").append(each.getDisplayString());
}
message.append("</html>");
Notifications.Bus.notify(new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "Cannot download sources", message.toString(), NotificationType.WARNING), psiFile.getProject());
}
if (downloadResult.resolvedSources.isEmpty()) {
resultWrapper.setRejected();
} else {
resultWrapper.setDone();
}
}
});
return resultWrapper;
}
});
}
use of org.jetbrains.idea.maven.project.MavenProjectsManager in project intellij-community by JetBrains.
the class MavenEditorTabTitleProvider method getEditorTabTitle.
public String getEditorTabTitle(Project project, VirtualFile file) {
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
if (!projectsManager.isMavenizedProject())
return null;
MavenProject mavenProject = projectsManager.findProject(file);
if (mavenProject == null)
return null;
return mavenProject.getMavenId().getArtifactId();
}
Aggregations