Search in sources :

Example 1 with MavenProjectsManager

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;
    }
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Element(org.jdom.Element) ProjectViewImpl(com.intellij.ide.projectView.impl.ProjectViewImpl) VcsConfiguration(com.intellij.openapi.vcs.VcsConfiguration)

Example 2 with MavenProjectsManager

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Module(com.intellij.openapi.module.Module)

Example 3 with MavenProjectsManager

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module)

Example 4 with MavenProjectsManager

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;
        }
    });
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) ActionCallback(com.intellij.openapi.util.ActionCallback) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Notification(com.intellij.notification.Notification) MavenArtifactDownloader(org.jetbrains.idea.maven.project.MavenArtifactDownloader) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Consumer(com.intellij.util.Consumer) Collection(java.util.Collection) AsyncResult(com.intellij.openapi.util.AsyncResult) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with MavenProjectsManager

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();
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Aggregations

MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)52 MavenProject (org.jetbrains.idea.maven.project.MavenProject)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Project (com.intellij.openapi.project.Project)13 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 Nullable (org.jetbrains.annotations.Nullable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)6 PsiFile (com.intellij.psi.PsiFile)6 Notification (com.intellij.notification.Notification)4 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)4 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)4 NotificationListener (com.intellij.notification.NotificationListener)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 XmlElement (com.intellij.psi.xml.XmlElement)2 List (java.util.List)2